Modified: branches/datasets/app/models/pack.rb (2871 => 2872)
--- branches/datasets/app/models/pack.rb 2011-12-07 15:22:44 UTC (rev 2871)
+++ branches/datasets/app/models/pack.rb 2011-12-08 11:34:28 UTC (rev 2872)
@@ -185,7 +185,7 @@
FileUtils.rm Dir.glob(Pack.archive_folder + "/" + "#{temp_file}*"), :force => true # 'force' option makes sure that exceptions are never raised
end
- zipfile.path
+ archive_file_path
end
def text_metadata(stats)
@@ -196,39 +196,39 @@
pack_entries = stats[:view_only]["Pack"] || {}
view_only = stats[:view_only].except("Pack")
- text = "********** Snapshot of the Pack: #{self.title} **********\n\n"
- text << "Downloaded from #{Conf.sitename}\n"
- text << "Snapshot generated at " + Time.now.strftime("%H:%M:%S on %A, %d %B %Y") + "\n\n\n\n"
- text << "========== Pack Details ==========\n\n"
+ text = "********** Snapshot of the Pack: #{self.title} **********\r\n\r\n"
+ text << "Downloaded from #{Conf.sitename}\r\n"
+ text << "Snapshot generated at " + Time.now.strftime("%H:%M:%S on %A, %d %B %Y") + "\r\n\r\n\r\n\r\n"
+ text << "========== Pack Details ==========\r\n\r\n"
text << "Title: #{self.title}"
- text << "\nItems: #{total_items}"
- text << "\nLocation: #{location_string("pack", self.id)}"
- text << "\nCreated by: " + uploader_string(self.contributor_type, self.contributor_id, false, false)
- text << "\nCreated at: " + self.created_at.strftime("%H:%M:%S on %A, %d %B %Y")
- text << "\nLast updated at: " + self.updated_at.strftime("%H:%M:%S on %A, %d %B %Y")
- text << "\n\nDescription: " + (self.description.nil? || self.description.empty? ? "none" : "\n\n" + prepare_description(self.description) )
- text << "\n\n\n\n========== Summary of Pack Items (#{total_items}) ==========\n\n"
- text << "Total number of items in the pack: #{total_items}\n\n"
- text << "Downloaded items: #{total_downloaded}\n"
+ text << "\r\nItems: #{total_items}"
+ text << "\r\nLocation: #{location_string("pack", self.id)}"
+ text << "\r\nCreated by: " + uploader_string(self.contributor_type, self.contributor_id, false, false)
+ text << "\r\nCreated at: " + self.created_at.strftime("%H:%M:%S on %A, %d %B %Y")
+ text << "\r\nLast updated at: " + self.updated_at.strftime("%H:%M:%S on %A, %d %B %Y")
+ text << "\r\n\r\nDescription: " + (self.description.nil? || self.description.empty? ? "none" : "\r\n\r\n" + prepare_description(self.description) )
+ text << "\r\n\r\n\r\n\r\n========== Summary of Pack Items (#{total_items}) ==========\r\n\r\n"
+ text << "Total number of items in the pack: #{total_items}\r\n\r\n"
+ text << "Downloaded items: #{total_downloaded}\r\n"
stats[:downloaded].each do |type, entries|
- text << " |- #{type.model_alias.titleize.pluralize}: #{entries.size}\n"
+ text << " |- #{type.model_alias.titleize.pluralize}: #{entries.size}\r\n"
end
- text << "\n"
- text << "Not downloaded items: #{total_items - total_downloaded}\n"
- text << " |- Packs : #{pack_entries.size} (download of nested packs is not supported)\n"
- text << " |- External items: #{self.remote_entries.size}\n"
+ text << "\r\n"
+ text << "Not downloaded items: #{total_items - total_downloaded}\r\n"
+ text << " |- Packs : #{pack_entries.size} (download of nested packs is not supported)\r\n"
+ text << " |- External items: #{self.remote_entries.size}\r\n"
- text << " |- Items that can be viewed, but not downloaded: #{view_only.values.flatten.size} (view-only permissions)\n"
+ text << " |- Items that can be viewed, but not downloaded: #{view_only.values.flatten.size} (view-only permissions)\r\n"
view_only.each do |type, entries|
- text << " |- #{type.model_alias.titleize.pluralize}: #{entries.size}\n"
+ text << " |- #{type.model_alias.titleize.pluralize}: #{entries.size}\r\n"
end
- text << " |- Items that cannot be viewed : #{stats[:hidden].size}\n\n"
+ text << " |- Items that cannot be viewed : #{stats[:hidden].size}\r\n\r\n"
# ====== Summary ======
- text << "\n\n========== Downloaded Items (#{total_downloaded}) ==========\n\n"
+ text << "\r\n\r\n========== Downloaded Items (#{total_downloaded}) ==========\r\n\r\n"
if total_downloaded == 0
- text << " // No items were downloaded //\n\n"
+ text << " // No items were downloaded //\r\n\r\n"
else
stats[:downloaded].each do |type, entries|
entries.each do |entry|
@@ -238,11 +238,11 @@
end
- text << "\n\n========== Not Downloaded Items (#{total_items - total_downloaded}) ==========\n"
+ text << "\r\n\r\n========== Not Downloaded Items (#{total_items - total_downloaded}) ==========\r\n"
# Packs
- text << "\n\n=== Packs within this pack (#{pack_entries.size}) ===\n\n"
+ text << "\r\n\r\n=== Packs within this pack (#{pack_entries.size}) ===\r\n\r\n"
if pack_entries.size == 0
- text << " // None //\n\n"
+ text << " // None //\r\n\r\n"
else
pack_entries.each do |entry|
text << entry_text_metadata("Pack", entry, false)
@@ -250,23 +250,23 @@
end
# External
- text << "\n\n=== External items (#{self.remote_entries.size}) ===\n\n"
+ text << "\r\n\r\n=== External items (#{self.remote_entries.size}) ===\r\n\r\n"
if self.remote_entries.size == 0
- text << " // None //\n\n"
+ text << " // None //\r\n\r\n"
else
self.remote_entries.each do |remote_item|
- text << "+ #{remote_item.title} - #{remote_item.uri}\n"
- text << " (alternate link: #{remote_item.alternate_uri.nil? || remote_item.alternate_uri.blank? ? "none" : remote_item.alternate_uri})\n"
+ text << "+ #{remote_item.title} - #{remote_item.uri}\r\n"
+ text << " (alternate link: #{remote_item.alternate_uri.nil? || remote_item.alternate_uri.blank? ? "none" : remote_item.alternate_uri})\r\n"
text << " | Added to pack by: #{uploader_string("user", remote_item.user_id, false, false)};" +
- " added on (#{remote_item.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\n"
- text << " | #{item_comment_string(remote_item, false)}\n\n"
+ " added on (#{remote_item.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\r\n"
+ text << " | #{item_comment_string(remote_item, false)}\r\n\r\n"
end
end
# View only
- text << "\n\n=== Items that can be viewed, but not downloaded (#{view_only.values.flatten.size}) ===\n\n"
+ text << "\r\n\r\n=== Items that can be viewed, but not downloaded (#{view_only.values.flatten.size}) ===\r\n\r\n"
if view_only.values.flatten.size == 0
- text << " // None //\n\n"
+ text << " // None //\r\n\r\n"
else
view_only.each do |type, entries|
entries.each do |entry|
@@ -276,17 +276,17 @@
end
# Hidden
- text << "\n\n=== Items that cannot be viewed (#{stats[:hidden].size}) ===\n\n"
+ text << "\r\n\r\n=== Items that cannot be viewed (#{stats[:hidden].size}) ===\r\n\r\n"
if stats[:hidden].size == 0
- text << " // None //\n\n"
+ text << " // None //\r\n\r\n"
else
stats[:hidden].each do |entry|
item = entry.contributable
text << (item.nil? ?
- "- The item this entry points to is not available. It may have been deleted.\n" :
- "- You don't have permissions to view this item\n"
+ "- The item this entry points to is not available. It may have been deleted.\r\n" :
+ "- You don't have permissions to view this item\r\n"
)
- text << " | Added to pack by: " + uploader_string("user", entry.user_id, false, false) + "; added on (#{entry.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\n"
+ text << " | Added to pack by: " + uploader_string("user", entry.user_id, false, false) + "; added on (#{entry.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\r\n"
end
end
@@ -305,19 +305,19 @@
text = "+ #{visible_type.titleize}: #{item.label}"
text << " (local copy: #{visible_type.underscore.pluralize}/#{item_filename(item)})" if downloaded
- text << "\n"
- text << " Location: #{location_string(type.downcase, item.id, entry.contributable_version)}\n"
- text << " Type: #{original_item.type_display_name}\n" if type == "Workflow"
+ text << "\r\n"
+ text << " Location: #{location_string(type.downcase, item.id, entry.contributable_version)}\r\n"
+ text << " Type: #{original_item.type_display_name}\r\n" if type == "Workflow"
if entry.contributable_version
- text << " Originally uploaded by: #{uploader_string(original_item.contributor_type, original_item.contributor_id, false, false)}\n"
- text << " Version: #{entry.contributable_version} (created on: #{item.created_at.strftime("%d/%m/%Y")}, last edited on: #{item.updated_at.strftime("%d/%m/%Y")})\n"
- text << " Version uploaded by: #{uploader_string(item.contributor_type, item.contributor_id, false, false)}\n"
+ text << " Originally uploaded by: #{uploader_string(original_item.contributor_type, original_item.contributor_id, false, false)}\r\n"
+ text << " Version: #{entry.contributable_version} (created on: #{item.created_at.strftime("%d/%m/%Y")}, last edited on: #{item.updated_at.strftime("%d/%m/%Y")})\r\n"
+ text << " Version uploaded by: #{uploader_string(item.contributor_type, item.contributor_id, false, false)}\r\n"
else
- text << " Uploaded by: #{uploader_string(item.contributor_type, item.contributor_id, false, false)}\n"
+ text << " Uploaded by: #{uploader_string(item.contributor_type, item.contributor_id, false, false)}\r\n"
end
text << " | Added to pack by: #{uploader_string("user", entry.user_id, false, false)};" +
- " added on (#{entry.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\n"
- text << " | #{item_comment_string(entry, false)}\n\n"
+ " added on (#{entry.created_at.strftime('%d/%m/%Y @ %H:%M:%S')})\r\n"
+ text << " | #{item_comment_string(entry, false)}\r\n\r\n"
text
end
@@ -646,9 +646,9 @@
# strips out all unnecessary html, preserving special characters and new lines
def prepare_description(description)
- # replace all the new line equivalents in html with \n's
- desc = description.gsub(/<br\/?>/, "\n")
- desc = desc.gsub("<p></p>", "\n")
+ # replace all the new line equivalents in html with \r\n's
+ desc = description.gsub(/<br\/?>/, "\r\n")
+ desc = desc.gsub("<p></p>", "\r\n")
# strip out all the rest of html tags
desc = desc.gsub(/<\/?[^>]*>/, "")
@@ -760,7 +760,7 @@
if item.comment.nil? || item.comment.blank?
return "Comment: " + (html_required ? "<span class='none_text'>none</span>" : "none")
else
- return "Comment: " + (html_required ? "<div class='comment_text'>#{white_list(simple_format(item.comment))}</div>" : ("\n | " + item.comment.gsub(/\n/, "\n | ")))
+ return "Comment: " + (html_required ? "<div class='comment_text'>#{white_list(simple_format(item.comment))}</div>" : ("\r\n | " + item.comment.gsub(/\r\n/, "\r\n | ")))
end
end