dynamic-sprites 0.0.4 → 0.0.5

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.
@@ -31,11 +31,13 @@ end
31
31
  layout_help = "specify layout orientation ( horizontal, vertical, packed )"
32
32
  selector_help = "specify custom selector to use ( default: 'img.sprite' )"
33
33
  output_help = "specify output location for generated image ( default: <sources folder>.png )"
34
+ geometry_help = "specify geometry of single sprite image element (e.g.: 160x65)"
34
35
 
35
36
  op.on("--layout [ORIENTATION]", layout_help) {|value| options[:layout] = value }
36
37
  op.on("--selector [SELECTOR]", selector_help) {|value| options[:selector] = value }
37
38
  op.on("--output [PATH]", output_help) {|value| options[:output] = value }
38
39
  op.on("--layout [ORIENTATION]", layout_help) {|value| options[:layout] = value }
40
+ op.on("--geometry [GEOMETRY]", geometry_help) {|value| options[:geometry] = value }
39
41
 
40
42
  begin
41
43
  op.parse!(ARGV)
@@ -2,11 +2,12 @@ module DynamicSprites
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
6
6
  SUMMARY = "Responsive sprites - SASS mixin and sprite generator"
7
7
  DESCRIPTION = "Generates sass mixin and combines directory of images into one sprite"
8
8
 
9
9
  require 'find'
10
+ require 'pathname'
10
11
  require 'RMagick'
11
12
 
12
13
  require_relative 'dynamic-sprites/runner' # Controller of this module
@@ -13,74 +13,60 @@ module DynamicSprites
13
13
  # path - Pathname of directory containing source images.
14
14
  # layout - sprite layout name as a String
15
15
  #
16
- def initialize(filename, path, layout)
16
+ def initialize(filename, path, layout, geometry)
17
17
  @filename = filename
18
18
  @layout = layout
19
19
  @files = Dir.glob(File.join(path, '*')).sort.select { |e| VALID_EXTENSIONS.include?(File.extname(e)) }
20
- @images = load(@files)
21
- @canvas = canvas
20
+ @images = Magick::ImageList.new(*@files)
21
+ @geometry = Magick::Geometry.from_s(geometry) rescue default_geometry
22
22
  end
23
23
 
24
24
  # Main method for sprites generation
25
25
  #
26
26
  def run!
27
- @canvas.opacity = Magick::MaxRGB
28
- offset_x = 0
29
- offset_y = 0
30
- @images.each do |image|
31
- @canvas.composite!(image[:image], offset_x, offset_y, Magick::SrcOverCompositeOp)
32
- if @layout == 'horizontal'
33
- offset_x += image[:width]
34
- else
35
- offset_y += image[:height]
36
- end
37
- end
38
- @canvas.write(@filename)
27
+ # @canvas.opacity = Magick::MaxRGB
28
+ geometry = @geometry
29
+ tile = grid
30
+ @images.montage do |c|
31
+ c.geometry = geometry if geometry
32
+ c.background_color = 'transparent'
33
+ c.tile = tile
34
+ end.write(@filename)
39
35
  end
40
36
 
41
37
  # Returns a call to sass mixin function with default attributes
42
38
  #
43
39
  def mixin_call
44
- call = "dynamic-sprite"
40
+ call = "img.sprite\n @include dynamic-sprite"
45
41
  call << "-horizontal" if @layout == "horizontal"
46
42
  arguments = [
47
- @filename,
48
- @files.map{ |f| File.basename(f) },
49
- "#{100 / (@files.size - 1)}%",
43
+ @filename.inspect,
44
+ classess,
45
+ "#{100.0 / (@images.length - 1)}%",
50
46
  "100%",
51
- "#{100 * @images.first[:height] / @images.first[:width]}%"
47
+ "#{100.0 * @geometry.height / @geometry.width}%"
52
48
  ]
53
49
  call << "(#{arguments.join(', ')})"
54
50
  end
55
51
 
56
52
  private
57
53
 
