Sha256: a90798e61cd3137a18b01b6cdf1834d7daf658ea5f5fc714d12b7e372c52e5e6

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

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

require "tagz"

module Ramaze
  module Template

    # Is responsible for compiling a template using the Tagz templating engine.
    # Can be found at: http://rubyforge.org/projects/codeforpeople/
    #   gem install tagz 
    # be sure you get version 1.0 or higher 

    class Tagz < Template
      ENGINES[self] = %w[ rb tagz ] 

      class << self

        # Entry point for Action#render

        def transform action
          result, file = result_and_file(action)
          if file
            markup = "tagz{#{ file }}" 
            action.instance.extend Methods
            result = eval markup, action.binding, file 
          end
          result
        end

      end

      # Methods defines a host of methods useful inside the context of a view
      # including print style methods that output content rather that printing to
      # STDOUT

      module Methods
        include ::Tagz

      private
        def << s
          tagz << s; self 
        end

        def concat *a 
          a.each{|s| tagz << s}; self
        end

        def puts *a
          a.each{|elem| tagz << "#{ elem.to_s.chomp }#{ eol }"}
        end

        def print *a
          a.each{|elem| tagz << elem}
        end

        def p *a
          a.each{|elem| tagz << "#{ CGI.escapeHTML elem.inspect }#{ eol }"}
        end

        def pp *a
          a.each{|elem| tagz << "#{ CGI.escapeHTML PP.pp(elem, '') }#{ eol }"}
        end

        def eol
          if response.content_type =~ %r|text/plain|io
            "\n"
          else
            "<br />"
          end
        end

        def __ *a
          concat eol 
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.3.9 lib/ramaze/template/tagz.rb
ramaze-0.3.9.1 lib/ramaze/template/tagz.rb