Permalink
Browse files

convert <% ... do %> to <%= ... do %> in README

  • Loading branch information...
1 parent 105386d commit bc5603babb7d36ec78dda8028cfe69bd913509c6 @justinfrench committed May 17, 2011
Showing with 42 additions and 42 deletions.
  1. +42 −42 README.textile
View
@@ -18,9 +18,9 @@ h2. The Story
One day, I finally had enough, so I opened up my text editor, and wrote a DSL for how I'd like to author forms:
<pre>
- <% semantic_form_for @article do |form| %>
+ <%= semantic_form_for @article do |form| %>
- <% form.inputs :name => "Basic" do %>
+ <%= form.inputs :name => "Basic" do %>
<%= form.input :title %>
<%= form.input :body %>
<%= form.input :section %>
@@ -29,19 +29,19 @@ One day, I finally had enough, so I opened up my text editor, and wrote a DSL fo
<%= form.input :allow_comments, :label => "Allow commenting on this article" %>
<% end %>
- <% form.inputs :name => "Advanced" do %>
+ <%= form.inputs :name => "Advanced" do %>
<%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
<%= form.input :extract, :required => false %>
<%= form.input :description, :required => false %>
<%= form.input :url_title, :required => false %>
<% end %>
- <% form.inputs :name => "Author", :for => :author do |author_form| %>
+ <%= form.inputs :name => "Author", :for => :author do |author_form| %>
<%= author_form.input :first_name %>
<%= author_form.input :last_name %>
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button %>
<% end %>
@@ -126,7 +126,7 @@ Forms are really boring to code... you want to get onto the good stuff as fast a
This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord @belongs_to@-association), followed by a submit button:
<pre>
- <% semantic_form_for @user do |form| %>
+ <%= semantic_form_for @user do |form| %>
<%= form.inputs %>
<%= form.buttons %>
<% end %>
@@ -137,7 +137,7 @@ This is a great way to get something up fast, but like scaffolding, it's not rec
You probably want to specify the order of the fields, skip some of the fields or even add in fields that Formtastic couldn't detect, you can pass in a list of field names to @inputs@ and list of button names to @buttons@:
<pre>
- <% semantic_form_for @user do |form| %>
+ <%= semantic_form_for @user do |form| %>
<%= form.inputs :title, :body, :section, :categories, :created_at %>
<%= form.buttons :commit %>
<% end %>
@@ -146,15 +146,15 @@ You probably want to specify the order of the fields, skip some of the fields or
You probably want control over the input type Formtastic uses for each field, you can expand the @inputs@ and @buttons@ blocks. This specifies the @:section@ input should be a set of radio buttons (rather than the default select box), and that the @:created_at@ field should be a string (rather than the default datetime selects):
<pre>
- <% semantic_form_for @post do |form| %>
- <% form.inputs do %>
+ <%= semantic_form_for @post do |form| %>
+ <%= form.inputs do %>
<%= form.input :title %>
<%= form.input :body %>
<%= form.input :section, :as => :radio %>
<%= form.input :categories %>
<%= form.input :created_at, :as => :string %>
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button %>
<% end %>
<% end %>
@@ -163,19 +163,19 @@ You probably want control over the input type Formtastic uses for each field, yo
If you want to customize the label text, or render some hint text below the field, specify which fields are required/optional, or break the form into two fieldsets, the DSL is pretty comprehensive:
<pre>
- <% semantic_form_for @post do |form| %>
- <% form.inputs "Basic", :id => "basic" do %>
+ <%= semantic_form_for @post do |form| %>
+ <%= form.inputs "Basic", :id => "basic" do %>
<%= form.input :title %>
<%= form.input :body %>
<% end %>
- <% form.inputs :name => "Advanced Options", :id => "advanced" do %>
+ <%= form.inputs :name => "Advanced Options", :id => "advanced" do %>
<%= form.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
<%= form.input :section, :as => :radio %>
<%= form.input :user, :label => "Author", :member_label => :full_name %>
<%= form.input :categories, :required => false %>
<%= form.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button %>
<% end %>
<% end %>
@@ -184,15 +184,15 @@ If you want to customize the label text, or render some hint text below the fiel
You can create forms for nested resources:
<pre>
- <% semantic_form_for [@author, @post] do |form| %>
+ <%= semantic_form_for [@author, @post] do |form| %>
</pre>
Nested forms are also supported (don't forget your models need to be setup correctly with @accepts_nested_attributes_for@). You can do it in the Rails way:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.inputs :title, :body, :created_at %>
- <% form.semantic_fields_for :author do |author| %>
+ <%= form.semantic_fields_for :author do |author| %>
<%= author.inputs :first_name, :last_name, :name => "Author" %>
<% end %>
<%= form.buttons %>
@@ -202,7 +202,7 @@ Nested forms are also supported (don't forget your models need to be setup corre
Or the Formtastic way with the @:for@ option:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.inputs :title, :body, :created_at %>
<%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
<%= form.buttons %>
@@ -212,7 +212,7 @@ Or the Formtastic way with the @:for@ option:
When working in has many association, you can even supply @"%i"@ in your fieldset name that it will be properly interpolated with the child index. For example:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.inputs %>
<%= form.inputs :name => 'Category #%i', :for => :categories %>
<%= form.buttons %>
@@ -223,18 +223,18 @@ If you have more than one form on the same page, it may lead to HTML invalidatio
a namespace for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate html id. For example:
<pre>
- <% semantic_form_for(@post, :namespace => 'cat_form') do |form| %>
- <%= form.input :title %> # id="cat_form_post_title"
- <%= form.input :body %> # id="cat_form_post_body"
- <%= form.input :created_at %> # id="cat_form_post_created_at"
- <%= form.buttons %>
+ <%= semantic_form_for(@post, :namespace => 'cat_form') do |form| %>
+ <%= form.input :title %> # id="cat_form_post_title"
+ <%= form.input :body %> # id="cat_form_post_body"
+ <%= form.input :created_at %> # id="cat_form_post_created_at"
+ <%= form.buttons %>
<% end %>
</pre>
Customize HTML attributes for any input using the @:input_html@ option. Typically this is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like "autogrow":http://plugins.jquery.com/project/autogrow textareas:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.input :title, :input_html => { :cols => 10 } %>
<%= form.input :body, :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 10 } %>
<%= form.input :created_at, :input_html => { :disabled => true } %>
@@ -245,9 +245,9 @@ Customize HTML attributes for any input using the @:input_html@ option. Typicall
The same can be done for buttons with the @:button_html@ option:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
...
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button :button_html => { :class => "primary", :disable_with => 'Wait...' } %>
<% end %>
<% end %>
@@ -256,7 +256,7 @@ The same can be done for buttons with the @:button_html@ option:
Customize the HTML attributes for the @<li>@ wrapper around every input with the @:wrapper_html@ option hash. There's one special key in the hash (@:class@), which will actually _append_ your string of classes to the existing classes provided by Formtastic (like @"required string error"@).
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.input :title, :wrapper_html => { :class => "important" } %>
<%= form.input :body %>
<%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
@@ -267,7 +267,7 @@ Customize the HTML attributes for the @<li>@ wrapper around every input with the
Customize the default class used for hints on each attribute or globally in the @config/formtastic.rb@ file. Similarly you can customize the error classes on an attribute level or globally.
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.input :title, :hint_class => 'custom-html-class', :error_class => 'custom-error-class' %>
<% end %>
</pre>
@@ -338,7 +338,7 @@ Formtastic got some neat I18n-features. ActiveRecord object names and attributes
Basic localization (labels only, with ActiveRecord):
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
<%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
<%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
@@ -391,13 +391,13 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
*3. ...and now you'll get:*
<pre>
- <% semantic_form_for Post.new do |form| %>
- <% form.inputs do %>
+ <%= semantic_form_for Post.new do |form| %>
+ <%= form.inputs do %>
<%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
<%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
<%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button %> # => "Create my %{model}"
<% end %>
<% end %>
@@ -408,8 +408,8 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
_Note: Slightly different because Formtastic can't guess how you group fields in a form. Legend text can be set with first (as in the sample below) specified value, or :name/:title options - depending on what flavor is preferred._
<pre>
- <% semantic_form_for @post do |form| %>
- <% form.inputs :post_details do %> # => :title => "Post details"
+ <%= semantic_form_for @post do |form| %>
+ <%= form.inputs :post_details do %> # => :title => "Post details"
# ...
<% end %>
# ...
@@ -419,13 +419,13 @@ _Note: Slightly different because Formtastic can't guess how you group fields in
*5. Override I18n settings:*
<pre>
- <% semantic_form_for @post do |form| %>
- <% form.inputs do %>
+ <%= semantic_form_for @post do |form| %>
+ <%= form.inputs do %>
<%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
<%= form.input :body, :hint => false %> # => :label => "Write something..."
<%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button :dummie %> # => "Launch!"
<% end %>
<% end %>
@@ -440,13 +440,13 @@ If I18n-lookups is disabled, i.e.:
...then you can enable I18n within the forms instead:
<pre>
- <% semantic_form_for @post do |form| %>
- <% form.inputs do %>
+ <%= semantic_form_for @post do |form| %>
+ <%= form.inputs do %>
<%= form.input :title, :label => true %> # => :label => "Choose a title..."
<%= form.input :body, :label => true %> # => :label => "Write something..."
<%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
<% end %>
- <% form.buttons do %>
+ <%= form.buttons do %>
<%= form.commit_button true %> # => "Update %{model}" (if we are in edit that is...)
<% end %>
<% end %>
@@ -492,7 +492,7 @@ h2. Semantic errors
You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
<pre>
- <% semantic_form_for @post do |form| %>
+ <%= semantic_form_for @post do |form| %>
<%= form.semantic_errors :state %>
<% end %>
</pre>

0 comments on commit bc5603b

Please sign in to comment.