Skip to content

Commit

Permalink
Merge pull request #6 from varvet/fauxparse-icon-prefix
Browse files Browse the repository at this point in the history
Adds icon prefixes
  • Loading branch information
johanhalse authored Apr 9, 2019
2 parents 495fd18 + 23de860 commit 664c32a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/scavenger/compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def symbolize(doc, id)
attribute.remove unless attribute.name == "viewBox"
end
doc.name = "symbol"
doc["id"] = id.chomp(".svg")
doc["id"] = Scavenger::Config.id_prefix + id.chomp(".svg")
doc["preserveAspectRatio"] = Scavenger::Config.aspect_ratio
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/scavenger/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ class << self
attr_accessor :svg_directory
attr_accessor :sprite_path
attr_accessor :class_prefix
attr_accessor :id_prefix
attr_accessor :aspect_ratio
end

self.aspect_ratio = "xMinYMin meet"
self.id_prefix = ""
end
end
2 changes: 1 addition & 1 deletion lib/scavenger/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def svg_sprite_sheet

def svg(ref, options = {})
options[:class] = "#{Scavenger::Config.class_prefix}#{ref}" if options[:class].nil?
content_tag :svg, "<use xlink:href=\"##{ref}\"/>".html_safe, options
content_tag :svg, "<use xlink:href=\"##{Scavenger::Config.id_prefix}#{ref}\"/>".html_safe, options
end

def scavenger_sprite_path
Expand Down
7 changes: 7 additions & 0 deletions test/scavenger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def test_can_compress_file
assert_equal expected_output, @compressor.compress_file("./test/svg/hejsna.svg", "hejsna.svg")
end

def test_adds_id_prefixes
Scavenger::Config.id_prefix = "foo-"
expected_output = "<symbol viewBox=\"0 0 173 173\" id=\"foo-hejsna\" preserveAspectRatio=\"xMinYMin meet\"><g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"><g transform=\"translate(1.000000, 1.000000)\"><circle stroke=\"#979797\" fill=\"#D8D8D8\" cx=\"85.5\" cy=\"85.5\" r=\"85.5\"></circle><path d=\"M83.5,117.5 L83.5,51.5\" stroke=\"#A80C0C\" stroke-linecap=\"square\" fill=\"#A80C0C\"></path><path d=\"M83.5,51.5 L80.5,62.3 L86.5,62.3 L83.5,51.5 Z\" stroke=\"#A80C0C\" stroke-linecap=\"square\" fill=\"#A80C0C\"></path><polygon stroke=\"#979797\" fill=\"#D8D8D8\" points=\"39 92 20.1908719 101.888544 23.7830957 80.9442719 8.56619148 66.1114562 29.595436 63.0557281 39 44 48.404564 63.0557281 69.4338085 66.1114562 54.2169043 80.9442719 57.8091281 101.888544\"></polygon><polygon fill=\"#EB8D8D\" points=\"125 56 154 114 96 114\"></polygon></g></g></symbol>"
assert_equal expected_output, @compressor.compress_file("./test/svg/hejsna.svg", "hejsna.svg")
Scavenger::Config.id_prefix = ""
end

def test_creates_sprite_file
@compressor.compress_dir
assert File.exist?(@sprite_path)
Expand Down

0 comments on commit 664c32a

Please sign in to comment.