Class: Tiny::Widget

Inherits:
Object
  • Object
show all
Includes:
Rendering
Defined in:
lib/tiny.rb

Overview

Examples:

class MyForm < Tiny::Widget
  def initialize(action)
    @action = action
  end

  def markup
    form(:action => @action) do
      fieldset do
        yield(self)
      end
    end
  end

  def text_input(name, value)
    TextInput.new(name, value).to_html
  end
end

class TextInput < Tiny::Widget
  def initialize(name, value)
    @name, @value = name, value
  end

  def markup
    label(@name.capitalize, :for => @name)
    input(:type => 'text', :id => @name, :name => @name, :value => @value)
  end
end

def my_form(action, &block)
  MyForm.new(action).to_html(&block)
end

my_form('/login') do |form|
  append! form.text_input 'email', '[email protected]'
end
# => <form action="/login">
  ...
  <fieldset>
    <label for="email">Email</label>
    <input type="text" id="email" name="email" value="[email protected]" />
  </fieldset>
  ...
</form>

# from template
<%= my_form('/login') do |form| %>
  <%= form.text_input 'email', '[email protected]' %>
<% end %>
# => <form action="/login">
  ...
  <fieldset>
    <label for="email">Email</label>
    <input type="text" id="email" name="email" value="[email protected]" />
  </fieldset>
  ...
</form>

See Also:

Method Summary

Methods included from Rendering

#markup, #render

Methods included from Helpers

escape_html, sanitize, #tag

Methods included from HamlTemplating

#with_buffer

Methods included from Markup

#cdata, #comment, #doctype, #html_tag

Methods included from Buffering

#append, #append!, #raw, #with_buffer

Methods included from ErubisTemplating

#capture_erb, #erb_block?, #with_buffer

Methods included from HTML

#a, #abbr, #address, #area, #article, #aside, #audio, #b, #base, #bdi, #bdo, #big, #blockquote, #body, #br, #button, #canvas, #caption, #cite, #code, #col, #colgroup, #command, content_tags, #datalist, #dd, #del, #details, #dfn, #div, #dl, #dt, #em, #embed, #fieldset, #figcaption, #figure, #footer, #form, #h1, #h2, #h3, #h4, #h5, #h6, #head, #header, #hgroup, #hr, #html, #i, #iframe, #img, #input, #ins, #kbd, #keygen, #label, #legend, #li, #link, #map, #mark, #meta, #meter, #nav, #noscript, #object, #ol, #optgroup, #option, #output, #p, #param, #pre, #progress, #q, #rp, #rt, #ruby, #s, #samp, #script, #section, #select, #small, #source, #span, #strike, #strong, #style, #sub, #summary, #sup, #table, #tbody, #td, #textarea, #tfoot, #th, #thead, #time, #title, #tr, #track, #tt, #u, #ul, #var, #video, void_tags, #wbr