Skip to content
This repository

Support for Formtastic form generation #46

Open
wants to merge 1 commit into from

1 participant

Mike Mayo
Mike Mayo

When generating themed views, you can now pass --formtastic to have the forms generated using the Formtastic format.

I tweaked base.css to remove some generic styles on <fieldset>s and <ol>s, and then modified the associated template views.

Calls to form_for were replaced with semantic_form_for, and all inputs are generated using f.input with appropriate label, container, and input classes added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 06, 2011
formtastic support 295d934
This page is out of date. Refresh to see the latest.
3  app/assets/stylesheets/web-app-theme/base.css
@@ -22,7 +22,8 @@ h3 { font-size: 18px; margin: 10px 0; font-weight: normal;}
22 22
 h4 { font-size: 16px; margin: 10px 0; font-weight: normal;}
23 23
 hr {height: 1px; border: 0; }
24 24
 p { margin: 15px 0;}
25  
-a img { border: none; }
  25
+a img, fieldset { border: none; }
  26
+ol { list-style-type: none; }
26 27
 
27 28
 body {
28 29
   font-size: 12px;
2  lib/generators/web_app_theme/themed/templates/view_edit.html.erb
@@ -9,7 +9,7 @@
9 9
   <div class="content">            
10 10
     <h2 class="title"><%%= t("web-app-theme.edit", :default => "Edit") %> <%= model_name %></h2>
11 11
     <div class="inner">
12  
-      <%%= form_for @<%= model_name.underscore  %>, :url => <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :html => { :class => :form } do |f| -%>
  12
+      <%%= <% if options.formtastic %>semantic_<% end %>form_for @<%= model_name.underscore  %>, :url => <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :html => { :class => 'form' } do |f| -%>
13 13
         <%%= render :partial => "form", :locals => {:f => f} %>
14 14
       <%% end -%>
15 15
     </div>
13  lib/generators/web_app_theme/themed/templates/view_form.html.erb
... ...
@@ -1,10 +1,21 @@
  1
+<% if options.formtastic %>
  2
+<% unless columns.blank? -%>
  3
+  <%%= f.inputs do %>
  4
+    <% columns.each do |column| %>
  5
+    <%%= f.input :<%= column.name %>, :wrapper_html => { :class => 'group' }, :label_html => { :class => 'label' }, :input_html => { :class => '<%= column.field_type %>' } %>
  6
+    <%- end -%>
  7
+    
  8
+  <%% end -%>
  9
+<%- end -%>
  10
+<%- else -%>
1 11
 <% columns.each do |column| %>
2 12
   <div class="group">
3 13
     <%%= f.label :<%= column.name %>, t("activerecord.attributes.<%= model_name.underscore %>.<%= column.name %>", :default => "<%= column.name.humanize %>"), :class => :label %>
4 14
     <%%= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>' %>
5 15
     <span class="description">Ex: a simple text</span>
6 16
   </div>
7  
-<%- end -%>        
  17
+<%- end -%>
  18
+<%- end -%>
8 19
 <div class="group navform wat-cf">
9 20
   <button class="button" type="submit">
10 21
     <%%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%%= t("web-app-theme.save", :default => "Save") %>
2  lib/generators/web_app_theme/themed/templates/view_new.html.erb
@@ -8,7 +8,7 @@
8 8
   <div class="content">            
9 9
     <h2 class="title"><%%= t("web-app-theme.new", :default => "New")%>  <%= model_name %></h2>
10 10
     <div class="inner">
11  
-      <%%= form_for :<%= model_name.underscore  %>, :url => <%= controller_routing_path %>_path, :html => { :class => :form } do |f| -%>
  11
+      <%%= <% if options.formtastic %>semantic_<% end %>form_for :<%= model_name.underscore  %>, :url => <%= controller_routing_path %>_path, :html => { :class => 'form' } do |f| -%>
12 12
         <%%= render :partial => "form", :locals => {:f => f} %>
13 13
       <%% end -%>
14 14
     </div>
1  lib/generators/web_app_theme/themed/themed_generator.rb
@@ -11,6 +11,7 @@ class ThemedGenerator < Rails::Generators::Base
11 11
     class_option :engine,         :type => :string,   :default => 'erb', :desc => 'Specify the template engine'
12 12
     class_option :will_paginate,  :type => :boolean,  :default => false, :desc => 'Specify if you use will_paginate'
13 13
     class_option :themed_type,    :type => :string,   :default => 'crud', :desc => 'Specify the themed type, crud or text. Default is crud'
  14
+    class_option :formtastic,     :type => :boolean,  :default => false, :desc => 'Specify if you use formtastic'
14 15
     
15 16
     def initialize(args, *options)
16 17
       super(args, *options)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.