rails3-generators 0.9.2 → 0.10.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 (29) hide show
  1. data/.gitignore +1 -1
  2. data/CHANGELOG.rdoc +11 -1
  3. data/VERSION +1 -1
  4. data/lib/generators/mustache.rb +9 -0
  5. data/lib/generators/mustache/README.md +22 -0
  6. data/lib/generators/mustache/controller/controller_generator.rb +39 -0
  7. data/lib/generators/mustache/controller/templates/view.html.mustache.erb +0 -0
  8. data/lib/generators/mustache/controller/templates/view.rb.erb +3 -0
  9. data/lib/generators/mustache/install/install_generator.rb +15 -0
  10. data/lib/generators/mustache/install/templates/config/initializers/mustache.rb +6 -0
  11. data/lib/generators/mustache/install/templates/lib/mustache_rails.rb +123 -0
  12. data/lib/generators/mustache/scaffold/scaffold_generator.rb +38 -0
  13. data/lib/generators/mustache/scaffold/templates/_form.html.mustache.erb +4 -0
  14. data/lib/generators/mustache/scaffold/templates/edit.html.mustache.erb +10 -0
  15. data/lib/generators/mustache/scaffold/templates/edit.rb.erb +53 -0
  16. data/lib/generators/mustache/scaffold/templates/index.html.mustache.erb +13 -0
  17. data/lib/generators/mustache/scaffold/templates/index.rb.erb +18 -0
  18. data/lib/generators/mustache/scaffold/templates/new.html.mustache.erb +11 -0
  19. data/lib/generators/mustache/scaffold/templates/new.rb.erb +50 -0
  20. data/lib/generators/mustache/scaffold/templates/show.html.mustache.erb +7 -0
  21. data/lib/generators/mustache/scaffold/templates/show.rb.erb +18 -0
  22. data/lib/generators/shoulda/controller/templates/controller.rb +15 -15
  23. data/lib/rails3-generators.rb +7 -0
  24. data/rails3-generators.gemspec +27 -3
  25. data/test/lib/generators/mustache/controller_generator_test.rb +31 -0
  26. data/test/lib/generators/mustache/scaffold_generator_test.rb +202 -0
  27. data/test/lib/generators/shoulda/controller_generator_test.rb +37 -0
  28. data/test/test_helper.rb +19 -0
  29. metadata +29 -5
data/.gitignore CHANGED
@@ -19,4 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
- tmp/**/*
22
+ tmp/**/*
data/CHANGELOG.rdoc CHANGED
@@ -1,8 +1,18 @@
1
1
  == TODO
2
- * Mustache generators
2
+ * Grow Mustache up.(fix the TODOs and move the source to a mustache-rails like gem)
3
+ * Write some documentation. (In both the github wiki and the source code)
3
4
  * Datamapper Tests
4
5
  * Mongomapper Tests
5
6
 
7
+ == 0.10.0
8
+ * enhancements
9
+ * added mustache:install
10
+ * added mustache:controller
11
+ * added mustache:scaffold
12
+
13
+ * fix
14
+ * fixed shoulda controller CamelCase problem.
15
+
6
16
  == 0.9.2
7
17
  * enhancements
