rails3-generators 0.4.0 → 0.5.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 (67) hide show
  1. data/.gitignore +2 -1
  2. data/README.rdoc +5 -3
  3. data/Rakefile +2 -2
  4. data/VERSION +1 -1
  5. data/lib/generators/formtastic_erb.rb +9 -0
  6. data/lib/generators/formtastic_erb/USAGE +8 -0
  7. data/lib/generators/formtastic_erb/controller/controller_generator.rb +24 -0
  8. data/lib/generators/formtastic_erb/controller/templates/view.html.erb +0 -0
  9. data/lib/generators/formtastic_erb/scaffold/scaffold_generator.rb +27 -0
  10. data/lib/generators/formtastic_erb/scaffold/templates/_form.html.erb +12 -0
  11. data/lib/generators/formtastic_erb/scaffold/templates/edit.html.erb +6 -0
  12. data/lib/generators/formtastic_erb/scaffold/templates/index.html.erb +27 -0
  13. data/lib/generators/formtastic_erb/scaffold/templates/layout.html.erb +16 -0
  14. data/lib/generators/formtastic_erb/scaffold/templates/new.html.erb +5 -0
  15. data/lib/generators/formtastic_erb/scaffold/templates/show.html.erb +10 -0
  16. data/lib/generators/formtastic_haml.rb +9 -0
  17. data/lib/generators/formtastic_haml/USAGE +8 -0
  18. data/lib/generators/formtastic_haml/controller/controller_generator.rb +24 -0
  19. data/lib/generators/formtastic_haml/controller/templates/view.html.haml +0 -0
  20. data/lib/generators/formtastic_haml/scaffold/scaffold_generator.rb +23 -0
  21. data/lib/generators/formtastic_haml/scaffold/templates/_form.haml.erb +9 -0
  22. data/lib/generators/formtastic_haml/scaffold/templates/edit.haml.erb +7 -0
  23. data/lib/generators/formtastic_haml/scaffold/templates/index.haml.erb +23 -0
  24. data/lib/generators/formtastic_haml/scaffold/templates/layout.haml.erb +9 -0
  25. data/lib/generators/formtastic_haml/scaffold/templates/new.haml.erb +5 -0
  26. data/lib/generators/formtastic_haml/scaffold/templates/show.haml.erb +9 -0
  27. data/lib/generators/haml/scaffold/templates/layout.haml.erb +1 -0
  28. data/lib/generators/machinist.rb +11 -0
  29. data/lib/generators/machinist/model/model_generator.rb +19 -0
  30. data/lib/generators/machinist/model/templates/blueprint.rb +5 -0
  31. data/lib/generators/machinist/model/templates/machinist_initializer.rb +19 -0
  32. data/lib/replaced_by_lib_generators/rspec.rb +25 -0
  33. data/lib/replaced_by_lib_generators/rspec/controller/controller_generator.rb +26 -0
  34. data/lib/replaced_by_lib_generators/rspec/controller/templates/controller_spec.rb +23 -0
  35. data/lib/replaced_by_lib_generators/rspec/controller/templates/view_spec.rb +12 -0
  36. data/lib/replaced_by_lib_generators/rspec/helper/helper_generator.rb +11 -0
  37. data/lib/replaced_by_lib_generators/rspec/helper/templates/helper_spec.rb +11 -0
  38. data/lib/replaced_by_lib_generators/rspec/install/install_generator.rb +28 -0
  39. data/lib/replaced_by_lib_generators/rspec/install/templates/lib/tasks/rspec.rake +182 -0
  40. data/lib/replaced_by_lib_generators/rspec/install/templates/script/autospec.tt +6 -0
  41. data/lib/replaced_by_lib_generators/rspec/install/templates/script/spec.tt +10 -0
  42. data/lib/replaced_by_lib_generators/rspec/install/templates/script/spec_server.tt +9 -0
  43. data/lib/replaced_by_lib_generators/rspec/install/templates/spec/rcov.opts +2 -0
  44. data/lib/replaced_by_lib_generators/rspec/install/templates/spec/spec.opts +4 -0
  45. data/lib/replaced_by_lib_generators/rspec/install/templates/spec/spec_helper.rb +51 -0
  46. data/lib/replaced_by_lib_generators/rspec/integration/integration_generator.rb +12 -0
  47. data/lib/replaced_by_lib_generators/rspec/integration/templates/integration_spec.rb +4 -0
  48. data/lib/replaced_by_lib_generators/rspec/mailer/mailer_generator.rb +21 -0
  49. data/lib/replaced_by_lib_generators/rspec/mailer/templates/fixture +3 -0
  50. data/lib/replaced_by_lib_generators/rspec/mailer/templates/mailer_spec.rb +14 -0
  51. data/lib/replaced_by_lib_generators/rspec/model/model_generator.rb +22 -0
  52. data/lib/replaced_by_lib_generators/rspec/model/templates/fixtures.yml +19 -0
  53. data/lib/replaced_by_lib_generators/rspec/model/templates/model_spec.rb +13 -0
  54. data/lib/replaced_by_lib_generators/rspec/observer/observer_generator.rb +12 -0
  55. data/lib/replaced_by_lib_generators/rspec/observer/templates/observer_spec.rb +5 -0
  56. data/lib/replaced_by_lib_generators/rspec/plugin/plugin_generator.rb +11 -0
  57. data/lib/replaced_by_lib_generators/rspec/plugin/templates/%file_name%_spec.rb.tt +5 -0
  58. data/lib/replaced_by_lib_generators/rspec/plugin/templates/test_helper.rb +5 -0
  59. data/lib/replaced_by_lib_generators/rspec/scaffold/scaffold_generator.rb +112 -0
  60. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/controller_spec.rb +127 -0
  61. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/edit_spec.rb +25 -0
  62. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/index_spec.rb +27 -0
  63. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/new_spec.rb +25 -0
  64. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/routing_spec.rb +67 -0
  65. data/lib/replaced_by_lib_generators/rspec/scaffold/templates/show_spec.rb +22 -0
  66. data/rails3-generators.gemspec +65 -5
  67. metadata +82 -10
