middleman-scavenger 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03fc307b4e2083ec766f6109af7695694015e0a7
4
- data.tar.gz: d1419d0d8734fa2efe621f9cfdddcf877699c4ca
3
+ metadata.gz: d355b651db278a9ed23af9258b0d419be240fa58
4
+ data.tar.gz: 903d63fa4fe4598aaea2c0657cc160a984e96dbf
5
5
  SHA512:
6
- metadata.gz: 7cd574ac3ad9e7d7ff714df4652eaca07f33f871f594c50c71e9065004d48ec3b3e6b8be07635318d561d12186325cdb40a82be5c891ce75fb69b5405270d346
7
- data.tar.gz: 36a5f38bdf0d2cc95b83b088e155bf4df8608c77a64322c0570b3158ce1cc299c36be1c9e16247f8ad35911025364471d64d9a2f3d039c006fc85c69b62d6215
6
+ metadata.gz: baa3545634e3c289c0b786766e97d7620ed2234fc7b9f122e243e2cff598b636e27bc8674b2edf099c22b13d347cbe32e2f1cdf2d12a9b184fdcaf2d50a2e02b
7
+ data.tar.gz: e3823d99c0813edf21ba31e0b3790d001b7f35a9162c8e76afa3545468ebfdbfd5a70b89927d39df6dadb432a0585515aadd43b29e3b6e5a777bc6cc854c8390
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.0.2 - 2015-11-10
4
+ Bug fixes
5
+ - Parses non `<g>` wrapped content properly (https://github.com/varvet/middleman-scavenger/issues/4)
6
+
3
7
  ### 1.0.1 - 2015-11-06
4
8
  Bug fixes
5
9
  - Removes hardcoded "images" path for sprite_path (https://github.com/varvet/middleman-scavenger/issues/1)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Middleman-scavenger
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/middleman-scavenger.svg)](https://rubygems.org/gems/middleman-scavenger) [![Code Climate](https://codeclimate.com/github/varvet/middleman-scavenger/badges/gpa.svg)](https://codeclimate.com/github/varvet/middleman-scavenger) [![Build Status](https://travis-ci.org/varvet/middleman-scavenger.svg?branch=master)](https://travis-ci.org/varvet/middleman-scavenger)
4
+
3
5
  A Middleman extension for creating svg sprite sheets. It's usable in modern (IE9+) browsers, uses `<symbol>` to include the svg:s, and can optionally inline the SVG images for speed. If you need legacy browser support it combines well with [svg4everybody](https://github.com/jonathantneal/svg4everybody).
4
6
 
5
7
 
data/Rakefile CHANGED
@@ -1,14 +1,15 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler"
2
+ require "rake/testtask"
3
3
 
4
- require 'cucumber/rake/task'
4
+ Bundler::GemHelper.install_tasks
5
5
 
6
- Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
- t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
6
+ Rake::TestTask.new(:minitest) do |t|
7
+ t.pattern = "test/unit/*.rb"
8
+ t.verbose = true
8
9
  end
9
10
 
10
- require 'rake/clean'
11
+ require "rake/clean"
11
12
 
12
- task test: ['cucumber']
13
+ task test: ["minitest"]
13
14
 
14
15
  task default: :test
@@ -1,5 +1,5 @@
1
1
  # Require core library
2
- require 'middleman-core'
2
+ require "middleman-core"
3
3
 
4
4
  # Extension namespace
5
5
  class MiddlemanScavenger < ::Middleman::Extension
@@ -1,4 +1,5 @@
1
1
  class SVGProcessor
2
+ require "middleman-core/logger"
2
3
  require "nokogiri"
3
4
 
4
5
  def initialize(path, prefix, sprite_path)
@@ -9,7 +10,7 @@ class SVGProcessor
9
10
 
10
11
  def rebuild
11
12
  @svgs = Dir["#{@path}/*.svg"].map { |file| get_svg(file) }
12
- puts "rebuilding: #{@svgs.length} svgs found"
13
+ logger.debug "rebuilding: #{@svgs.length} svgs found"
13
14
  @symbols = @svgs.map { |svg| convert_to_symbol(svg) }
14
15
 
15
16
  @symbol_string = @symbols.join("\n")
@@ -25,6 +26,10 @@ class SVGProcessor
25
26
 
26
27
  private
27
28
 
29
+ def logger
30
+ ::Middleman::Logger.singleton(1)
31
+ end
32
+
28
33
  def get_svg(file)
29
34
  f = File.open(file)
30
35
  doc = Nokogiri::XML(f)
@@ -38,8 +43,8 @@ class SVGProcessor
38
43
 
39
44
  def convert_to_symbol(svg)
40
45
  svg[:xml].xpath('//@id').remove
41
- g = svg[:xml].at_css("g")
46
+ content = svg[:xml].at_css("svg").children
42
47
  viewbox_size = svg[:xml].xpath("//@viewBox").first.value
43
- "<symbol viewBox=\"#{viewbox_size}\" id=\"#{@prefix}#{svg[:filename]}\">#{g.to_s}</symbol>"
48
+ "<symbol viewBox=\"#{viewbox_size}\" id=\"#{@prefix}#{svg[:filename]}\">#{content.to_s.strip}</symbol>"
44
49
  end
45
50
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "middleman-scavenger"
6
- s.version = "1.0.1"
6
+ s.version = "1.0.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Johan Halse"]
9
9
  s.email = ["johan.halse@varvet.com"]
