lib/polymer/dsl.rb in polymer-1.0.0.beta.4 vs lib/polymer/dsl.rb in polymer-1.0.0.beta.5
- old
+ new
@@ -112,11 +112,11 @@
if definition.has_key?(:name)
# Can't have a :name segment and an explicit name option.
raise Polymer::DslError,
"Sprite '#{source} => #{sprite}' has both a :name path segment " \
"and a :name option; please use only one."
- elsif sprite !~ /:name/
+ elsif sprite != :data_uri and sprite !~ /:name/
raise Polymer::MissingName,
"Sprite '#{source} => #{sprite}' requires a :name segment in " \
"the sprite path."
else
_define_multiple_sprites(source, sprite, definition)
@@ -136,11 +136,11 @@
#
def to_project
project_config = @config.to_h
Project.new(@root, @sprites.map do |definition|
- definition = _create_sprite(definition, project_config)
+ _create_sprite(definition, project_config)
end, project_config)
end
#######
private
@@ -176,11 +176,13 @@
# @raise [Polymer::DuplicateName]
# Raised when the sprite uses a name which has been taken by an
# existing sprite.
#
def _define_sprite(sources, sprite, options)
- sources, sprite = @root + sources, @root + sprite
+ sources = @root + sources
+ sprite = @root + sprite unless sprite == :data_uri
+
name = options[:name] || sprite.basename(sprite.extname).to_s
if @sprites.detect { |definition| definition[:name] == name }
raise DuplicateName,
"You tried to create a sprite whose name is `#{name}', but a " \
@@ -191,11 +193,11 @@
sources = sources + '*' if sources.directory?
@sprites << options.merge(
:name => name,
:sources => Pathname.glob(sources),
- :save_path => @root + sprite
+ :save_path => sprite
)
end
# Defines multiple sprites with a :name segment.
#
@@ -214,11 +216,12 @@
sprite_opts = options.dup # Create a copy for each sprite.
sprite_opts[:name] = entry.basename.to_s # Use directory as the name
source_path = "#{leading}#{sprite_opts[:name]}#{trailing}"
- sprite_path = sprite.gsub(/:name/, sprite_opts[:name])
+ sprite_path = (sprite == :data_uri) ?
+ :data_uri : sprite.gsub(/:name/, sprite_opts[:name])
_define_sprite(source_path, sprite_path, sprite_opts)
end
end
@@ -230,19 +233,26 @@
# The global project configuration.
#
# @return [Polymer::Sprite]
#
def _create_sprite(definition, project_config)
- url = definition.fetch(:url, project_config[:url]).dup
- url.gsub!(/:name/, definition[:name])
- url.gsub!(/:filename/, definition[:save_path].basename.to_s)
+ if definition[:save_path] == :data_uri and not project_config[:sass]
+ raise DslError, "The `#{definition[:name]}' sprite wants to use a " \
+ "data URI, but you have disabled Sass"
+ end
+ unless definition[:save_path] == :data_uri
+ url = definition.fetch(:url, project_config[:url]).dup
+ url.gsub!(/:name/, definition[:name])
+ url.gsub!(/:filename/, definition[:save_path].basename.to_s)
+ end
+
Polymer::Sprite.new \
definition[:name],
definition[:sources],
definition[:save_path],
definition.fetch(:padding, project_config[:padding]),
- url
+ url || ''
end
# Provides the DSL for the global configuration options.
#
# @private