Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Formtastic form generation #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/assets/stylesheets/web-app-theme/base.css
Expand Up @@ -22,7 +22,8 @@ h3 { font-size: 18px; margin: 10px 0; font-weight: normal;}
h4 { font-size: 16px; margin: 10px 0; font-weight: normal;}
hr {height: 1px; border: 0; }
p { margin: 15px 0;}
a img { border: none; }
a img, fieldset { border: none; }
ol { list-style-type: none; }

body {
font-size: 12px;
Expand Down
Expand Up @@ -9,7 +9,7 @@
<div class="content">
<h2 class="title"><%%= t("web-app-theme.edit", :default => "Edit") %> <%= model_name %></h2>
<div class="inner">
<%%= form_for @<%= model_name.underscore %>, :url => <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :html => { :class => :form } do |f| -%>
<%%= <% if options.formtastic %>semantic_<% end %>form_for @<%= model_name.underscore %>, :url => <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :html => { :class => 'form' } do |f| -%>
<%%= render :partial => "form", :locals => {:f => f} %>
<%% end -%>
</div>
Expand Down
13 changes: 12 additions & 1 deletion lib/generators/web_app_theme/themed/templates/view_form.html.erb
@@ -1,10 +1,21 @@
<% if options.formtastic %>
<% unless columns.blank? -%>
<%%= f.inputs do %>
<% columns.each do |column| %>
<%%= f.input :<%= column.name %>, :wrapper_html => { :class => 'group' }, :label_html => { :class => 'label' }, :input_html => { :class => '<%= column.field_type %>' } %>
<%- end -%>

<%% end -%>
<%- end -%>
<%- else -%>
<% columns.each do |column| %>
<div class="group">
<%%= f.label :<%= column.name %>, t("activerecord.attributes.<%= model_name.underscore %>.<%= column.name %>", :default => "<%= column.name.humanize %>"), :class => :label %>
<%%= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>' %>
<span class="description">Ex: a simple text</span>
</div>
<%- end -%>
<%- end -%>
<%- end -%>
<div class="group navform wat-cf">
<button class="button" type="submit">
<%%= image_tag("web-app-theme/icons/tick.png", :alt => "#{t("web-app-theme.save", :default => "Save")}") %> <%%= t("web-app-theme.save", :default => "Save") %>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<div class="content">
<h2 class="title"><%%= t("web-app-theme.new", :default => "New")%> <%= model_name %></h2>
<div class="inner">
<%%= form_for :<%= model_name.underscore %>, :url => <%= controller_routing_path %>_path, :html => { :class => :form } do |f| -%>
<%%= <% if options.formtastic %>semantic_<% end %>form_for :<%= model_name.underscore %>, :url => <%= controller_routing_path %>_path, :html => { :class => 'form' } do |f| -%>
<%%= render :partial => "form", :locals => {:f => f} %>
<%% end -%>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/generators/web_app_theme/themed/themed_generator.rb
Expand Up @@ -11,6 +11,7 @@ class ThemedGenerator < Rails::Generators::Base
class_option :engine, :type => :string, :default => 'erb', :desc => 'Specify the template engine'
class_option :will_paginate, :type => :boolean, :default => false, :desc => 'Specify if you use will_paginate'
class_option :themed_type, :type => :string, :default => 'crud', :desc => 'Specify the themed type, crud or text. Default is crud'
class_option :formtastic, :type => :boolean, :default => false, :desc => 'Specify if you use formtastic'

def initialize(args, *options)
super(args, *options)
Expand Down