Sha256: a2ed654a221c554c6f61e924a825de9b91fc32e64db2983a4110047acc61cc7d

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

# This module serves as a namespace for all templates, it will autoload
# Amrita2, Erubis, Haml, Liquid and Markaby if you refer to them.

module Ramaze
  module Template

    %w[ Amrita2 Erubis Haml Liquid Markaby Remarkably ].each do |const|
      autoload(const, "ramaze/template/#{const.downcase}")
    end

    # The superclass for all templates, doesn't do much more than including
    # Ramaze::Helper and defining #reaction_or_file

    class Template
      include Ramaze::Helper

      class << self

        # pass it the results of the method of the controller
        # and a possible file, it will see if the file is an actual file

        def reaction_or_file action
          reaction = render_method(action)

          if file = action.template
            File.read(file)
          else
            reaction.to_s
          end
        end

        def result_and_file(action)
          result = render_method(action)

          if file = action.template
            content = File.read(file)
          end

          [result, content]
        end

        def render_method(action)
          return unless method = action.method
          action.controller.__send__(method, *action.params)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramaze-0.1.1 lib/ramaze/template.rb