@@ -0,0 +1,3 @@
1
+ <svg viewBox="0 0 34 22" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd">
2
+ <path d="M33.7.9c0-.1-.1-.2-.1-.2s0-.1-.1-.1l-.1-.1-.2-.2-.2-.1-.2-.1c-.1 0-.2 0-.2-.1h-31.6c-.1 0-.2 0-.2.1l-.2.1-.2.2-.1.1s0 .1-.1.1l-.1.2c0 .1 0 .2-.1.3v18.8c0 .7.6 1.2 1.2 1.2h31.2c.7 0 1.2-.6 1.2-1.2v-18.8c.1-.1.1-.1.1-.2zm-4.9 1.6l-11.9 9.2-11.9-9.2h23.8zm-26.3 16.3v-14.9l13.6 10.5c.2.2.5.3.8.3.3 0 .5-.1.8-.3l13.6-10.5v14.9h-28.8z"/>
3
+ </svg>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="270.477px" height="284px" viewBox="0 0 270.477 284" enable-background="new 0 0 270.477 284" xml:space="preserve">
6
+ <g>
7
+ <path fill="#FFFFFF" d="M135.238,0L0,81.143V284h270.477V81.143L135.238,0z M52.554,255.374H40.572v-27.969h11.982V255.374z
8
+ M52.554,223.41H40.572v-27.962h11.982V223.41z M52.554,191.453H40.572v-27.966h11.982V191.453z M52.554,159.492H40.572v-27.965
9
+ h11.982V159.492z M68.541,255.374H56.549v-27.969h11.992V255.374z M68.541,223.41H56.549v-27.962h11.992V223.41z M68.541,191.453
10
+ H56.549v-27.966h11.992V191.453z M68.541,159.492H56.549v-27.965h11.992V159.492z M84.521,255.374H72.536v-27.969h11.985V255.374z
11
+ M84.521,223.41H72.536v-27.962h11.985V223.41z M84.521,191.453H72.536v-27.966h11.985V191.453z M84.521,159.492H72.536v-27.965
12
+ h11.985V159.492z M100.498,255.374H88.516v-27.969h11.982V255.374z M100.498,223.41H88.516v-27.962h11.982V223.41z
13
+ M100.498,191.453H88.516v-27.966h11.982V191.453z M100.498,159.492H88.516v-27.965h11.982V159.492z M116.475,255.374h-11.982
14
+ v-27.969h11.982V255.374z M116.475,223.41h-11.982v-27.962h11.982V223.41z M116.475,191.453h-11.982v-27.966h11.982V191.453z
15
+ M116.475,159.492h-11.982v-27.965h11.982V159.492z M165.983,255.374h-11.981v-27.969h11.981V255.374z M165.983,223.41h-11.981
16
+ v-27.962h11.981V223.41z M165.983,191.453h-11.981v-27.966h11.981V191.453z M165.983,159.492h-11.981v-27.965h11.981V159.492z
17
+ M181.971,255.374h-11.992v-27.969h11.992V255.374z M181.971,223.41h-11.992v-27.962h11.992V223.41z M181.971,191.453h-11.992
18
+ v-27.966h11.992V191.453z M181.971,159.492h-11.992v-27.965h11.992V159.492z M197.951,255.374h-11.985v-27.969h11.985V255.374z
19
+ M197.951,223.41h-11.985v-27.962h11.985V223.41z M197.951,191.453h-11.985v-27.966h11.985V191.453z M197.951,159.492h-11.985
20
+ v-27.965h11.985V159.492z M213.928,255.374h-11.981v-27.969h11.981V255.374z M213.928,223.41h-11.981v-27.962h11.981V223.41z
21
+ M213.928,191.453h-11.981v-27.966h11.981V191.453z M213.928,159.492h-11.981v-27.965h11.981V159.492z M229.905,255.374h-11.982
22
+ v-27.969h11.982V255.374z M229.905,223.41h-11.982v-27.962h11.982V223.41z M229.905,191.453h-11.982v-27.966h11.982V191.453z
23
+ M229.905,159.492h-11.982v-27.965h11.982V159.492z"/>
24
+ </g>
25
+ </svg>
@@ -0,0 +1 @@
1
+ <svg width="29" height="29" viewBox="0 0 29 29" xmlns="http://www.w3.org/2000/svg"><title>checkbox</title><g transform="translate(1 1)" stroke="#FAB131" fill="none" fill-rule="evenodd"><ellipse fill="#FFF" cx="13.519" cy="13.522" rx="13.434" ry="13.257"/><path d="M6.724 13.533l5.057 4.99 9.337-9.212" stroke-width="2"/></g></svg>
@@ -0,0 +1,40 @@
1
+ require "minitest/autorun"
2
+ require "middleman-scavenger"
3
+ require "svg_processor"
4
+
5
+ class SvgProcessorTest < Minitest::Test
6
+ def teardown
7
+ File.delete("sprite.svg") if File.exist?("sprite.svg")
8
+ end
9
+
10
+ def test_has_no_content_before_rebuild
11
+ @svg_processor = SVGProcessor.new("test/svg", nil, nil)
12
+ assert_nil @svg_processor.to_s
13
+ end
14
+
15
+ def test_writes_no_file_if_sprite_path_is_nil
16
+ @svg_processor = SVGProcessor.new("test/svg", nil, nil)
17
+ @svg_processor.rebuild
18
+ refute File.exist?("sprite.svg")
19
+ end
20
+
21
+ def test_writes_file_if_sprite_path_is_set
22
+ @svg_processor = SVGProcessor.new("test/svg", nil, "sprite.svg")
23
+ @svg_processor.rebuild
24
+ assert File.exist?("sprite.svg")
25
+ end
26
+
27
+ def test_adds_prefix
28
+ @svg_processor = SVGProcessor.new("test/svg", "icon-", nil)
29
+ @svg_processor.rebuild
30
+ str = "<symbol viewBox=\"0 0 34 22\" id=\"icon-basic-svg\"><path d=\"M33.7.9c0-.1-.1-.2-.1-.2s0-.1-.1-.1l-.1-.1-.2-.2-.2-.1-.2-.1c-.1 0-.2 0-.2-.1h-31.6c-.1 0-.2 0-.2.1l-.2.1-.2.2-.1.1s0 .1-.1.1l-.1.2c0 .1 0 .2-.1.3v18.8c0 .7.6 1.2 1.2 1.2h31.2c.7 0 1.2-.6 1.2-1.2v-18.8c.1-.1.1-.1.1-.2zm-4.9 1.6l-11.9 9.2-11.9-9.2h23.8zm-26.3 16.3v-14.9l13.6 10.5c.2.2.5.3.8.3.3 0 .5-.1.8-.3l13.6-10.5v14.9h-28.8z\"/></symbol>\n<symbol viewBox=\"0 0 270.477 284\" id=\"icon-illustrator-svg\"><g>\n <path fill=\"#FFFFFF\" d=\"M135.238,0L0,81.143V284h270.477V81.143L135.238,0z M52.554,255.374H40.572v-27.969h11.982V255.374z M52.554,223.41H40.572v-27.962h11.982V223.41z M52.554,191.453H40.572v-27.966h11.982V191.453z M52.554,159.492H40.572v-27.965 h11.982V159.492z M68.541,255.374H56.549v-27.969h11.992V255.374z M68.541,223.41H56.549v-27.962h11.992V223.41z M68.541,191.453 H56.549v-27.966h11.992V191.453z M68.541,159.492H56.549v-27.965h11.992V159.492z M84.521,255.374H72.536v-27.969h11.985V255.374z M84.521,223.41H72.536v-27.962h11.985V223.41z M84.521,191.453H72.536v-27.966h11.985V191.453z M84.521,159.492H72.536v-27.965 h11.985V159.492z M100.498,255.374H88.516v-27.969h11.982V255.374z M100.498,223.41H88.516v-27.962h11.982V223.41z M100.498,191.453H88.516v-27.966h11.982V191.453z M100.498,159.492H88.516v-27.965h11.982V159.492z M116.475,255.374h-11.982 v-27.969h11.982V255.374z M116.475,223.41h-11.982v-27.962h11.982V223.41z M116.475,191.453h-11.982v-27.966h11.982V191.453z M116.475,159.492h-11.982v-27.965h11.982V159.492z M165.983,255.374h-11.981v-27.969h11.981V255.374z M165.983,223.41h-11.981 v-27.962h11.981V223.41z M165.983,191.453h-11.981v-27.966h11.981V191.453z M165.983,159.492h-11.981v-27.965h11.981V159.492z M181.971,255.374h-11.992v-27.969h11.992V255.374z M181.971,223.41h-11.992v-27.962h11.992V223.41z M181.971,191.453h-11.992 v-27.966h11.992V191.453z M181.971,159.492h-11.992v-27.965h11.992V159.492z M197.951,255.374h-11.985v-27.969h11.985V255.374z M197.951,223.41h-11.985v-27.962h11.985V223.41z M197.951,191.453h-11.985v-27.966h11.985V191.453z M197.951,159.492h-11.985 v-27.965h11.985V159.492z M213.928,255.374h-11.981v-27.969h11.981V255.374z M213.928,223.41h-11.981v-27.962h11.981V223.41z M213.928,191.453h-11.981v-27.966h11.981V191.453z M213.928,159.492h-11.981v-27.965h11.981V159.492z M229.905,255.374h-11.982 v-27.969h11.982V255.374z M229.905,223.41h-11.982v-27.962h11.982V223.41z M229.905,191.453h-11.982v-27.966h11.982V191.453z M229.905,159.492h-11.982v-27.965h11.982V159.492z\"/>\n</g></symbol>\n<symbol viewBox=\"0 0 29 29\" id=\"icon-sketch-svg\"><title>checkbox</title><g transform=\"translate(1 1)\" stroke=\"#FAB131\" fill=\"none\" fill-rule=\"evenodd\">\n <ellipse fill=\"#FFF\" cx=\"13.519\" cy=\"13.522\" rx=\"13.434\" ry=\"13.257\"/>\n <path d=\"M6.724 13.533l5.057 4.99 9.337-9.212\" stroke-width=\"2\"/>\n</g></symbol>"
31
+ assert_equal str, @svg_processor.to_s
32
+ end
33
+
34
+ def test_output_is_correct
35
+ str = "<symbol viewBox=\"0 0 34 22\" id=\"basic-svg\"><path d=\"M33.7.9c0-.1-.1-.2-.1-.2s0-.1-.1-.1l-.1-.1-.2-.2-.2-.1-.2-.1c-.1 0-.2 0-.2-.1h-31.6c-.1 0-.2 0-.2.1l-.2.1-.2.2-.1.1s0 .1-.1.1l-.1.2c0 .1 0 .2-.1.3v18.8c0 .7.6 1.2 1.2 1.2h31.2c.7 0 1.2-.6 1.2-1.2v-18.8c.1-.1.1-.1.1-.2zm-4.9 1.6l-11.9 9.2-11.9-9.2h23.8zm-26.3 16.3v-14.9l13.6 10.5c.2.2.5.3.8.3.3 0 .5-.1.8-.3l13.6-10.5v14.9h-28.8z\"/></symbol>\n<symbol viewBox=\"0 0 270.477 284\" id=\"illustrator-svg\"><g>\n <path fill=\"#FFFFFF\" d=\"M135.238,0L0,81.143V284h270.477V81.143L135.238,0z M52.554,255.374H40.572v-27.969h11.982V255.374z M52.554,223.41H40.572v-27.962h11.982V223.41z M52.554,191.453H40.572v-27.966h11.982V191.453z M52.554,159.492H40.572v-27.965 h11.982V159.492z M68.541,255.374H56.549v-27.969h11.992V255.374z M68.541,223.41H56.549v-27.962h11.992V223.41z M68.541,191.453 H56.549v-27.966h11.992V191.453z M68.541,159.492H56.549v-27.965h11.992V159.492z M84.521,255.374H72.536v-27.969h11.985V255.374z M84.521,223.41H72.536v-27.962h11.985V223.41z M84.521,191.453H72.536v-27.966h11.985V191.453z M84.521,159.492H72.536v-27.965 h11.985V159.492z M100.498,255.374H88.516v-27.969h11.982V255.374z M100.498,223.41H88.516v-27.962h11.982V223.41z M100.498,191.453H88.516v-27.966h11.982V191.453z M100.498,159.492H88.516v-27.965h11.982V159.492z M116.475,255.374h-11.982 v-27.969h11.982V255.374z M116.475,223.41h-11.982v-27.962h11.982V223.41z M116.475,191.453h-11.982v-27.966h11.982V191.453z M116.475,159.492h-11.982v-27.965h11.982V159.492z M165.983,255.374h-11.981v-27.969h11.981V255.374z M165.983,223.41h-11.981 v-27.962h11.981V223.41z M165.983,191.453h-11.981v-27.966h11.981V191.453z M165.983,159.492h-11.981v-27.965h11.981V159.492z M181.971,255.374h-11.992v-27.969h11.992V255.374z M181.971,223.41h-11.992v-27.962h11.992V223.41z M181.971,191.453h-11.992 v-27.966h11.992V191.453z M181.971,159.492h-11.992v-27.965h11.992V159.492z M197.951,255.374h-11.985v-27.969h11.985V255.374z M197.951,223.41h-11.985v-27.962h11.985V223.41z M197.951,191.453h-11.985v-27.966h11.985V191.453z M197.951,159.492h-11.985 v-27.965h11.985V159.492z M213.928,255.374h-11.981v-27.969h11.981V255.374z M213.928,223.41h-11.981v-27.962h11.981V223.41z M213.928,191.453h-11.981v-27.966h11.981V191.453z M213.928,159.492h-11.981v-27.965h11.981V159.492z M229.905,255.374h-11.982 v-27.969h11.982V255.374z M229.905,223.41h-11.982v-27.962h11.982V223.41z M229.905,191.453h-11.982v-27.966h11.982V191.453z M229.905,159.492h-11.982v-27.965h11.982V159.492z\"/>\n</g></symbol>\n<symbol viewBox=\"0 0 29 29\" id=\"sketch-svg\"><title>checkbox</title><g transform=\"translate(1 1)\" stroke=\"#FAB131\" fill=\"none\" fill-rule=\"evenodd\">\n <ellipse fill=\"#FFF\" cx=\"13.519\" cy=\"13.522\" rx=\"13.434\" ry=\"13.257\"/>\n <path d=\"M6.724 13.533l5.057 4.99 9.337-9.212\" stroke-width=\"2\"/>\n</g></symbol>"
36
+ @svg_processor = SVGProcessor.new("test/svg", nil, nil)
37
+ @svg_processor.rebuild
38
+ assert_equal str, @svg_processor.to_s
39
+ end
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-scavenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Halse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -57,6 +57,10 @@ files:
57
57
  - lib/middleman_extension.rb
58
58
  - lib/svg_processor.rb
59
59
  - middleman-scavenger.gemspec
60
+ - test/svg/basic-svg.svg
61
+ - test/svg/illustrator-svg.svg
62
+ - test/svg/sketch-svg.svg
63
+ - test/unit/svg_processor_test.rb
60
64
  homepage: https://github.com/varvet/middleman-scavenger
61
65
  licenses:
62
66
  - MIT
@@ -77,10 +81,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
81
  version: '0'
78
82
  requirements: []
79
83
  rubyforge_project:
80
- rubygems_version: 2.4.5
84
+ rubygems_version: 2.4.5.1
81
85
  signing_key:
82
86
  specification_version: 4
83
87
  summary: A middleman extension for automatically creating SVG sprite sheets
84
88
  test_files:
85
89
  - features/support/env.rb
90
+ - test/svg/basic-svg.svg
91
+ - test/svg/illustrator-svg.svg
92
+ - test/svg/sketch-svg.svg
93
+ - test/unit/svg_processor_test.rb
86
94
  has_rdoc: