dynamic-sprites 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e66fb4237da83f5be891b1d055a33a7db84ed1e
4
- data.tar.gz: accd4811e105cffdd89760e68b256fbd1e2e192c
3
+ metadata.gz: faa40ab1ffdd8cab5bd6efe205dcd152f5ce3f67
4
+ data.tar.gz: e3509247bdbc37b22bd3ffa6171106eceb68a306
5
5
  SHA512:
6
- metadata.gz: 6578afb03c296b402be255ce957df3fe68efe74e8bcd8a7e624279b6df5e69aef27fdaf28d549da7b12c15e16b5e257c530b591422c768f11083055e0fad32a0
7
- data.tar.gz: 4bf1e72083d3b38223cc21b0877ff85c6d8dce45bf6809dd9a5d510817d4d3acd576c359f6aff14e556d9717fb5efe210496a5cdf0625831de4c86a19d1209a4
6
+ metadata.gz: fb07230f0c29f5eeadc2858c567bb6c7a04ca6695a00167364eb92d6c9cba1323e4a9acb46916982c6a272101125c630c0b61936400e6ba98d620e8c03da4357
7
+ data.tar.gz: ed2e34a5a6d10be91578c698ef67c9e422cf1a24226615d3af652ef7d4c1a00d361aeaa3d1654c4fb875b4963d3e762daaac3eac8e567ed2180b845c0071dde4
@@ -2,8 +2,8 @@ module DynamicSprites
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "0.0.2"
6
- SUMMARY = "Dynamic sprites mixin in SASS with sprite generator"
5
+ VERSION = "0.0.3"
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'
@@ -1,15 +1,12 @@
1
1
  module DynamicSprites
2
2
  # Generates sprites
3
+ #
3
4
  class Generator
4
5
 
5
6
  # Array of file extensions used for creating sprites.
6
7
  #
7
8
  VALID_EXTENSIONS = %w(.png .jpg .jpeg .gif .ico)
8
9
 
9
- attr :filename
10
- attr :layout
11
- attr :files
12
-
13
10
  # Initializer
14
11
  #
15
12
  # filename - Pathname where generated file should be placed to.
@@ -19,13 +16,41 @@ module DynamicSprites
19
16
  def initialize(filename, path, layout)
20
17
  @filename = filename
21
18
  @layout = layout
22
- @files = Dir.glob(File.join(path, '*')).select { |e| VALID_EXTENSIONS.include?(File.extname(e)) }
19
+ @files = Dir.glob(File.join(path, '*')).sort.select { |e| VALID_EXTENSIONS.include?(File.extname(e)) }
20
+ @images = load(@files)
21
+ @canvas = canvas
23
22
  end
24
23
 
25
24
  # Main method for sprites generation
26
25
  #
27
26
  def run!
28
- create(filename, load(files), layout)
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)
39
+ end
40
+
41
+ # Returns a call to sass mixin function with default attributes
42
+ #
43
+ def mixin_call
44
+ call = "dynamic-sprite"
45
+ call << "-horizontal" if @layout == "horizontal"
46
+ arguments = [
47
+ @filename,
48
+ @files.map{ |f| File.basename(f) },
49
+ "#{100 / (@files.size - 1)}%",
50
+ "100%",
51
+ "#{100 * @images.first[:height] / @images.first[:width]}%"
52
+ ]
53
+ call << "(#{arguments.join(', ')})"
29
54
  end
30
55
 
31
56
  private
@@ -43,31 +68,19 @@ module DynamicSprites
43
68
  end
44
69
  end
45
70
 
46
- # Generates sprite
71
+ # Returns canvas on which images will be sequentially placed
47
72
  #
48
- def create(filename, images, layout)
49
- images_width = images.map{ |i| i[:width] }
50
- images_height = images.map{ |i| i[:height] }
51
- if layout == 'horizontal'
73
+ def canvas
74
+ images_width = @images.map{ |i| i[:width] }
75
+ images_height = @images.map{ |i| i[:height] }
76
+ if @layout == 'horizontal'
52
77
  width = images_width.reduce(:+)
53
78
  height = images_height.max
54
79
  else
55
80
  height = images_height.reduce(:+)
56
81
  width = images_width.max
57
82
  end
58
- target = Magick::Image.new(width, height)
59
- target.opacity = Magick::MaxRGB
60
- offset_x = 0
61
- offset_y = 0
62
- images.each do |image|
63
- target.composite!(image[:image], offset_x, offset_y, Magick::SrcOverCompositeOp)
64
- if layout == 'horizontal'
65
- offset_x += image[:width]
66
- else
67
- offset_y += image[:height]
68
- end
69
- end
70
- target.write(filename)
83
+ Magick::Image.new(width, height)
71
84
  end
72
85
  end
73
86
  end
@@ -29,8 +29,10 @@ module DynamicSprites
29
29
  puts "Mixin generated in #{path}"
30
30
  end
31
31
 
32
- def generate_sprite_summary(path)
32
+ def generate_sprite_summary(path, mixin_call)
33
33
  puts "Sprite generated in #{path}"
34
+ puts "\nYou can use it by calling this code in your sass document:"
35
+ puts mixin_call
34
36
  end
35
37
 
36
38
  private
@@ -38,8 +38,9 @@ module DynamicSprites
38
38
  # Generates sprite using provided options.
39
39
  #
40
40
  def generate_sprite!
41
- Generator.new(options[:output], path, options[:layout]).run!
42
- interface.generate_sprite_summary(@options[:output])
41
+ generator = Generator.new(options[:output], path, options[:layout])
42
+ generator.run!
43
+ interface.generate_sprite_summary(@options[:output], generator.mixin_call)
43
44
  end
44
45
 
45
46
  # Chooses one of possible options of defining sass directory path.
@@ -59,7 +60,6 @@ module DynamicSprites
59
60
  #
60
61
  def sass_directories
61
62
  style_directories = []
62
-
63
63
  Find.find(Dir.pwd) do |path|
64
64
  next unless FileTest.directory?(path)
65
65
  if File.basename(path).match /sass|style/
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-sprites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Walusiak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Dynamic sprites mixin in SASS with sprite generator.
13
+ description: Generates sass mixin and combines directory of images into one sprite
14
14
  email: rabsztok@gmail.com
15
15
  executables:
16
16
  - dynamic-sprites
@@ -46,6 +46,6 @@ rubyforge_project:
46
46
  rubygems_version: 2.0.7
47
47
  signing_key:
48
48
  specification_version: 4
49
- summary: Dynamic sprites
49
+ summary: Responsive sprites - SASS mixin and sprite generator
50
50
  test_files: []
51
51
  has_rdoc: