Skip to content

Commit af18cb7

Browse files
committed
Reorganizing Sass Mixin Generators
1 parent 3464aa3 commit af18cb7

File tree

6 files changed

+82
-76
lines changed

6 files changed

+82
-76
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.3
1+
0.1.4

lib/sprite/styles.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require 'sprite/styles/sass_generator'
22
require 'sprite/styles/css_generator'
3+
require 'sprite/styles/sass_yml_generator'
34
require 'sprite/styles/sass_mixin_generator'
4-
require 'sprite/styles/sass_if_generator'
55

66
module Sprite::Styles
77
GENERATORS = {
88
"css" => "CssGenerator",
99
"sass" => "SassGenerator",
1010
"sass_mixin" => "SassMixinGenerator",
11-
"sass_if" => "SassIfGenerator"
11+
"sass_yml" => "SassYmlGenerator"
1212
}
1313

1414
def self.get(config)

lib/sprite/styles/sass_if_generator.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/sprite/styles/sass_mixin_generator.rb

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'yaml'
21
module Sprite
32
module Styles
43
# renders a yml file that is later parsed by a sass extension when generating the mixins
@@ -7,44 +6,30 @@ def initialize(builder)
76
@builder = builder
87
end
98

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)
1410
# write the sass mixins to disk
1511
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+
1814
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(http://github.com/'/%3Cspan%20class=pl-s1%3E%3Cspan%20class=pl-kos%3E#{%3C/span%3E%3Cspan%20class=pl-c1%3E@builder%3C/span%3E%3Cspan%20class=pl-kos%3E.%3C/span%3E%3Cspan%20class=pl-en%3Econfig%3C/span%3E%3Cspan%20class=pl-kos%3E[%3C/span%3E%3Cspan%20class=pl-s%3E'image_output_path'%3C/span%3E%3Cspan%20class=pl-kos%3E]%3C/span%3E%3Cspan%20class=pl-kos%3E}%3C/span%3E%3C/span%3E%3Cspan%20class=pl-s1%3E%3Cspan%20class=pl-kos%3E#{%3C/span%3E%3Cspan%20class=pl-s1%3Esprite_file%3C/span%3E%3Cspan%20class=pl-kos%3E}%3C/span%3E%3C/span%3E') no-repeat #{sprite[:x]}px #{sprite[:y]}px"
26+
f.puts " width: #{sprite[:width]}px"
27+
f.puts " height: #{sprite[:height]}px"
3528
end
3629
end
3730
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
4631
end
47-
32+
4833
def extension
4934
"sass"
5035
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

sprite.gemspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
Gem::Specification.new do |s|
77
s.name = %q{sprite}
8-
s.version = "0.1.2"
8+
s.version = "0.1.3"
99

1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Jacques Crocker", "Richard Huang"]
12-
s.date = %q{2009-11-17}
12+
s.date = %q{2009-11-18}
1313
s.default_executable = %q{sprite}
1414
s.description = %q{sprite is a rails/merb plugin that generates sprites for css, sass}
1515
s.email = %q{[email protected]}
@@ -27,6 +27,12 @@ Gem::Specification.new do |s|
2727
"lib/sprite/builder.rb",
2828
"lib/sprite/image_combiner.rb",
2929
"lib/sprite/runner.rb",
30+
"lib/sprite/sass_extensions.rb",
31+
"lib/sprite/styles.rb",
32+
"lib/sprite/styles/css_generator.rb",
33+
"lib/sprite/styles/sass_generator.rb",
34+
"lib/sprite/styles/sass_if_generator.rb",
35+
"lib/sprite/styles/sass_mixin_generator.rb",
3036
"rails/init.rb",
3137
"sprite.gemspec",
3238
"tasks/sprite_tasks.rake"

0 commit comments

Comments
 (0)