58
- # Converts Array of Filenames into an Array of Magic::Image objects
59
- #
60
- def load(files)
61
- files.map do |filename|
62
- image = Magick::Image.read(filename)[0]
63
- {
64
- :image => image,
65
- :width => image.columns,
66
- :height => image.rows
67
- }
54
+ def grid
55
+ if @layout == 'horizontal'
56
+ Magick::Geometry.new(@images.length, 1)
57
+ else
58
+ Magick::Geometry.new(1, @images.length)
68
59
  end
69
60
  end
70
61
 
71
- # Returns canvas on which images will be sequentially placed
62
+ # Changes array of files into String containing classes derived from file names.
72
63
  #
73
- def canvas
74
- images_width = @images.map{ |i| i[:width] }
75
- images_height = @images.map{ |i| i[:height] }
76
- if @layout == 'horizontal'
77
- width = images_width.reduce(:+)
78
- height = images_height.max
79
- else
80
- height = images_height.reduce(:+)
81
- width = images_width.max
82
- end
83
- Magick::Image.new(width, height)
64
+ def classess
65
+ '(' + @files.map{ |f| File.basename(f).split('.').first.inspect }.join(', ') + ')'
66
+ end
67
+
68
+ def default_geometry
69
+ Magick::Geometry.new(@images.first.columns, @images.first.rows)
84
70
  end
85
71
  end
86
72
  end
@@ -38,7 +38,7 @@ module DynamicSprites
38
38
  # Generates sprite using provided options.
39
39
  #
40
40
  def generate_sprite!
41
- generator = Generator.new(options[:output], path, options[:layout])
41
+ generator = Generator.new(options[:output], path, options[:layout], options[:geometry])
42
42
  generator.run!
43
43
  interface.generate_sprite_summary(@options[:output], generator.mixin_call)
44
44
  end
@@ -62,7 +62,7 @@ module DynamicSprites
62
62
  style_directories = []
63
63
  Find.find(Dir.pwd) do |path|
64
64
  next unless FileTest.directory?(path)
65
- if File.basename(path).match /sass|style/
65
+ if File.basename(path).match(/sass|style/)
66
66
  style_directories << Pathname.new(path)
67
67
  elsif File.basename(path)[0] == ?.
68
68
  Find.prune
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-sprites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Maciej Walusiak
@@ -13,15 +14,17 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rmagick
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  description: Generates sass mixin and combines directory of images into one sprite
@@ -40,26 +43,26 @@ files:
40
43
  homepage: https://github.com/Rabsztok/dynamic-sprites
41
44
  licenses:
42
45
  - GPL
43
- metadata: {}
44
46
  post_install_message:
45
47
  rdoc_options: []
46
48
  require_paths:
47
49
  - lib
48
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
49
52
  requirements:
50
- - - '>='
53
+ - - ! '>='
51
54
  - !ruby/object:Gem::Version
52
55
  version: '0'
53
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
54
58
  requirements:
55
- - - '>='
59
+ - - ! '>='
56
60
  - !ruby/object:Gem::Version
57
61
  version: '0'
58
62
  requirements: []
59
63
  rubyforge_project:
60
- rubygems_version: 2.0.7
64
+ rubygems_version: 1.8.23
61
65
  signing_key:
62
- specification_version: 4
66
+ specification_version: 3
63
67
  summary: Responsive sprites - SASS mixin and sprite generator
64
68
  test_files: []
65
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 553c885d412eb736a3beed0a9b847ac2a0145c64
4
- data.tar.gz: 24c0b52c1ab69571dcbeb6f9ae5ef1f1822354b8
5
- SHA512:
6
- metadata.gz: 3f7b1e70cb89157cf48491b0f8cfd9ce9cd51fc592c1fda6f994d9d5c6865025d993d53018c1797550714f369315c7036ef6fdc2918bb008e4b88112e9def44d
7
- data.tar.gz: 6e80466b1aff7ac1d661ba987e9c3fea3397b0592020d044edd67735e6ebbb944995f59da473d54a2ec0dd5307d3ae3159cee321d45ce111016278d6a9a77558