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
data/.gitignore
CHANGED
@@ -10,4 +10,7 @@ doc
|
|
10
10
|
|
11
11
|
spec/fixtures/project1/public/images/sprites/*.png
|
12
12
|
spec/fixtures/project1/public/stylesheets/sprites/*.css
|
13
|
+
spec/fixtures/rails_project1/log
|
14
|
+
spec/fixtures/rails_project1/app/assets/images/sprites
|
15
|
+
spec/fixtures/rails_project1/app/assets/stylesheets
|
13
16
|
|
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2012 Sam Woodard - http://github.com/shwoodard
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,21 @@
|
|
2
2
|
|
3
3
|
Sprites is a library that let's you define the sprites for your application with configuration or convention. Sprites will generate your sprites, and a corresponding stylesheet for each using either the cli or from within a Rails application.
|
4
4
|
|
5
|
-
##
|
5
|
+
## The DSL for sprites.rb
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
sprite :bas
|
9
|
+
|
10
|
+
sprite :buttons, :path => "buttons.png", :stylesheet_path => "buttons.css", :autoload => false do
|
11
|
+
sprite_piece 'buttons/btn-black-default-28.png', 'a.black.button > span, button.black.submit span'
|
12
|
+
sprite_piece 'buttons/btn-black-default-cap-28.png', 'a.black.button, button.black.submit', :x => 'right'
|
13
|
+
...
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
## For the cli
|
18
|
+
|
19
|
+
### Project Structure
|
6
20
|
|
7
21
|
|
|
8
22
|
|\_config
|
@@ -16,3 +30,64 @@ Sprites is a library that let's you define the sprites for your application with
|
|
16
30
|
\_sprite_name2
|
17
31
|
|\_blue_icon.png
|
18
32
|
\_green_icon.png
|
33
|
+
|
34
|
+
gem install sprites
|
35
|
+
|
36
|
+
execute:
|
37
|
+
|
38
|
+
cd PROJECT_ROOT
|
39
|
+
sprites
|
40
|
+
|
41
|
+
For usage
|
42
|
+
|
43
|
+
sprites --help
|
44
|
+
|
45
|
+
|
46
|
+
## In your Rails app
|
47
|
+
|
48
|
+
#### Gemfile
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
gem 'sprites'
|
52
|
+
```
|
53
|
+
|
54
|
+
#### application.rb
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
config.uses_sprites = true
|
58
|
+
```
|
59
|
+
|
60
|
+
Optionally include a `config/sprites.rb` (see above). Otherwise _Sprites_ will use it's auto-load feature. Example, if you have `app/assets/images/sprite_images/foo/bar.png` and `app/assets/images/sprite_images/foo/bas.png`, _Sprites_ will create `app/assets/stylesheets/sprites/foo.css` and `app/assets/images/sprites/foo.png`. The class for `bar.png` will be `.bar` and for `bas.png`, `.bas`, etc.
|
61
|
+
|
62
|
+
|
63
|
+
rake sprites
|
64
|
+
|
65
|
+
to generate.
|
66
|
+
|
67
|
+
## In your Rails Engine
|
68
|
+
|
69
|
+
#### engine.rb
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
module MyGem
|
73
|
+
class Engine < Rails::Engine
|
74
|
+
config.uses_sprites = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Use `app/assets` in your gem like you would your rails app and use the asset pipeline.
|
80
|
+
|
81
|
+
From your rails root
|
82
|
+
|
83
|
+
ENGINES=true rake sprites
|
84
|
+
|
85
|
+
Note: this will generate your sprites for your _Sprites_ enabled Engines _and_ your _Sprites_ enabled Rails app.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,44 +1,9 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'cucumber/rake/task'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
7
|
-
# Put spec opts in a file named .rspec in root
|
8
|
-
end
|
5
|
+
RSpec::Core::RakeTask.new :spec
|
6
|
+
Cucumber::Rake::Task.new
|
9
7
|
|
10
|
-
desc
|
11
|
-
RSpec::Core::RakeTask.new(:coverage) do |t|
|
12
|
-
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
13
|
-
t.rcov = true
|
14
|
-
t.rcov_opts = ['--exclude', 'spec']
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
namespace :spec do
|
19
|
-
desc 'Create spec'
|
20
|
-
task :create, :path do |t, args|
|
21
|
-
spec_path = File.join('spec', args[:path].gsub(%r{.rb$}, '_spec.rb'))
|
22
|
-
klass = File.basename(args[:path], File.extname(args[:path])).split('_').map {|s| "#{s[0,1].upcase}#{s[1..-1]}" }.join
|
23
|
-
mkdir_p File.dirname(spec_path)
|
24
|
-
|
25
|
-
spec_doc = <<-EOS
|
26
|
-
require 'spec_helper'
|
27
|
-
|
28
|
-
describe #{klass} do
|
29
|
-
end
|
30
|
-
EOS
|
31
|
-
|
32
|
-
File.open(spec_path, 'w+') do |f|
|
33
|
-
f.puts spec_doc
|
34
|
-
end
|
35
|
-
|
36
|
-
puts spec_doc
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "Run cucumber"
|
41
|
-
task(:cucumber) { sh 'cucumber' }
|
42
|
-
|
43
|
-
desc 'Default: run specs.'
|
8
|
+
desc 'Default: run specs and features.'
|
44
9
|
task :default => [:spec, :cucumber]
|
data/bin/sprites
CHANGED
@@ -3,16 +3,14 @@
|
|
3
3
|
require 'sprites'
|
4
4
|
require 'sprites/cli'
|
5
5
|
|
6
|
-
include Sprites
|
7
|
-
|
8
6
|
begin
|
9
|
-
options = CommandLineOptionParser.new(ARGV)
|
7
|
+
options = Sprites::CommandLineOptionParser.new(ARGV)
|
10
8
|
options.parse
|
11
9
|
|
12
10
|
sprite_definition_file_path = options.definition_file_path
|
13
|
-
configuration = Configuration.new_for_command_line_options(options.options)
|
11
|
+
configuration = Sprites::Configuration.new_for_command_line_options(options.options)
|
14
12
|
|
15
|
-
CliApplication.run(sprite_definition_file_path, configuration)
|
16
|
-
rescue CliApplication::DefinitionFileNotFound
|
17
|
-
abort 'No Sprite Definition File found. Please supply a path or place your definition file in `pwd
|
13
|
+
Sprites::CliApplication.run(sprite_definition_file_path, configuration)
|
14
|
+
rescue Sprites::CliApplication::DefinitionFileNotFound
|
15
|
+
abort 'No Sprite Definition File found. Please supply a path or place your definition file in `pwd/config`'
|
18
16
|
end
|
data/features/cli.feature
CHANGED
@@ -7,5 +7,5 @@ Feature: Creating sprites and stylesheets
|
|
7
7
|
Given a project folder
|
8
8
|
And it contains a sprites dsl definition file
|
9
9
|
And it contains sprite images
|
10
|
-
When I run the executable "sprites"
|
10
|
+
When I run the executable "sprites" with flags "-r spec/fixtures/project1"
|
11
11
|
Then I should get valid sprites
|
@@ -14,23 +14,25 @@ Given(/^it contains sprite images$/) do
|
|
14
14
|
Dir['public/images/sprite_images/**/*.png'].should_not be_empty
|
15
15
|
end
|
16
16
|
|
17
|
-
When
|
18
|
-
`#{GEM_ROOT}/bin/#{bin}`
|
17
|
+
When /^I run the executable "([^"]*)" with flags "([^"]*)"$/ do |bin, flags|
|
18
|
+
`#{GEM_ROOT}/bin/#{bin} #{flags}`
|
19
19
|
$?.to_i.should be(0)
|
20
20
|
end
|
21
21
|
|
22
22
|
Then(/^I should get valid sprites$/) do
|
23
|
-
options = CommandLineOptionParser.new($*)
|
23
|
+
options = Sprites::CommandLineOptionParser.new($*)
|
24
24
|
options.parse
|
25
25
|
|
26
26
|
sprite_definition_file_path = options.definition_file_path
|
27
|
-
configuration = Configuration.new_for_command_line_options(options.options)
|
27
|
+
configuration = Sprites::Configuration.new_for_command_line_options(options.options)
|
28
28
|
|
29
|
-
|
29
|
+
sprites = Sprites.new
|
30
|
+
sprites.configure configuration.to_options
|
31
|
+
sprites.load
|
30
32
|
|
31
|
-
tester = SpriteGeneratorTester.new(
|
33
|
+
tester = Sprites::SpriteGeneratorTester.new(sprites[:buttons])
|
32
34
|
tester.should be_accurate
|
33
35
|
|
34
|
-
FileUtils.rm
|
35
|
-
FileUtils.rm
|
36
|
+
FileUtils.rm sprites[:buttons].path
|
37
|
+
FileUtils.rm sprites[:buttons].stylesheet_path
|
36
38
|
end
|
data/lib/sprites.rb
CHANGED
@@ -2,32 +2,142 @@ require 'active_support'
|
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
require "sprites/version"
|
4
4
|
|
5
|
-
|
5
|
+
require 'forwardable'
|
6
|
+
|
7
|
+
class Sprites
|
6
8
|
extend ActiveSupport::Autoload
|
7
9
|
|
8
|
-
autoload :Application
|
9
10
|
autoload :Configuration
|
10
|
-
autoload :Sprites
|
11
11
|
autoload :Sprite
|
12
12
|
autoload :SpritePieces
|
13
13
|
autoload :SpritePiece
|
14
14
|
autoload :Stylesheet
|
15
15
|
autoload :ChunkyPngGenerator, 'sprites/sprite_generators/chunky_png_generator'
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
include Enumerable
|
18
|
+
extend Forwardable
|
19
|
+
def_delegators :@sprites, :clear, :empty?, :count, :[]
|
20
|
+
|
21
|
+
attr_reader :configuration
|
22
|
+
|
23
|
+
def initialize(configuration = Configuration.new)
|
24
|
+
@configuration = configuration
|
25
|
+
|
26
|
+
@sprites = Hash.new do |sprites, name|
|
27
|
+
sprites[name] = Sprite.new(name, self)
|
20
28
|
end
|
29
|
+
@loaded = false
|
30
|
+
end
|
21
31
|
|
22
|
-
|
23
|
-
|
32
|
+
def [](sprite_identifier)
|
33
|
+
@sprites[sprite_identifier] if @sprites.has_key?(sprite_identifier)
|
34
|
+
end
|
35
|
+
|
36
|
+
def each(&blk)
|
37
|
+
@sprites.values.each(&blk)
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure(options)
|
41
|
+
configuration.configure(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# The +sprite+ method adds sprites to the sprites collection
|
45
|
+
#
|
46
|
+
# === Examples ===
|
47
|
+
# sprite :foo
|
48
|
+
# sprite :foo, :orientation => :horizontal, :css_prefix => '.foo '
|
49
|
+
#
|
50
|
+
# options:
|
51
|
+
# => :orientation - sprite orientation
|
52
|
+
# default: :vertical
|
53
|
+
# => :path - path to which to write the sprite relative to config.sprites_path
|
54
|
+
# default: public/images/sprites/{name}.png
|
55
|
+
# => :stylesheet_path - path to which to write the stylesheet relative to config.sprite_stylesheets_path
|
56
|
+
# default: public/stylesheets/sprites/{name}.css
|
57
|
+
# => :url - path to use in background attribute in stylesheet
|
58
|
+
# default: /images/sprites/{name}.png
|
59
|
+
# => :autoload - whether or not to auto-define the sprite based on directory contents
|
60
|
+
# default: true
|
61
|
+
# => :css_prefix - a css string to prepend to all css classes define or autogenerated
|
62
|
+
# examples: '.icon', '.contacts '
|
63
|
+
# default: ''
|
64
|
+
#
|
65
|
+
def sprite(name, options = {}, &blk)
|
66
|
+
sprite = @sprites[name.to_sym]
|
67
|
+
sprite.configure(options, &blk)
|
68
|
+
end
|
69
|
+
|
70
|
+
def add(sprite)
|
71
|
+
@sprites[sprite.name] = sprite
|
72
|
+
end
|
73
|
+
|
74
|
+
def loaded?
|
75
|
+
@loaded
|
76
|
+
end
|
77
|
+
|
78
|
+
def load
|
79
|
+
return if loaded?
|
80
|
+
if configuration.definition_file
|
81
|
+
load_file configuration.definition_file
|
82
|
+
elsif configuration.autoload
|
83
|
+
auto_load
|
24
84
|
end
|
85
|
+
@loaded = true
|
86
|
+
end
|
25
87
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@configuration
|
88
|
+
def auto_load
|
89
|
+
Dir[File.join(configuration.sprite_pieces_path, '*')].each do |sprite_path|
|
90
|
+
sprite(File.basename(sprite_path).intern) if File.directory?(sprite_path)
|
30
91
|
end
|
31
|
-
|
92
|
+
end
|
93
|
+
|
94
|
+
def load_file(path)
|
95
|
+
instance_eval File.read(path), path, 0
|
96
|
+
end
|
97
|
+
|
98
|
+
alias define instance_eval
|
99
|
+
public :define
|
100
|
+
|
101
|
+
def reset!
|
102
|
+
clear
|
103
|
+
@configuration = Configuration.new
|
104
|
+
@loaded = false
|
105
|
+
end
|
106
|
+
|
107
|
+
def all_files
|
108
|
+
files = {}
|
109
|
+
|
110
|
+
all_files = []
|
111
|
+
if configuration.definition_file
|
112
|
+
files[configuration.definition_file] = all_files
|
113
|
+
end
|
114
|
+
|
115
|
+
@sprites.each do |name, sprite|
|
116
|
+
all_files.concat sprite.all_sprite_piece_files
|
117
|
+
files[sprite.stylesheet_path] = sprite.all_sprite_piece_files
|
118
|
+
files[sprite.path] = sprite.all_sprite_piece_files
|
119
|
+
end
|
120
|
+
|
121
|
+
all_files.uniq!
|
122
|
+
|
123
|
+
files
|
124
|
+
end
|
125
|
+
|
126
|
+
def generate(generator = configuration.generator)
|
127
|
+
generator.new(self).generate
|
128
|
+
end
|
129
|
+
|
130
|
+
def define_file_tasks(task_name = :sprites)
|
131
|
+
extend Rake::DSL
|
132
|
+
all_files.each do |output, inputs|
|
133
|
+
FileList[inputs]
|
134
|
+
file output => inputs do
|
135
|
+
# XXX this will currently run once per output, we need to fix that.
|
136
|
+
generate
|
137
|
+
end
|
138
|
+
end
|
139
|
+
task task_name => all_files.keys
|
32
140
|
end
|
33
141
|
end
|
142
|
+
|
143
|
+
require 'sprites/railtie' if defined?(Rails)
|
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
class Sprites
|
2
2
|
class CliApplication
|
3
3
|
class DefinitionFileNotFound < StandardError; end
|
4
4
|
|
5
5
|
def self.run(def_file, configuration)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
sprites = Sprites.new
|
7
|
+
sprites.configure(configuration.to_options)
|
8
|
+
sprites.load
|
9
|
+
sprite_generator = ChunkyPngGenerator.new(sprites)
|
10
|
+
sprite_generator.generate
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,14 +1,13 @@
|
|
1
|
+
require 'pathname'
|
1
2
|
require 'optparse'
|
2
3
|
|
3
|
-
|
4
|
+
class Sprites
|
4
5
|
class CommandLineOptionParser < OptionParser
|
5
|
-
PRIMARY_DEF_FILE_LOCATION = 'config/sprites.rb'
|
6
|
-
SECONDARY_DEF_FILE_LOCATION = 'sprites.rb'
|
7
|
-
|
8
6
|
attr_reader :definition_file_path, :options
|
9
7
|
|
10
8
|
def initialize(arguments)
|
11
|
-
@
|
9
|
+
@arguments, @raw_arguments = arguments.clone, arguments
|
10
|
+
@definition_file_path = extract_sprite_definition_file_path(@arguments)
|
12
11
|
@options = Hash.new
|
13
12
|
|
14
13
|
super do |opts|
|
@@ -17,25 +16,19 @@ module Sprites
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def parse
|
20
|
-
super(@
|
19
|
+
super(@raw_arguments)
|
21
20
|
end
|
22
21
|
|
23
22
|
def extract_sprite_definition_file_path(arguments)
|
24
23
|
sprite_def_file_pathname = if arguments[0] =~ %r{^.+\.rb}
|
25
24
|
Pathname(arguments.shift)
|
26
|
-
elsif
|
27
|
-
Pathname(
|
25
|
+
elsif File.exists?(path = File.join(Dir.pwd, 'config/sprites.rb'))
|
26
|
+
Pathname(path)
|
28
27
|
else
|
29
|
-
raise
|
28
|
+
raise CliApplication::DefinitionFileNotFound
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
rescue
|
34
|
-
raise CliApplication::DefinitionFileNotFound
|
35
|
-
end
|
36
|
-
|
37
|
-
def file_exists?(path)
|
38
|
-
Pathname(path).exist?
|
31
|
+
sprite_def_file_pathname.realpath.to_s
|
39
32
|
end
|
40
33
|
|
41
34
|
def setup_parser(opts)
|
@@ -44,6 +37,13 @@ module Sprites
|
|
44
37
|
opts.separator ""
|
45
38
|
opts.separator "Specific options:"
|
46
39
|
|
40
|
+
opts.on("-r", "--project_root", <<-EOS
|
41
|
+
Define the path to the root of the project. DEFAULT: pwd
|
42
|
+
EOS
|
43
|
+
) do |path|
|
44
|
+
@options[:project_root] = path || Dir.pwd
|
45
|
+
end
|
46
|
+
|
47
47
|
opts.on("-s", "--sprites_path", <<-EOS
|
48
48
|
Define the path to where the sprites should be placed. DEFAULT: 'public/images/sprites'
|
49
49
|
EOS
|