Module: Tiny::Rendering

Includes:
HTML, Helpers
Included in:
Widget
Defined in:
lib/tiny.rb

Overview

Support for HTML markup generation for classes, can be included in any class that is to be represented with HTML markup.

Examples:

class User < Model
  include Tiny::Rendering

  def markup
    div(:id => "user-#{self.id}") do
      img :src => self.avatar_url
      dl do
        dt "First Name"
        dd self.first_name
        dt "Last Name"
        dd self.last_name
      end
    end
  end
end

user = User.create(:first_name => 'Macario',
  :last_name => 'Ortega',
  :avatar_url => 'http://example.com/profile/dbg.jpeg')
user.to_html
# => <div id="user-1">
  <img src="http://example.com/profile/dbg.jpeg" />
  <dl>
    <dt>First Name</dt>
    <dd>Macario</dd>
    <dt>Last Name</dt>
    <dd>Ortega</dd>
  </dl>
</div>

See Also:

Instance Method Summary collapse

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, #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, #wbr

Instance Method Details

#markup {|self| ... } ⇒ Object

Override this method with specific markup.

Yields:

  • (self)

    Content block (from calling to #render).

Raises:

  • (NotImplementedError)

See Also:



409
410
411
# File 'lib/tiny.rb', line 409

def markup
  raise NotImplementedError
end

#render(&block) ⇒ String Also known as: to_html

Renders the html markup specified by #markup.

Returns:

See Also:



418
419
420
421
422
423
424
425
426
427
# File 'lib/tiny.rb', line 418

def render(&block)
  output = with_buffer do
    next markup unless block_given?
    markup do |args|
      context = eval('self', block.binding)
      append! context.instance_eval{ with_buffer(*args, &block) }
    end
  end
  SafeString.new output
end