nested_scaffold 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/README.rdoc +2 -2
  2. data/Rakefile +29 -37
  3. data/lib/generators/USAGE +1 -1
  4. data/lib/generators/nested_scaffold_generator.rb +8 -3
  5. data/test/dummy/README.rdoc +3 -0
  6. data/test/dummy/Rakefile +7 -0
  7. data/test/dummy/app/assets/javascripts/application.js +15 -0
  8. data/test/dummy/app/assets/javascripts/boxes.js +2 -0
  9. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  10. data/test/dummy/app/assets/stylesheets/boxes.css +4 -0
  11. data/test/dummy/app/controllers/application_controller.rb +3 -0
  12. data/test/dummy/app/controllers/boxes_controller.rb +83 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/helpers/boxes_helper.rb +2 -0
  15. data/test/dummy/app/models/box.rb +2 -0
  16. data/test/dummy/app/views/boxes/_form.html.erb +25 -0
  17. data/test/dummy/app/views/boxes/edit.html.erb +6 -0
  18. data/test/dummy/app/views/boxes/index.html.erb +25 -0
  19. data/test/dummy/app/views/boxes/new.html.erb +5 -0
  20. data/test/dummy/app/views/boxes/show.html.erb +15 -0
  21. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +56 -0
  24. data/test/dummy/config/boot.rb +10 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +37 -0
  28. data/test/dummy/config/environments/production.rb +67 -0
  29. data/test/dummy/config/environments/test.rb +37 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/inflections.rb +15 -0
  32. data/test/dummy/config/initializers/mime_types.rb +5 -0
  33. data/test/dummy/config/initializers/secret_token.rb +7 -0
  34. data/test/dummy/config/initializers/session_store.rb +8 -0
  35. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  36. data/test/dummy/config/locales/en.yml +5 -0
  37. data/test/dummy/config/routes.rb +60 -0
  38. data/test/dummy/db/migrate/20120313224522_create_boxes.rb +10 -0
  39. data/test/dummy/db/schema.rb +44 -0
  40. data/test/dummy/db/test.sqlite3 +0 -0
  41. data/test/dummy/log/test.log +18 -0
  42. data/test/dummy/public/404.html +26 -0
  43. data/test/dummy/public/422.html +26 -0
  44. data/test/dummy/public/500.html +25 -0
  45. data/test/dummy/public/favicon.ico +0 -0
  46. data/test/dummy/script/rails +6 -0
  47. data/test/dummy/test/fixtures/boxes.yml +9 -0
  48. data/test/dummy/test/functional/boxes_controller_test.rb +49 -0
  49. data/test/dummy/test/unit/box_test.rb +7 -0
  50. data/test/dummy/test/unit/helpers/boxes_helper_test.rb +4 -0
  51. data/test/nested_scaffold_test.rb +70 -0
  52. data/test/test_helper.rb +18 -0
  53. metadata +144 -79
  54. data/.document +0 -5
  55. data/Gemfile +0 -11
  56. data/Gemfile.lock +0 -16
  57. data/VERSION +0 -1
  58. data/nested_scaffold.gemspec +0 -75
@@ -11,7 +11,7 @@ A scaffold command that generates a set of perfectly working nested resource for
11
11
 
12
12
  == Rails versions
13
13
 
14
- 3.0.x and 3.1
14
+ 3.0.x, 3.1 and 3.2
15
15
 
16
16
  == Install
17
17
 
@@ -23,7 +23,7 @@ Then bundle:
23
23
 
24
24
  == Usage
25
25
 
26
- % rails generate scaffold PARENT_NAME/NAME [field:type field:type] [options]
26
+ % rails generate nested_scaffold PARENT_NAME/NAME [field:type field:type] [options]
27
27
 
28
28
  (Expects PARENT model to exist in advance)
29
29
 
data/Rakefile CHANGED
@@ -1,46 +1,38 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ #!/usr/bin/env rake
3
2
  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
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
9
6
  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'
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
26
13
  end
27
- Jeweler::RubygemsDotOrgTasks.new
28
14
 
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
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Nested Scaffold'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
21
  end
35
22
 
36
- task :default => :test
37
23
 
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
24
 
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "nested_scaffold #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
46
35
  end
36
+
37
+
38
+ task :default => :test
@@ -1,5 +1,5 @@
1
1
  Description:
2
- Generats nested scaffold
2
+ Generates nested scaffold
3
3
 
4
4
  Example:
5
5
  rails g nested_scaffold group/user name:string age:integer
@@ -2,7 +2,6 @@ require 'rails/generators/rails/scaffold/scaffold_generator'
2
2
  require File.join(File.dirname(__FILE__), 'base')
3
3
  require File.join(File.dirname(__FILE__), 'scaffold_controller/scaffold_controller_generator')
4
4
  require File.join(File.dirname(__FILE__), 'active_record/active_record_generator')
5
- require File.join(File.dirname(__FILE__), 'stylesheets/stylesheets_generator')
6
5
 
