Sha256: e61526dec9dff24c097fab17434e1f5dcdb5ff85c345f49da213410cc35e3f18

Contents?: true

Size: 644 Bytes

Versions: 4

Compression:

Stored size: 644 Bytes

Contents

require 'erb'

module Tadpole
  module SectionProviders
    class ERBProvider < SectionProvider
      EXTENSIONS = ['.erb']
      
      def initialize(full_path, owner)
        super

        erb = ERB.new(content, nil, '<>')
        instance_eval(<<-eof, full_path, 1)
          def render(locals = nil, &block)
            if locals
              opts = owner.options
              owner.options = owner.options.to_hash.update(locals)
            end
            out = owner.instance_eval(#{erb.src.inspect}, __FILE__, __LINE__)
            owner.options = opts if locals
            out
          end
        eof
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tadpole-0.1.7 lib/tadpole/providers/erb.rb
tadpole-0.1.4 lib/tadpole/providers/erb.rb
tadpole-0.1.5 lib/tadpole/providers/erb.rb
tadpole-0.1.6 lib/tadpole/providers/erb.rb