Class: Meatloaf::Sprite
- Inherits:
-
Object
- Object
- Meatloaf::Sprite
- Defined in:
- lib/meatloaf.rb
Instance Method Summary collapse
-
#add_image(image_css_url) ⇒ Object
Add an image to this sprite.
- #finalize! ⇒ Object
-
#initialize(group, css_name) ⇒ Sprite
constructor
A new instance of Sprite.
Constructor Details
#initialize(group, css_name) ⇒ Sprite
Returns a new instance of Sprite.
26 27 28 29 30 31 |
# File 'lib/meatloaf.rb', line 26 def initialize(group, css_name) @group = group @css_name = css_name @ingredients = {} @height = 0 end |
Instance Method Details
#add_image(image_css_url) ⇒ Object
Add an image to this sprite. Returns CSS for ‘background: ’
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meatloaf.rb', line 34 def add_image(image_css_url) return get_css_for(@ingredients[image_css_url]) if @ingredients[image_css_url] # For now, just place the image at the bottom of the sprite. # TODO: improve positioning algorithm ingredient = Ingredient.new(image_css_url, 0, @height) @height += ingredient.height @ingredients[image_css_url] = ingredient get_css_for(ingredient) end |
#finalize! ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/meatloaf.rb', line 45 def finalize! # Create ImageMagick command. final_image_path = "#{Rails.root}/app/assets/images/#{filename}" input_files_string = @ingredients.values.collect{ |ing| "'#{ing.image_path}'" }.join(' ') command = "convert #{input_files_string} -append '#{final_image_path}'" `#{command}` end |