Hobo Cookbook

View Source

Rapid

<view>

Provides a read-only view tailored to the type of the object being viewed. <view> is a polymorphic tag which means that there are a variety of definitions, each one written for a particular type. For example there are views for Date, Time, Numeric, String and Boolean. The type specific view is enclosed in a wrapper tag (typically a <span> or <div>) with some useful classes automatically added.

Usage

Assuming the context is a blog post…

  • Viewing a DateTime field:

      <view:created_at/> -> <span class="view blog-post-created-at">June 09, 2008 15:36</span>
  • Viewing a String field:

      <view:title/> -> <span class="view blog-post-title">My First Blog Post</span>
  • Viewing an Integer field:

      <view:comment_count/> -> <span class="view blog-post-comment-count">4</span>
  • Viewing the blog post itself results in a link to the blog post (using Rapid’s <a> tag):

      <view/> -> <span class="view model:blog-post-1"><a href="/blog_posts/1">My First Blog Post</a></span>

Additional Notes

  • The wrapper tag is <span> unless the field type is Text (different to String) where it is <div>. Use the inline or block attributes to force a <span> or a <div>, e.g.

      <view:body/> -> <div class="view blog-post-body">This is my blog post body</div>
    
      <view:body inline/> -> <span class="view blog-post-body">This is my blog post body</span>
    
      <view:created_at block/> -> <div class="view blog-post-created-at">June 09, 2008 15:36</div>
  • Use the no-wrapper attribute to remove the wrapper tag completely. e.g.

      <view:created_at no-wrapper/> -> June 09, 2008 15:36

Show Source

<view for='ActiveRecord::Base'>

Renders a link (<a>) to this

Show Source

<view for='Date'>

Renders this.to_s(:long), or this.strftime(format) if the format attribute is given

Show Source

<view for='Time'>

Renders this.to_s(:long), or this.strftime(format) if the format attribute is given

Show Source

<view for='ActiveSupport::TimeWithZone'>

Renders this.to_s(:long), or this.strftime(format) if the format attribute is given

Show Source

<view for='Numeric'>

Renders this.to_s, or format % this if the format attribute is given

Show Source

<view for='string'>

Renders this with HTML escaping and newlines replaced with <br> tags

Show Source

<view for='boolean'>

Renders ‘Yes’ for true and ‘No’ for false

Show Source

Comments

No comments to display