data/.gitignore CHANGED
@@ -3,4 +3,5 @@ coverage
3
3
  rdoc
4
4
  pkg
5
5
 
6
- ## PROJECT::SPECIFIC
6
+ ## PROJECT::SPECIFIC
7
+ .idea
@@ -10,10 +10,12 @@ Fork the repo, add a generator, send a pull request. Pretty simple.
10
10
 
11
11
  DataMapper generators: Jose Valim
12
12
 
13
- Haml: Paul Berry, Anuj Dutta, Louis T
13
+ Haml: Paul Barry, Anuj Dutta, Louis T
14
14
 
15
- Factory Girl: Paul Berry
15
+ Factory Girl: Paul Barry
16
16
 
17
17
  Authlogic: Jeff Tucker
18
18
 
19
- MongoMapper: Jai-Gouk Kim
19
+ MongoMapper: Jai-Gouk Kim
20
+
21
+ Machinist: Darcy Laycock
data/Rakefile CHANGED
@@ -6,10 +6,10 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "rails3-generators"
8
8
  gem.summary = %Q{Rails 3 compatible generators}
9
- gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, and Mongomapper}
9
+ gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper and Machinist}
10
10
  gem.email = "andre@arko.net"
11
11
  gem.homepage = "http://github.com/indirect/rails3-generators"
12
- gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim"]
12
+ gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
14
  end
