sprites 0.0.1.rc2 → 0.0.1.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +0 -8
- data/MIT-LICENSE +20 -0
- data/README.md +76 -1
- data/Rakefile +4 -39
- data/bin/sprites +5 -7
- data/features/cli.feature +1 -1
- data/features/step_definitions/common_steps.rb +10 -8
- data/lib/sprites.rb +123 -13
- data/lib/sprites/cli/cli_application.rb +6 -4
- data/lib/sprites/cli/command_line_option_parser.rb +16 -16
- data/lib/sprites/configuration.rb +26 -7
- data/lib/sprites/railtie.rb +56 -0
- data/lib/sprites/sprite.rb +80 -46
- data/lib/sprites/sprite_generators/chunky_png_generator.rb +14 -8
- data/lib/sprites/sprite_piece.rb +20 -9
- data/lib/sprites/sprite_pieces.rb +10 -10
- data/lib/sprites/test/sprite_generator_tester.rb +23 -12
- data/lib/sprites/version.rb +2 -2
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/bas/bar.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/bas/bas.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/bas/bkgd_main_copy.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/bas/foo.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/bas/fubar.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-default-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-default-cap-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-default-cap-long.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-onclick-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-onclick-cap-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-onclick-cap-long.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-rollover-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-28.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-rollover-cap-long.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-black-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blackarrow-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blackarrow-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blackarrow-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-blue-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-green-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-red-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-trans-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-white-rollover.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-default-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-default-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-default-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-default.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-onclick-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-onclick-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-onclick-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-onclick.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-rollover-cap.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-rollover-drop.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-rollover-edge.png +0 -0
- data/spec/fixtures/{rails_project2 → fake_engine}/app/assets/images/sprite_images/buttons/btn-yellow-rollover.png +0 -0
- data/spec/fixtures/fake_engine/config/sprites.rb +91 -0
- data/spec/fixtures/fake_engine/lib/fake_engine.rb +5 -0
- data/spec/fixtures/project1/config/sprites.rb +143 -145
- data/spec/fixtures/rails_project1/config/application.rb +4 -3
- data/spec/fixtures/rails_project1/config/sprites.rb +90 -92
- data/spec/integration/rails/rails_spec.rb +46 -13
- data/spec/lib/sprites/configuration_spec.rb +11 -5
- data/spec/lib/sprites/sprite_generators/chunky_png_generator_spec.rb +10 -9
- data/spec/lib/sprites/sprite_piece_spec.rb +25 -24
- data/spec/lib/sprites/sprite_pieces_spec.rb +5 -2
- data/spec/lib/sprites/sprite_spec.rb +30 -33
- data/spec/lib/sprites/test/sprite_generator_tester_spec.rb +37 -9
- data/spec/lib/sprites_spec.rb +163 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/sprites_helper.rb +1 -1
- data/sprites.gemspec +6 -5
- metadata +134 -660
- data/lib/sprites/application.rb +0 -60
- data/lib/sprites/autoload.rb +0 -1
- data/lib/sprites/autoloader.rb +0 -16
- data/lib/sprites/notifier.rb +0 -4
- data/lib/sprites/rails.rb +0 -20
- data/lib/sprites/rails/autoload.rb +0 -13
- data/lib/sprites/rails/sprites.rake +0 -15
- data/lib/sprites/sprites.rb +0 -47
- data/lib/sprites/stylesheet.rb +0 -26
- data/spec/fixtures/rails_project1/Rakefile +0 -5
- data/spec/fixtures/rails_project1/config/boot.rb +0 -6
- data/spec/fixtures/rails_project1/config/environment.rb +0 -7
- data/spec/fixtures/rails_project2/Rakefile +0 -5
- data/spec/fixtures/rails_project2/config/application.rb +0 -61
- data/spec/fixtures/rails_project2/config/boot.rb +0 -6
- data/spec/fixtures/rails_project2/config/environment.rb +0 -7
- data/spec/fixtures/rails_project2/config/sprites.rb +0 -93
- data/spec/lib/sprites/application_spec.rb +0 -50
- data/spec/lib/sprites/autoloader_spec.rb +0 -21
- data/spec/lib/sprites/cli/command_line_option_parser_spec.rb +0 -5
- data/spec/lib/sprites/notifier_spec.rb +0 -5
- data/spec/lib/sprites/sprites_spec.rb +0 -100
- data/spec/lib/sprites/stylesheet_spec.rb +0 -24
@@ -1,11 +1,16 @@
|
|
1
|
-
|
1
|
+
class Sprites
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
PATH_FIELDS = %w{definition_file sprites_path sprite_stylesheets_path sprite_pieces_path}
|
4
|
+
OTHER_FIELDS = %w{definition_file autoload sprite_asset_path generator}
|
5
|
+
FIELDS = PATH_FIELDS + OTHER_FIELDS
|
4
6
|
|
5
7
|
DEFAULT_CONFIGURATION = {
|
6
8
|
'sprites_path' => 'public/images/sprites',
|
7
9
|
'sprite_stylesheets_path' => 'public/stylesheets/sprites',
|
8
|
-
'sprite_pieces_path' => 'public/images/sprite_images'
|
10
|
+
'sprite_pieces_path' => 'public/images/sprite_images',
|
11
|
+
'sprite_asset_path' => '/images/sprites',
|
12
|
+
'generator' => ChunkyPngGenerator,
|
13
|
+
'autoload' => true
|
9
14
|
}
|
10
15
|
|
11
16
|
attr_accessor *FIELDS
|
@@ -14,13 +19,19 @@ module Sprites
|
|
14
19
|
DEFAULT_CONFIGURATION.each {|k,v| self.send(:"#{k}=", v)}
|
15
20
|
end
|
16
21
|
|
22
|
+
def configure(options)
|
23
|
+
# p options
|
24
|
+
options.each {|k,v| self.send(:"#{k}=", v)}
|
25
|
+
end
|
26
|
+
|
17
27
|
def config
|
18
28
|
self
|
19
29
|
end
|
20
30
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
31
|
+
def to_options
|
32
|
+
options = Hash.new
|
33
|
+
FIELDS.each {|option| options[option.intern] = send(option) }
|
34
|
+
options
|
24
35
|
end
|
25
36
|
|
26
37
|
def configured?
|
@@ -31,11 +42,19 @@ module Sprites
|
|
31
42
|
|
32
43
|
def self.new_for_command_line_options(options)
|
33
44
|
config = new
|
45
|
+
|
34
46
|
options.each do |k, v|
|
35
|
-
if
|
47
|
+
if options.has_key? :project_root
|
48
|
+
if PATH_FIELDS.include?(k.to_s)
|
49
|
+
config.send(:"#{path_field}=", File.join(options[:project_root], options[path_field.intern]))
|
50
|
+
elsif OTHER_FIELDS.include?(k.to_s)
|
51
|
+
config.send(:"#{k}=", v)
|
52
|
+
end
|
53
|
+
elsif FIELDS.include?(k.to_s)
|
36
54
|
config.send(:"#{k}=", v)
|
37
55
|
end
|
38
56
|
end
|
57
|
+
|
39
58
|
config
|
40
59
|
end
|
41
60
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Sprites
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
rake_tasks do
|
4
|
+
desc "Generate sprites and stylesheets"
|
5
|
+
task :sprites => :environment do
|
6
|
+
Sprites::Railtie.each_sprited_engine do |engine|
|
7
|
+
next if engine.class.superclass == Rails::Engine && !ENV['ENGINES']
|
8
|
+
|
9
|
+
sprites = engine.config.send(Sprites::Railtie.config_field_name(engine.engine_name))
|
10
|
+
sprite_generator = Sprites::ChunkyPngGenerator.new(sprites)
|
11
|
+
sprite_generator.generate
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer 'sprites._rails-configuration' do
|
17
|
+
Sprites::Railtie.each_sprited_engine do |engine|
|
18
|
+
assets_path = "app/assets"
|
19
|
+
|
20
|
+
sprites = Sprites.new
|
21
|
+
|
22
|
+
engine.config.send(Sprites::Railtie.config_field_name_with_equals(engine.engine_name), sprites)
|
23
|
+
sprites.configuration.configure(
|
24
|
+
:sprites_path => engine.root.join(assets_path, 'images/sprites'),
|
25
|
+
:sprite_stylesheets_path => engine.root.join(assets_path, 'stylesheets/sprites'),
|
26
|
+
:sprite_pieces_path => engine.root.join(assets_path, 'images/sprite_images'),
|
27
|
+
:sprite_asset_path => '/assets/sprites'
|
28
|
+
)
|
29
|
+
|
30
|
+
default_definition_file = File.join(engine.config.root, 'config/sprites.rb')
|
31
|
+
if File.exists? default_definition_file
|
32
|
+
sprites.configuration.definition_file = default_definition_file
|
33
|
+
else
|
34
|
+
sprites.configuration.autoload = true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.each_sprited_engine
|
42
|
+
(Rails.application.railties.engines + [Rails.application]).each do |engine|
|
43
|
+
next unless engine.config.respond_to?(:uses_sprites) && engine.config.uses_sprites
|
44
|
+
yield engine
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.config_field_name(engine_name)
|
49
|
+
:"sprites_for_#{engine_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.config_field_name_with_equals(engine_name)
|
53
|
+
:"#{config_field_name(engine_name)}="
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/sprites/sprite.rb
CHANGED
@@ -2,9 +2,10 @@ require 'fileutils'
|
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
require 'sprites/sprite_pieces'
|
4
4
|
require 'sprites/sprite_piece'
|
5
|
-
require 'sprites/stylesheet'
|
6
5
|
|
7
|
-
|
6
|
+
require 'forwardable'
|
7
|
+
|
8
|
+
class Sprites
|
8
9
|
class Sprite
|
9
10
|
class InvalidOrientation < StandardError; end
|
10
11
|
module Orientations
|
@@ -12,22 +13,24 @@ module Sprites
|
|
12
13
|
HORIZONTAL = 2
|
13
14
|
end
|
14
15
|
|
16
|
+
SUPPORTED_OPTIONS = %w{orientation path stylesheet_path url autoload css_prefix}
|
17
|
+
|
15
18
|
DEFAULT_OPTIONS = {
|
16
19
|
:orientation => Orientations::VERTICAL,
|
17
|
-
:path => lambda {|sprite| "#{sprite.name}.png" },
|
18
|
-
:stylesheet_path => lambda {|sprite| sprite.stylesheet.path },
|
19
|
-
:url => lambda {|sprite| sprite.stylesheet.url },
|
20
|
-
:auto_define => true,
|
21
20
|
:css_prefix => ''
|
22
21
|
}
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
attr_reader :name, :sprite_pieces
|
26
|
+
attr_accessor *SUPPORTED_OPTIONS
|
27
|
+
|
28
|
+
def_delegator :@sprites, :configuration
|
26
29
|
|
27
|
-
def initialize(name,
|
28
|
-
@name, @
|
29
|
-
|
30
|
-
@
|
30
|
+
def initialize(name, sprites)
|
31
|
+
@name, @sprites = name, sprites
|
32
|
+
|
33
|
+
@sprite_pieces = SpritePieces.new(@sprites, self)
|
31
34
|
end
|
32
35
|
|
33
36
|
def orientation=(val)
|
@@ -35,65 +38,96 @@ module Sprites
|
|
35
38
|
@orientation = val
|
36
39
|
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def sprite_file_name
|
42
|
+
"#{name}.png"
|
43
|
+
end
|
44
|
+
|
45
|
+
def stylesheet_file_name
|
46
|
+
sprite_file_name.gsub(/png$/, 'css')
|
47
|
+
end
|
48
|
+
|
49
|
+
def background_property_url
|
50
|
+
@url || File.join(@sprites.configuration.sprite_asset_path, sprite_file_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Output file for the sprites image
|
54
|
+
def path
|
55
|
+
File.join(@sprites.configuration.sprites_path, @path || sprite_file_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Output file for the sprites stylesheet
|
59
|
+
def stylesheet_path
|
60
|
+
File.join(@sprites.configuration.sprite_stylesheets_path, @stylesheet_path || stylesheet_file_name)
|
49
61
|
end
|
50
62
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
63
|
+
def do_autolaod?
|
64
|
+
if autoload == false
|
65
|
+
false
|
54
66
|
else
|
55
|
-
|
67
|
+
@sprites.configuration.autoload
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
71
|
+
def css_prefix
|
72
|
+
@css_prefix || DEFAULT_OPTIONS[:css_prefix]
|
73
|
+
end
|
74
|
+
|
75
|
+
def orientation
|
76
|
+
@orientation || DEFAULT_OPTIONS[:orientation]
|
77
|
+
end
|
78
|
+
|
59
79
|
def configure(options = {}, &blk)
|
60
|
-
options.symbolize_keys!.assert_valid_keys(*
|
80
|
+
options.symbolize_keys!.assert_valid_keys(*(SUPPORTED_OPTIONS.map(&:intern)))
|
81
|
+
|
61
82
|
options.each {|k,v| send(:"#{k}=", v)}
|
62
|
-
|
83
|
+
|
84
|
+
autoload! if do_autolaod?
|
85
|
+
|
63
86
|
instance_eval(&blk) if block_given?
|
87
|
+
|
64
88
|
self
|
65
89
|
end
|
66
90
|
|
67
91
|
def write_stylesheet(configuration, sprite_pieces = @sprite_pieces)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
f << stylesheet.css(configuration, self, sprite_pieces)
|
92
|
+
FileUtils.mkdir_p(File.dirname(stylesheet_path))
|
93
|
+
File.open stylesheet_path, 'w+' do |f|
|
94
|
+
f << sprite_pieces.css
|
72
95
|
end
|
73
96
|
end
|
74
97
|
|
75
|
-
|
98
|
+
##
|
99
|
+
# The +sprite_piece+ method adds sprite_piecess to the sprite
|
100
|
+
#
|
101
|
+
# === Example ===
|
102
|
+
# sprite :foo do
|
103
|
+
# sprite_piece 'buttons/btn-black-default-28.png', 'a.black.wf_button > span, button.black.wf_submit span'
|
104
|
+
#
|
105
|
+
# Arguments:
|
106
|
+
# [String] the path to sprite piece relatie to config.sprite_pieces_path
|
107
|
+
# [String] (optional) the css selector to use for this sprite piece
|
108
|
+
#
|
109
|
+
# Options:
|
110
|
+
##
|
111
|
+
def sprite_piece(path, css_class = nil, options = {})
|
112
|
+
css_class ||= File.basename(path, File.extname(path)).split('/').join('-')
|
76
113
|
@sprite_pieces.add(path, css_class, options)
|
77
114
|
end
|
78
115
|
|
79
|
-
def
|
80
|
-
File.join(configuration.
|
116
|
+
def autoload!
|
117
|
+
Dir[File.join(@sprites.configuration.sprite_pieces_path, name.to_s, '*.png')].each do |path|
|
118
|
+
sprite_piece "#{name}/#{File.basename(path)}", ".#{File.basename(path, File.extname(path))}"
|
119
|
+
end
|
81
120
|
end
|
82
121
|
|
83
|
-
def
|
84
|
-
|
85
|
-
# TODO what if there is another app in the path
|
86
|
-
"/assets/sprites/#{File.basename(sprite_full_path(configuration, sprite))}"
|
122
|
+
def all_sprite_pieces
|
123
|
+
@sprite_pieces.all
|
87
124
|
end
|
88
125
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
126
|
+
def all_sprite_piece_files
|
127
|
+
@sprite_pieces.map do |sp|
|
128
|
+
sp.source_path
|
92
129
|
end
|
93
130
|
end
|
94
131
|
|
95
|
-
def stylesheet_path
|
96
|
-
@stylesheet_path || path.to_s.gsub(/png$/, 'css')
|
97
|
-
end
|
98
132
|
end
|
99
133
|
end
|
@@ -4,15 +4,21 @@ rescue
|
|
4
4
|
require 'chunky_png'
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
class Sprites
|
8
8
|
class ChunkyPngGenerator
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :sprites
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(sprites)
|
12
|
+
@sprites = sprites
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def configuration
|
16
|
+
sprites.configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate
|
20
|
+
sprites.load
|
21
|
+
|
16
22
|
# verbose = ENV['VERBOSE'] == 'true' || ENV['DEBUG']
|
17
23
|
#
|
18
24
|
# if verbose
|
@@ -31,8 +37,8 @@ module Sprites
|
|
31
37
|
# end
|
32
38
|
#
|
33
39
|
|
34
|
-
sprite_path =
|
35
|
-
sprite_stylesheet_path =
|
40
|
+
sprite_path = sprite.path
|
41
|
+
sprite_stylesheet_path = sprite.stylesheet_path
|
36
42
|
|
37
43
|
orientation = sprite.orientation
|
38
44
|
sprite_pieces = sprite.sprite_pieces
|
@@ -77,7 +83,7 @@ module Sprites
|
|
77
83
|
width, height = 0, 0
|
78
84
|
|
79
85
|
image_list = sprite_pieces.map do |sp|
|
80
|
-
sprite_piece_path =
|
86
|
+
sprite_piece_path = sp.source_path
|
81
87
|
sp_image = ChunkyPNG::Image.from_file(sprite_piece_path)
|
82
88
|
sp.left = orientation == Sprite::Orientations::VERTICAL ? 0 : width
|
83
89
|
sp.top = orientation == Sprite::Orientations::VERTICAL ? height : 0
|
data/lib/sprites/sprite_piece.rb
CHANGED
@@ -1,27 +1,38 @@
|
|
1
|
-
|
1
|
+
class Sprites
|
2
2
|
class SpritePiece
|
3
|
-
|
4
|
-
|
3
|
+
SUPPORTED_OPTIONS = %w(x y)
|
4
|
+
|
5
|
+
attr_reader :path, :sprite
|
6
|
+
attr_accessor :css_selector, :width, :height, :top, :left, *SUPPORTED_OPTIONS
|
5
7
|
alias_method :selector, :css_selector
|
6
8
|
|
7
|
-
def initialize(path)
|
9
|
+
def initialize(sprites, sprite, path)
|
10
|
+
@sprites, @sprite = sprites, sprite
|
8
11
|
@path = path
|
9
12
|
end
|
10
13
|
|
11
|
-
def
|
12
|
-
|
14
|
+
def configure(options)
|
15
|
+
options.symbolize_keys!.assert_valid_keys(*(SUPPORTED_OPTIONS.map(&:intern)))
|
16
|
+
|
17
|
+
options.each {|k,v| send(:"#{k}=", v) }
|
13
18
|
end
|
14
19
|
|
15
|
-
def
|
16
|
-
|
20
|
+
def background_property_url
|
21
|
+
@sprite.background_property_url
|
22
|
+
end
|
23
|
+
|
24
|
+
def source_path
|
25
|
+
File.join(@sprites.configuration.sprite_pieces_path, path)
|
26
|
+
end
|
17
27
|
|
28
|
+
def css
|
18
29
|
<<-CSS
|
19
30
|
#{selector}
|
20
31
|
{
|
21
32
|
display:block;
|
22
33
|
width:#{width}px;
|
23
34
|
height:#{height}px;
|
24
|
-
background:url('#{
|
35
|
+
background:url('#{background_property_url}?#{Time.now.to_i}') no-repeat #{x || negative_pixelize(left)} #{y || negative_pixelize(top)};
|
25
36
|
}
|
26
37
|
CSS
|
27
38
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'active_support/ordered_hash'
|
2
2
|
|
3
|
-
|
3
|
+
class Sprites
|
4
4
|
class SpritePieces
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
def initialize
|
7
|
+
def initialize(sprites, sprite)
|
8
|
+
@sprites, @sprite = sprites, sprite
|
8
9
|
@sprite_pieces = ActiveSupport::OrderedHash.new do |sprite_pieces, path|
|
9
|
-
sprite_pieces[path] = SpritePiece.new(path)
|
10
|
+
sprite_pieces[path] = SpritePiece.new(sprites, sprite, path)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def add(path, css_selector, options = {})
|
14
15
|
@sprite_pieces[path].css_selector = css_selector
|
15
|
-
|
16
|
+
@sprite_pieces[path].configure(options)
|
17
|
+
|
16
18
|
self
|
17
19
|
end
|
18
20
|
|
@@ -29,17 +31,15 @@ module Sprites
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def [](val)
|
32
|
-
@sprite_pieces.has_key?(val)
|
33
|
-
@sprite_pieces[val] :
|
34
|
-
nil
|
34
|
+
@sprite_pieces[val] if @sprite_pieces.has_key?(val)
|
35
35
|
end
|
36
36
|
|
37
37
|
def element_at(index)
|
38
38
|
@sprite_pieces.values[index]
|
39
39
|
end
|
40
40
|
|
41
|
-
def css
|
42
|
-
@sprite_pieces.values.map {|sp| sp.css
|
41
|
+
def css
|
42
|
+
@sprite_pieces.values.map {|sp| sp.css}.join("\n")
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -6,32 +6,35 @@ rescue LoadError
|
|
6
6
|
require 'RMagick'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
class Sprites
|
10
10
|
class SpriteGeneratorTester
|
11
11
|
include Magick
|
12
12
|
|
13
13
|
Selector = Struct.new(:selector, :x, :y, :width, :height)
|
14
14
|
|
15
|
-
attr_reader :sprite
|
16
|
-
private :sprite
|
15
|
+
attr_reader :sprite
|
16
|
+
private :sprite
|
17
17
|
|
18
|
-
def initialize(sprite
|
19
|
-
@sprite
|
18
|
+
def initialize(sprite)
|
19
|
+
@sprite = sprite
|
20
20
|
end
|
21
21
|
|
22
22
|
def accurate?
|
23
23
|
test_generate.all? {|x| x == 0}
|
24
24
|
end
|
25
25
|
|
26
|
+
def background_property_urls
|
27
|
+
background_property_urls = []
|
28
|
+
parser.each_rule_set do |rs|
|
29
|
+
background_property_urls << rs['background'][%r{url\('?(.+)(?:\?\d+)(?:')\)}, 1]
|
30
|
+
end
|
31
|
+
background_property_urls
|
32
|
+
end
|
33
|
+
|
26
34
|
private
|
27
35
|
def test_generate(gem_root = GEM_ROOT)
|
28
36
|
sprite_pieces = @sprite.sprite_pieces
|
29
|
-
sprite_image = Image.read(
|
30
|
-
|
31
|
-
stylesheet_path = Stylesheet.stylesheet_full_path(configuration, sprite.stylesheet)
|
32
|
-
stylesheet_absolute_path = gem_root.join(stylesheet_path)
|
33
|
-
parser = CssParser::Parser.new
|
34
|
-
parser.load_file!(File.basename(stylesheet_absolute_path), File.dirname(stylesheet_absolute_path), :screen)
|
37
|
+
sprite_image = Image.read(sprite.path).first
|
35
38
|
|
36
39
|
sprite_pieces_with_selector_data = []
|
37
40
|
|
@@ -52,7 +55,7 @@ module Sprites
|
|
52
55
|
percent_diferences = sprite_pieces_with_selector_data.map do |sp, selector_data|
|
53
56
|
begin
|
54
57
|
raise selector_data.inspect if sp.nil?
|
55
|
-
sprite_piece_path =
|
58
|
+
sprite_piece_path = sp.source_path
|
56
59
|
sprite_piece_image = Image.read(sprite_piece_path).first
|
57
60
|
|
58
61
|
curr_sprite_image = sprite_image.crop(
|
@@ -75,5 +78,13 @@ module Sprites
|
|
75
78
|
sprite_image.destroy! if sprite_image
|
76
79
|
sprite_image = nil
|
77
80
|
end
|
81
|
+
|
82
|
+
def parser
|
83
|
+
stylesheet_path = sprite.stylesheet_path
|
84
|
+
parser = CssParser::Parser.new
|
85
|
+
parser.load_file!(File.basename(stylesheet_path), File.dirname(stylesheet_path), :screen)
|
86
|
+
parser
|
87
|
+
end
|
88
|
+
|
78
89
|
end
|
79
90
|
end
|