8
18
  * added koala:install
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.10.0
@@ -0,0 +1,9 @@
1
+ class Mustache
2
+ module Generators
3
+ module TemplatePath
4
+ def source_root
5
+ @_mustache_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'mustache', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ ## Rails 3 Generators for Mustache
2
+
3
+ [Mustache](http://github.com/defunkt/mustache) support for [Rails 3](http://weblog.rubyonrails.org/2010/6/8/rails-3-0-beta-4-now-rc-in-days) is [still developing](http://github.com/defunkt/mustache/issues/#issue/3). Following the work of others, I have built a provisional template handler that is included with these generators. To install it in your project, `rails g mustache:install`
4
+
5
+ I'm assuming that the Mustache template engine that gets the official blessing will expect to find files where Chris W. and others have suggested the files should go, so I have built my generators and provisional template handler accordingly. I.e. the files for widget views go in:
6
+
7
+ * app/views/widgets/action.rb for view class definitions
8
+ * app/templates/widgets/action.html.mustache for templates
9
+
10
+
11
+ ### To Do
12
+
13
+ * Enable mustache layout usage (uses default application.erb for now)
14
+ * Add controller-retrofit generator to build default mustache views for existing controllers
15
+ * Generate different fields for different attribute types
16
+ * Helper generation for leaner view files
17
+
18
+ ### Thanks
19
+
20
+ * Louis T. for running the umbrella Rails 3 Generators project and giving me pointers on writing generators.
21
+ * Paul Barry for invaluable help figuring out how Rails template handlers work.
22
+ * José Valim, Paul Barry, and Jeremy McAnally for good information.
@@ -0,0 +1,39 @@
1
+ require 'generators/mustache'
2
+ require 'rails/generators/named_base'
3
+
4
+ class Mustache
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
+ model_path = File.join(class_path, file_name)
13
+
14
+ base_mustache_view_path = File.join("app/views", model_path)
15
+ empty_directory base_mustache_view_path
16
+
17
+ base_mustache_template_path = File.join("app/templates", model_path)
18
+ empty_directory base_mustache_template_path
19
+
20
+ actions.each do |action|
21
+ @action = action
22
+ mustache_view_path = File.join(base_mustache_view_path,
23
+ "#{action}.rb")
24
+ mustache_template_path = File.join(base_mustache_template_path,
25
+ "#{action}.html.mustache")
26
+
27
+ template "view.rb.erb", mustache_view_path
28
+ template "view.html.mustache.erb", mustache_template_path
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ def handler
35
+ :haml
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ class <%= singular_name.camelize %>::<%= @action.camelize %> < Mustache::Rails
2
+
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'generators/mustache'
2
+
3
+ class Mustache
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ extend TemplatePath
7
+
8
+ def copy_initializer_files
9
+ copy_file "config/initializers/mustache.rb", "config/initializers/mustache.rb"
10
+ copy_file "lib/mustache_rails.rb", "lib/mustache_rails.rb"
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ # Be sure to install mustache gem and include mustache gem in project Gemfile.
2
+
3
+ # Template Handler
4
+ require 'mustache_rails'
5
+ # Generator
6
+ Rails.application.config.generators.template_engine :mustache
@@ -0,0 +1,123 @@
1
+ require 'action_view'
2
+ require 'active_support'
3
+ require 'mustache'
4
+
5
+ class Mustache
6
+
7
+ # Remember to use {{{yield}}} (3 mustaches) to skip escaping HTML
8
+ # Using {{{tag}}} will skip escaping HTML so if your mustache methods return
9
+ # HTML, be sure to interpolate them using 3 mustaches.
10
+
11
+ class Rails < Mustache
12
+ attr_accessor :view
13
+
14
+ def method_missing(method, *args, &block)
15
+ view.send(method, *args, &block)
16
+ end
17
+
18
+ def respond_to?(method, include_private=false)
19
+ super(method, include_private) || view.respond_to?(method, include_private)
20
+ end
21
+
22
+ # Redefine where Mustache::Rails templates locate their partials:
23
+ #
24
+ # (1) in the same directory as the current template file.
25
+ # (2) in the shared templates path (can be configured via Config.shared_path=(value))
26
+ #
27
+ def partial(name)
28
+ partial_name = "_#{name}.#{Config.template_extension}"
29
+ template_dir = Pathname.new(self.class.template_file).dirname
30
+ partial_path = File.expand_path("#{template_dir}/#{partial_name}")
31
+ unless File.file?(partial_path)
32
+ partial_path = "#{Config.shared_path}/#{partial_name}"
33
+ end
34
+ File.read(partial_path)
35
+ end
36
+
37
+ # You can change these defaults in, say, a Rails initializer or
38
+ # environment.rb, e.g.:
39
+ #
40
+ # Mustache::Rails::Config.template_base_path = Rails.root.join('app', 'templates')
41
+ module Config
42
+ def self.template_base_path
43
+ @template_base_path ||= ::Rails.root.join('app', 'templates')
44
+ end
45
+
46
+ def self.template_base_path=(value)
47
+ @template_base_path = value
48
+ end
49
+
50
+ def self.template_extension
51
+ @template_extension ||= 'html.mustache'
52
+ end
53
+
54
+ def self.template_extension=(value)
55
+ @template_extension = value
56
+ end
57
+
58
+ def self.shared_path
59
+ @shared_path ||= ::Rails.root.join('app', 'templates', 'shared')
60
+ end
61
+
62
+ def self.shared_path=(value)
63
+ @shared_path = value
64
+ end
65
+ end
66
+
67
+ class TemplateHandler < ActionView::Template::Handler
68
+
69
+ include ActionView::Template::Handlers::Compilable
70
+
71
+ self.default_format = :mustache
72
+
73
+ # @return [String] its evaled in the context of the action view
74
+ # hence the hack below
75
+ #
76
+ # @param [ActionView::Template]
77
+ def compile(template)
78
+ mustache_class = mustache_class_from_template(template)
79
+ mustache_class.template_file = mustache_template_file(template)
80
+
81
+ <<-MUSTACHE
82
+ mustache = ::#{mustache_class}.new
83
+ mustache.view = self
84
+ mustache[:yield] = content_for(:layout)
85
+ mustache.context.update(local_assigns)
86
+ variables = controller.instance_variable_names
87
+ variables -= %w[@template]
88
+
89
+ if controller.respond_to?(:protected_instance_variables)
90
+ variables -= controller.protected_instance_variables
91
+ end
92
+
93
+ variables.each do |name|
94
+ mustache.instance_variable_set(name, controller.instance_variable_get(name))
95
+ end
96
+
97
+ # Declaring an +attr_reader+ for each instance variable in the
98
+ # Mustache::Rails subclass makes them available to your templates.
99
+ mustache.class.class_eval do
100
+ attr_reader *variables.map { |name| name.sub(/^@/, '').to_sym }
101
+ end
102
+
103
+ mustache.render
104
+ MUSTACHE
105
+ end
106
+
107
+ private
108
+
109
+ def mustache_class_from_template(template)
110
+ const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
111
+ defined?(const_name) ? const_name.constantize : Mustache
112
+ end
113
+
114
+ def mustache_template_file(template)
115
+ "#{Config.template_base_path}/#{template.virtual_path}.#{Config.template_extension}"
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+
122
+ ::ActiveSupport::Dependencies.load_paths << Rails.root.join("app", "views")
123
+ ::ActionView::Template.register_template_handler(:rb, Mustache::Rails::TemplateHandler)
@@ -0,0 +1,38 @@
1
+ require 'generators/mustache'
2
+ require 'rails/generators/erb/scaffold/scaffold_generator'
3
+
4
+ class Mustache
5
+ module Generators
6
+ class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
+ extend TemplatePath
8
+
9
+ # TODO Layout files? snusnu claims his template engine supports layouts:
10
+ # http://github.com/defunkt/mustache/issues/#issue/3/comment/263445
11
+
12
+ def copy_view_files
13
+ views = available_views
14
+ views.delete("index") if options[:singleton]
15
+
16
+ views.each do |view|
17
+ template "#{view}.rb.erb",
18
+ File.join("app/views", controller_file_path, "#{view}.rb")
19
+ template "#{view}.html.mustache.erb",
20
+ File.join("app/templates",
21
+ controller_file_path,
22
+ "#{view}.html.mustache")
23
+ end
24
+ template "_form.html.mustache.erb",
25
+ File.join("app/templates",
26
+ controller_file_path,
27
+ "_form.html.mustache")
28
+ end
29
+
30
+ private
31
+
32
+ def available_views
33
+ %w(index edit show new)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ <p><% for attribute in attributes -%>
2
+ {{{<%= attribute.name %>_label}}}: {{{<%= attribute.name %>_text_field}}}<br />
3
+ <% end -%></p>
4
+ {{{form_submit}}}
@@ -0,0 +1,10 @@
1
+ <p>Editing <%= singular_name.capitalize %></p>
2
+
3
+ {{{errors_display_div}}}
4
+
5
+ <hr />
6
+ {{{<%= singular_name %>_form_tag}}}
7
+ {{> form }}
8
+ </form>
9
+ <hr />
10
+ <a href="{{show_path}}">Back to record</a>
@@ -0,0 +1,53 @@
1
+ class <%= plural_name.camelize %>::Edit < Mustache::Rails
2
+
3
+ <%# TODO: extract errors_display settings to to module methods -%>
4
+ def errors_display_div
5
+ return "" unless <%= singular_name %>.errors.any?
6
+ content_tag("div", :id=>"errorExplanation", :class=>"errorExplanation") do
7
+ content_tag("h2", error_header) + content_tag("ul") do
8
+ <%= singular_name %>.errors.full_messages.inject("") do |memo,msg|
9
+ memo += content_tag("li", msg)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def <%= singular_name %>_form_tag
16
+ form_tag(update_path, :class => "<%= singular_name %>_form", :method => :put, :id => "edit_<%= singular_name %>_#{<%= singular_name %>.id}_form")
17
+ end
18
+
19
+ <% for attribute in attributes -%>
20
+ def <%= attribute.name %>_label
21
+ label :<%= singular_name %>, :<%= attribute.name %>
22
+ end
23
+ <%# TODO: Different fields for different attribute types -%>
24
+
25
+ def <%= attribute.name %>_text_field
26
+ text_field(:<%= singular_name %>, :<%= attribute.name %>, :id => "<%= attribute.name %>_text_field")
27
+ end
28
+
29
+ <% end -%>
30
+
31
+ def form_submit
32
+ submit_tag "Update"
33
+ end
34
+
35
+ def show_path
36
+ <%= singular_name %>_path(<%= singular_name %>)
37
+ end
38
+
39
+ def index_path
40
+ <%= plural_name %>_path
41
+ end
42
+
43
+ private
44
+
45
+ def update_path
46
+ <%= singular_name %>_path(<%= singular_name %>)
47
+ end
48
+
49
+ def error_header
50
+ "u r dong it rong"
51
+ end
52
+
53
+ end
@@ -0,0 +1,13 @@
1
+ <p>Listing <%= plural_name.capitalize %></p>
2
+
3
+ {{#listing}}
4
+
5
+ <p>
6
+ <% attributes.collect do |attribute| -%>
7
+ <b><%= attribute.human_name %></b>: {{<%= attribute.name %>}}
8
+ <% end.join(" | ") -%>
9
+ | <a href="{{show_path}}">Details</a></p>
10
+
11
+ {{/listing}}
12
+
13
+ <p><a href="{{new_path}}">New</a></p>
@@ -0,0 +1,18 @@
1
+ class <%= plural_name.camelize %>::Index < Mustache::Rails
2
+
3
+ def new_path
4
+ new_<%= singular_name %>_path()
5
+ end
6
+
7
+ def listing
8
+ <%= plural_name %>.collect do |record|
9
+ {
10
+ <% for attribute in attributes -%>
11
+ :<%= attribute.name %> => record.<%= attribute.name %>,
12
+ <% end -%>
13
+ :show_path => <%= singular_name %>_path(record)
14
+ }
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,11 @@
1
+ <p>New <%= singular_name.capitalize %></p>
2
+
3
+ {{{errors_display_div}}}
4
+
5
+ <hr />
6
+ {{{<%= singular_name %>_form_tag}}}
7
+ {{> form }}
8
+ </form>
9
+ <hr />
10
+
11
+ <a href="{{index_path}}">Back to listing</a>
@@ -0,0 +1,50 @@
1
+ class <%= plural_name.camelize %>::New < Mustache::Rails
2
+
3
+ <%# TODO: extract errors_display settings to to module methods -%>
4
+ def errors_display_div
5
+ return "" unless <%= singular_name %>.errors.any?
6
+ content_tag("div", :id=>"errorExplanation", :class=>"errorExplanation") do
7
+ content_tag("h2", error_header) + content_tag("ul") do
8
+ <%= singular_name %>.errors.full_messages.inject("") do |memo,msg|
9
+ memo += content_tag("li", msg)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def <%= singular_name %>_form_tag
16
+ form_tag(create_path, :class => "<%= singular_name %>_form", :id => "edit_<%= singular_name %>_#{<%= singular_name %>.id}_form")
17
+ end
18
+
19
+ <% for attribute in attributes -%>
20
+ def <%= attribute.name %>_label
21
+ label :<%= singular_name %>, :<%= attribute.name %>
22
+ end
23
+ <%# TODO: Different fields for different attribute types -%>
24
+
25
+ def <%= attribute.name %>_text_field
26
+ text_field(:<%= singular_name %>, :<%= attribute.name %>, :id => "<%= attribute.name %>_text_field")
27
+ end
28
+
29
+ <% end -%>
30
+
31
+ def form_submit
32
+ submit_tag "Create"
33
+ end
34
+
35
+
36
+ def index_path
37
+ <%= plural_name %>_path
38
+ end
39
+
40
+ private
41
+
42
+ def create_path
43
+ <%= plural_name %>_path
44
+ end
45
+
46
+ def error_header
47
+ "u r dong it rong"
48
+ end
49
+
50
+ end
@@ -0,0 +1,7 @@
1
+ <p>Displaying <%= singular_name.capitalize %></p>
2
+
3
+ <% for attribute in attributes -%>
4
+ <p><b><%= attribute.human_name %></b>: {{<%= attribute.name %>}}</p>
5
+ <% end -%>
6
+
7
+ <a href="{{edit_path}}">Edit</a> | <a href="{{index_path}}">Back</a>
@@ -0,0 +1,18 @@
1
+ class <%= plural_name.camelize %>::Show < Mustache::Rails
2
+
3
+ <% for attribute in attributes -%>
4
+ def <%= attribute.name %>
5
+ <%= singular_name %>.<%= attribute.name %>
6
+ end
7
+
8
+ <% end -%>
9
+
10
+ def edit_path
11
+ edit_<%= singular_name %>_path(@<%= singular_name %>)
12
+ end
13
+
14
+ def index_path
15
+ <%= plural_name %>_path
16
+ end
17
+
18
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
- class <%= plural_name %>ControllerTest < ActionController::TestCase
4
- <% if actions.include?('index') %>
3
+ class <%= class_name %>ControllerTest < ActionController::TestCase
4
+ <% if actions.include?('index') -%>
5
5
 
6
6
  context "index action" do
7
7
  should "render index template" do
@@ -9,8 +9,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
9
9
  assert_template 'index'
10
10
  end
11
11
  end
12
- <% end %>
13
- <% if actions.include?('show') %>
12
+ <% end -%>
13
+ <% if actions.include?('show') -%>
14
14
 
15
15
  context "show action" do
16
16
  should "render show template" do
@@ -18,8 +18,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
18
18
  assert_template 'show'
19
19
  end
20
20
  end
21
- <% end %>
22
- <% if actions.include?('new') %>
21
+ <% end -%>
22
+ <% if actions.include?('new') -%>
23
23
 
24
24
  context "new action" do
25
25
  should "render new template" do
@@ -27,8 +27,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
27
27
  assert_template 'new'
28
28
  end
29
29
  end
30
- <% end %>
31
- <% if actions.include?('create') %>
30
+ <% end -%>
31
+ <% if actions.include?('create') -%>
32
32
 
33
33
  context "create action" do
34
34
  should "render new template when model is invalid" do
@@ -43,8 +43,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
43
43
  assert_redirected_to
44
44
  end
45
45
  end
46
- <% end %>
47
- <% if actions.include?('edit') %>
46
+ <% end -%>
47
+ <% if actions.include?('edit') -%>
48
48
 
49
49
  context "edit action" do
50
50
  should "render edit template" do
@@ -52,8 +52,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
52
52
  assert_template 'edit'
53
53
  end
54
54
  end
55
- <% end %>
56
- <% if actions.include?('update') %>
55
+ <% end -%>
56
+ <% if actions.include?('update') -%>
57
57
 
58
58
  context "update action" do
59
59
  should "render edit template when model is invalid" do
@@ -68,8 +68,8 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
68
68
  assert_redirected_to
69
69
  end
70
70
  end
71
- <% end %>
72
- <% if actions.include?('destroy') %>
71
+ <% end -%>
72
+ <% if actions.include?('destroy') -%>
73
73
 
74
74
  context "destroy action" do
75
75
  should "destroy model and redirect to index action" do
@@ -79,6 +79,6 @@ class <%= plural_name %>ControllerTest < ActionController::TestCase
79
79
  assert !<%= class_name %>.exists?(<%= singular_name %>.id)
80
80
  end
81
81
  end
82
- <% end %>
82
+ <% end -%>
83
83
 
84
84
  end
@@ -54,4 +54,11 @@ end
54
54
  ]
55
55
  end
56
56
 
57
+ Rails::Generators.hidden_namespaces <<
58
+ [
59
+ "mustache:controller",
60
+ "mustache:scaffold",
61
+ "mustache:install"
62
+ ]
63
+
57
64
  Rails::Generators.hidden_namespaces.flatten!
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3-generators}
8
- s.version = "0.9.2"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza", "Peter Gumeson"]
12
- s.date = %q{2010-06-22}
12
+ s.date = %q{2010-07-02}
13
13
  s.description = %q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, Shoulda, Formtastic and SimpleForm}
