Class: Sprite::Builder
- Inherits:
-
Object
- Object
- Sprite::Builder
- Defined in:
- lib/sprite/builder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #image_path(group) ⇒ Object
-
#initialize(config = nil, images = nil) ⇒ Builder
constructor
A new instance of Builder.
-
#style_output_path(relative = false) ⇒ Object
get the disk path for the style output file.
Constructor Details
#initialize(config = nil, images = nil) ⇒ Builder
Returns a new instance of Builder.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sprite/builder.rb', line 12 def initialize(config = nil, images = nil) @config = config || {} set_config_defaults @images = images || [] if @images.empty? @images = default_images end # initialize datestamp @datestamp_query = "?#{Time.now.to_i}" if @config["add_datestamps"] # initialize sprite files @sprite_files = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/sprite/builder.rb', line 4 def config @config end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
5 6 7 |
# File 'lib/sprite/builder.rb', line 5 def images @images end |
Class Method Details
.from_config(path = nil) ⇒ Object
7 8 9 10 |
# File 'lib/sprite/builder.rb', line 7 def self.from_config(path = nil) results = Config.read_config(path) new(results["config"], results["images"]) end |
Instance Method Details
#build ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sprite/builder.rb', line 29 def build @sprite_files = {} if images.size > 0 # create images images.each do |image| write_image(image) end if @sprite_files.values.length > 0 # write css write_styles end end end |
#image_path(group) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/sprite/builder.rb', line 56 def image_path(group) image_info = images.detect{|image| image['name'] == group} image_config = ImageConfig.new(image_info, config) cache_buster = "-#{config['cache_buster']}" if config['cache_buster'] sprite_file = "#{image_config.name}#{cache_buster}.#{image_config.format}" "#{config['css_image_path']}#{sprite_file}" end |
#style_output_path(relative = false) ⇒ Object
get the disk path for the style output file
46 47 48 49 50 51 52 53 54 |
# File 'lib/sprite/builder.rb', line 46 def style_output_path(relative = false) style = Styles.get(config["style"]).new(self) path = config['style_output_path'] unless path.include?(".#{style.extension}") path = "#{path}.#{style.extension}" end Config.new(config).public_path(path, relative) end |