7
6
  module NestedScaffold
8
7
  module Generators
@@ -11,11 +10,17 @@ module NestedScaffold
11
10
 
12
11
  # override ScaffoldGenerator
13
12
  hook_for :scaffold_controller, :required => true
14
- # override ScaffoldGenerator
15
- hook_for :stylesheets
13
+
14
+ # Ensure assets get created with the correct name
15
+ hook_for :assets, :in => :rails do |source, generator|
16
+ source.invoke generator, [ source.file_name.pluralize ]
17
+ end
18
+
16
19
  # override ModelGenerator
17
20
  hook_for :orm, :required => true
18
21
 
22
+ # replacing hook for adding config/routes
23
+ remove_hook_for :resource_route
19
24
  # override
20
25
  def add_resource_route
21
26
  return if options[:actions].present?
@@ -0,0 +1,3 @@
1
+ == This is a Dummy Rails app for testing Nested Scaffold
2
+
3
+ If the nested scaffold is generated properly, you should be able to fire up rails and run this application in the usual way.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,83 @@
1
+ class BoxesController < ApplicationController
2
+ # GET /boxes
3
+ # GET /boxes.json
4
+ def index
5
+ @boxes = Box.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @boxes }
10
+ end
11
+ end
12
+
13
+ # GET /boxes/1
14
+ # GET /boxes/1.json
15
+ def show
16
+ @box = Box.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @box }
21
+ end
22
+ end
23
+
24
+ # GET /boxes/new
25
+ # GET /boxes/new.json
26
+ def new
27
+ @box = Box.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @box }
32
+ end
33
+ end
34
+
35
+ # GET /boxes/1/edit
36
+ def edit
37
+ @box = Box.find(params[:id])
38
+ end
39
+
40
+ # POST /boxes
41
+ # POST /boxes.json
42
+ def create
43
+ @box = Box.new(params[:box])
44
+
45
+ respond_to do |format|
46
+ if @box.save
47
+ format.html { redirect_to @box, notice: 'Box was successfully created.' }
48
+ format.json { render json: @box, status: :created, location: @box }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @box.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /boxes/1
57
+ # PUT /boxes/1.json
58
+ def update
59
+ @box = Box.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @box.update_attributes(params[:box])
63
+ format.html { redirect_to @box, notice: 'Box was successfully updated.' }
64
+ format.json { head :no_content }
65
+ else
66
+ format.html { render action: "edit" }
67
+ format.json { render json: @box.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /boxes/1
73
+ # DELETE /boxes/1.json
74
+ def destroy
75
+ @box = Box.find(params[:id])
76
+ @box.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to boxes_url }
80
+ format.json { head :no_content }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module BoxesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Box < ActiveRecord::Base
2
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@box) do |f| %>
2
+ <% if @box.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@box.errors.count, "error") %> prohibited this box from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @box.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %><br />
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :notes %><br />
20
+ <%= f.text_area :notes %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing box</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @box %> |
6
+ <%= link_to 'Back', boxes_path %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing boxes</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Notes</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @boxes.each do |box| %>
13
+ <tr>
14
+ <td><%= box.name %></td>
15
+ <td><%= box.notes %></td>
16
+ <td><%= link_to 'Show', box %></td>
17
+ <td><%= link_to 'Edit', edit_box_path(box) %></td>
18
+ <td><%= link_to 'Destroy', box, confirm: 'Are you sure?', method: :delete %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New Box', new_box_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New box</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', boxes_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @box.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Notes:</b>
10
+ <%= @box.notes %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_box_path(@box) %> |
15
+ <%= link_to 'Back', boxes_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require
6
+ #require "nested_scaffold_generator"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Custom directories with classes and modules you want to be autoloadable.
15
+ # config.autoload_paths += %W(#{config.root}/extras)
16
+
17
+ # Only load the plugins named here, in the order given (default is alphabetical).
18
+ # :all can be used as a placeholder for all plugins not explicitly named.
19
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
+
21
+ # Activate observers that should always be running.
22
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Configure the default encoding used in templates for Ruby 1.9.
33
+ config.encoding = "utf-8"
34
+
35
+ # Configure sensitive parameters which will be filtered from the log file.
36
+ config.filter_parameters += [:password]
37
+
38
+ # Use SQL instead of Active Record's schema dumper when creating the database.
39
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
40
+ # like if you have constraints or database-specific column types
41
+ # config.active_record.schema_format = :sql
42
+
43
+ # Enforce whitelist mode for mass assignment.
44
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
45
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
46
+ # parameters by using an attr_accessible or attr_protected declaration.
47
+ # config.active_record.whitelist_attributes = true
48
+
49
+ # Enable the asset pipeline
50
+ config.assets.enabled = true
51
+
52
+ # Version of your assets, change this if you want to expire all your assets
53
+ config.assets.version = '1.0'
54
+ end
55
+ end
56
+