15
15
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -0,0 +1,9 @@
1
+ module FormtasticErb
2
+ module Generators
3
+ module TemplatePath
4
+ def source_root
5
+ @_formtastic_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'formtastic_erb', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate formtastic Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,24 @@
1
+ require 'generators/formtastic'
2
+ require 'rails/generators/named_base'
3
+
4
+ module FormtasticErb
5
+ module Generators
6
+ class ControllerGenerator < Rails::Generators::NamedBase
7
+ extend TemplatePath
8
+
9
+ argument :actions, :type => :array, :default => [], :banner => "action action"
10
+
11
+ def create_view_files
12
+ base_path = File.join("app/views", class_path, file_name)
13
+ empty_directory base_path
14
+
15
+ actions.each do |action|
16
+ @action = action
17
+ @path = File.join(base_path, "#{action}.html.haml")
18
+
19
+ template 'view.html.haml', @path
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'generators/formtastic_erb'
2
+ require 'generators/erb/scaffold/scaffold_generator'
3
+
4
+ module FormtasticErb
5
+ module Generators
6
+ class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
+ extend TemplatePath
8
+
9
+ def copy_layout_file
10
+ return unless options[:layout]
11
+ template "layout.html.erb",
12
+ File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.erb")
13
+ end
14
+
15
+ protected
16
+
17
+ def copy_view(view)
18
+ if view =~ /^_.*/
19
+ template "#{view}.html.erb", File.join("app/views", controller_file_path, "#{view}.html.erb")
20
+ else
21
+ super view
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ <%% semantic_form_for @<%= singular_name %> do |form| %>
2
+ <%- if attributes.empty? -%>
3
+ <%% form.inputs %>
4
+ <%- else -%>
5
+ <%% form.inputs do %>
6
+ <%- for attribute in attributes -%>
7
+ <%%= form.input :<%= attribute.name %>, :label => '<%= attribute.name.titleize %>' %>
8
+ <%- end -%>
9
+ <%% end %>
10
+ <%- end -%>
11
+ <%%= form.buttons %>
12
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', @<%= singular_name %> %> |
6
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing <%= plural_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_name %>.each do |<%= singular_name %>| %>
14
+ <tr>
15
+ <% for attribute in attributes -%>
16
+ <td><%%= <%= singular_name %>.<%= attribute.name %> %></td>
17
+ <% end -%>
18
+ <td><%%= link_to 'Show', <%= singular_name %> %></td>
19
+ <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
20
+ <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <%% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= controller_class_name %>: <%%= controller.action_name %></title>
5
+ <%%= stylesheet_link_tag 'scaffold' %>
6
+ <%%= javascript_include_tag :defaults %>
7
+ <%%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <p class="notice"><%%= notice %></p>
12
+
13
+ <%%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.human_name %>:</b>
4
+ <%%= @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,9 @@
1
+ module FormtasticHaml
2
+ module Generators
3
+ module TemplatePath
4
+ def source_root
5
+ @_formtastic_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'formtastic_haml', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate formtastic Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,24 @@
1
+ require 'generators/formtastic'
2
+ require 'rails/generators/named_base'
3
+
4
+ module FormtasticHaml
5
+ module Generators
6
+ class ControllerGenerator < Rails::Generators::NamedBase
7
+ extend TemplatePath
8
+
9
+ argument :actions, :type => :array, :default => [], :banner => "action action"
10
+
11
+ def create_view_files
12
+ base_path = File.join("app/views", class_path, file_name)
13
+ empty_directory base_path
14
+
15
+ actions.each do |action|
16
+ @action = action
17
+ @path = File.join(base_path, "#{action}.html.haml")
18
+
19
+ template 'view.html.haml', @path
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'generators/formtastic_haml/'
2
+ require 'generators/erb/scaffold/scaffold_generator'
3
+
4
+ module FormtasticHaml
5
+ module Generators
6
+ class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
+ extend TemplatePath
8
+
9
+ def copy_layout_file
10
+ return unless options[:layout]
11
+ template "layout.haml.erb",
12
+ File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.haml")
13
+ end
14
+
15
+ protected
16
+
17
+ def copy_view(view)
18
+ template "#{view}.haml.erb", File.join("app/views", controller_file_path, "#{view}.html.haml")
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ - semantic_form_for @<%= singular_name %> do |form|
2
+ <%- if attributes.empty? -%>
3
+ - form.inputs
4
+ <%- else -%>
5
+ <%- for attribute in attributes -%>
6
+ = form.input :<%= attribute.name %>, :label => '<%= attribute.name.titleize %>'
7
+ <%- end -%>
8
+ <%- end -%>
9
+ = form.buttons
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= singular_name %>
6
+ \|
7
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,23 @@
1
+ %h1 Listing <%= plural_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_name %>.each do |<%= singular_name %>|
13
+ %tr
14
+ <% for attribute in attributes -%>
15
+ %td= <%= singular_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ %td= link_to 'Show', <%= singular_name %>
18
+ %td= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>)
19
+ %td= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
20
+
21
+ %br
22
+
23
+ = link_to 'New <%= singular_name %>', new_<%= singular_name %>_path
@@ -0,0 +1,9 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title= "<%= controller_class_name %>:#{controller.action_name}"
5
+ = csrf_meta_tag
6
+ = stylesheet_link_tag 'scaffold'
7
+ %body
8
+ %p.notice= notice
9
+ = yield
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,9 @@
1
+ <% for attribute in attributes -%>
2
+ %p
3
+ %b <%= attribute.human_name %>:
4
+ = @<%= singular_name %>.<%= attribute.name %>
5
+ <% end -%>
6
+
7
+ = link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
8
+ \|
9
+ = link_to 'Back', <%= plural_name %>_path
@@ -2,6 +2,7 @@
2
2
  %html
