spriter 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.markdown +69 -0
  2. data/Rakefile +3 -5
  3. data/lib/rack/spriter.rb +27 -7
  4. metadata +7 -8
  5. data/README +0 -0
data/README.markdown ADDED
@@ -0,0 +1,69 @@
1
+ # Spriter #
2
+
3
+ [CSS sprites][1] are a simple way of combining lots of small images into a single large image and reducing the number of HTTP requests a web page has to make. Spriter makes it easy to create and maintain CSS sprites in Ruby apps.
4
+
5
+ You just write some modified CSS rules in a `.spriter` file:
6
+
7
+ span.icon {
8
+ color: red;
9
+ -spriter-background: 'example.png';
10
+ }
11
+
12
+ And then run all your `.spriter` files through Spriter to get some `.css` files and a shared sprite image:
13
+
14
+ span.icon {
15
+ color: red;
16
+ background: url(/images/sprites.png) no-repeat 0 -98px; /* example.png */
17
+ }
18
+
19
+ The conversion can take place dynamically whenever the CSS files are requested using a handy [Rack][2] middleware (useful for development) or static files can be generated using a few lines of Ruby (as part of your deploy scripts, for example).
20
+
21
+ ## Dependancies ##
22
+
23
+ You must have [Image Magick][3] installed, and the `convert` command must be in the path of the user or app that is using Spriter.
24
+
25
+ ## Usage ##
26
+
27
+ ### Middleware ###
28
+
29
+ Just add the `Rack::Spriter` middleware to your rack stack. For example, in a Rails app you would add this line to your `environment.rb`:
30
+
31
+ config.middleware.use 'Rack::Spriter'
32
+
33
+ You can pass a hash of options to the middleware, using these keys:
34
+
35
+ * `:sprite_image_path` - the path to write the sprite image to (Rails default: `'RAILS_ROOT/public/images/sprites.png'`)
36
+ * `:sprite_image_url` - the URL of the sprite image that will be used in the generated CSS files (default: `'/images/sprites.png'`)
37
+ * `:stylesheets_url_pattern` - URLs matching this pattern will trigger the middleware (default: `/stylesheets\/(.+)\.css$/`)
38
+ * `:stylesheets_path` - the directory to look for .spriter files in (Rails default: `'RAILS_ROOT/pubic/stylesheets'`)
39
+ * `:assets_path` - the directory to look for source images in (Rails default: `'RAILS_ROOT/public/images/sprite_assets'`)
40
+
41
+ ### Generating static CSS files ###
42
+
43
+ To generate static CSS files, you can pass an array of paths to `.spriter` files into the `transform_files` method. A `.css` equivalent for each `.spriter` file and a shared sprites image will be created.
44
+
45
+ The CSS files will be created in the same directories as the `.spriter` source files. The paths for the source images and generated sprite image should be set using the following options before calling `transform_files`:
46
+
47
+ * `Spriter.assets_path` - the directory to look for source images in
48
+ * `Spriter.sprite_image_path` - the path to write the sprite image to
49
+ * `Spriter.sprite_image_url` - the URL of the sprite image that will be used in the generated CSS files
50
+
51
+ For example:
52
+
53
+ Spriter.assets_path = '/example_app/public/images/sprite_assets'
54
+ Spriter.sprite_image_path = '/example_app/public/images/sprites.png'
55
+ Spriter.sprite_image_url = '/images/sprites.png'
56
+
57
+ paths = Dir.glob('/my/example/app/public/stylesheets/*.spriter').sort
58
+ Spriter.transform_files(*paths)
59
+
60
+ ## License ##
61
+
62
+ Copyright Revieworld Ltd. 2010
63
+
64
+ You may use, copy and redistribute this library under the same terms as [Ruby itself][4] or under the MIT license.
65
+
66
+ [1]: http://www.alistapart.com/articles/sprites/
67
+ [2]: http://rack.rubyforge.org/
68
+ [3]: http://www.imagemagick.org/
69
+ [4]: http://www.ruby-lang.org/en/LICENSE.txt
data/Rakefile CHANGED
@@ -14,17 +14,15 @@ spec = Gem::Specification.new do |s|
14
14
 
15
15
  # Change these as appropriate
16
16
  s.name = "spriter"
17
- s.version = "0.6.0"
17
+ s.version = "0.7.0"
18
18
  s.summary = "Managers sprites and your css in a mega way."
19
19
  s.author = "Reevoo"
20
20
  s.homepage = "http://www.reevoo.com"
21
21
 