14
14
  s.email = %q{andre@arko.net}
15
15
  s.extra_rdoc_files = [
@@ -76,6 +76,24 @@ Gem::Specification.new do |s|
76
76
  "lib/generators/mongomapper/model/model_generator.rb",
77
77
  "lib/generators/mongomapper/model/templates/model.rb",
78
78
  "lib/generators/mongomapper/observer/observer_generator.rb",
79
+ "lib/generators/mustache.rb",
80
+ "lib/generators/mustache/README.md",
81
+ "lib/generators/mustache/controller/controller_generator.rb",
82
+ "lib/generators/mustache/controller/templates/view.html.mustache.erb",
83
+ "lib/generators/mustache/controller/templates/view.rb.erb",
84
+ "lib/generators/mustache/install/install_generator.rb",
85
+ "lib/generators/mustache/install/templates/config/initializers/mustache.rb",
86
+ "lib/generators/mustache/install/templates/lib/mustache_rails.rb",
87
+ "lib/generators/mustache/scaffold/scaffold_generator.rb",
88
+ "lib/generators/mustache/scaffold/templates/_form.html.mustache.erb",
89
+ "lib/generators/mustache/scaffold/templates/edit.html.mustache.erb",
90
+ "lib/generators/mustache/scaffold/templates/edit.rb.erb",
91
+ "lib/generators/mustache/scaffold/templates/index.html.mustache.erb",
92
+ "lib/generators/mustache/scaffold/templates/index.rb.erb",
93
+ "lib/generators/mustache/scaffold/templates/new.html.mustache.erb",
94
+ "lib/generators/mustache/scaffold/templates/new.rb.erb",
95
+ "lib/generators/mustache/scaffold/templates/show.html.mustache.erb",
96
+ "lib/generators/mustache/scaffold/templates/show.rb.erb",
79
97
  "lib/generators/shoulda.rb",
80
98
  "lib/generators/shoulda/controller/controller_generator.rb",
81
99
  "lib/generators/shoulda/controller/templates/controller.rb",
@@ -104,12 +122,15 @@ Gem::Specification.new do |s|
104
122
  "test/lib/generators/machinist/model_generator_test.rb",
105
123
  "test/lib/generators/mongomapper/model_generator_test.rb",
106
124
  "test/lib/generators/mongomapper/observer_generator_test.rb",
125
+ "test/lib/generators/mustache/controller_generator_test.rb",
126
+ "test/lib/generators/mustache/scaffold_generator_test.rb",
127
+ "test/lib/generators/shoulda/controller_generator_test.rb",
107
128
  "test/lib/generators/simple_form/scaffold_generators_test.rb",
108
129
  "test/test_helper.rb"
109
130
  ]
