lib/polymer/project.rb in polymer-1.0.0.beta.4 vs lib/polymer/project.rb in polymer-1.0.0.beta.5
- old
+ new
@@ -41,10 +41,17 @@
#
# @return [Array<Polymer::Sprite>]
#
attr_reader :sprites
+ # Returns a subset of +sprites+ containing sprites which are to be written
+ # as a data URI in a Sass file.
+ #
+ # @return [Array<Polymer::Sprite>]
+ #
+ attr_reader :data_uri_sprites
+
# Creates a new Project.
#
# Note that +new+ does not validation of the given paths or options; it
# expects them to be correct. You're probably better using +DSL.build+.
#
@@ -70,19 +77,27 @@
@sprites = sprites
@sass = extract_path :sass, options
@css = extract_path :css, options
@cachefile = extract_path :cache, options
+
+ # Sprites which are to be saved as a data URI need to have a save
+ # path explicitly set.
+ @data_uri_sprites = @sprites.select do |sprite|
+ if sprite.save_path == :data_uri
+ sprite.save_path = tmpdir.join("#{sprite.name.to_s}.png")
+ end
+ end
end
# Returns the sprite whose name is +name+.
#
# @param [String] name
# The name of the sprite to be retrieved.
#
# @return [Polymer::Sprite] The sprite.
- # @return [nil] If no such sprite exists.
+ # @return [nil] If no such sprite exists.
#
def sprite(name)
sprites.detect { |sprite| sprite.name == name }
end
@@ -99,9 +114,20 @@
#
# @return [Polymer::Cache]
#
def cache
@cache ||= Polymer::Cache.new(@cachefile)
+ end
+
+ # Returns a path to a temporary directory which may be used by this
+ # project.
+ #
+ # The temporary directory will be created if it does not already exist.
+ #
+ # @return [Pathname] Path to the temporary directory.
+ #
+ def tmpdir
+ @tmpdir ||= Pathname.new(Dir.mktmpdir).tap { |p| p.mkpath }
end
private # ================================================================
# Extracts a path, typically specified in the DSL, and converts it to