Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Simple form #75

Open
wants to merge 15 commits into from

5 participants

@JonasNielsen

With some help from greenplastik, this branch now support simple_form

Jonas Bruun ... and others added some commits
Jonas Bruun Nielsen Added --simple_form option 47eb7d1
Jonas Bruun Nielsen First commit ever. Who would have expected that to work? :-)
Anyhow, now the gem does what I wanted it to. Use --simple_form to get simple_form format of your forms.
c3ee46b
Jonas Bruun Nielsen Fixed so that it works with limited actions as well (without _form pa…
…rtial)
d3b37a9
Jonas Bruun Nielsen Added error messages and changed - to = for simple_form 82e32f6
@greenplastik greenplastik added simple form dependency; fixed/added option for simple_form in s…
…caffold_generator and nifty_scaffold_generator; added simple_form? method
8eadafe
@greenplastik greenplastik added simple form dependency; fixed/added option for simple_form in s…
…caffold_generator and nifty_scaffold_generator; added simple_form? method
413cd8c
@greenplastik greenplastik added simple form dependency; fixed/added option for simple_form in s…
…caffold_generator and nifty_scaffold_generator; added simple_form? method
d874c01
@greenplastik greenplastik added simple form dependency; fixed/added option for simple_form in s…
…caffold_generator and nifty_scaffold_generator
d3fafe9
@greenplastik greenplastik added simple form dependency; fixed/added option for simple_form in s…
…caffold_generator and nifty_scaffold_generator; changed handling for simple_form option
ee481d3
@JonasNielsen JonasNielsen Correcting readme and gemspec before pull request 3fcb37c
@greenplastik greenplastik Replaced _simple_form.html.erb template with one from simple_form gem. 0a38186
@greenplastik greenplastik Replaced _simple_form.html.erb template with one from simple_form gem. d92169c
@greenplastik greenplastik Fixed conflict d46ede8
@JonasNielsen JonasNielsen Merge branch 'master' of https://github.com/greenplastik/nifty-genera…
…tors into greenplastik-master
30d91cc
@JonasNielsen JonasNielsen Corrected haml version to work with errors in the same way as erb 432d05d
@ryanb
Owner

Sorry for not addressing this sooner. The patch looks good and I'll work on getting it into the 0.5 release.

@Inza

Thanks a lot guys! The simple_form support in the nifty_generators would be wonderful! I have been waiting for this. A very nice job! Thx!

@shaunbrazier

Hi guys,

Was this completed? I tried using the --simple_form option but it didn't make any difference to the forms generated.

Thanks for the great job.
Shaun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2010
  1. Added --simple_form option

    Jonas Bruun Nielsen authored
  2. First commit ever. Who would have expected that to work? :-)

    Jonas Bruun Nielsen authored
    Anyhow, now the gem does what I wanted it to. Use --simple_form to get simple_form format of your forms.
  3. Fixed so that it works with limited actions as well (without _form pa…

    Jonas Bruun Nielsen authored
    …rtial)
Commits on Nov 18, 2010
  1. Added error messages and changed - to = for simple_form

    Jonas Bruun Nielsen authored
Commits on Dec 4, 2010
  1. @greenplastik

    added simple form dependency; fixed/added option for simple_form in s…

    greenplastik authored
    …caffold_generator and nifty_scaffold_generator; added simple_form? method
  2. @greenplastik

    added simple form dependency; fixed/added option for simple_form in s…

    greenplastik authored
    …caffold_generator and nifty_scaffold_generator; added simple_form? method
  3. @greenplastik

    added simple form dependency; fixed/added option for simple_form in s…

    greenplastik authored
    …caffold_generator and nifty_scaffold_generator; added simple_form? method
  4. @greenplastik

    added simple form dependency; fixed/added option for simple_form in s…

    greenplastik authored
    …caffold_generator and nifty_scaffold_generator
  5. @greenplastik

    added simple form dependency; fixed/added option for simple_form in s…

    greenplastik authored
    …caffold_generator and nifty_scaffold_generator; changed handling for simple_form option
  6. @JonasNielsen
Commits on Dec 5, 2010
  1. @greenplastik
  2. @greenplastik
  3. @greenplastik

    Fixed conflict

    greenplastik authored
Commits on Dec 15, 2010
  1. @JonasNielsen
  2. @JonasNielsen
