jekyll-inline-svg 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b35ca0aca2374d360e32fb944580c58dd17379f
4
- data.tar.gz: ca91fc4965c53f6c0cd0e5c2dadfd602b5c45d55
3
+ metadata.gz: 54bf469b224e7c7af5dd5168fa7f417cde9aefe8
4
+ data.tar.gz: 6419acd66b53406b7d62633a11fb6e439a5c9945
5
5
  SHA512:
6
- metadata.gz: 7750d9db908305c278698367020be6781019cf16c598f83cdfd4a5dbc5329049460a7388d84f10baf2abb91120ecfb033f974609e38b199edeeef827896e314c
7
- data.tar.gz: d47ab973339952966e826de0d3b943c013b7da34bcfe44772d3bd503840dd8193892a5b8ec6cdf45b6df54e22a4b4f0e716c1e9bcbb1b9247c47ceaab16c453b
6
+ metadata.gz: e4ef60f184b0179b254afa2cb641a87b52d51dae78c6a87123aa1e3be9b3aa276f69fd81dd340f524ab1491d73387475be1eaf2df49bbe821627cefb225ec71d
7
+ data.tar.gz: 8692d77303fb7400b35705ced6a9bc1a7f654a976088777b6e6b544f5494542f6bb152be76e3dda94351e06edb60b467e8c5ed243e476840f29b36d452014c24
data/README.md CHANGED
@@ -2,13 +2,28 @@
2
2
 
3
3
  SVG optimizer and inliner for jekyll
4
4
 
5
- This liquid tag will let you inline SVG images in your jekyll sites.
5
+ This liquid tag will let you inline SVG images in your jekyll sites. It will add `{%svg %}` to `Liquid::Tag`.
6
+
7
+ ## Installation
8
+
9
+ Run `gem install jekyll-inline-svg` or add `gem "jekyll-inline-svg", "~>0.0.1"` to your **Gemfile**.
10
+
11
+ Then in your **_config.yml** :
12
+
13
+ ```
14
+ gems:
15
+ - jekyll-inline-svg
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ Use the Liquid tag in your pages :
6
21
 
7
22
  ```
8
- {% svg /path/to/file.svg width=24 foo="bar" %}
23
+ {% svg /path/to/square.svg width=24 foo="bar" %}
9
24
  ```
10
25
 
11
- Will include the svg file in your output HTML like this :
26
+ Jekyll will include the svg file in your output HTML like this :
12
27
 
13
28
  ```
14
29
  <svg width=24 foo="bar" version="1.1" id="square" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 24 24" >
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  A Liquid tag to inline and optimize SVG images in your HTML
8
8
  Supports custom DOM Attributes parameters and variables interpretation.
9
9
  EOF
10
- spec.version = "0.0.1"
10
+ spec.version = "0.0.2"
11
11
  spec.authors = ["Sebastien DUMETZ"]
12
12
  spec.email = "s.dumetz@holusion.com"
13
13
  spec.homepage = "https://github.com/sdumetz/jekyll-inline-svg"
@@ -1,7 +1,7 @@
1
1
  require 'svg_optimizer'
2
- require 'shellwords'
3
2
  require 'jekyll/liquid_extensions'
4
3
  class RemoveSize < SvgOptimizer::Plugins::Base
4
+ # remove "width" and "height" attributes
5
5
  def process
6
6
  xml.root.remove_attribute("height")
7
7
  xml.root.remove_attribute("width")
@@ -17,15 +17,18 @@ PLUGINS = SvgOptimizer::DEFAULT_PLUGINS.delete_if {|plugin|
17
17
  RemoveSize
18
18
  ]
19
19
 
20
- #logger.info(PLUGINS)
20
+
21
21
  module Jekyll
22
22
  module Tags
23
23
  class JekyllInlineSvg < Liquid::Tag
24
-
25
- include Jekyll::LiquidExtensions #import lookup_variable function
24
+ #import lookup_variable function
26
25
  # https://github.com/jekyll/jekyll/blob/master/lib/jekyll/liquid_extensions.rb
26
+ include Jekyll::LiquidExtensions
27
+
27
28
  # For interpoaltion, look for liquid variables
