Class: Awestruct::Handlers::InterpolationHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/awestruct/handlers/interpolation_handler.rb

Instance Attribute Summary

Attributes inherited from BaseHandler

#delegate, #site

Instance Method Summary collapse

Methods inherited from BaseHandler

#content_line_offset, #content_syntax, #dependencies, #execute_shell, #front_matter, #inherit_front_matter, #input_mtime, #output_extension, #output_filename, #output_path, #path, #raw_content, #relative_source_path, #simple_name, #stale?, #to_chain

Constructor Details

#initialize(site, delegate) ⇒ InterpolationHandler

Returns a new instance of InterpolationHandler.



8
9
10
# File 'lib/awestruct/handlers/interpolation_handler.rb', line 8

def initialize(site, delegate)
  super( site, delegate )
end

Instance Method Details

#rendered_content(context, with_layouts = true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/awestruct/handlers/interpolation_handler.rb', line 12

def rendered_content(context, with_layouts=true)
  content = delegate.raw_content

  return nil if content.nil?
  return content unless front_matter.fetch('interpolate', site.interpolate) == true

  content = content.gsub( /\\/, '\\\\\\\\' )
  content = content.gsub( /\\\\#/, '\\#' )
  content = content.gsub( /#(?!\{)/, '\#' )
  content = content.gsub( '@', '\@' )
  content = "%@#{content}@"
  begin
    c = context.instance_eval( content )
  rescue Exception => e # Don't barf all over ourselves if an exception is thrown
    ExceptionHelper.log_building_error e, relative_source_path
    c = delegate.raw_content
  end
  c

end