110
131
  s.homepage = %q{http://github.com/indirect/rails3-generators}
111
132
  s.post_install_message = %q{
112
- rails3-generators-0.9.2
133
+ rails3-generators-0.10.0
113
134
 
114
135
  Be sure to check out the wiki, http://wiki.github.com/indirect/rails3-generators/,
115
136
  for information about recent changes to this project.
@@ -140,6 +161,9 @@ g.template_engine :erubis
140
161
  "test/lib/generators/machinist/model_generator_test.rb",
141
162
  "test/lib/generators/mongomapper/model_generator_test.rb",
142
163
  "test/lib/generators/mongomapper/observer_generator_test.rb",
164
+ "test/lib/generators/mustache/controller_generator_test.rb",
165
+ "test/lib/generators/mustache/scaffold_generator_test.rb",
166
+ "test/lib/generators/shoulda/controller_generator_test.rb",
143
167
  "test/lib/generators/simple_form/scaffold_generators_test.rb",
144
168
  "test/test_helper.rb"
145
169
  ]
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class Mustache::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
4
+ destination File.join(Rails.root)
5
+ tests Rails::Generators::ControllerGenerator
6
+ arguments %w(Account foo bar --template-engine mustache)
7
+
8
+ setup :prepare_destination
9
+ setup :copy_routes
10
+
11
+ test "should generate mustache views" do
12
+ run_generator
13
+ assert_file "app/views/account/foo.rb"
14
+ assert_file "app/views/account/bar.rb"
15
+ end
16
+
17
+ test "should generate mustache views as classes with scoped names extending Mustache::Rails" do
18
+ run_generator
19
+ assert_file "app/views/account/foo.rb",
20
+ %r(class Account::Foo < Mustache::Rails)
21
+ assert_file "app/views/account/bar.rb",
22
+ %r(class Account::Bar < Mustache::Rails)
23
+ end
24
+
25
+ test "should generate mustache template files" do
26
+ run_generator
27
+ assert_file "app/templates/account/foo.html.mustache"
28
+ assert_file "app/templates/account/bar.html.mustache"
29
+ end
30
+
31
+ end
@@ -0,0 +1,202 @@
1
+ require 'test_helper'
2
+
3
+ class Mustache::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
4
+ destination File.join(Rails.root)
5
+ tests Rails::Generators::ScaffoldGenerator
6
+ arguments %w(product_line title:string price:integer --template-engine mustache)
7
+
8
+ setup :prepare_destination
9
+ setup :copy_routes
10
+
11
+ test "should generate mustache views for each action" do
12
+ run_generator
13
+ %w(index edit new show).each { |view| assert_file "app/views/product_lines/#{view}.rb" }
14
+ end
15
+
16
+ test "should generate a form partial mustache template" do
17
+ run_generator
18
+ assert_file "app/templates/product_lines/_form.html.mustache"
19
+ end
20
+
21
+ test "should generate mustache templates for each action" do
22
+ run_generator
23
+ %w(index edit new show).each { |view| assert_file "app/templates/product_lines/#{view}.html.mustache" }
24
+ end
25
+
26
+ ### SHOW
27
+
28
+ test "should place methods for each attribute in the show view" do
29
+ run_generator
30
+ assert_file "app/views/product_lines/show.rb",
31
+ %r(def title)
32
+ assert_file "app/views/product_lines/show.rb",
33
+ %r(def price)
34
+ end
35
+
36
+ test "should place methods for edit path and index path in the show view" do
37
+ run_generator
38
+ assert_file "app/views/product_lines/show.rb",
39
+ %r(def edit_path)
40
+ assert_file "app/views/product_lines/show.rb",
41
+ %r(def index_path)
42
+ end
43
+
44
+ test "should place attribute tags in the mustache template for show action" do
45
+ run_generator
46
+ assert_file "app/templates/product_lines/show.html.mustache",
47
+ %r({{title}})
48
+ assert_file "app/templates/product_lines/show.html.mustache",
49
+ %r({{price}})
50
+ end
51
+
52
+ test "should place tags for edit path and index path in the mustache template for show action" do
53
+ run_generator
54
+ assert_file "app/templates/product_lines/show.html.mustache",
55
+ %r({{edit_path}})
56
+ assert_file "app/templates/product_lines/show.html.mustache",
57
+ %r({{index_path}})
58
+ end
59
+
60
+ ### INDEX
61
+
62
+ test "should place methods for listing each item in the index view" do
63
+ run_generator
64
+ assert_file "app/views/product_lines/index.rb",
65
+ %r(def listing)
66
+ end
67
+
68
+ test "should place methods for new path in the index view" do
69
+ run_generator
70
+ assert_file "app/views/product_lines/index.rb",
71
+ %r(def new_path)
72
+ end
73
+
74
+ test "should place 'listing' loop tags in the mustache template for index action" do
75
+ run_generator
76
+ assert_file "app/templates/product_lines/index.html.mustache",
77
+ %r({{#listing}})
78
+ assert_file "app/templates/product_lines/index.html.mustache",
79
+ %r({{/listing}})
80
+ end
81
+
82
+ test "should place a tag for each attribute in the mustache template for index action" do
83
+ run_generator
84
+ assert_file "app/templates/product_lines/index.html.mustache",
85
+ %r({{title}})
86
+ assert_file "app/templates/product_lines/index.html.mustache",
87
+ %r({{price}})
88
+ end
89
+
90
+ test "should place a tag for the item's show link the mustache template for index action" do
91
+ run_generator
92
+ assert_file "app/templates/product_lines/index.html.mustache",
93
+ %r({{show_path}})
94
+ end
95
+
96
+ test "should place a tag for a new index link the mustache template for index action" do
97
+ run_generator
98
+ assert_file "app/templates/product_lines/index.html.mustache",
99
+ %r({{new_path}})
100
+ end
101
+
102
+
103
+ ### FORM partial
104
+
105
+ test "should place attribute tags in the mustache template for form partial" do
106
+ run_generator
107
+ assert_file "app/templates/product_lines/_form.html.mustache",
108
+ %r({{title_label}})
109
+ assert_file "app/templates/product_lines/_form.html.mustache",
110
+ %r({{title_text_field}})
111
+ assert_file "app/templates/product_lines/_form.html.mustache",
112
+ %r({{price_text_field}})
113
+ assert_file "app/templates/product_lines/_form.html.mustache",
114
+ %r({{price_label}})
115
+ end
116
+
117
+
118
+ ### NEW
119
+
120
+ test "should place a method that returns a form tag to create item" do
121
+ run_generator
122
+ assert_file "app/views/product_lines/new.rb",
123
+ %r(def product_line_form_tag\s*form_tag\(create_path,)
124
+ end
125
+
126
+ test "should place label and form input methods for each item attribute in the new view" do
127
+ run_generator
128
+ assert_file "app/views/product_lines/new.rb",
129
+ %r(def title_label)
130
+ assert_file "app/views/product_lines/new.rb",
131
+ %r(def title_text_field)
132
+ assert_file "app/views/product_lines/new.rb",
133
+ %r(def price_label)
134
+ assert_file "app/views/product_lines/new.rb",
135
+ %r(def price_text_field)
136
+ end
137
+
138
+ test "should place methods for create path and index path in the new view" do
139
+ run_generator
140
+ assert_file "app/views/product_lines/new.rb",
141
+ %r(def index_path)
142
+ assert_file "app/views/product_lines/new.rb",
143
+ %r(def create_path)
144
+ end
145
+
146
+
147
+ test "should place a new form tag in the mustache template for new action" do
148
+ run_generator
149
+ assert_file "app/templates/product_lines/new.html.mustache",
150
+ %r({{product_line_form_tag}})
151
+ end
152
+
153
+ test "should place tags for index path in the mustache template for new action" do
154
+ run_generator
155
+ assert_file "app/templates/product_lines/new.html.mustache",
156
+ %r({{index_path}})
157
+ end
158
+
159
+
160
+ ### EDIT
161
+
162
+ test "should place a method that returns a form tag to update item in the edit view" do
163
+ run_generator
164
+ assert_file "app/views/product_lines/edit.rb",
165
+ %r(def product_line_form_tag\s*form_tag\(update_path,)
166
+ end
167
+
168
+ test "should place label and form input methods for each item attribute in the edit view" do
169
+ run_generator
170
+ assert_file "app/views/product_lines/edit.rb",
171
+ %r(def title_label)
172
+ assert_file "app/views/product_lines/edit.rb",
173
+ %r(def title_text_field)
174
+ assert_file "app/views/product_lines/edit.rb",
175
+ %r(def price_label)
176
+ assert_file "app/views/product_lines/edit.rb",
177
+ %r(def price_text_field)
178
+ end
179
+
180
+ test "should place methods for update path and show path in the edit view" do
181
+ run_generator
182
+ assert_file "app/views/product_lines/edit.rb",
183
+ %r(def show_path)
184
+ assert_file "app/views/product_lines/edit.rb",
185
+ %r(def update_path)
186
+ end
187
+
188
+
189
+ test "should place a form tag in the mustache template for edit action" do
190
+ run_generator
191
+ assert_file "app/templates/product_lines/edit.html.mustache",
192
+ %r({{product_line_form_tag}})
193
+ end
194
+
195
+ test "should place tags for show path in the mustache template for edit action" do
196
+ run_generator
197
+ assert_file "app/templates/product_lines/edit.html.mustache",
198
+ %r({{show_path}})
199
+ end
200
+
201
+ end
202
+
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class Shoulda::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
4
+ destination File.join(Rails.root)
5
+ tests Rails::Generators::ControllerGenerator
6
+ arguments %w(accounts index show new create edit update destroy --test-framework shoulda)
7
+
8
+ setup :prepare_destination
9
+ setup :copy_routes
10
+
11
+ test "should invoke test framework" do
12
+ run_generator
13
+ assert_file "test/functional/accounts_controller_test.rb"
14
+ end
15
+
16
+ test "should create test class" do
17
+ run_generator
18
+ assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
19
+ assert_class "AccountsControllerTest", controller_test
20
+ end
21
+ end
22
+
23
+ test "should create controller action tests" do
24
+ run_generator
25
+ assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
26
+ assert_class "AccountsControllerTest", controller_test do |klass|
27
+ assert_match /context "index action"/, klass
28
+ assert_match /context "show action"/, klass
29
+ assert_match /context "new action"/, klass
30
+ assert_match /context "create action"/, klass
31
+ assert_match /context "edit action"/, klass
32
+ assert_match /context "update action"/, klass
33
+ assert_match /context "destroy action"/, klass
34
+ end
35
+ end
36
+ end
37
+ end
data/test/test_helper.rb CHANGED
@@ -29,9 +29,27 @@ def copy_routes
29
29
  FileUtils.cp File.expand_path(routes), destination
30
30
  end
31
31
 
32
+ # Asserts the given class exists in the given content. When a block is given,
33
+ # it yields the content of the class.
34
+ #
35
+ # assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
36
+ # assert_class "AccountsControllerTest", controller_test do |klass|
37
+ # assert_match /context "index action"/, klass
38
+ # end
39
+ # end
40
+ #
41
+ def assert_class(klass, content)
42
+ assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
43
+ yield $2.strip if block_given?
44
+ end
45
+
32
46
  require 'rails/generators/rails/scaffold/scaffold_generator'
33
47
  require 'rails/generators/rails/controller/controller_generator'
34
48
 
49
+ # require 'generators/mustache/install/install_generator'
50
+ require 'generators/mustache/scaffold/scaffold_generator'
51
+ require 'generators/mustache/controller/controller_generator'
52
+
35
53
  require 'generators/haml/install/install_generator'
36
54
  require 'generators/haml/scaffold/scaffold_generator'
37
55
  require 'generators/haml/controller/controller_generator'
@@ -55,3 +73,4 @@ require 'generators/jquery/install/install_generator'
55
73
 
56
74
  require 'generators/koala/install/install_generator'
57
75
 
76
+ require 'generators/shoulda/controller/controller_generator'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 9
8
- - 2
9
- version: 0.9.2
7
+ - 10
8
+ - 0
9
+ version: 0.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jose Valim
@@ -22,7 +22,7 @@ autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
24
 
25
- date: 2010-06-22 00:00:00 -04:00
25
+ date: 2010-07-02 00:00:00 -04:00
26
26
  default_executable:
27
27
  dependencies: []
28
28
 
@@ -95,6 +95,24 @@ files:
95
95
  - lib/generators/mongomapper/model/model_generator.rb
96
96
  - lib/generators/mongomapper/model/templates/model.rb
97
97
  - lib/generators/mongomapper/observer/observer_generator.rb
98
+ - lib/generators/mustache.rb
99
+ - lib/generators/mustache/README.md
100
+ - lib/generators/mustache/controller/controller_generator.rb
101
+ - lib/generators/mustache/controller/templates/view.html.mustache.erb
102
+ - lib/generators/mustache/controller/templates/view.rb.erb
103
+ - lib/generators/mustache/install/install_generator.rb
104
+ - lib/generators/mustache/install/templates/config/initializers/mustache.rb
105
+ - lib/generators/mustache/install/templates/lib/mustache_rails.rb
106
+ - lib/generators/mustache/scaffold/scaffold_generator.rb
107
+ - lib/generators/mustache/scaffold/templates/_form.html.mustache.erb
108
+ - lib/generators/mustache/scaffold/templates/edit.html.mustache.erb
109
+ - lib/generators/mustache/scaffold/templates/edit.rb.erb
110
+ - lib/generators/mustache/scaffold/templates/index.html.mustache.erb
111
+ - lib/generators/mustache/scaffold/templates/index.rb.erb
112
+ - lib/generators/mustache/scaffold/templates/new.html.mustache.erb
113
+ - lib/generators/mustache/scaffold/templates/new.rb.erb
114
+ - lib/generators/mustache/scaffold/templates/show.html.mustache.erb
115
+ - lib/generators/mustache/scaffold/templates/show.rb.erb
98
116
  - lib/generators/shoulda.rb
99
117
  - lib/generators/shoulda/controller/controller_generator.rb
100
118
  - lib/generators/shoulda/controller/templates/controller.rb
@@ -123,6 +141,9 @@ files:
123
141
  - test/lib/generators/machinist/model_generator_test.rb
124
142
  - test/lib/generators/mongomapper/model_generator_test.rb
125
143
  - test/lib/generators/mongomapper/observer_generator_test.rb
144
+ - test/lib/generators/mustache/controller_generator_test.rb
145
+ - test/lib/generators/mustache/scaffold_generator_test.rb
146
+ - test/lib/generators/shoulda/controller_generator_test.rb
126
147
  - test/lib/generators/simple_form/scaffold_generators_test.rb
127
148
  - test/test_helper.rb
128
149
  has_rdoc: true
@@ -130,7 +151,7 @@ homepage: http://github.com/indirect/rails3-generators
130
151
  licenses: []
131
152
 
132
153
  post_install_message: "\n\
133
- rails3-generators-0.9.2\n\n\
154
+ rails3-generators-0.10.0\n\n\
134
155
  Be sure to check out the wiki, http://wiki.github.com/indirect/rails3-generators/,\n\
135
156
  for information about recent changes to this project.\n\n\
136
157
  note: if you use erb templates add the follow to your generators block to take full advantage of this gem.\n\
@@ -180,5 +201,8 @@ test_files:
180
201
  - test/lib/generators/machinist/model_generator_test.rb
181
202
  - test/lib/generators/mongomapper/model_generator_test.rb
182
203
  - test/lib/generators/mongomapper/observer_generator_test.rb
204
+ - test/lib/generators/mustache/controller_generator_test.rb
205
+ - test/lib/generators/mustache/scaffold_generator_test.rb
206
+ - test/lib/generators/shoulda/controller_generator_test.rb
183
207
  - test/lib/generators/simple_form/scaffold_generators_test.rb
184
208
  - test/test_helper.rb