### Home Classes Methods

### In Files

- lib/ramaze/gestalt.rb

### Parent

Object

### Methods

- ::build
- ::new
- #_gestalt_build_tag
- #_gestalt_call_tag
- #_gestalt_escape_entities
- #method_missing
- #p
- #select
- #tag
- #to_s
- #to_str

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Reloader::Watcher
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# 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
    def self.build(&block)
      self.new(&block).to_s
    end

new(&block) click to toggle source

Gestalt.new is like ::build but will return itself. you can either access out 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
    def initialize(&block)
      @out = []
      instance_eval(&block) if block_given?
    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
    def _gestalt_build_tag(name, attr = {}, text = [])
      @out << "<#{name}"
      @out << attr.map{|(k,v)| %[ #{k}="#{_gestalt_escape_entities(v)}"] }.join
      if text != [] or block_given?
        @out << ">"
        @out << _gestalt_escape_entities([text].join)
        if block_given?
          text = yield
          @out << text.to_str if text != @out and text.respond_to?(:to_str)
        end
        @out << "</#{name}>"
      else
        @out << ' />'
      end
    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
    def _gestalt_call_tag(name, args, &block)
      if args.size == 1 and args[0].kind_of? Hash
        # args are just attributes, children in block...
        _gestalt_build_tag name, args[0], &block
      elsif args[1].kind_of? Hash
        # args are text and attributes ie. a('mylink', :href => '/mylink')
        _gestalt_build_tag(name, args[1], args[0], &block)
      else
        # no attributes, but text
        _gestalt_build_tag name, {}, args, &block
      end
    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
    def _gestalt_escape_entities(s)
      s.to_s.gsub(/&/, '&amp;').
        gsub(/"/, '&quot;').
        gsub(/'/, '&apos;').
        gsub(/</, '&lt;').
        gsub(/>/, '&gt;')
    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
    def method_missing(meth, *args, &block)
      _gestalt_call_tag meth, args, &block
    end

p(*args, &block) click to toggle source

Workaround for Kernel#p to make <p /> 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
    def p(*args, &block)
      _gestalt_call_tag :p, args, &block
    end

select(*args, &block) click to toggle source

Workaround for Kernel#select to make <select></select> 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
    def select(*args, &block)
      _gestalt_call_tag(:select, args, &block)
    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
    def tag(name, *args, &block)
      _gestalt_call_tag(name.to_s, args, &block)
    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
    def to_s
      @out.join
    end

Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.