From 93a9f8a24b8c825f4b4484bcaab64b4fa4eaf769 Mon Sep 17 00:00:00 2001 From: zz9pzza Date: Thu, 18 May 2017 21:57:53 +0100 Subject: [PATCH] AO3-4736 Broken skins path (#2919) * New Rails.public_path behaviour http://stackoverflow.com/questions/8714645/how-to-specify-the-path-of-the-public-directory-in-a-ruby-on-rails-app * Fix first tests --- app/models/challenge_signup.rb | 2 +- app/models/skin.rb | 15 +++++----- lib/tasks/after_tasks.rake | 53 +++++++++++++++++----------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/app/models/challenge_signup.rb b/app/models/challenge_signup.rb index 0b05f7d1544..f1e03512c0f 100755 --- a/app/models/challenge_signup.rb +++ b/app/models/challenge_signup.rb @@ -217,7 +217,7 @@ def self.generate_summary_in_background(collection) end def self.summary_dir - "#{Rails.public_path}/static/challenge_signup_summaries" + Rails.public_path.join("static/challenge_signup_summaries").to_s end def self.summary_file(collection) diff --git a/app/models/skin.rb b/app/models/skin.rb index 9d9a01f6c48..2599a5402bd 100755 --- a/app/models/skin.rb +++ b/app/models/skin.rb @@ -271,10 +271,10 @@ def parse_sheet_role(role_string) end def get_css - if self.filename - File.read(Rails.public_path + self.filename) + if filename + File.read(Rails.public_path.join("." + filename)) else - self.css + css end end @@ -386,7 +386,8 @@ def get_cached_style(roles_to_include) end def stylesheet_link(file, media) - '' + # we want one and only one / in the url path + '' end def self.naturalized(string) @@ -472,7 +473,7 @@ def skin_dirname end def self.skins_dir - Rails.public_path + SKIN_PATH + Rails.public_path.join(SKIN_PATH).to_s end def self.skin_dir_entries(dir, regex) @@ -480,7 +481,7 @@ def self.skin_dir_entries(dir, regex) end def self.site_skins_dir - Rails.public_path + SITE_SKIN_PATH + Rails.public_path.join(SITE_SKIN_PATH).to_s end # Get the most recent version and find the topmost skin @@ -505,7 +506,7 @@ def self.create_default skin = Skin.find_or_create_by(title: "Default", css: "", public: true, role: "user") current_version = Skin.get_current_version if current_version - File.open(Skin.site_skins_dir + current_version + 'preview.png', 'rb') {|preview_file| skin.icon = preview_file} + File.open(Skin.site_skins_dir + current_version + '/preview.png', 'rb') {|preview_file| skin.icon = preview_file} else File.open(Skin.site_skins_dir + 'preview.png', 'rb') {|preview_file| skin.icon = preview_file} end diff --git a/lib/tasks/after_tasks.rake b/lib/tasks/after_tasks.rake index b059761b3e0..73a5c97a599 100644 --- a/lib/tasks/after_tasks.rake +++ b/lib/tasks/after_tasks.rake @@ -153,17 +153,16 @@ namespace :After do # end # end - - desc "Clear out old epub files" - task(:remove_old_epubs => :environment) do - download_dir = "#{Rails.public_path}/downloads/" - cmd = %Q{find #{download_dir} -depth -name epub -exec rm -rf {} \\;} - puts cmd - `#{cmd}` - cmd = %Q{find #{download_dir} -name "*.epub" -exec rm {} \\;} - puts cmd - `#{cmd}` - end +# desc "Clear out old epub files" +# task(:remove_old_epubs => :environment) do +# download_dir = Rails.public_path.join("downloads").to_s +# cmd = %Q{find #{download_dir} -depth -name epub -exec rm -rf {} \\;} +# puts cmd +# `#{cmd}` +# cmd = %Q{find #{download_dir} -name "*.epub" -exec rm {} \\;} +# puts cmd +# `#{cmd}` +# end # desc "update filter taggings since nov 21" # task(:update_filter_taggings => :environment) do @@ -234,7 +233,7 @@ namespace :After do # end - + # desc "Set complete status for works" # task(:set_complete_status => :environment) do # Work.update_all("complete = 1", "expected_number_of_chapters = 1") @@ -280,7 +279,7 @@ namespace :After do # convert_restriction_tagset(meme.request_restriction, owners, title + "_requests") # end # end -# +# # def convert_restriction_tagset(restriction, owner_pseuds, title) # if restriction && restriction.tag_set_id # tag_set_title = "Tag Set For #{title.gsub(/[^\w\s]+/, '_')}" @@ -296,7 +295,7 @@ namespace :After do # end # end # end -# +# # desc "Convert existing skins to be based off version 1.0" # task(:convert_existing_skins => :environment) do # oldskin = Skin.find_by_title_and_official("Archive 1.0", true) @@ -322,7 +321,7 @@ namespace :After do # # # require 'nokogiri' -# +# # desc "Esacape ampersands in work titles" # task(:escape_ampersands => :environment) do # Work.where("title LIKE '%&%'").each do |work| @@ -330,7 +329,7 @@ namespace :After do # work.save # end # end -# +# # desc "Set stat counts for works" # task(:set_work_stats => :environment) do # Work.find_each do |work| @@ -338,7 +337,7 @@ namespace :After do # work.update_stat_counter # end # end -# +# # desc "Set anon/unrevealed status for works" # task(:set_anon_unrevealed => :environment) do # CollectionItem.where("(anonymous = 1 OR unrevealed = 1) AND item_type = 'Work'").each do |collection_item| @@ -346,13 +345,13 @@ namespace :After do # work = collection_item.item # if work.present? # work.update_attributes( -# in_anon_collection: collection_item.anonymous, +# in_anon_collection: collection_item.anonymous, # in_unrevealed_collection: collection_item.unrevealed # ) # end # end # end -# +# # desc "Add filters to external works" # task(:external_work_filters => :environment) do # ExternalWork.find_each do |ew| @@ -362,19 +361,19 @@ namespace :After do # end #### Add your new tasks here - + desc "Set initial values for sortable tag names" task(:sortable_tag_names => :environment) do Media.all.each{ |m| m.save } - + Fandom.find_each do |fandom| fandom.set_sortable_name puts fandom.sortable_name fandom.save end end - + desc "Increase skins' width threshold for handheld devices to 640px" task(:increase_handheld_width => :environment) do hh_width_media = "only screen and (max-width: 480px)" @@ -395,9 +394,9 @@ namespace :After do lang = Language.find_by_short(short) if lang.present? Locale.create( - iso: iso, - short: short, - name: lang.name, + iso: iso, + short: short, + name: lang.name, language_id: lang.id ) else @@ -465,7 +464,7 @@ namespace :After do end if skin.background_color.present? || skin.foreground_color.present? || skin.font.present? || skin.base_em.present? - wizard_css += "body, #main { + wizard_css += "body, #main { #{skin.background_color.present? ? "background: #{skin.background_color}; " : ''} #{skin.foreground_color.present? ? "color: #{skin.foreground_color}; " : ''} " if skin.base_em.present? @@ -507,7 +506,7 @@ end # this is the end that you have to put new tasks above # ADD NEW MIGRATE TASKS TO THIS LIST ONCE THEY ARE WORKING # Remove tasks from the list once they've been run on the deployed site -# NOTE: +# NOTE: desc "Run all current migrate tasks" # task :After => ['After:convert_tag_sets', 'autocomplete:reload_tagset_data', 'skins:disable_all', 'skins:unapprove_all', # 'skins:load_site_skins', 'After:convert_existing_skins', 'skins:load_user_skins', 'After:remove_old_epubs']