Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into cotampanie-master
  • Loading branch information
jakesgordon committed Jan 17, 2015
2 parents 876739e + 1953c9d commit 3aa5838
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/sprite_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class << self
attr_accessor :cssurl
attr_accessor :pngcrush
attr_accessor :nocomments
attr_accessor :directory_separator
end

#----------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions lib/sprite_factory/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def initialize(input, config = {})
@config[:report] ||= SpriteFactory.report
@config[:pngcrush] ||= SpriteFactory.pngcrush
@config[:nocomments] ||= SpriteFactory.nocomments
@config[:directory_separator] ||= SpriteFactory.directory_separator || '_'
end

#----------------------------------------------------------------------------

def run!(&block)

raise RuntimeError, "unknown layout #{layout_name}" if !Layout.respond_to?(layout_name)
raise RuntimeError, "unknown style #{style_name}" if !Style.respond_to?(style_name)
raise RuntimeError, "unknown library #{library_name}" if !Library.respond_to?(library_name)
Expand Down Expand Up @@ -139,6 +139,10 @@ def nocomments?
config[:nocomments] # set true if you dont want any comments in the output style file
end

def directory_separator
config[:directory_separator]
end

def custom_style_file
File.join(input, File.basename(input) + ".#{style_name}")
end
Expand Down Expand Up @@ -174,6 +178,7 @@ def library

def load_images
input_path = Pathname.new(input)

images = library.load(image_files)
images.each do |i|
i[:name], i[:ext] = map_image_filename(i[:filename], input_path)
Expand All @@ -184,7 +189,7 @@ def load_images
end

def map_image_filename(filename, input_path)
name = Pathname.new(filename).relative_path_from(input_path).to_s.gsub(File::SEPARATOR, "_")
name = Pathname.new(filename).relative_path_from(input_path).to_s.gsub(File::SEPARATOR, directory_separator)
name = name.gsub('--', ':')
name = name.gsub('__', ' ')
ext = File.extname(name)
Expand Down
24 changes: 24 additions & 0 deletions test/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_defaults
assert_equal(:horizontal, r.layout_name)
assert_equal(:css, r.style_name)
assert_equal(:rmagick, r.library_name)
assert_equal(DIRECTORY_SEPARATOR, r.directory_separator)

r = Runner.new(IRREGULAR_PATH)
assert_equal(IRREGULAR_PATH, r.input)
Expand All @@ -28,6 +29,18 @@ def test_defaults
assert_equal(:horizontal, r.layout_name)
assert_equal(:css, r.style_name)
assert_equal(:rmagick, r.library_name)
assert_equal(DIRECTORY_SEPARATOR, r.directory_separator)

r = Runner.new(IRREGULAR_PATH, :directory_separator => '.')
assert_equal(IRREGULAR_PATH, r.input)
assert_equal(IRREGULAR_PATH, r.output)
assert_equal(IRREGULAR_PATH + ".png", r.output_image_file)
assert_equal(IRREGULAR_PATH + ".css", r.output_style_file)
assert_equal(IRREGULAR, r.image_files)
assert_equal(:horizontal, r.layout_name)
assert_equal(:css, r.style_name)
assert_equal(:rmagick, r.library_name)
assert_equal('.', r.directory_separator)

r = Runner.new(REGULAR_PATH, :output => IRREGULAR_PATH)
assert_equal(REGULAR_PATH, r.input)
Expand All @@ -38,6 +51,7 @@ def test_defaults
assert_equal(:horizontal, r.layout_name)
assert_equal(:css, r.style_name)
assert_equal(:rmagick, r.library_name)
assert_equal(DIRECTORY_SEPARATOR, r.directory_separator)

r = Runner.new(REGULAR_PATH, :output_image => "foo.png", :output_style => "bar.css.sass.erb")
assert_equal(REGULAR_PATH, r.input)
Expand All @@ -48,6 +62,7 @@ def test_defaults
assert_equal(:horizontal, r.layout_name)
assert_equal(:css, r.style_name)
assert_equal(:rmagick, r.library_name)
assert_equal(DIRECTORY_SEPARATOR, r.directory_separator)

r = Runner.new(REGULAR_PATH, :layout => :vertical, :library => :chunkypng, :style => :sass)
assert_equal(REGULAR_PATH, r.input)
Expand All @@ -58,6 +73,7 @@ def test_defaults
assert_equal(:vertical, r.layout_name)
assert_equal(:sass, r.style_name)
assert_equal(:chunkypng, r.library_name)
assert_equal(DIRECTORY_SEPARATOR, r.directory_separator)

end

Expand Down Expand Up @@ -223,6 +239,14 @@ def test_images_are_secondary_sorted_on_psuedoclass
end
end

def test_use_specified_directory_separator
Runner.publicize_methods do
expected = %w(england.amy england.bob france.bob usa.amy usa.bob)
actual = Runner.new(SUBFOLDERS_PATH, :directory_separator => '.').load_images.map{|i| i[:name]}
assert_equal(expected, actual)
end
end

#----------------------------------------------------------------------------

end
Expand Down
2 changes: 2 additions & 0 deletions test/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TestCase < Test::Unit::TestCase
{ :filename => IRREGULAR[4], :width => 46, :height => 25 }
]

DIRECTORY_SEPARATOR = '_'

def output_path(name)
File.join(IMAGES_PATH, name)
end
Expand Down

0 comments on commit 3aa5838

Please sign in to comment.