Class: RailsSprite::SpriteUtil
- Inherits:
-
Object
- Object
- RailsSprite::SpriteUtil
- Defined in:
- lib/rails_sprite/sprite_util.rb
Instance Attribute Summary collapse
-
#css_class_prefix ⇒ Object
readonly
Returns the value of attribute css_class_prefix.
-
#css_class_shared ⇒ Object
readonly
Returns the value of attribute css_class_shared.
-
#css_extend ⇒ Object
readonly
Returns the value of attribute css_extend.
-
#file_extend ⇒ Object
readonly
Returns the value of attribute file_extend.
-
#file_extend_name ⇒ Object
readonly
Returns the value of attribute file_extend_name.
-
#image_scope_name ⇒ Object
readonly
Returns the value of attribute image_scope_name.
-
#image_source_folder ⇒ Object
readonly
Returns the value of attribute image_source_folder.
-
#image_to_file_path ⇒ Object
readonly
Returns the value of attribute image_to_file_path.
-
#image_to_folder ⇒ Object
readonly
Returns the value of attribute image_to_folder.
-
#recipe_path ⇒ Object
readonly
Returns the value of attribute recipe_path.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#scope_name ⇒ Object
readonly
Returns the value of attribute scope_name.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
-
#stylesheet_scope_name ⇒ Object
readonly
Returns the value of attribute stylesheet_scope_name.
-
#stylesheet_to ⇒ Object
readonly
Returns the value of attribute stylesheet_to.
-
#zoom ⇒ Object
readonly
Returns the value of attribute zoom.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SpriteUtil
constructor
:css_extend => “”, :root_path => ‘.’, :scope_name => “rails_xxx”, :recipe_path => “icons/16x16”, :file_extend => ‘.png’, :spacing => 10, :image_to_folder => “app/assets/images”, :image_source_folder => ‘app/assets/images/rails_xxx/sprite_sources’, :stylesheet_to => “app/assets/stylesheets/rails_xxx/sprite/icons/16x16.css.scss.erb”, :image_to_file_path => “rails_xxx/sprite/icons/16x16.png”.
- #perform ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SpriteUtil
:css_extend => “”,
:root_path => '.',
:scope_name => "rails_xxx",
:recipe_path => "icons/16x16",
:file_extend => '.png',
:spacing => 10,
:image_to_folder => "app/assets/images",
:image_source_folder => 'app/assets/images/rails_xxx/sprite_sources',
:stylesheet_to => "app/assets/stylesheets/rails_xxx/sprite/icons/16x16.css.scss.erb",
:image_to_file_path => "rails_xxx/sprite/icons/16x16.png"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rails_sprite/sprite_util.rb', line 23 def initialize ={} @root_path = .fetch(:root_path, ::Rails.root) @scope_name = .fetch(:scope_name, '') @scope_name = "#{scope_name}/" unless scope_name.end_with?('/') @recipe_path = .fetch(:recipe_path, '') @recipe_path = recipe_path.chomp('/') if recipe_path.end_with?('/') @file_extend = .fetch(:file_extend, '.png').downcase @css_extend = .fetch(:css_extend, ".css.scss.erb") @file_extend_name = file_extend.gsub('.', '') @spacing = .fetch(:spacing, 10) @stylesheet_scope_name = "#{scope_name}sprite/#{recipe_path}#{css_extend}" @stylesheet_to = .fetch(:stylesheet_to, "#{root_path}/app/assets/stylesheets/#{stylesheet_scope_name}") @image_source_folder = .fetch( :image_source_folder, "#{root_path}/app/assets/images/#{scope_name}sprite_sources/#{recipe_path}" ) @image_to_folder = .fetch(:image_to_folder, "#{root_path}/app/assets/images") @image_scope_name = "#{scope_name}sprite/#{recipe_path}#{file_extend}" @image_to_file_path = .fetch(:image_to_file_path, "#{image_to_folder}/#{image_scope_name}") @scope_str = scope_name.chomp('/').gsub('/', '-') @recipe_str = recipe_path.chomp('/').gsub('/', '-') @css_class_shared = .fetch(:css_class_shared, "rs-#{@scope_str}") @css_class_prefix = .fetch(:css_class_prefix, "rs-#{@scope_str}-#{@recipe_str}-") @zoom = .fetch(:zoom, 1).to_i end |
Instance Attribute Details
#css_class_prefix ⇒ Object (readonly)
Returns the value of attribute css_class_prefix.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def css_class_prefix @css_class_prefix end |
#css_class_shared ⇒ Object (readonly)
Returns the value of attribute css_class_shared.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def css_class_shared @css_class_shared end |
#css_extend ⇒ Object (readonly)
Returns the value of attribute css_extend.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def css_extend @css_extend end |
#file_extend ⇒ Object (readonly)
Returns the value of attribute file_extend.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def file_extend @file_extend end |
#file_extend_name ⇒ Object (readonly)
Returns the value of attribute file_extend_name.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def file_extend_name @file_extend_name end |
#image_scope_name ⇒ Object (readonly)
Returns the value of attribute image_scope_name.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def image_scope_name @image_scope_name end |
#image_source_folder ⇒ Object (readonly)
Returns the value of attribute image_source_folder.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def image_source_folder @image_source_folder end |
#image_to_file_path ⇒ Object (readonly)
Returns the value of attribute image_to_file_path.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def image_to_file_path @image_to_file_path end |
#image_to_folder ⇒ Object (readonly)
Returns the value of attribute image_to_folder.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def image_to_folder @image_to_folder end |
#recipe_path ⇒ Object (readonly)
Returns the value of attribute recipe_path.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def recipe_path @recipe_path end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def root_path @root_path end |
#scope_name ⇒ Object (readonly)
Returns the value of attribute scope_name.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def scope_name @scope_name end |
#spacing ⇒ Object (readonly)
Returns the value of attribute spacing.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def spacing @spacing end |
#stylesheet_scope_name ⇒ Object (readonly)
Returns the value of attribute stylesheet_scope_name.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def stylesheet_scope_name @stylesheet_scope_name end |
#stylesheet_to ⇒ Object (readonly)
Returns the value of attribute stylesheet_to.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def stylesheet_to @stylesheet_to end |
#zoom ⇒ Object (readonly)
Returns the value of attribute zoom.
5 6 7 |
# File 'lib/rails_sprite/sprite_util.rb', line 5 def zoom @zoom end |
Instance Method Details
#perform ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rails_sprite/sprite_util.rb', line 58 def perform file_infos = [] # puts "image_source_folder: #{image_source_folder}" # puts "image_to_file_path: #{image_to_file_path}" # puts "stylesheet_to: #{stylesheet_to}" counter = 0 x = 0 y = 0 max_w = 0 max_h = 0 Dir.entries( image_source_folder ).each do |file_name| if file_name != '.' && file_name != '..' && file_name.end_with?(file_extend) file_path = "#{image_source_folder}/#{file_name}" if ::File.file?(file_path) file_name_split = file_name.split('.') file_name_split.pop file_purename = file_name_split.join('.') file_info = { :filepath => file_path, :filename => file_name, :file_purename => file_purename, :idx => counter }.merge( _library.load( file_path ) ) file_info[:x] = x file_info[:y] = y y += (spacing + file_info[:height]) max_w = [max_w, file_info[:width]].max max_h = y file_infos << file_info counter += 1 end end end _composite_images( :file_infos => file_infos, :max_w => max_w, :max_h => max_h ) _composite_css( file_infos ) end |