Refactor DiscourseSassImporter.

This commit is contained in:
Guo Xiang Tan 2016-04-19 14:58:03 +08:00
parent 95e0948fba
commit fb6e7c1e19
No known key found for this signature in database
GPG Key ID: 19C321C8952B0F72

View File

@ -37,21 +37,9 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
def find(name, options) def find(name, options)
if name == "category_backgrounds"
contents = ""
Category.where('background_url IS NOT NULL').each do |c|
contents << special_imports[name].call(c) if c.background_url.present?
end
return ::Sass::Engine.new(contents, options.merge(
filename: "#{name}.scss",
importer: self,
syntax: :scss
))
end
if special_imports.has_key? name if special_imports.has_key? name
if name == "theme_variables" case name
when "theme_variables"
contents = "" contents = ""
if color_scheme = ColorScheme.enabled if color_scheme = ColorScheme.enabled
ColorScheme.base_colors.each do |n, base_hex| ColorScheme.base_colors.each do |n, base_hex|
@ -63,12 +51,11 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
contents << File.read(css_file) contents << File.read(css_file)
end end
end end
when "category_backgrounds"
::Sass::Engine.new(contents, options.merge( contents = ""
filename: "#{name}.scss", Category.where('background_url IS NOT NULL').each do |c|
importer: self, contents << special_imports[name].call(c) if c.background_url.present?
syntax: :scss end
))
else else
stylesheets = special_imports[name] stylesheets = special_imports[name]
contents = "" contents = ""
@ -80,13 +67,13 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
end end
depend_on(css_file) depend_on(css_file)
end end
end
::Sass::Engine.new(contents, options.merge( ::Sass::Engine.new(contents, options.merge(
filename: "#{name}.scss", filename: "#{name}.scss",
importer: self, importer: self,
syntax: :scss syntax: :scss
)) ))
end
else else
engine_from_path(name, root, options) engine_from_path(name, root, options)
end end