Class: ActiveAssets::ActiveSprites::Sprite
- Inherits:
-
Object
- Object
- ActiveAssets::ActiveSprites::Sprite
- Defined in:
- lib/active_assets/active_sprites/sprite.rb
Defined Under Namespace
Modules: Orientation Classes: OrientationInvalid, ValidationError
Constant Summary collapse
- REQUIRED_PROPS =
[:path, :stylesheet_path, :orientation]
Instance Attribute Summary collapse
-
#matte_color ⇒ Object
readonly
Returns the value of attribute matte_color.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#stylesheet_path ⇒ Object
readonly
Returns the value of attribute stylesheet_path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #[](path) ⇒ Object
- #configure(sprite_path, stylesheet_path, options = {}, &blk) ⇒ Object
- #has_sprite_piece_with_path?(path) ⇒ Boolean
-
#initialize ⇒ Sprite
constructor
A new instance of Sprite.
- #sprite_piece(options, &blk) ⇒ Object (also: #sp, #_)
- #sprite_pieces ⇒ Object
- #valid! ⇒ Object
- #valid? ⇒ Boolean
- #validation_error ⇒ Object
Constructor Details
#initialize ⇒ Sprite
Returns a new instance of Sprite.
26 27 28 29 30 31 32 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 26 def initialize # Ordered Hash? @sprite_pieces = ActiveSupport::OrderedHash.new do |sprite_pieces, path| raise SpritePiece::ValidationError.new(nil, [:path]) if path.blank? sprite_pieces[path] = SpritePiece.new end end |
Instance Attribute Details
#matte_color ⇒ Object
Returns the value of attribute matte_color.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def matte_color @matte_color end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def name @name end |
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def orientation @orientation end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def path @path end |
#quality ⇒ Object
Returns the value of attribute quality.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def quality @quality end |
#stylesheet_path ⇒ Object (readonly)
Returns the value of attribute stylesheet_path.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def stylesheet_path @stylesheet_path end |
#url ⇒ Object
Returns the value of attribute url.
24 25 26 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 24 def url @url end |
Instance Method Details
#[](path) ⇒ Object
38 39 40 41 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 38 def [](path) return nil unless @sprite_pieces.has_key?(path) @sprite_pieces[path] end |
#configure(sprite_path, stylesheet_path, options = {}, &blk) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 47 def configure(sprite_path, stylesheet_path, = {}, &blk) @path ||= sprite_path @name = .delete(:as) || sprite_path @stylesheet_path = stylesheet_path @orientation = .delete(:orientation) || :vertical .each {|k,v| send("#{k}=",v)} valid! instance_eval(&blk) if block_given? self end |
#has_sprite_piece_with_path?(path) ⇒ Boolean
34 35 36 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 34 def has_sprite_piece_with_path?(path) @sprite_pieces.has_key?(path) end |
#sprite_piece(options, &blk) ⇒ Object Also known as: sp, _
58 59 60 61 62 63 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 58 def sprite_piece(, &blk) path, css_selector = .find {|k, v| k.is_a?(String)} .delete(path) mapping = SpritePiece::Mapping.new(path, css_selector) @sprite_pieces[path].configure(mapping, , &blk) end |
#sprite_pieces ⇒ Object
43 44 45 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 43 def sprite_pieces @sprite_pieces.values end |
#valid! ⇒ Object
78 79 80 81 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 78 def valid! e = validation_error raise e if e end |
#valid? ⇒ Boolean
74 75 76 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 74 def valid? !validation_error end |
#validation_error ⇒ Object
67 68 69 70 71 72 |
# File 'lib/active_assets/active_sprites/sprite.rb', line 67 def validation_error missing_fields = REQUIRED_PROPS.reject {|prop| send(prop).present?} return OrientationInvalid.new(self, orientation) if orientation && ![:vertical, :horizontal].include?(orientation.to_sym) return if missing_fields.empty? ValidationError.new(self, missing_fields) end |