Class: Jekyll::Engine::Erb
Defined Under Namespace
Modules: Helpers Classes: LazyStruct
Class Attribute Summary collapse
-
.renderer ⇒ Object
Returns the value of attribute renderer.
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Attributes inherited from Base
#content, #data, #info, #payload
Instance Method Summary collapse
- #_render(doc, binding, args = []) ⇒ Object
- #_render_erb(doc, binding, args = Rendering::ERB_OPTIONS) ⇒ Object
-
#initialize(*args) ⇒ Erb
constructor
A new instance of Erb.
-
#render(content = content, local_assigns = {}, *args) ⇒ Object
call-seq: engine.render => aString engine.render(content) => aString engine.render(content, local_assigns) => aString.
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Erb
Returns a new instance of Erb.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/jekyll/rendering.rb', line 168 def initialize(*args) super if ''.respond_to?(:force_encoding) @encoding = site.respond_to?(:encoding) && site.encoding || Encoding.default_external data.each_value { |val| if val.respond_to?(:force_encoding) && !val.frozen? val.force_encoding(encoding) end } end [Helpers, *info[:filters]].each { |mod| extend mod } %w[site page paginator].each { |key| value = payload[key] or next instance_variable_set("@#{key}", LazyStruct.new(value)) } @renderer = self.class.renderer || (Object.const_defined?(:Erubis) ? Erubis::FastEruby : ERB) end |
Class Attribute Details
.renderer ⇒ Object
Returns the value of attribute renderer.
164 165 166 |
# File 'lib/jekyll/rendering.rb', line 164 def renderer @renderer end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
166 167 168 |
# File 'lib/jekyll/rendering.rb', line 166 def encoding @encoding end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
166 167 168 |
# File 'lib/jekyll/rendering.rb', line 166 def page @page end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
166 167 168 |
# File 'lib/jekyll/rendering.rb', line 166 def renderer @renderer end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
166 167 168 |
# File 'lib/jekyll/rendering.rb', line 166 def site @site end |
Instance Method Details
#_render(doc, binding, args = []) ⇒ Object
216 217 218 |
# File 'lib/jekyll/rendering.rb', line 216 def _render(doc, binding, args = []) renderer.new(doc, *args).result(binding) end |
#_render_erb(doc, binding, args = Rendering::ERB_OPTIONS) ⇒ Object
211 212 213 214 |
# File 'lib/jekyll/rendering.rb', line 211 def _render_erb(doc, binding, args = Rendering::ERB_OPTIONS) res = renderer.new(doc, *args).result(binding) encoding ? res.force_encoding(encoding) : res end |
#render(content = content, local_assigns = {}, *args) ⇒ Object
call-seq:
engine.render => aString
engine.render(content) => aString
engine.render(content, local_assigns) => aString
Renders the content
as ERB template. Assigns optional local_assigns
for use in template if provided.
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/jekyll/rendering.rb', line 200 def render(content = content, local_assigns = {}, *args) assigns = '<% ' << local_assigns.keys.map { |var| "#{var} = local_assigns[#{var.inspect}]" }.join("\n") << " %>\n" unless local_assigns.empty? args.insert(0, "#{assigns}#{content}", binding) renderer == ERB ? _render_erb(*args) : _render(*args) rescue => err render_error(err, renderer) end |