correct theme importer to support embedded.scss

This commit is contained in:
Sam 2017-04-12 11:30:16 -04:00
parent 95d095c97d
commit a7ed8a0310
3 changed files with 14 additions and 3 deletions

View File

@ -44,7 +44,16 @@ class RemoteTheme < ActiveRecord::Base
Theme.targets.keys.each do |target|
Theme::ALLOWED_FIELDS.each do |field|
value = importer["#{target}/#{field=="scss"?"#{target}.scss":"#{field}.html"}"]
lookup =
if field == "scss"
"#{target}.scss"
elsif field == "embedded_scss" && target == :common
"embedded.scss"
else
"#{field}.html"
end
value = importer["#{target}/#{lookup}"]
theme.set_field(target.to_sym, field, value)
end
end

View File

@ -4,7 +4,7 @@ require_dependency 'stylesheet/manager'
class Theme < ActiveRecord::Base
ALLOWED_FIELDS = %w{scss head_tag header after_header body_tag footer}
ALLOWED_FIELDS = %w{scss embedded_scss head_tag header after_header body_tag footer}
@cache = DistributedCache.new('theme')

View File

@ -28,6 +28,7 @@ describe RemoteTheme do
"desktop/desktop.scss" => "body {color: red;}",
"common/header.html" => "I AM HEADER",
"common/random.html" => "I AM SILLY",
"common/embedded.scss" => "EMBED",
)
end
@ -51,12 +52,13 @@ describe RemoteTheme do
expect(remote.about_url).to eq("https://www.site.com/about")
expect(remote.license_url).to eq("https://www.site.com/license")
expect(@theme.theme_fields.length).to eq(2)
expect(@theme.theme_fields.length).to eq(3)
mapped = Hash[*@theme.theme_fields.map{|f| ["#{f.target}-#{f.name}", f.value]}.flatten]
expect(mapped["0-header"]).to eq("I AM HEADER")
expect(mapped["1-scss"]).to eq("body {color: red;}")
expect(mapped["0-embedded_scss"]).to eq("EMBED")
expect(remote.remote_updated_at).to eq(time)