sprite 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/lib/sprite/styles.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'sprite/styles/sass_generator'
2
2
  require 'sprite/styles/css_generator'
3
+ require 'sprite/styles/sass_yml_generator'
3
4
  require 'sprite/styles/sass_mixin_generator'
4
- require 'sprite/styles/sass_if_generator'
5
5
 
6
6
  module Sprite::Styles
7
7
  GENERATORS = {
8
8
  "css" => "CssGenerator",
9
9
  "sass" => "SassGenerator",
10
10
  "sass_mixin" => "SassMixinGenerator",
11
- "sass_if" => "SassIfGenerator"
11
+ "sass_yml" => "SassYmlGenerator"
12
12
  }
13
13
 
14
14
  def self.get(config)
@@ -1,4 +1,3 @@
1
- require 'yaml'
2
1
  module Sprite
3
2
  module Styles
4
3
  # renders a yml file that is later parsed by a sass extension when generating the mixins
@@ -7,44 +6,30 @@ module Sprite
7
6
  @builder = builder
8
7
  end
9
8
 
10
- def write(path, sprite_files)
11
- # build the yml file
12
- config_location = write_config(path, sprite_files)
13
-
9
+ def write(path, sprite_files)
14
10
  # write the sass mixins to disk
15
11
  File.open(File.join(Sprite.root, path), 'w') do |f|
16
- f.puts "!sprite_data = '#{config_location}'"
17
- f.puts ""
12
+ add_else = false
13
+
18
14
  f.puts "= sprite(!group_name, !image_name)"
19
- f.puts " background= sprite_background(!group_name, !image_name)"
20
- f.puts " width= sprite_width(!group_name, !image_name)"
21
- f.puts " height= sprite_height(!group_name, !image_name)"
22
- f.puts ""
23
- end
24
- end
25
-
26
- # write the sprite configuration file (used by the yml extension)
27
- def write_config(path, sprite_files)
28
- # build a grouped hash with all the sprites in it
29
- result = {}
30
- sprite_files.each do |sprite_file, sprites|
31
- sprites.each do |sprite|
32
- if sprite[:group]
33
- result[sprite[:group]] ||= {}
34
- result[sprite[:group]][sprite[:name]] = sprite
15
+ sprite_files.each do |sprite_file, sprites|
16
+ sprites.each do |sprite|
17
+
18
+ f << " @"
19
+ if add_else
20
+ f << "else "
21
+ end
22
+ add_else = true
23
+
24
+ f.puts %{if !group_name == "#{sprite[:group]}" and !image_name == "#{sprite[:name]}"}
25
+ f.puts " background: url('/#{@builder.config['image_output_path']}#{sprite_file}') no-repeat #{sprite[:x]}px #{sprite[:y]}px"
26
+ f.puts " width: #{sprite[:width]}px"
27
+ f.puts " height: #{sprite[:height]}px"
35
28
  end
36
29
  end
37
30
  end
38
-
39
- # write the config yml to disk
40
- config_path = path.gsub(".sass", ".yml")
41
- File.open(File.join(Sprite.root, config_path), 'w') do |f|
42
- YAML.dump(result, f)
43
- end
44
-
45
- config_path
46
31
  end
47
-
32
+
48
33
  def extension
49
34
  "sass"
50
35
  end
@@ -0,0 +1,54 @@
1
+ require 'yaml'
2
+ module Sprite
3
+ module Styles
4
+ # renders a yml file that is later parsed by a sass extension when generating the mixins
5
+ class SassYmlGenerator
6
+ def initialize(builder)
7
+ @builder = builder
8
+ end
9
+
10
+ def write(path, sprite_files)
11
+ # build the yml file
12
+ config_location = write_config(path, sprite_files)
13
+
14
+ # write the sass mixins to disk
15
+ File.open(File.join(Sprite.root, path), 'w') do |f|
16
+ f.puts "!sprite_data = '#{config_location}'"
17
+ f.puts ""
18
+ f.puts "= sprite(!group_name, !image_name)"
19
+ f.puts " background= sprite_background(!group_name, !image_name)"
20
+ f.puts " width= sprite_width(!group_name, !image_name)"
21
+ f.puts " height= sprite_height(!group_name, !image_name)"
22
+ f.puts ""
23
+ end
24
+ end
25
+
26
+ # write the sprite configuration file (used by the yml extension)
27
+ def write_config(path, sprite_files)
28
+ # build a grouped hash with all the sprites in it
29
+ result = {}
30
+ sprite_files.each do |sprite_file, sprites|
31
+ sprites.each do |sprite|
32
+ if sprite[:group]
33
+ result[sprite[:group]] ||= {}
34
+ result[sprite[:group]][sprite[:name]] = sprite
35
+ end
36
+ end
37
+ end
38
+
39
+ # write the config yml to disk
40
+ config_path = path.gsub(".sass", ".yml")
41
+ File.open(File.join(Sprite.root, config_path), 'w') do |f|
42
+ YAML.dump(result, f)
43
+ end
44
+
45
+ config_path
46
+ end
47
+
48
+ def extension
49
+ "sass"
50
+ end
51
+
52
+ end
53
+ end
54
+ end
data/sprite.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sprite}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jacques Crocker", "Richard Huang"]
@@ -31,8 +31,8 @@ Gem::Specification.new do |s|
31
31
  "lib/sprite/styles.rb",
32
32
  "lib/sprite/styles/css_generator.rb",
33
33
  "lib/sprite/styles/sass_generator.rb",
34
- "lib/sprite/styles/sass_if_generator.rb",
35
34
  "lib/sprite/styles/sass_mixin_generator.rb",
35
+ "lib/sprite/styles/sass_yml_generator.rb",
36
36
  "rails/init.rb",
37
37
  "sprite.gemspec",
38
38
  "tasks/sprite_tasks.rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacques Crocker
@@ -36,8 +36,8 @@ files:
36
36
  - lib/sprite/styles.rb
37
37
  - lib/sprite/styles/css_generator.rb
38
38
  - lib/sprite/styles/sass_generator.rb
39
- - lib/sprite/styles/sass_if_generator.rb
40
39
  - lib/sprite/styles/sass_mixin_generator.rb
40
+ - lib/sprite/styles/sass_yml_generator.rb
41
41
  - rails/init.rb
42
42
  - sprite.gemspec
43
43
  - tasks/sprite_tasks.rake
@@ -1,39 +0,0 @@
1
- module Sprite
2
- module Styles
3
- # renders a yml file that is later parsed by a sass extension when generating the mixins
4
- class SassIfGenerator
5
- def initialize(builder)
6
- @builder = builder
7
- end
8
-
9
- def write(path, sprite_files)
10
- # write the sass mixins to disk
11
- File.open(File.join(Sprite.root, path), 'w') do |f|
12
- add_else = false
13
-
14
- f.puts "= sprite(!group_name, !image_name)"
15
- sprite_files.each do |sprite_file, sprites|
16
- sprites.each do |sprite|
17
-
18
- f << " @"
19
- if add_else
20
- f << "else "
21
- end
22
- add_else = true
23
-
24
- f.puts %{if !group_name == "#{sprite[:group]}" and !image_name == "#{sprite[:name]}"}
25
- f.puts " background: url('/#{@builder.config['image_output_path']}#{sprite_file}') no-repeat #{sprite[:x]}px #{sprite[:y]}px"
26
- f.puts " width: #{sprite[:width]}px"
27
- f.puts " height: #{sprite[:height]}px"
28
- end
29
- end
30
- end
31
- end
32
-
33
- def extension
34
- "sass"
35
- end
36
-
37
- end
38
- end
39
- end