nested_scaffold 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/.document +5 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +16 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +46 -0
  7. data/VERSION +1 -0
  8. data/lib/generators/USAGE +10 -0
  9. data/lib/generators/active_record/active_record_generator.rb +39 -0
  10. data/lib/generators/base.rb +32 -0
  11. data/lib/generators/erb/erb_generator.rb +12 -0
  12. data/lib/generators/erb/templates/_form.html.erb +23 -0
  13. data/lib/generators/erb/templates/edit.html.erb +6 -0
  14. data/lib/generators/erb/templates/index.html.erb +27 -0
  15. data/lib/generators/erb/templates/new.html.erb +5 -0
  16. data/lib/generators/erb/templates/show.html.erb +12 -0
  17. data/lib/generators/haml/haml_generator.rb +17 -0
  18. data/lib/generators/haml/templates/_form.html.haml +15 -0
  19. data/lib/generators/haml/templates/edit.html.haml +7 -0
  20. data/lib/generators/haml/templates/index.html.haml +23 -0
  21. data/lib/generators/haml/templates/new.html.haml +5 -0
  22. data/lib/generators/haml/templates/show.html.haml +11 -0
  23. data/lib/generators/helper/helper_generator.rb +16 -0
  24. data/lib/generators/nested_scaffold_generator.rb +29 -0
  25. data/lib/generators/scaffold_controller/scaffold_controller_generator.rb +25 -0
  26. data/lib/generators/scaffold_controller/templates/controller.rb +84 -0
  27. data/lib/generators/stylesheets/stylesheets_generator.rb +9 -0
  28. data/lib/generators/test_unit/helper_generator.rb +14 -0
  29. data/lib/generators/test_unit/model_generator.rb +14 -0
  30. data/lib/generators/test_unit/scaffold_generator.rb +14 -0
  31. data/lib/generators/test_unit/templates/functional_test.rb +50 -0
  32. data/nested_scaffold.gemspec +75 -0
  33. metadata +130 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.1"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.0.0)