3
3
  %head
4
4
  %title= "<%= controller_class_name %>:#{controller.action_name}"
5
+ = csrf_meta_tag
5
6
  = stylesheet_link_tag 'scaffold'
6
7
  %body
7
8
  %p.notice= notice
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Machinist
4
+ module Generators
5
+ class Base < Rails::Generators::NamedBase #:nodoc:
6
+ def self.source_root
7
+ @_machinist_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'machinist', generator_name, 'templates'))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'generators/machinist'
2
+
3
+ module Machinist
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
+ class_option :dir, :type => :string, :default => "test/blueprints", :desc => "The directory where the blueprints should go"
8
+
9
+ def create_machinist_initializer
10
+ return if File.exists?(File.expand_path("config/initializers/machinist.rb", self.destination_root))
11
+ template "machinist_initializer.rb", "config/initializers/machinist.rb"
12
+ end
13
+
14
+ def create_blueprint_file
15
+ template 'blueprint.rb', File.join(options[:dir], "#{table_name}.rb")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ <%= class_name %>.blueprint do
2
+ <% attributes.each do |attribute| -%>
3
+ <%= attribute.name %> <%= attribute.default.inspect %>
4
+ <% end -%>
5
+ end
@@ -0,0 +1,19 @@
1
+ # Add other envs here e.g. cucumber
2
+ if Rails.env.test?
3
+ require 'machinist'
4
+ # require 'machinist/active_record'
5
+
6
+ def Machinist.clear!
7
+ Sham.clear
8
+ # ActiveRecord::Base.clear_blueprints!
9
+ end
10
+
11
+ def Machinist.load_blueprints
12
+ Dir[Rails.root.join(<%= options[:dir].inspect %>, "**", "*.rb")].each do |file|
13
+ load file
14
+ end
15
+ end
16
+
17
+ # Put Machinist.load_blueprints in the test_helper.rb
18
+
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Rspec
4
+ module Generators
5
+ class Base < Rails::Generators::NamedBase #:nodoc:
6
+ def self.source_root
7
+ @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ module Rails
14
+ module Generators
15
+ class GeneratedAttribute #:nodoc:
16
+ def input_type
17
+ @input_type ||= if type == :text
18
+ "textarea"
19
+ else
20
+ "input"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end