module Jekyll::Minibundle::VariableTemplate::Generator

Transforms array of tokens to Ruby interpolation string.

Idea adapted from Mustache's [Generator](github.com/mustache/mustache/blob/master/lib/mustache/generator.rb).

Public Class Methods

compile(tokens) click to toggle source
    # File lib/jekyll/minibundle/variable_template.rb
126 def self.compile(tokens)
127   result = '"'
128 
129   tokens.each do |token|
130     result +=
131       if token.variable?
132         %(#\{variables["#{escape_token(token.value)}"].to_s})
133       else
134         escape_token(token.value)
135       end
136   end
137 
138   result += '"'
139 
140   result
141 end
escape_token(token) click to toggle source
    # File lib/jekyll/minibundle/variable_template.rb
143 def self.escape_token(token)
144   token.inspect[1..-2]
145 end