16
+ jeweler (~> 1.5.1)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Akira Matsuda
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = nested_scaffold
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to nested_scaffold
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Akira Matsuda. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "nested_scaffold"
16
+ gem.homepage = "http://github.com/amatsuda/nested_scaffold"
17
+ gem.license = "MIT"
18
+ gem.summary = 'Nested scaffold generator for Rails 3'
19
+ gem.description = 'Nested scaffold generator for Rails 3'
20
+ gem.email = "ronnie@dio.jp"
21
+ gem.authors = ["Akira Matsuda"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "nested_scaffold #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Generats nested scaffold
3
+
4
+ Example:
5
+ rails g nested_scaffold group/user name:string age:integer
6
+
7
+ This will create:
8
+ user {model, controller, helper, views, tests}
9
+ nested resource route
10
+ Group.has_many :user association
@@ -0,0 +1,39 @@
1
+ require 'rails/generators/active_record/model/model_generator'
2
+ require File.join(File.dirname(__FILE__), '../test_unit/model_generator')
3
+ require File.join(File.dirname(__FILE__), '../base')
4
+
5
+ module NestedScaffold
6
+ module Generators
7
+ class ActiveRecordGenerator < ::ActiveRecord::Generators::ModelGenerator
8
+ include ::NestedScaffold::Base
9
+
10
+ source_root superclass.source_root
11
+
12
+ hook_for :test_framework, :in => 'nested_scaffold:model'
13
+
14
+ def initialize(args, *options) #:nodoc:
15
+ super
16
+ #DIRTY HACK remove noise. don't know why but the first attribute type is always suffixed by " #{parent_name}"
17
+ attributes.each do |attribute|
18
+ attribute.type = attribute.type.to_s.split(' ').first if attribute.type.to_s.include?(' ')
19
+ end
20
+ # prefer parent:references to parent_id:integer
21
+ attributes.delete_if {|a| (a.name == nested_parent_id) && (a.type.to_s == 'integer')}
22
+ unless attributes.map {|a| [a.name, a.type.to_s]}.include? [nested_parent_name, 'references']
23
+ #DIRTY HACK add 'references' attribute
24
+ attributes.insert 0, Rails::Generators::GeneratedAttribute.new(nested_parent_name, 'references')
25
+ end
26
+ end
27
+
28
+ # add has_many_association to parent model
29
+ def add_association
30
+ if File.exist?(parent_file = File.join('app/models', "#{nested_parent_name}.rb"))
31
+ inject_into_file parent_file, " has_many :#{table_name}\n", :after => " < ActiveRecord::Base\n"
32
+ end
33
+ end
34
+
35
+ protected
36
+ def migration_action; 'add'; end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ module NestedScaffold
2
+ module Base
3
+ protected
4
+ def nested_parent_name
5
+ @class_path.join('/')
6
+ end
7
+
8
+ def nested_parent_id
9
+ "#{nested_parent_name}_id"
10
+ end
11
+
12
+ def nested_parent_class_name
13
+ nested_parent_name.classify
14
+ end
15
+
16
+ def plural_nested_parent_name
17
+ nested_parent_name.pluralize
18
+ end
19
+
20
+ def class_path
21
+ []
22
+ end
23
+
24
+ def regular_class_path
25
+ []
26
+ end
27
+
28
+ def controller_class_path
29
+ []
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators/erb/scaffold/scaffold_generator'
2
+ require File.join(File.dirname(__FILE__), '../base')
3
+
4
+ module NestedScaffold
5
+ module Generators
6
+ class ErbGenerator < ::Erb::Generators::ScaffoldGenerator
7
+ include ::NestedScaffold::Base
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ <%%= form_for([@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>]) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
+
6
+ <ul>
7
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
8
+ <li><%%= msg %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </div>
12
+ <%% end %>
13
+
14
+ <% for attribute in attributes -%>
15
+ <div class="field">
16
+ <%%= f.label :<%= attribute.name %> %><br />
17
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
18
+ </div>
19
+ <% end -%>
20
+ <div class="actions">
21
+ <%%= f.submit %>
22
+ </div>
23
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', [@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>] %> |
6
+ <%%= link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>) %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% for attribute in attributes -%>
6
+ <th><%= attribute.human_name %></th>
7
+ <% end -%>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
14
+ <tr>
15
+ <% for attribute in attributes -%>
16
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
17
+ <% end -%>
18
+ <td><%%= link_to 'Show', [<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>] %></td>
19
+ <td><%%= link_to 'Edit', edit_<%= nested_parent_name %>_<%= singular_table_name %>_path(<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>) %></td>
20
+ <td><%%= link_to 'Destroy', [<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>], :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <%% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%%= link_to 'New <%= human_name %>', new_<%= nested_parent_name %>_<%= singular_table_name %>_path(params[:<%= nested_parent_name %>_id]) %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>) %>
@@ -0,0 +1,12 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% for attribute in attributes -%>
4
+ <p>
5
+ <b><%= attribute.human_name %>:</b>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+
11
+ <%%= link_to 'Edit', edit_<%= nested_parent_name %>_<%= singular_table_name %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>) %> |
12
+ <%%= link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>) %>
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/erb/scaffold/scaffold_generator'
2
+ require File.join(File.dirname(__FILE__), '../base')
3
+
4
+ module NestedScaffold
5
+ module Generators
6
+ class HamlGenerator < ::Erb::Generators::ScaffoldGenerator
7
+ include ::NestedScaffold::Base
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ protected
12
+ def handler
13
+ :haml
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ = form_for [@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>] do |f|
2
+ -if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ %ul
6
+ - @<%= singular_table_name %>.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ <% for attribute in attributes -%>
10
+ .field
11
+ = f.label :<%= attribute.name %>
12
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', [@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>] %>
6
+ \|
7
+ = link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>)
@@ -0,0 +1,23 @@
1
+ %h1 Listing <%= plural_table_name %>
2
+
3
+ %table
4
+ %tr
5
+ <% for attribute in attributes -%>
6
+ %th <%= attribute.human_name %>
7
+ <% end -%>
8
+ %th
9
+ %th
10
+ %th
11
+
12
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
13
+ %tr
14
+ <% for attribute in attributes -%>
15
+ %td= <%= singular_table_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ %td= link_to 'Show', [<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>]
18
+ %td= link_to 'Edit', edit_<%= nested_parent_name %>_<%= singular_table_name %>_path(<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>)
19
+ %td= link_to 'Destroy', [<%= singular_table_name %>.<%= nested_parent_name %>, <%= singular_table_name %>], :confirm => 'Are you sure?', :method => :delete
20
+
21
+ %br
22
+
23
+ = link_to 'New <%= human_name %>', new_<%= nested_parent_name %>_<%= singular_table_name %>_path(params[:<%= nested_parent_name %>_id])
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>)
@@ -0,0 +1,11 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to 'Edit', edit_<%= nested_parent_name %>_<%= singular_table_name %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>, @<%= singular_table_name %>)
10
+ \|
11
+ = link_to 'Back', <%= nested_parent_name %>_<%= index_helper %>_path(@<%= singular_table_name %>.<%= nested_parent_name %>)
@@ -0,0 +1,16 @@
1
+ require 'rails/generators/rails/helper/helper_generator'
2
+ require File.join(File.dirname(__FILE__), '../test_unit/helper_generator')
3
+ require File.join(File.dirname(__FILE__), '../base')
4
+
5
+ module NestedScaffold
6
+ module Generators
7
+ class HelperGenerator < ::Rails::Generators::HelperGenerator
8
+ include ::NestedScaffold::Base
9
+
10
+ source_root superclass.source_root
11
+
12
+ # override
13
+ hook_for :test_framework, :in => 'nested_scaffold:helper'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/rails/scaffold/scaffold_generator'
2
+ require File.join(File.dirname(__FILE__), 'base')
3
+ require File.join(File.dirname(__FILE__), 'scaffold_controller/scaffold_controller_generator')
4
+ require File.join(File.dirname(__FILE__), 'active_record/active_record_generator')
5
+ require File.join(File.dirname(__FILE__), 'stylesheets/stylesheets_generator')
6
+
7
+ module NestedScaffold
8
+ module Generators
9
+ class NestedScaffoldGenerator < ::Rails::Generators::ScaffoldGenerator
10
+ include ::NestedScaffold::Base
11
+
12
+ # override ScaffoldGenerator
13
+ hook_for :scaffold_controller, :required => true
14
+ # override ScaffoldGenerator
15
+ hook_for :stylesheets
16
+ # override ModelGenerator
17
+ hook_for :orm, :required => true
18
+
19
+ # override
20
+ def add_resource_route
21
+ return if options[:actions].present?
22
+ route_config = "resources :#{plural_nested_parent_name} do\n"
23
+ route_config << " resources :#{file_name.pluralize}\n"
24
+ route_config << " end"
25
+ route route_config
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
2
+ require File.join(File.dirname(__FILE__), '../erb/erb_generator')
3
+ require File.join(File.dirname(__FILE__), '../haml/haml_generator')
4
+ require File.join(File.dirname(__FILE__), '../helper/helper_generator')
5
+ require File.join(File.dirname(__FILE__), '../test_unit/scaffold_generator')
6
+ require File.join(File.dirname(__FILE__), '../base')
7
+
8
+ module NestedScaffold
9
+ module Generators
10
+ class ScaffoldControllerGenerator < ::Rails::Generators::ScaffoldControllerGenerator
11
+ include ::NestedScaffold::Base
12
+
13
+ source_root File.expand_path('../templates', __FILE__)
14
+
15
+ # override ScaffoldControllerGenerator
16
+ hook_for :template_engine
17
+ hook_for :test_framework, :in => 'nested_scaffold:scaffold'
18
+
19
+ # override ScaffoldControllerGenerator
20
+ hook_for :helper, :as => :scaffold do |invoked|
21
+ invoke invoked, [ controller_name ]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,84 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>
3
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>.xml
4
+ def index
5
+ <%= "@#{plural_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}" %>
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @<%= plural_name %> }
10
+ end
11
+ end
12
+
13
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1
14
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml
15
+ def show
16
+ <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %>
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @<%= singular_name %> }
21
+ end
22
+ end
23
+
24
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/new
25
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/new.xml
26
+ def new
27
+ <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.build" %>
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @<%= singular_name %> }
32
+ end
33
+ end
34
+
35
+ # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1/edit
36
+ def edit
37
+ <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %>
38
+ end
39
+
40
+ # POST <%= plural_nested_parent_name %>/1/<%= plural_name %>
41
+ # POST <%= plural_nested_parent_name %>/1/<%= plural_name %>.xml
42
+ def create
43
+ <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.build(params[:#{singular_name}])" %>
44
+
45
+ respond_to do |format|
46
+ if @<%= singular_name %>.save
47
+ format.html { redirect_to([@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>], :notice => '<%= human_name %> was successfully created.') }
48
+ format.xml { render :xml => @<%= singular_name %>, :status => :created, :location => [@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>] }
49
+ else
50
+ format.html { render :action => "new" }
51
+ format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT <%= plural_nested_parent_name %>/1/<%= plural_name %>/1
57
+ # PUT <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml
58
+ def update
59
+ <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %>
60
+
61
+ respond_to do |format|
62
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
63
+ format.html { redirect_to([@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>], :notice => '<%= human_name %> was successfully updated.') }
64
+ format.xml { head :ok }
65
+ else
66
+ format.html { render :action => "edit" }
67
+ format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE <%= plural_nested_parent_name %>/1/<%= plural_name %>/1
73
+ # DELETE <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml
74
+ def destroy
75
+ <%= "#{nested_parent_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}])" %>
76
+ <%= "@#{singular_name} = #{nested_parent_name}.#{plural_name}.find(params[:id])" %>
77
+ @<%= singular_name %>.destroy
78
+
79
+ respond_to do |format|
80
+ format.html { redirect_to <%= nested_parent_name %>_<%= index_helper %>_url(<%= nested_parent_name %>) }
81
+ format.xml { head :ok }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/generators/rails/stylesheets/stylesheets_generator'
2
+
3
+ module NestedScaffold
4
+ module Generators
5
+ class StylesheetsGenerator < ::Rails::Generators::StylesheetsGenerator
6
+ source_root superclass.source_root
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/test_unit/helper/helper_generator'
2
+ require File.join(File.dirname(__FILE__), '../base')
3
+
4
+ module NestedScaffold
5
+ module Generators
6
+ module Helper
7
+ class TestUnitGenerator < ::TestUnit::Generators::HelperGenerator
8
+ include ::NestedScaffold::Base
9
+
10
+ source_root superclass.source_root
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/test_unit/model/model_generator'
2
+ require File.join(File.dirname(__FILE__), '../base')
3
+
4
+ module NestedScaffold
5
+ module Generators
6
+ module Model
7
+ class TestUnitGenerator < ::TestUnit::Generators::ModelGenerator
8
+ include ::NestedScaffold::Base
9
+
10
+ source_root superclass.source_root
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/test_unit/scaffold/scaffold_generator'
2
+ require File.join(File.dirname(__FILE__), '../base')
3
+
4
+ module NestedScaffold
5
+ module Generators
6
+ module Scaffold
7
+ class TestUnitGenerator < ::TestUnit::Generators::ScaffoldGenerator
8
+ include ::NestedScaffold::Base
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ setup do
5
+ @<%= nested_parent_name %> = <%= plural_nested_parent_name %>(:one)
6
+ @<%= singular_table_name %> = <%= table_name %>(:one)
7
+ end
8
+
9
+ test "should get index" do
10
+ get :index, :<%= nested_parent_id %> => @<%= nested_parent_name %>
11
+ assert_response :success
12
+ assert_not_nil assigns(:<%= table_name %>)
13
+ end
14
+
15
+ test "should get new" do
16
+ get :new, :<%= nested_parent_id %> => @<%= nested_parent_name %>
17
+ assert_response :success
18
+ end
19
+
20
+ test "should create <%= singular_table_name %>" do
21
+ assert_difference('<%= class_name %>.count') do
22
+ post :create, :<%= nested_parent_id %> => @<%= nested_parent_name %>, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
23
+ end
24
+
25
+ assert_redirected_to <%= nested_parent_name %>_<%= singular_table_name %>_path(@<%= nested_parent_name %>, assigns(:<%= singular_table_name %>))
26
+ end
27
+
28
+ test "should show <%= singular_table_name %>" do
29
+ get :show, :<%= nested_parent_id %> => @<%= nested_parent_name %>, :id => @<%= singular_table_name %>.to_param
30
+ assert_response :success
31
+ end
32
+
33
+ test "should get edit" do
34
+ get :edit, :<%= nested_parent_id %> => @<%= nested_parent_name %>, :id => @<%= singular_table_name %>.to_param
35
+ assert_response :success
36
+ end
37
+
38
+ test "should update <%= singular_table_name %>" do
39
+ put :update, :<%= nested_parent_id %> => @<%= nested_parent_name %>, :id => @<%= singular_table_name %>.to_param, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
40
+ assert_redirected_to <%= nested_parent_name %>_<%= singular_table_name %>_path(@<%= nested_parent_name %>, assigns(:<%= singular_table_name %>))
41
+ end
42
+
43
+ test "should destroy <%= singular_table_name %>" do
44
+ assert_difference('<%= class_name %>.count', -1) do
45
+ delete :destroy, :<%= nested_parent_id %> => @<%= nested_parent_name %>, :id => @<%= singular_table_name %>.to_param
46
+ end
47
+
48
+ assert_redirected_to <%= nested_parent_name %>_<%= index_helper %>_path(@<%= nested_parent_name %>)
49
+ end
50
+ end
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nested_scaffold}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Akira Matsuda"]
12
+ s.date = %q{2010-12-12}
13
+ s.description = %q{Nested scaffold generator for Rails 3}
14
+ s.email = %q{ronnie@dio.jp}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/USAGE",
28
+ "lib/generators/active_record/active_record_generator.rb",
29
+ "lib/generators/base.rb",
30
+ "lib/generators/erb/erb_generator.rb",
31
+ "lib/generators/erb/templates/_form.html.erb",
32
+ "lib/generators/erb/templates/edit.html.erb",
33
+ "lib/generators/erb/templates/index.html.erb",
34
+ "lib/generators/erb/templates/new.html.erb",
35
+ "lib/generators/erb/templates/show.html.erb",
36
+ "lib/generators/haml/haml_generator.rb",
37
+ "lib/generators/haml/templates/_form.html.haml",
38
+ "lib/generators/haml/templates/edit.html.haml",
39
+ "lib/generators/haml/templates/index.html.haml",
40
+ "lib/generators/haml/templates/new.html.haml",
41
+ "lib/generators/haml/templates/show.html.haml",
42
+ "lib/generators/helper/helper_generator.rb",
43
+ "lib/generators/nested_scaffold_generator.rb",
44
+ "lib/generators/scaffold_controller/scaffold_controller_generator.rb",
45
+ "lib/generators/scaffold_controller/templates/controller.rb",
46
+ "lib/generators/stylesheets/stylesheets_generator.rb",
47
+ "lib/generators/test_unit/helper_generator.rb",
48
+ "lib/generators/test_unit/model_generator.rb",
49
+ "lib/generators/test_unit/scaffold_generator.rb",
50
+ "lib/generators/test_unit/templates/functional_test.rb",
51
+ "nested_scaffold.gemspec"
52
+ ]
53
+ s.homepage = %q{http://github.com/amatsuda/nested_scaffold}
54
+ s.licenses = ["MIT"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.7}
57
+ s.summary = %q{Nested scaffold generator for Rails 3}
58
+
59
+ if s.respond_to? :specification_version then
60
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
66
+ else
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
73
+ end
74
+ end
75
+
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nested_scaffold
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Akira Matsuda
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-12 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ name: bundler
35
+ requirement: *id001
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 1
45
+ segments:
46
+ - 1
47
+ - 5
48
+ - 1
49
+ version: 1.5.1
50
+ name: jeweler
51
+ requirement: *id002
52
+ type: :development
53
+ description: Nested scaffold generator for Rails 3
54
+ email: ronnie@dio.jp
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.rdoc
68
+ - Rakefile
69
+ - VERSION
70
+ - lib/generators/USAGE
71
+ - lib/generators/active_record/active_record_generator.rb
72
+ - lib/generators/base.rb
73
+ - lib/generators/erb/erb_generator.rb
74
+ - lib/generators/erb/templates/_form.html.erb
75
+ - lib/generators/erb/templates/edit.html.erb
76
+ - lib/generators/erb/templates/index.html.erb
77
+ - lib/generators/erb/templates/new.html.erb
78
+ - lib/generators/erb/templates/show.html.erb
79
+ - lib/generators/haml/haml_generator.rb
80
+ - lib/generators/haml/templates/_form.html.haml
81
+ - lib/generators/haml/templates/edit.html.haml
82
+ - lib/generators/haml/templates/index.html.haml
83
+ - lib/generators/haml/templates/new.html.haml
84
+ - lib/generators/haml/templates/show.html.haml
85
+ - lib/generators/helper/helper_generator.rb
86
+ - lib/generators/nested_scaffold_generator.rb
87
+ - lib/generators/scaffold_controller/scaffold_controller_generator.rb
88
+ - lib/generators/scaffold_controller/templates/controller.rb
89
+ - lib/generators/stylesheets/stylesheets_generator.rb
90
+ - lib/generators/test_unit/helper_generator.rb
91
+ - lib/generators/test_unit/model_generator.rb
92
+ - lib/generators/test_unit/scaffold_generator.rb
93
+ - lib/generators/test_unit/templates/functional_test.rb
94
+ - nested_scaffold.gemspec
95
+ has_rdoc: true
96
+ homepage: http://github.com/amatsuda/nested_scaffold
97
+ licenses:
98
+ - MIT
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.3.7
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Nested scaffold generator for Rails 3
129
+ test_files: []
130
+