sprite 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +50 -0
  3. data/README.md +27 -23
  4. data/Rakefile +37 -20
  5. data/lib/sprite.rb +5 -0
  6. data/lib/sprite/builder.rb +90 -101
  7. data/lib/sprite/config.rb +48 -0
  8. data/lib/sprite/image_combiner.rb +17 -10
  9. data/lib/sprite/image_config.rb +40 -0
  10. data/lib/sprite/image_reader.rb +14 -0
  11. data/lib/sprite/image_resizer.rb +19 -0
  12. data/lib/sprite/image_writer.rb +29 -0
  13. data/lib/sprite/runner.rb +6 -4
  14. data/lib/sprite/sass_extensions.rb +93 -48
  15. data/lib/sprite/styles.rb +3 -1
  16. data/lib/sprite/styles/css_generator.rb +19 -15
  17. data/lib/sprite/styles/sass_generator.rb +5 -4
  18. data/lib/sprite/styles/sass_mixin_generator.rb +7 -7
  19. data/lib/sprite/styles/sass_yml_generator.rb +15 -16
  20. data/lib/sprite/styles/templated_css_generator.rb +41 -0
  21. data/spec/output/android_horizontal/images/sprites/android-icons.png +0 -0
  22. data/spec/output/android_horizontal/stylesheets/android-icons.css +1 -0
  23. data/spec/output/android_vertical/images/sprites/android-icons.png +0 -0
  24. data/spec/output/android_vertical/stylesheets/android-icons.css +1 -0
  25. data/spec/resources/android_css.erb +5 -0
  26. data/spec/resources/configs/android-icons.yml +19 -0
  27. data/spec/resources/configs/config-test.yml +26 -0
  28. data/spec/resources/images/android-icons/LICENSE +1 -0
  29. data/spec/resources/images/android-icons/barcode.png +0 -0
  30. data/spec/resources/images/android-icons/cards.png +0 -0
  31. data/spec/resources/images/android-icons/chart.png +0 -0
  32. data/spec/resources/images/android-icons/clock.png +0 -0
  33. data/spec/resources/images/android-icons/cloud.png +0 -0
  34. data/spec/resources/images/android-icons/colour-picker.png +0 -0
  35. data/spec/resources/images/android-icons/dialog.png +0 -0
  36. data/spec/resources/images/android-icons/dice.png +0 -0
  37. data/spec/resources/images/android-icons/disc.png +0 -0
  38. data/spec/resources/images/android-icons/equalizer.png +0 -0
  39. data/spec/resources/images/android-icons/filter.png +0 -0
  40. data/spec/resources/images/android-icons/flag.png +0 -0
  41. data/spec/resources/images/android-icons/flash.png +0 -0
  42. data/spec/resources/images/android-icons/globe.png +0 -0
  43. data/spec/resources/images/android-icons/happy.png +0 -0
  44. data/spec/resources/images/android-icons/large-tiles.png +0 -0
  45. data/spec/resources/images/android-icons/light.png +0 -0
  46. data/spec/resources/images/android-icons/love.png +0 -0
  47. data/spec/resources/images/android-icons/magnet.png +0 -0
  48. data/spec/resources/images/android-icons/monitor.png +0 -0
  49. data/spec/resources/images/android-icons/music.png +0 -0
  50. data/spec/resources/images/android-icons/pie-chart.png +0 -0
  51. data/spec/resources/images/android-icons/ruler.png +0 -0
  52. data/spec/resources/images/android-icons/sad.png +0 -0
  53. data/spec/resources/images/android-icons/seal.png +0 -0
  54. data/spec/resources/images/android-icons/shopping.png +0 -0
  55. data/spec/resources/images/android-icons/small-tiles.png +0 -0
  56. data/spec/resources/images/android-icons/sun.png +0 -0
  57. data/spec/resources/images/android-icons/tag.png +0 -0
  58. data/spec/resources/images/android-icons/umbrella.png +0 -0
  59. data/spec/resources/images/topics/good-topic.gif +0 -0
  60. data/spec/resources/images/topics/mid-topic.gif +0 -0
  61. data/spec/spec_helper.rb +32 -0
  62. data/spec/sprite/builder_spec.rb +76 -0
  63. data/spec/sprite/config_spec.rb +64 -0
  64. data/spec/sprite/image_combiner_spec.rb +40 -0
  65. data/spec/sprite/image_reader_spec.rb +16 -0
  66. data/spec/sprite/styles/css_spec.rb +0 -0
  67. data/spec/sprite/styles/sass_mixin_spec.rb +0 -0
  68. data/spec/sprite/styles/sass_spec.rb +0 -0
  69. data/sprite.gemspec +30 -49
  70. metadata +142 -21
  71. data/VERSION +0 -1
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem "rake"
5
+
6
+ gem "ruby-debug", :platforms => :mri_18
7
+ gem "ruby-debug19", :platforms => :mri_19
8
+
9
+ gem "rmagick"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sprite (0.2.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ archive-tar-minitar (0.5.2)
10
+ columnize (0.3.2)
11
+ diff-lcs (1.1.2)
12
+ linecache (0.43)
13
+ linecache19 (0.5.11)
14
+ ruby_core_source (>= 0.1.4)
15
+ rake (0.8.7)
16
+ rmagick (2.13.1)
17
+ rspec (2.5.0)
18
+ rspec-core (~> 2.5.0)
19
+ rspec-expectations (~> 2.5.0)
20
+ rspec-mocks (~> 2.5.0)
21
+ rspec-core (2.5.1)
22
+ rspec-expectations (2.5.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.5.0)
25
+ ruby-debug (0.10.4)
26
+ columnize (>= 0.1)
27
+ ruby-debug-base (~> 0.10.4.0)
28
+ ruby-debug-base (0.10.4)
29
+ linecache (>= 0.3)
30
+ ruby-debug-base19 (0.11.24)
31
+ columnize (>= 0.3.1)
32
+ linecache19 (>= 0.5.11)
33
+ ruby_core_source (>= 0.1.4)
34
+ ruby-debug19 (0.11.6)
35
+ columnize (>= 0.3.1)
36
+ linecache19 (>= 0.5.11)
37
+ ruby-debug-base19 (>= 0.11.19)
38
+ ruby_core_source (0.1.4)
39
+ archive-tar-minitar (>= 0.5.2)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ rake
46
+ rmagick
47
+ rspec (~> 2.0)
48
+ ruby-debug
49
+ ruby-debug19
50
+ sprite!
data/README.md CHANGED
@@ -13,21 +13,20 @@
13
13
  if you have any problems with the rmagick gem, install imagemagick via macports first:
14
14
 
15
15
  sudo port install libxml2
16
- sudo port install ImageMagick
16
+ sudo port install ImageMagick
17
17
 
18
18
  or via installer: http://github.com/maddox/magick-installer/tree/master
19
19
 
20
20
  ### Install the `sprite` gem ###
21
21
 
22
- Install the `sprite` gem from gemcutter
22
+ Install the `sprite` gem
23
23
 
24
- gem sources -a http://gemcutter.org
25
24
  gem install sprite
26
25
 
27
26
  ## USAGE ##
28
27
 
29
- if installed as a gem, at your root project folder you can just run
30
-
28
+ if installed as a gem, at your root project folder you can just run
29
+
31
30
  sprite
32
31
 
33
32
  ### Intelligent Defaults ###
@@ -35,7 +34,7 @@ if installed as a gem, at your root project folder you can just run
35
34
  Without having to configure anything, `sprite` will allow you to easily generate sprites based on a couple default folder settings we give you right off the bat.
36
35
 
37
36
  For example, given you have the following setup:
38
-
37
+
39
38
  public/
40
39
  images/
41
40
  sprites/
@@ -44,14 +43,14 @@ For example, given you have the following setup:
44
43
  go.png
45
44
  back.png
46
45
  forward.png
47
-
46
+
48
47
  weather/
49
48
  sunny.gif
50
49
  rainy.gif
51
50
  cloudy.gif
52
-
51
+
53
52
  Running `sprite` with no configuration file will generate the following new files:
54
-
53
+
55
54
  public/
56
55
  stylesheets/
57
56
  sprites.css
@@ -60,32 +59,37 @@ Running `sprite` with no configuration file will generate the following new file
60
59
  black-icons.png
61
60
  weather.png
62
61
 
63
- Any folders within `public/images/sprites/` will get compressed into a merged image file at the same
64
- location. Then `sprites.css` will get generated in the stylesheets folder with all the class definitions for
62
+ Any folders within `public/images/sprites/` will get compressed into a merged image file at the same
63
+ location. Then `sprites.css` will get generated in the stylesheets folder with all the class definitions for
65
64
  these files. Just add a link to `sprites.css` into your html <head> and you're ready to go!
66
65
 
67
66
 
68
67
  ## CONFIGURATION ##
69
68
 
70
69
  Configuration of `sprite` is done via `config/sprite.yml`. It allows you to set sprite configuration options, and fine tune exactly which sprites get generated where.
71
-
70
+
72
71
  * `config:` section defines all the global properties for sprite generation. Such as how it generates the styles, where it looks for images, where it writes it output file to, and what image file format it uses by default
73
72
  - `style:` defines how the style rules are outputted. built in options are `css`, `sass`, and `sass_mixin`. (defaults to `css`)
74
- - `style_output_path:` defines the file path where your style settings get written (defaults to `stylesheets/sprites`). the file extension not needed as it will be set based on the `style:` setting
73
+ - `style_output_path:` defines the file path where your style settings get written (defaults to `stylesheets/sprites`). the file extension not needed as it will be set based on the `style:` setting
75
74
  - `image_output_path:` defines the folder path where the combined sprite images files are written (defaults to `images/sprites/`)
75
+ - `css_image_path:` defines the path used in css to find sprite image files (defaults to `/images/sprites/`)
76
76
  - `image_source_path:` defines the folder where source image files are read from (defaults to `images/`)
77
77
  - `public_path:` defines the root folder where static assets live (defaults to `public/`)
78
78
  - `sprites_class:` defines the class name that gets added to all sprite stylesheet rules (defaults to `sprites`)
79
79
  - `default_format:` defines the default file image format of the generated files. (defaults to `png`)
80
80
  - `default_spacing:` defines the default pixel spacing between sprites (defaults to 0)
81
+ - `resize_to:` width and height (in the format "120x60") to resize all source images to before composition. (defaults to no nil, or no resizing)
81
82
  - `class_separator:` used to generated the class name by separating the image name and sprite name (defaults to `-`)
82
83
  - `add_datestamps`: whether or not to add datestamps to the generated background image urls. this will allow proper cache versioning (defaults to `true`)
83
-
84
+ - `external_base`: change the base path for your images. (defaults to `/`)
85
+ - `url_helper`: css helper used to specify the url (defaults to `url`). For compass, you can set this to image-url instead
86
+
84
87
  * `images:` section provides an array of configurations which define which image files are built, and where they get their sprites from. each image setup provides the following config options:
85
88
  - `name:` name of image (required)
86
89
  - `sources:` defines a list of source image filenames to build the target image from (required). They are parsed by <code>Dir.glob</code>
87
90
  - `align:` defines the composite gravity type, horizontal or vertical. (defaults to `vertical`)
88
91
  - `spaced_by:` spacing (in pixels) between the combined images. (defaults to `0`)
92
+ - `resize_to:` width and height (in the format "120x60") to resize all source images to before composition. (defaults to no nil, or no resizing)
89
93
  - `format:` define what image file format gets created (optional, uses `default_format` setting if not set)
90
94
 
91
95
  All image and style paths should be set relative to the public folder (which is configurable via public_path setting).
@@ -104,9 +108,9 @@ All image and style paths should be set relative to the public folder (which is
104
108
  class_separator: '-'
105
109
  default_format: png
106
110
  default_spacing: 50
107
-
111
+
108
112
  # defines what sprite collections get created
109
- images:
113
+ images:
110
114
 
111
115
  # creates a public/images/sprites/blue_stars.png image with 4 sprites in it
112
116
  - name: blue_stars
@@ -118,8 +122,8 @@ All image and style paths should be set relative to the public folder (which is
118
122
  - icons/blue-stars/medium.png
119
123
  - icons/blue-stars/large.png
120
124
  - icons/blue-stars/xlarge.png
121
-
122
- # creates a public/images/sprites/green-stars.jpg image with
125
+
126
+ # creates a public/images/sprites/green-stars.jpg image with
123
127
  # all the gif files contained within /images/icons/green-stars/
124
128
  - name: green_stars
125
129
  format: png
@@ -154,18 +158,18 @@ By default, it will use with `style: css` and generate the file at `public/style
154
158
  }
155
159
 
156
160
  We also support mixin syntax via `style: sass_mixin`. If set, it will generate a SASS mixin which you can use in order to mix in these sprites anywhere within your SASS stylesheets. For this option, set `style_output_path:` to `stylesheets/sass/_sprites` in order to generate the sass mixin file at `stylesheets/sass/_sprites.sass`
157
-
161
+
158
162
  @import "sass/mixins/sprites.sass"
159
-
163
+
160
164
  // you can then use your sprite like this
161
165
  .largebluestar
162
166
  +sprite("blue-stars", "large")
163
167
 
164
168
  .mysmallbluestar
165
169
  +sprite("blue-stars", "small")
166
-
170
+
167
171
  Additional style generators are very easy to add. We have one for `style: sass` and `style: sass_ext`. The `sass_ext` style is a work in progress, as it's attempting to write the sprite data to yml and use a dynamic sass extension to provide the mixin. Eventually, if it works, this will be the default for `sass_mixin`
168
-
172
+
169
173
  ## Framework Integration?? ##
170
174
 
171
175
  `sprite` is provided as a command line helper. Deep web framework integration is not implemented at this time, however it shouldn't be needed. Just generate your sprites on your dev machine by running the command line, check in the resulting sprite images and stylesheets to your source control, and deploy!
@@ -176,7 +180,7 @@ You can also easily script it out via capistrano. You could also run `sprite` on
176
180
 
177
181
  `sprite` was originally based off of Richard Huang's excellent Rails plugin: [css_sprite](http://github.com/flyerhzm/css_sprite)
178
182
 
179
- Since then it's been rebuilt (with some reuse of the image generation code) to be a general purpose ruby executable, with hooks for merb/rails/sinatra
183
+ Since then it's been rebuilt (with some reuse of the image generation code) to be a general purpose ruby executable.
180
184
 
181
185
 
182
186
  ## LICENSE ##
data/Rakefile CHANGED
@@ -1,27 +1,44 @@
1
+ # encoding: UTF-8
2
+ require "bundler"
3
+ Bundler.setup
4
+
1
5
  require 'rake'
2
- require 'spec/rake/spectask'
3
- require 'jeweler'
6
+ require 'rake/gempackagetask'
7
+
8
+ gemspec = eval(File.read('sprite.gemspec'))
9
+ Rake::GemPackageTask.new(gemspec) do |pkg|
10
+ pkg.gem_spec = gemspec
11
+ end
12
+
13
+ desc "build the gem and release it to rubygems.org"
14
+ task :release => :gem do
15
+ puts "Tagging #{gemspec.version}..."
16
+ system "git tag -a #{gemspec.version} -m 'Tagging #{gemspec.version}'"
17
+ puts "Pushing to Github..."
18
+ system "git push --tags"
19
+ puts "Pushing to rubygems.org..."
20
+ system "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
21
+ end
22
+
23
+ require "rspec"
24
+ require "rspec/core/rake_task"
4
25
 
5
- desc 'Default: run unit tests.'
6
- task :default => :spec
26
+ Rspec::Core::RakeTask.new(:spec) do |spec|
27
+ spec.pattern = "spec/**/*_spec.rb"
28
+ end
7
29
 
8
- desc "Run all specs in spec directory"
9
- Spec::Rake::SpecTask.new(:spec) do |t|
10
- t.spec_files = FileList['spec/**/*_spec.rb']
30
+ Rspec::Core::RakeTask.new('spec:progress') do |spec|
31
+ spec.rspec_opts = %w(--format progress)
32
+ spec.pattern = "spec/**/*_spec.rb"
11
33
  end
12
34
 
13
- Jeweler::Tasks.new do |gemspec|
14
- gemspec.name = "sprite"
15
- gemspec.summary = "generate your css sprites automagically"
16
- gemspec.description = "sprite is a rails/merb plugin that generates sprites for css, sass"
17
- gemspec.email = "merbjedi@gmail.com"
18
- gemspec.homepage = "http://github.com/merbjedi/sprite"
19
- gemspec.authors = ["Jacques Crocker"]
20
- gemspec.files.exclude '.gitignore'
21
-
22
- # removing test files and specs from the gem to save space
23
- gemspec.files -= Dir.glob("spec/**/*")
24
- gemspec.test_files = []
35
+ require "rake/rdoctask"
36
+ Rake::RDocTask.new do |rdoc|
37
+ rdoc.rdoc_dir = "rdoc"
38
+ rdoc.title = "Sprite #{gemspec.version}"
39
+ rdoc.rdoc_files.include("README*")
40
+ rdoc.rdoc_files.include("lib/**/*.rb")
25
41
  end
26
- Jeweler::GemcutterTasks.new
27
42
 
43
+
44
+ task :default => :spec
data/lib/sprite.rb CHANGED
@@ -19,5 +19,10 @@ module Sprite
19
19
  end
20
20
 
21
21
  require 'sprite/builder'
22
+ require 'sprite/config'
22
23
  require 'sprite/image_combiner'
24
+ require 'sprite/image_config'
25
+ require 'sprite/image_reader'
26
+ require 'sprite/image_resizer'
27
+ require 'sprite/image_writer'
23
28
  require 'sprite/styles'
@@ -1,138 +1,157 @@
1
1
  require 'fileutils'
2
2
  module Sprite
3
- class Builder
4
- DEFAULT_CONFIG_PATH = 'config/sprite.yml'
5
-
3
+ class Builder
6
4
  attr_reader :config
7
5
  attr_reader :images
8
-
9
- def self.from_config(path = nil)
10
- results = {}
11
- config_path = File.join(Sprite.root, path || DEFAULT_CONFIG_PATH)
12
-
13
- # read configuration
14
- if File.exists?(config_path)
15
- begin
16
- results = File.open(config_path) {|f| YAML::load(f)} || {}
17
- rescue => e
18
- puts "Error reading sprite config: #{config_path}"
19
- puts e.to_s
20
- end
21
- end
22
6
 
7
+ def self.from_config(path = nil)
8
+ results = Config.read_config(path)
23
9
  new(results["config"], results["images"])
24
10
  end
25
11
 
26
12
  def initialize(config = nil, images = nil)
27
13
  @config = config || {}
28
14
  set_config_defaults
29
-
15
+
30
16
  @images = images || []
31
- set_image_defaults
17
+ if @images.empty?
18
+ @images = default_images
19
+ end
32
20
  expand_image_paths
33
21
 
34
22
  # initialize datestamp
35
23
  @datestamp_query = "?#{Time.now.to_i}" if @config["add_datestamps"]
36
-
24
+
37
25
  # initialize sprite files
38
26
  @sprite_files = {}
39
27
  end
40
-
41
- def build
28
+
29
+ def build
42
30
  @sprite_files = {}
43
-
31
+
44
32
  if images.size > 0
45
33
  # create images
46
34
  images.each do |image|
47
35
  write_image(image)
48
36
  end
49
-
37
+
50
38
  if @sprite_files.values.length > 0
51
39
  # write css
52
40
  write_styles
53
41
  end
54
42
  end
55
43
  end
56
-
57
- protected
44
+
45
+ # get the disk path for the style output file
46
+ def style_output_path(relative = false)
47
+ style = Styles.get(config["style"]).new(self)
48
+
49
+ path = config['style_output_path']
50
+ unless path.include?(".#{style.extension}")
51
+ path = "#{path}.#{style.extension}"
52
+ end
53
+ Config.new(config).public_path(path, relative)
54
+ end
55
+
56
+ def image_path(group)
57
+ image_info = images.detect{|image| image['name'] == group}
58
+ image_config = ImageConfig.new(image_info, config)
59
+
60
+ cache_buster = "-#{config['cache_buster']}" if config['cache_buster']
61
+ sprite_file = "#{image_config.name}#{cache_buster}.#{image_config.format}"
62
+ "#{config['css_image_path']}#{sprite_file}"
63
+ end
64
+
65
+ def background_url(name)
66
+ "#{@config['url_helper']}('#{@config['external_base']}#{@config['image_output_path']}#{name}')"
67
+ end
68
+
69
+ protected
70
+
58
71
  def write_image(image)
59
72
  results = []
60
- sources = image['sources'].to_a
73
+ image_config = ImageConfig.new(image, config)
74
+ sources = image_config.sources.to_a.sort
61
75
  return unless sources.length > 0
62
-
63
- name = image['name']
64
- format = image['format'] || config["default_format"]
65
- spaced_by = image['spaced_by'] || config["default_spacing"] || 0
66
-
67
- combiner = ImageCombiner.new
68
-
69
- dest_image = combiner.get_image(sources.shift)
76
+
77
+ name = image_config.name
78
+ resizer = ImageResizer.new(image_config.resize_to)
79
+ combiner = ImageCombiner.new(image_config)
80
+
81
+ # Let's get the sprite started with the first image
82
+ first_image = ImageReader.read(sources.shift)
83
+ resizer.resize(first_image)
84
+
85
+ dest_image = first_image
70
86
  results << combiner.image_properties(dest_image).merge(:x => 0, :y => 0, :group => name)
87
+
88
+ # Now let's add the rest of the images in turn
71
89
  sources.each do |source|
72
- source_image = combiner.get_image(source)
73
- if image['align'].to_s == 'horizontal'
74
- x = dest_image.columns + spaced_by
90
+ source_image = ImageReader.read(source)
91
+ resizer.resize(source_image)
92
+ if image_config.horizontal_layout?
93
+ x = dest_image.columns + image_config.spaced_by
75
94
  y = 0
76
95
  align = "horizontal"
77
96
  else
78
97
  x = 0
79
- y = dest_image.rows + spaced_by
98
+ y = dest_image.rows + image_config.spaced_by
80
99
  align = "vertical"
81
100
  end
82
101
  results << combiner.image_properties(source_image).merge(:x => -x, :y => -y, :group => name, :align => align)
83
102
  dest_image = combiner.composite_images(dest_image, source_image, x, y)
84
103
  end
85
-
86
- # set up path
87
- path = image_output_path(name, format)
88
- FileUtils.mkdir_p(File.dirname(path))
89
-
90
- # write sprite image file to disk
91
- dest_image.write(path)
92
- @sprite_files["#{name}.#{format}#{@datestamp_query}"] = results
104
+
105
+ ImageWriter.new(config).write(dest_image, name, image_config.format, image_config.quality, image_config.background_color)
106
+
107
+ @sprite_files["#{name}.#{image_config.format}#{@datestamp_query}"] = results
93
108
  end
94
-
109
+
95
110
  def write_styles
96
- style = Styles.get(config["style"]).new(self)
97
-
98
111
  # use the absolute style output path to make sure we have the directory set up
99
- path = style_output_path(style.extension, false)
112
+ path = style_output_path
100
113
  FileUtils.mkdir_p(File.dirname(path))
101
-
114
+
102
115
  # send the style the relative path
103
- style.write(style_output_path(style.extension, true), @sprite_files)
116
+ style.write(style_output_path(true), @sprite_files)
117
+ end
118
+
119
+ def style
120
+ @style ||= Styles.get(config["style"]).new(self)
104
121
  end
105
-
122
+
106
123
  # sets all the default values on the config
107
124
  def set_config_defaults
108
125
  @config['style'] ||= 'css'
109
126
  @config['style_output_path'] ||= 'stylesheets/sprites'
110
127
  @config['image_output_path'] ||= 'images/sprites/'
128
+ @config['css_image_path'] ||= "/#{@config['image_output_path']}"
111
129
  @config['image_source_path'] ||= 'images/'
112
130
  @config['public_path'] ||= 'public/'
131
+ @config['external_base'] ||= '/'
113
132
  @config['default_format'] ||= 'png'
114
133
  @config['class_separator'] ||= '-'
115
134
  @config["sprites_class"] ||= 'sprites'
116
135
  @config["default_spacing"] ||= 0
117
-
136
+ @config['url_helper'] ||= 'url'
137
+
118
138
  unless @config.has_key?("add_datestamps")
119
139
  @config["add_datestamps"] = true
120
140
  end
121
141
  end
122
-
142
+
123
143
  # if no image configs are detected, set some intelligent defaults
124
- def set_image_defaults
125
- return unless @images.size == 0
126
-
144
+ def default_images
127
145
  sprites_path = image_source_path("sprites")
128
-
146
+ collection = []
147
+
129
148
  if File.exists?(sprites_path)
130
149
  Dir.glob(File.join(sprites_path, "*")) do |dir|
131
150
  next unless File.directory?(dir)
132
151
  source_name = File.basename(dir)
133
152
 
134
153
  # default to finding all png, gif, jpg, and jpegs within the directory
135
- images << {
154
+ collection << {
136
155
  "name" => source_name,
137
156
  "sources" => [
138
157
  File.join("sprites", source_name, "*.png"),
@@ -143,8 +162,9 @@ module Sprite
143
162
  }
144
163
  end
145
164
  end
165
+ collection
146
166
  end
147
-
167
+
148
168
  # expands out sources, taking the Glob paths and turning them into separate entries in the array
149
169
  def expand_image_paths
150
170
  # cycle through image sources and expand out globs
@@ -155,51 +175,20 @@ module Sprite
155
175
  }.flatten.compact
156
176
  end
157
177
  end
158
-
159
- # get the disk path for the style output file
160
- def style_output_path(file_ext, relative = false)
161
- path = config['style_output_path']
162
- unless path.include?(".#{file_ext}")
163
- path = "#{path}.#{file_ext}"
164
- end
165
- public_path(path, relative)
166
- end
167
-
168
- # get the disk path for a location within the image output folder
169
- def image_output_path(name, format, relative = false)
170
- path_parts = []
171
- path_parts << chop_trailing_slash(config['image_output_path']) if path_present?(config['image_output_path'])
172
- path_parts << "#{name}.#{format}"
173
- public_path(File.join(*path_parts), relative)
174
- end
175
-
178
+
176
179
  # get the disk path for an image source file
177
180
  def image_source_path(location, relative = false)
178
181
  path_parts = []
179
- path_parts << chop_trailing_slash(config["image_source_path"]) if path_present?(config['image_source_path'])
182
+ path_parts << Config.chop_trailing_slash(config["image_source_path"]) if Config.path_present?(config['image_source_path'])
180
183
  path_parts << location
181
- public_path(File.join(*path_parts), relative)
184
+ Config.new(config).public_path(File.join(*path_parts), relative)
182
185
  end
183
-
184
- # get the disk path for a location within the public folder (if set)
185
- def public_path(location, relative = false)
186
+
187
+ def style_template_source_path(image, relative = false)
188
+ location = image["style_output_template"]
186
189
  path_parts = []
187
- path_parts << Sprite.root unless relative
188
- path_parts << chop_trailing_slash(config['public_path']) if path_present?(config['public_path'])
189
190
  path_parts << location
190
-
191
- File.join(*path_parts)
192
- end
193
-
194
- # chop off the trailing slash on a directory path (if it exists)
195
- def chop_trailing_slash(path)
196
- path = path[0...-1] if path[-1] == File::SEPARATOR
197
- path
198
- end
199
-
200
- # check if the path is set
201
- def path_present?(path)
202
- path.to_s.strip != ""
191
+ Config.new(config).public_path(File.join(*path_parts), relative)
203
192
  end
204
193
  end
205
- end
194
+ end