Sha256: fc120a1dacc912bed36f73cb37b8b527aae22afa4aea8c44d576425ae24da826

Contents?: true

Size: 999 Bytes

Versions: 29

Compression:

Stored size: 999 Bytes

Contents

require 'awestruct/util/exception_helper'
require 'awestruct/handlers/base_handler'

module Awestruct
  module Handlers
    class InterpolationHandler < BaseHandler

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

      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
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
awestruct-0.6.7 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.6 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.5 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.4 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.3 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.2 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.1 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.0 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.0.RC1 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.0.alpha4 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.0.alpha3 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.6.0.alpha1 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.7 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.7.RC2 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.7.RC1 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.6 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.6.beta9 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.6.beta8 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.6.beta7 lib/awestruct/handlers/interpolation_handler.rb
awestruct-0.5.6.beta6 lib/awestruct/handlers/interpolation_handler.rb