28
29
  VARIABLE = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
30
+
31
+ #Separate file path from other attributes
29
32
  PATH_SYNTAX = %r!
30
33
  ^(?<path>[^\s"']+|"[^"]*"|'[^']*')
31
34
  (?<params>.*)
@@ -34,20 +37,22 @@ module Jekyll
34
37
  def initialize(tag_name, input, tokens)
35
38
  super
36
39
 
37
- #@logger = Logger.new(STDOUT)
38
- #@logger.level = Logger::INFO
39
40
  @svg, @params = JekyllInlineSvg.parse_params(input)
40
- #@logger.info(@svg +", "+@width)
41
41
  end
42
+
43
+ #lookup Liquid variables from markup in context
42
44
  def interpolate(markup, context)
43
45
  markup.scan VARIABLE do |variable|
44
- markup = markup.gsub(VARIABLE, lookup_variable(context, variable.first))
46
+ markup = markup.sub(VARIABLE, lookup_variable(context, variable.first))
45
47
  end
46
48
  markup
47
49
  end
50
+
51
+ #Parse parameters. Returns : [svg_path, parameters]
52
+ # Does not interpret variables as it's done at render time
48
53
  def self.parse_params(input)
49
54
  matched = input.strip.match(PATH_SYNTAX)
50
- return matched["path"].strip.gsub("\"","").gsub("'",""), matched["params"].strip
55
+ return matched["path"].gsub("\"","").gsub("'","").strip, matched["params"].strip
51
56
  end
52
57
  def render(context)
53
58
  #global site variable
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  svgname: square
3
+ svgclass: hello
3
4
  ---
4
5
  Hello world
5
6
  <div id="base">
@@ -21,5 +22,5 @@ Hello world
21
22
  <div id="interpret">
22
23
  <label>Interpret embedded variables</label>
23
24
  {% svg /files/{{page.svgname}}.svg %}
24
- {% svg /files/square.svg id="name-{{page.svgname}}" %}
25
+ {% svg /files/square.svg id="name-{{page.svgname}}" class="class-{{page.svgclass}}" %}
25
26
  </div>
@@ -27,16 +27,25 @@ describe(Jekyll::Tags::JekyllInlineSvg) do
27
27
  svg, params = Jekyll::Tags::JekyllInlineSvg.parse_params("'/path/to/foo space'")
28
28
  expect(svg).to eq("/path/to/foo space")
29
29
  end
30
+ it "strip leading and trailing spaces" do
31
+ svg, params = Jekyll::Tags::JekyllInlineSvg.parse_params(" /path/to/foo ")
32
+ expect(svg).to eql("/path/to/foo")
33
+ end
34
+ # required when a variable is defined with leading/trailing space then embedded.
35
+ it "strip in-quote leading and trailing spaces" do
36
+ svg, params = Jekyll::Tags::JekyllInlineSvg.parse_params("'/path/to/foo '")
37
+ expect(svg).to eql("/path/to/foo")
38
+ end
39
+ it "keep Liquid variables" do
40
+ svg, params = Jekyll::Tags::JekyllInlineSvg.parse_params("/path/to/{{foo}}")
41
+ expect(svg).to eql("/path/to/{{foo}}")
42
+ end
30
43
  it "don't parse parameters" do
31
44
  svg, params = Jekyll::Tags::JekyllInlineSvg.parse_params("'/path/to/foo space' id='bar' style=\"hello\"")
32
45
  expect(params).to eq("id='bar' style=\"hello\"")
33
46
  end
34
47
  end
35
48
 
36
- describe "Interpolate variables" do
37
-
38
- end
39
-
40
49
  describe "Integration" do
41
50
 
42
51
  before(:context) do
@@ -79,6 +88,7 @@ describe(Jekyll::Tags::JekyllInlineSvg) do
79
88
  expect(data.size).to eq(2)
80
89
  expect(data[0].to_xml).to eql(ref)
81
90
  expect(data[1].get_attribute("id")).to eql("name-square")
91
+ expect(data[1].get_attribute("class")).to eql("class-hello")
82
92
  end
83
93
  end
84
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-inline-svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien DUMETZ