Class: Jekyll::Tags::JekyllInlineSvg
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Tags::JekyllInlineSvg
- Includes:
- LiquidExtensions
- Defined in:
- lib/jekyll-inline-svg.rb
Constant Summary collapse
- VARIABLE =
github.com/jekyll/jekyll/blob/master/lib/jekyll/liquid_extensions.rb For interpoaltion, look for liquid variables
/\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i- PATH_SYNTAX =
%r! ^(?<path>[^\s"']+|"[^"]*"|'[^']*') (?<params>.*) !x
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tag_name, input, tokens) ⇒ JekyllInlineSvg
constructor
A new instance of JekyllInlineSvg.
-
#interpolate(markup, context) ⇒ Object
@logger.info(@svg “, ”@width).
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, input, tokens) ⇒ JekyllInlineSvg
Returns a new instance of JekyllInlineSvg.
34 35 36 37 38 39 40 41 |
# File 'lib/jekyll-inline-svg.rb', line 34 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 |
Class Method Details
.parse_params(input) ⇒ Object
48 49 50 51 |
# File 'lib/jekyll-inline-svg.rb', line 48 def self.parse_params(input) matched = input.strip.match(PATH_SYNTAX) return matched["path"].strip.gsub("\"","").gsub("'",""), matched["params"].strip end |
Instance Method Details
#interpolate(markup, context) ⇒ Object
@logger.info(@svg “, ”@width)
42 43 44 45 46 47 |
# File 'lib/jekyll-inline-svg.rb', line 42 def interpolate(markup, context) markup.scan VARIABLE do |variable| markup = markup.gsub(VARIABLE, lookup_variable(context, variable.first)) end markup end |
#render(context) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jekyll-inline-svg.rb', line 52 def render(context) #global site variable site = context.registers[:site] #check if given name is a variable. Otherwise use it as a file name svg_file = Jekyll.sanitized_path(site.source, interpolate(@svg,context)) params = interpolate(@params,context) xml = File.open(svg_file, "rb") optimized = SvgOptimizer.optimize(xml.read, PLUGINS) "#{optimized.sub("<svg ","<svg #{params} ")}" end |