Sha256: 439517810aaa954aae960b1e7be138fc30a084e553cdf2f7e1dcdab35411c0e3

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

require 'tagz'

module Ramaze
  module View
    module Tagz
      def self.call(action, string)
        return string, 'text/html' unless action.view

        markup = "tagz{#{string}}"
        action.instance.extend(Ramaze::View::Tagz::Methods)
        binding = action.binding

        html = eval(markup, binding, action.view)

        return html, 'text/html'
      end

      # 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 << "#{ Rack::Utils.escape_html elem.inspect }#{ eol }"}
        end

        def pp(*a)
          a.each{|elem| tagz << "#{ Rack::Utils.escape_html 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

29 entries across 29 versions & 4 rubygems

Version Path
Pistos-ramaze-2009.04.08 lib/ramaze/view/tagz.rb
Pistos-ramaze-2009.06.12 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.04.01 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.04.08 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.04.18 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.04.22 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.04 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.05.08 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.05 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.06.04 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.06.12 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.06 lib/ramaze/view/tagz.rb
manveru-ramaze-2009.07 lib/ramaze/view/tagz.rb
rjspotter-ramaze-2009.06.29 lib/ramaze/view/tagz.rb
rjspotter-ramaze-2009.06.31 lib/ramaze/view/tagz.rb
ramaze-2011.01.30 lib/ramaze/view/tagz.rb
ramaze-2011.01 lib/ramaze/view/tagz.rb
ramaze-2010.06.18 lib/ramaze/view/tagz.rb
ramaze-2010.04.04 lib/ramaze/view/tagz.rb
ramaze-2010.04 lib/ramaze/view/tagz.rb