Parent

Class Index [+]

Quicksearch

Ramaze::Gestalt

Gestalt is the custom HTML/XML builder for Ramaze, based on a very simple DSL it will build your markup.

@example

  html =
    Gestalt.build do
      html do
        head do
          title "Hello, World!"
        end
        body do
          h1 "Hello, World!"
        end
      end
    end

Attributes

out[RW]

Public Class Methods

build(&block) click to toggle source

The default way to start building your markup. Takes a block and returns the markup.

@param [Block] block

    # File lib/ramaze/gestalt.rb, line 31
31:     def self.build(&block)
32:       self.new(&block).to_s
33:     end
new(&block) click to toggle source

Gestalt.new is like ::build but will return itself. you can either access # or .to_s it, which will return the actual markup.

Useful for distributed building of one page.

@param [Block] block

    # File lib/ramaze/gestalt.rb, line 44
44:     def initialize(&block)
45:       @out = []
46:       instance_eval(&block) if block_given?
47:     end

Public Instance Methods

_gestalt_build_tag(name, attr = {}, text = []) click to toggle source

Build a tag for `name`, using `args` and an optional block that will be yielded.

@param [String] name @param [Hash] attr @param [Hash] text

     # File lib/ramaze/gestalt.rb, line 110
110:     def _gestalt_build_tag(name, attr = {}, text = [])
111:       @out << "<#{name}"
112:       @out << attr.map{|(k,v)| %[ #{k}="#{_gestalt_escape_entities(v)}"] }.join
113:       if text != [] or block_given?
114:         @out << ">"
115:         @out << _gestalt_escape_entities([text].join)
116:         if block_given?
117:           text = yield
118:           @out << text.to_str if text != @out and text.respond_to?(:to_str)
119:         end
120:         @out << "</#{name}>"
121:       else
122:         @out << ' />'
123:       end
124:     end
_gestalt_call_tag(name, args, &block) click to toggle source

Calls a particular tag based on the specified parameters.

@param [String] name @param [Hash] args @param [Block] block

     # File lib/ramaze/gestalt.rb, line 89
 89:     def _gestalt_call_tag(name, args, &block)
 90:       if args.size == 1 and args[0].kind_of? Hash
 91:         # args are just attributes, children in block...
 92:         _gestalt_build_tag name, args[0], &block
 93:       elsif args[1].kind_of? Hash
 94:         # args are text and attributes ie. a('mylink', :href => '/mylink')
 95:         _gestalt_build_tag(name, args[1], args[0], &block)
 96:       else
 97:         # no attributes, but text
 98:         _gestalt_build_tag name, {}, args, &block
 99:       end
100:     end
_gestalt_escape_entities(s) click to toggle source

Replace common HTML characters such as “ and < with their entities.

@param [String] s The HTML string that needs to be escaped.

     # File lib/ramaze/gestalt.rb, line 131
131:     def _gestalt_escape_entities(s)
132:       s.to_s.gsub(/&/, '&amp;').
133:         gsub(/"/, '&quot;').
134:         gsub(/'/, '&apos;').
135:         gsub(/</, '&lt;').
136:         gsub(/>/, '&gt;')
137:     end
method_missing(meth, *args, &block) click to toggle source

Catching all the tags. passing it to _gestalt_build_tag

@param [String] method The method that was called. @param [Hash] args Additional arguments passed to the called method. @param [Block] block

    # File lib/ramaze/gestalt.rb, line 56
56:     def method_missing(meth, *args, &block)
57:       _gestalt_call_tag meth, args, &block
58:     end
p(*args, &block) click to toggle source

Workaround for Kernel#p to make

tags possible.

@param [Hash] args Extra arguments that should be processed before

 creating the paragraph tag.

@param [Block] block

    # File lib/ramaze/gestalt.rb, line 67
67:     def p(*args, &block)
68:       _gestalt_call_tag :p, args, &block
69:     end
select(*args, &block) click to toggle source

Workaround for Kernel#select to make work.

@param [Hash] args Extra arguments that should be processed before

 creating the select tag.

@param [Block] block

    # File lib/ramaze/gestalt.rb, line 78
78:     def select(*args, &block)
79:       _gestalt_call_tag(:select, args, &block)
80:     end
tag(name, *args, &block) click to toggle source

Shortcut for building tags,

@param [String] name @param [Hash] args @param [Block] block

     # File lib/ramaze/gestalt.rb, line 146
146:     def tag(name, *args, &block)
147:       _gestalt_call_tag(name.to_s, args, &block)
148:     end
to_s() click to toggle source

Convert the final output of Gestalt to a string. This method has the following alias: “to_str“.

@return [String]

     # File lib/ramaze/gestalt.rb, line 156
156:     def to_s
157:       @out.join
158:     end
Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.