-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allowed extensions #1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowed extensions #1312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ def self.relative_name(sprite) | |
end | ||
end | ||
|
||
def self.sprite_engine_class | ||
constantize("Compass::SassExtensions::Sprites::#{self.modulize}Engine") | ||
end | ||
|
||
def initialize(sprites, path, name, context, kwargs) | ||
@image_names = sprites | ||
@path = path | ||
|
@@ -81,10 +85,23 @@ def method_missing(meth, *args, &block) | |
|
||
private | ||
|
||
def modulize | ||
def self.modulize | ||
@modulize ||= Compass::configuration.sprite_engine.to_s.scan(/([^_.]+)/).flatten.map {|chunk| "#{chunk[0].chr.upcase}#{chunk[1..-1]}" }.join | ||
end | ||
|
||
def self.constantize(camel_cased_word) | ||
names = camel_cased_word.split('::') | ||
names.shift if names.empty? || names.first.empty? | ||
|
||
constant = Object | ||
names.each do |name| | ||
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) | ||
end | ||
constant | ||
end | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neeeeeewlineeeeees. |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ def compute_image_metadata! | |
end | ||
|
||
def init_engine | ||
@engine = eval("::Compass::SassExtensions::Sprites::#{modulize}Engine.new(nil, nil, nil)") | ||
@engine = self.class.sprite_engine_class.new | ||
@engine.width = @width | ||
@engine.height = @height | ||
@engine.images = @images | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just pass these arguments to the initializer instead of making them optional? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
require 'erb' | ||
require 'compass' | ||
require 'compass/sprite_importer/binding' | ||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neeeeeewlineeeeees! |
||
module Compass | ||
class SpriteImporter < Sass::Importers::Base | ||
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/ | ||
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png} | ||
VALID_EXTENSIONS = ['.png'] | ||
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with relaxing this glob restriction, but unless the user specifies a valid extension in the glob explicitly, I think we should return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the entire point of this was to move the required extensions down a level to the engine classes so things like svg gif or whatever people wanted could be created and also allow me to move forward using the same code to work on a svg -> font glyph engine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine. My point is that when the glob matches, we always return a sass engine. Instead, the sprite engine should be able to look at that glob and decide if it has files in it that it can process. If not, this importer should return nil and then a different importer can handle it. Or maybe Sass will just give an error that says that it cannot import that. |
||
|
||
TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'sprite_importer') | ||
CONTENT_TEMPLATE_FILE = File.join(TEMPLATE_FOLDER, 'content.erb') | ||
|
@@ -15,7 +19,7 @@ class SpriteImporter < Sass::Importers::Base | |
# finds all sprite files | ||
def self.find_all_sprite_map_files(path) | ||
hex = "[0-9a-f]" | ||
glob = "*-s#{hex*10}{#{VALID_EXTENSIONS.join(",")}}" | ||
glob = "*-s#{hex*10}{#{valid_extensions.join(",")}}" | ||
Sass::Util.glob(File.join(path, "**", glob)) | ||
end | ||
|
||
|
@@ -53,7 +57,7 @@ def key(uri, options={}) | |
end | ||
|
||
def self.path_and_name(uri) | ||
if uri =~ SPRITE_IMPORTER_REGEX | ||
if uri =~ sprite_importer_regex_with_ext | ||
[$1, $3] | ||
else | ||
raise Compass::Error, "invalid sprite path" | ||
|
@@ -107,6 +111,16 @@ def self.content_for_images(uri, name, skip_overrides = false) | |
binder = Compass::Sprites::Binding.new(:name => name, :uri => uri, :skip_overrides => skip_overrides, :sprite_names => sprite_names(uri), :files => files(uri)) | ||
CONTENT_TEMPLATE.result(binder.get_binding) | ||
end | ||
|
||
private | ||
|
||
def self.valid_extensions | ||
@valid_extensions ||= SassExtensions::Sprites::SpriteMap.sprite_engine_class::VALID_EXTENSIONS | ||
end | ||
|
||
def self.sprite_importer_regex_with_ext | ||
@importer_regex ||= %r{#{SPRITE_IMPORTER_REGEX}(#{valid_extensions.join('|')})} | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here is where the glob is scoped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I'd still like to not return any engine if there's no files that match the glob. |
||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea was 4 months ago :(