This page is out of date. Refresh to see the latest.
View
4 CHANGELOG
@@ -1,3 +1,7 @@
+0.4.3 (October 25, 2010)
+
+* added simple_form option --simple_form
+
0.4.2 (October 15, 2010)
* adding mocha to Gemfile automatically if it's not there already
View
2  README.rdoc
@@ -52,7 +52,7 @@ One of the primary differences is that nifty_scaffold allows you to choose which
There are a few changes to the generated code as well, such as no XML format by default.
-It also offers support for HAML, Shoulda, and RSpec.
+It also offers support for HAML, simple_form, Shoulda, and RSpec.
<b>I get "undefined method 'title'" error.</b>
View
13 lib/generators/nifty/scaffold/scaffold_generator.rb
@@ -21,6 +21,7 @@ class ScaffoldGenerator < Base
class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
+ class_option :simple_form, :desc => 'Use simple_form for forms in views.', :type => :boolean
def initialize(*args, &block)
super
@@ -97,7 +98,11 @@ def create_controller
end
if form_partial?
- template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ if options.simple_form?
+ template "views/#{view_language}/_simple_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ else
+ template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ end
end
route "resources #{plural_name.to_sym.inspect}"
@@ -158,7 +163,11 @@ def render_form
"<%= render 'form' %>"
end
else
- read_template("views/#{view_language}/_form.html.#{view_language}")
+ if options.simple_form?
+ read_template("views/#{view_language}/_simple_form.html.#{view_language}")
+ else
+ read_template("views/#{view_language}/_form.html.#{view_language}")
+ end
end
end
View
23 lib/generators/nifty/scaffold/templates/views/erb/_simple_form.html.erb
@@ -0,0 +1,23 @@
+<%%= simple_form_for(@<%= singular_name %>) do |f| %>
+ <%% if @<%= singular_name %>.errors.any? %>
+ <div id="error_explanation">
+ <h2><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this <%= singular_name %> from being saved:</h2>
+
+ <ul>
+ <%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
+ <li><%%= msg %></li>
+ <%% end %>
+ </ul>
+ </div>
+ <%% end %>
+
+ <div class="inputs">
+ <%- model_attributes.each do |attribute| -%>
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
+ <%- end -%>
+ </div>
+
+ <div class="actions">
+ <%%= f.button :submit %>
+ </div>
+<%% end %>
View
13 lib/generators/nifty/scaffold/templates/views/haml/_simple_form.html.haml
@@ -0,0 +1,13 @@
+= simple_form_for @<%= singular_name %> do |f|
+ - if @<%= singular_name %>.errors.any?
+ #error_explanation
+ %h2
+ = pluralize(@<%= singular_name %>.errors.count, "error")
+ prohibited this <%= singular_name %> from being saved:
+ %ul
+ - @<%= singular_name %>.errors.full_messages.each do |msg|
+ %li=msg
+ <%- for attribute in model_attributes -%>
+ = f.input :<%= attribute.name %>
+ <%- end -%>
+ = f.submit
View
3  nifty-generators.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "nifty-generators"
- s.version = "0.4.2"
+ s.version = "0.4.3"
s.author = "Ryan Bates"
s.email = "ryan@railscasts.com"
s.homepage = "http://github.com/ryanb/nifty-generators"
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'mocha', '~> 0.9.8'
s.add_development_dependency 'bcrypt-ruby', '~> 2.1.2'
s.add_development_dependency 'sqlite3-ruby', '~> 1.3.1'
+ s.add_development_dependency 'simple_form'
s.rubyforge_project = s.name
s.required_rubygems_version = ">= 1.3.4"
View
11 rails_generators/nifty_scaffold/nifty_scaffold_generator.rb
@@ -77,7 +77,11 @@ def manifest
end
if form_partial?
- m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ if simple_form?
+ m.template "views/#{view_language}/_simple_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ else
+ m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
+ end
end
m.route_resources plural_name
@@ -184,6 +188,10 @@ def model_columns_for_attributes
def rspec?
test_framework == :rspec
end
+
+ def simple_form?
+ options[:simple_form]
+ end
protected
@@ -211,6 +219,7 @@ def add_options!(opt)
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
+ opt.on("--simple_form", "Use simple_form for forms in views.") { |v| options[:simple_form] = v }
end
# is there a better way to do this? Perhaps with const_defined?
View
23 rails_generators/nifty_scaffold/templates/views/erb/_simple_form.html.erb
@@ -0,0 +1,23 @@
+<%% simple_form_for(@<%= singular_name %>) do |f| %>
+ <%% if @<%= singular_name %>.errors.any? %>
+ <div id="error_explanation">
+ <h2><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this <%= singular_name %> from being saved:</h2>
+
+ <ul>
+ <%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
+ <li><%%= msg %></li>
+ <%% end %>
+ </ul>
+ </div>
+ <%% end %>
+
+ <div class="inputs">
+ <%- model_attributes.each do |attribute| -%>
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
+ <%- end -%>
+ </div>
+
+ <div class="actions">
+ <%%= f.button :submit %>
+ </div>
+<%% end %>
View
5 rails_generators/nifty_scaffold/templates/views/haml/_simple_form.html.haml
@@ -0,0 +1,5 @@
+= simple_form_for @<%= singular_name %> do |f|
+ <%- for attribute in attributes -%>
+ = f.input :<%= attribute.name %>
+ <%- end -%>
+ = f.submit
Something went wrong with that request. Please try again.