lib/jekyll-inline-svg.rb in jekyll-inline-svg-0.0.1 vs lib/jekyll-inline-svg.rb in jekyll-inline-svg-0.0.2
- old
+ new
@@ -1,9 +1,9 @@
require 'svg_optimizer'
-require 'shellwords'
require 'jekyll/liquid_extensions'
class RemoveSize < SvgOptimizer::Plugins::Base
+ # remove "width" and "height" attributes
def process
xml.root.remove_attribute("height")
xml.root.remove_attribute("width")
end
end
@@ -15,40 +15,45 @@
PLUGINS_BLACKLIST.include? plugin
}+[
RemoveSize
]
-#logger.info(PLUGINS)
+
module Jekyll
module Tags
class JekyllInlineSvg < Liquid::Tag
-
- include Jekyll::LiquidExtensions #import lookup_variable function
+ #import lookup_variable function
# https://github.com/jekyll/jekyll/blob/master/lib/jekyll/liquid_extensions.rb
+ include Jekyll::LiquidExtensions
+
# For interpoaltion, look for liquid variables
VARIABLE = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
+
+ #Separate file path from other attributes
PATH_SYNTAX = %r!
^(?<path>[^\s"']+|"[^"]*"|'[^']*')
(?<params>.*)
!x
def initialize(tag_name, input, tokens)
super
- #@logger = Logger.new(STDOUT)
- #@logger.level = Logger::INFO
@svg, @params = JekyllInlineSvg.parse_params(input)
- #@logger.info(@svg +", "+@width)
end
+
+ #lookup Liquid variables from markup in context
def interpolate(markup, context)
markup.scan VARIABLE do |variable|
- markup = markup.gsub(VARIABLE, lookup_variable(context, variable.first))
+ markup = markup.sub(VARIABLE, lookup_variable(context, variable.first))
end
markup
end
+
+ #Parse parameters. Returns : [svg_path, parameters]
+ # Does not interpret variables as it's done at render time
def self.parse_params(input)
matched = input.strip.match(PATH_SYNTAX)
- return matched["path"].strip.gsub("\"","").gsub("'",""), matched["params"].strip
+ return matched["path"].gsub("\"","").gsub("'","").strip, matched["params"].strip
end
def render(context)
#global site variable
site = context.registers[:site]
#check if given name is a variable. Otherwise use it as a file name