Sha256: 0b995d5c660001f26c35008ddad58a2b4cce051aa66bbed3e24e224e8ae04141

Contents?: true

Size: 990 Bytes

Versions: 6

Compression:

Stored size: 990 Bytes

Contents

require 'tilt'

module Lotus
  module View
    # A logic-less template.
    #
    # @since 0.1.0
    class Template
      def initialize(template)
        @_template = Tilt.new(template)
      end

      # Returns the format that the template handles.
      #
      # @return [Symbol] the format name
      #
      # @since 0.1.0
      #
      # @example
      #   require 'lotus/view'
      #
      #   template = Lotus::View::Template.new('index.html.erb')
      #   template.format # => :html
      def format
        @_template.basename.match(/\.([^.]+)/).captures.first.to_sym
      end

      # Render the template within the context of the given scope.
      #
      # @param scope [Lotus::View::Scope] the rendering scope
      #
      # @return [String] the output of the rendering process
      #
      # @api private
      # @since 0.1.0
      #
      # @see Lotus::View::Scope
      def render(scope, &blk)
        @_template.render(scope, {}, &blk)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lotus-view-0.4.4 lib/lotus/view/template.rb
lotus-view-0.4.3 lib/lotus/view/template.rb
lotus-view-0.4.2 lib/lotus/view/template.rb
lotus-view-0.4.1 lib/lotus/view/template.rb
lotus-view-0.4.0 lib/lotus/view/template.rb
lotus-view-0.3.0 lib/lotus/view/template.rb