22
- s.has_rdoc = true
23
- s.extra_rdoc_files = %w(README)
24
- s.rdoc_options = %w(--main README)
22
+ s.has_rdoc = false
25
23
 
26
24
  # Add any extra files to include in the gem (like your README)
27
- s.files = %w(Rakefile) + Dir.glob("{test,lib/**/*}")
25
+ s.files = %w(Rakefile) + Dir.glob("{README*,test,lib/**/*}")
28
26
  s.require_paths = ["lib"]
29
27
 
30
28
  s.add_development_dependency("shoulda")
data/lib/rack/spriter.rb CHANGED
@@ -6,10 +6,30 @@ module Rack
6
6
  File = ::File
7
7
 
8
8
  def initialize(app, options = {})
9
+ options = default_options.merge(options)
9
10
  @app = app
10
- ::Spriter.assets_path = options[:assets_path] || File.join(Rails.root, *%w[ public images sprite_assets ])
11
- ::Spriter.sprite_image_path = options[:sprite_image_path] || File.join(Rails.root, *%w[ public images sprites.png ])
12
- ::Spriter.sprite_image_url = options[:sprite_image_url] || '/images/sprites.png'
11
+ @stylesheets_path = options[:stylesheets_path]
12
+ @stylesheets_url_pattern = options[:stylesheets_url_pattern]
13
+ ::Spriter.assets_path = options[:assets_path]
14
+ ::Spriter.sprite_image_path = options[:sprite_image_path]
15
+ ::Spriter.sprite_image_url = options[:sprite_image_url]
16
+ end
17
+
18
+ def default_options
19
+ defaults = {
20
+ :sprite_image_url => '/images/sprites.png',
21
+ :stylesheets_url_pattern => %r{stylesheets\/(.+)\.css$}
22
+ }
23
+
24
+ if defined? Rails
25
+ defaults.merge(
26
+ :stylesheets_path => File.join(Rails.root, *%w[ public stylesheets ]),
27
+ :assets_path => File.join(Rails.root, *%w[ public images sprite_assets ]),
28
+ :sprite_image_path => File.join(Rails.root, *%w[ public images sprites.png ])
29
+ )
30
+ else
31
+ defaults
32
+ end
13
33
  end
14
34
 
15
35
  def call(env)
@@ -22,20 +42,20 @@ module Rack
22
42
 
23
43
  private
24
44
  def generate_css(env)
25
- if Rack::Request.new(env).path =~ %r{stylesheets\/(.+)\.css$}
45
+ if Rack::Request.new(env).path =~ @stylesheets_url_pattern
26
46
  name = $1
27
- spriter_path = File.join(Rails.root, 'public', 'stylesheets', "#{name}.spriter")
47
+ spriter_path = File.join(@stylesheets_path, "#{name}.spriter")
28
48
  generated_css($1) if File.exist? spriter_path
29
49
  end
30
50
  end
31
51
 
32
52
  def generated_css(name)
33
- paths = Dir.glob(File.join(Rails.root, 'public', 'stylesheets', '*.spriter'))
53
+ paths = Dir.glob(File.join(@stylesheets_path, '*.spriter'))
34
54
  paths.sort!
35
55
  files = paths.map{ |p| File.new(p, 'r') }
36
56
 
37
57
  if @generated_css.nil? or files.max{ |a,b| a.mtime <=> b.mtime }.mtime > @generated_at
38
- names = paths.map{ |p| p =~ %r{stylesheets/(.+)\.spriter$}; $1 }
58
+ names = paths.map{ |p| p =~ %r{([^/]+)\.spriter$}; $1 }
39
59
  css = ::Spriter.transform(*files)
40
60
  css = [css] unless css.is_a? Array
41
61
  @generated_at = Time.now
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spriter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reevoo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-26 00:00:00 +00:00
12
+ date: 2010-02-04 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,21 +28,20 @@ executables: []
28
28
 
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files:
32
- - README
31
+ extra_rdoc_files: []
32
+
33
33
  files:
34
34
  - Rakefile
35
+ - README.markdown
35
36
  - lib/rack/spriter.rb
36
37
  - lib/spriter.rb
37
- - README
38
38
  has_rdoc: true
39
39
  homepage: http://www.reevoo.com
40
40
  licenses: []
41
41
 
42
42
  post_install_message:
43
- rdoc_options:
44
- - --main
45
- - README
43
+ rdoc_options: []
44
+
46
45
  require_paths:
47
46
  - lib
48
47
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
File without changes