Sha256: 8f17744860df7f031cbbcf4579cbdb418d6a7169744ee2ac7cf48350f5e193d1
Contents?: true
Size: 1.88 KB
Versions: 2
Compression:
Stored size: 1.88 KB
Contents
module ActiveAssets module ActiveSprites class SpritePiece class ValidationError < StandardError attr_reader :sprite_piece, :missing_fields def initialize(sprite_piece, missing_fields) @sprite, @missing_fields = sprite_piece, missing_fields super("#{"Your sprite piece could not be created. " if @sprite_piece.nil?} Your sprite piece is invalid. It is missing the following fields: #{@missing_fields.join(', ')}") end end class Mapping attr_reader :path, :css_selector def initialize(path, css_selector) raise ValidationError.new(nil, [:path]) if path.blank? @path, @css_selector = path, css_selector end end Details = Struct.new(:sprite_path, :x, :y, :width, :height) GEOMETRY_PROPS = [:x, :y, :width, :height] attr_reader(*GEOMETRY_PROPS) attr_accessor :details delegate :path, :css_selector, :to => :mapping def configure(mapping, options = {}, &blk) @mapping = mapping options.each {|k,v| send(k, v)} instance_eval(&blk) if block_given? self end def to_css return '' if details.nil? <<-CSS #{css_selector} { width:#{width || "#{details.width}px"}; height:#{height || "#{details.height}px"}; background:url('#{details.sprite_path}') no-repeat #{x || "#{-details.x}px"} #{y || "#{-details.y}px"}; display:block; } CSS end def to_s "|\t#{path}\t|\t#{css_selector}\t|\t#{details.x}\t|\t#{details.y}\t|\t#{details.width}\t|\t#{details.height}\t|\n" end GEOMETRY_PROPS.each do |prop| eval <<-METH def #{prop}(*args) #{prop}, *_ = args @#{prop} = #{prop} if #{prop} @#{prop} end METH end private def mapping @mapping end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_assets-0.3.1 | lib/active_assets/active_sprites/sprite_piece.rb |
active_assets-0.3.0 | lib/active_assets/active_sprites/sprite_piece.rb |