Skip to content
Browse files

Merged in HAML generators.

This adds --template-engine option to generator
and HAML templates.

Squashed commit of the following:

commit 0fb870a
Author: Jonas Nicklas <jonas.nicklas@gmail.com>
Date:   Sat Aug 9 15:14:17 2008 +0200

    added haml templates for layout, resource_controller and controller generators (thanks jonuts)

commit eeecf5f
Author: Jonas Nicklas <jonas.nicklas@gmail.com>
Date:   Sat Aug 9 14:30:16 2008 +0200

    made erb template engine explicit for controller generator
  • Loading branch information...
1 parent 0232f1c commit e9f309ede5289fc80b6ac04e28cd8727f1a63677 @michaelklishin michaelklishin committed Aug 9, 2008
Showing with 182 additions and 1 deletion.
  1. +2 −1 merb-gen/lib/generators/controller.rb
  2. +4 −0 merb-haml/lib/generators/controller.rb
  3. +4 −0 merb-haml/lib/generators/layout.rb
  4. +12 −0 merb-haml/lib/generators/resource_controller.rb
  5. +1 −0 merb-haml/lib/generators/templates/controller/app/views/%file_name%/index.html.haml
  6. +9 −0 merb-haml/lib/generators/templates/layout/app/views/layout/%file_name%.html.haml
  7. +5 −0 ...ml/lib/generators/templates/resource_controller/activerecord/app/views/%file_name%/edit.html.haml
  8. +5 −0 ...l/lib/generators/templates/resource_controller/activerecord/app/views/%file_name%/index.html.haml
  9. +5 −0 ...aml/lib/generators/templates/resource_controller/activerecord/app/views/%file_name%/new.html.haml
  10. +5 −0 ...ml/lib/generators/templates/resource_controller/activerecord/app/views/%file_name%/show.html.haml
  11. +22 −0 ...haml/lib/generators/templates/resource_controller/datamapper/app/views/%file_name%/edit.html.haml
  12. +26 −0 ...aml/lib/generators/templates/resource_controller/datamapper/app/views/%file_name%/index.html.haml
  13. +20 −0 ...-haml/lib/generators/templates/resource_controller/datamapper/app/views/%file_name%/new.html.haml
  14. +16 −0 ...haml/lib/generators/templates/resource_controller/datamapper/app/views/%file_name%/show.html.haml
  15. +5 −0 merb-haml/lib/generators/templates/resource_controller/none/app/views/%file_name%/edit.html.haml
  16. +5 −0 merb-haml/lib/generators/templates/resource_controller/none/app/views/%file_name%/index.html.haml
  17. +5 −0 merb-haml/lib/generators/templates/resource_controller/none/app/views/%file_name%/new.html.haml
  18. +5 −0 merb-haml/lib/generators/templates/resource_controller/none/app/views/%file_name%/show.html.haml
  19. +5 −0 merb-haml/lib/generators/templates/resource_controller/sequel/app/views/%file_name%/edit.html.haml
  20. +5 −0 merb-haml/lib/generators/templates/resource_controller/sequel/app/views/%file_name%/index.html.haml
  21. +5 −0 merb-haml/lib/generators/templates/resource_controller/sequel/app/views/%file_name%/new.html.haml
  22. +5 −0 merb-haml/lib/generators/templates/resource_controller/sequel/app/views/%file_name%/show.html.haml
  23. +6 −0 merb-haml/lib/merb-haml.rb
View
3 merb-gen/lib/generators/controller.rb
@@ -11,6 +11,7 @@ def self.source_root
DESC
option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
+ option :template_engine, :default => :erb, :desc => 'Template engine to use (one of: erb, haml, markaby, etc...)'
first_argument :name, :required => true, :desc => "controller name"
@@ -21,7 +22,7 @@ def self.source_root
destination("app/controllers", base_path, "#{file_name}.rb")
end
- template :index do
+ template :index_erb, :template_engine => :erb do
source('app/views/%file_name%/index.html.erb')
destination("app/views", base_path, "#{file_name}/index.html.erb")
end
View
4 merb-haml/lib/generators/controller.rb
@@ -0,0 +1,4 @@
+Merb::Generators::ControllerGenerator.template :index_haml, :template_engine => :haml do
+ source(File.dirname(__FILE__), 'templates/controller/app/views/%file_name%/index.html.haml')
+ destination("app/views", base_path, "#{file_name}/index.html.haml")
+end
View
4 merb-haml/lib/generators/layout.rb
@@ -0,0 +1,4 @@
+Merb::Generators::LayoutGenerator.template :layout_haml, :template_engine => :haml do
+ source(File.dirname(__FILE__), 'templates/layout/app/views/layout/%file_name%.html.haml')
+ destination("app/views/layout/#{file_name}.html.haml")
+end
View
12 merb-haml/lib/generators/resource_controller.rb
@@ -0,0 +1,12 @@
+[:activerecord, :datamapper, :sequel, :none].each do |orm|
+
+ [:show, :index, :edit, :new].each do |view|
+
+ Merb::Generators::ResourceControllerGenerator.template "view_#{view}_haml", :orm => orm, :template_engine => :haml do
+ source(File.dirname(__FILE__), "templates/resource_controller/#{orm}/app/views/%file_name%/#{view}.html.haml")
+ destination("app/views", base_path, "#{file_name}/#{view}.html.haml")
+ end
+
+ end
+
+end
View
1 merb-haml/lib/generators/templates/controller/app/views/%file_name%/index.html.haml
@@ -0,0 +1 @@
+You're in index of the <%= class_name %> controller.
View
9 merb-haml/lib/generators/templates/layout/app/views/layout/%file_name%.html.haml
@@ -0,0 +1,9 @@
+!!! Strict
+%html{ html_attrs("en_us") }
+ %head
+ %title
+ Fresh Merb App
+ %meta{ :content => "text/html; charset=utf-8", "http-equiv" => "content-type" }/
+ %link{ :href => "/stylesheets/master.css", :rel => "stylesheet", :media => "screen", :type => "text/css", :charset => "utf-8" }/
+ %body
+ = catch_content :for_layout
View
5 ...enerators/templates/resource_controller/activerecord/app/views/%file_name%/edit.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, edit action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/edit.html.haml
View
5 ...nerators/templates/resource_controller/activerecord/app/views/%file_name%/index.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, index action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/index.html.haml
View
5 ...generators/templates/resource_controller/activerecord/app/views/%file_name%/new.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, new action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/new.html.haml
View
5 ...enerators/templates/resource_controller/activerecord/app/views/%file_name%/show.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, show action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/show.html.haml
View
22 .../generators/templates/resource_controller/datamapper/app/views/%file_name%/edit.html.haml
@@ -0,0 +1,22 @@
+%h1
+ <%= class_name %> controller, edit action
+%p
+ Edit this file in
+ %tt
+ app/views/<%= file_name %>/edit.html.erb
+= error_messages_for :<%= singular_model %>
+
+- form_for(@<%= singular_model %>, :action => url(:<%= singular_model %>, @<%= singular_model %>)) do
+<% for property in properties.select{|p| !p.key?} -%>
+ %p
+ %b
+ <%= DataMapper::Inflection.humanize(property.field) %>
+ %br/
+ = <%= field_from_type(property.type) %> :<%= property.getter %>
+<% end -%>
+ %p
+ = submit_button "Update"
+
+= link_to 'Show', url(:<%= singular_model %>, @<%= singular_model %>)
+|
+= link_to 'Back', url(:<%= plural_model %>)
View
26 ...generators/templates/resource_controller/datamapper/app/views/%file_name%/index.html.haml
@@ -0,0 +1,26 @@
+%h1
+ <%= class_name %> controller, index action
+%p
+ Edit this file in
+ %tt
+ app/views/<%= file_name %>/index.html.erb
+%table
+ %tr
+<% for property in properties.reject{|p| p.lazy?} -%>
+ %th
+ <%= DataMapper::Inflection.humanize(property.field) %>
+<% end -%>
+ - for <%= singular_model %> in @<%= plural_model %>
+ %tr
+<% for property in properties.reject{|p| p.lazy?} -%>
+ %td
+ =h <%= singular_model %>.<%= property.getter %>
+<% end -%>
+ %td
+ = link_to 'Show', url(:<%= singular_model %>, <%= singular_model %>)
+ %td
+ = link_to 'Edit', url(:edit_<%= singular_model %>, <%= singular_model %>)
+ %td
+ = delete_button :<%= singular_model %>, <%= singular_model %>
+
+= link_to 'New', url(:new_<%= singular_model %>)
View
20 ...b/generators/templates/resource_controller/datamapper/app/views/%file_name%/new.html.haml
@@ -0,0 +1,20 @@
+%h1 <%= class_name %> controller, new action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/new.html.erb
+
+= error_messages_for :<%= singular_model %>
+
+- form_for(@<%= singular_model %>, :action => url(:<%= plural_model %>) ) do |f|
+<% for property in properties.select{|p| !p.key?} -%>
+ %p
+ %b
+ <%= DataMapper::Inflection.humanize(property.field) %></b>
+ = <%= field_from_type(property.type) %> :<%= property.getter %>
+
+<% end -%>
+ %p
+ = submit_button "Create"
+
+= link_to 'Back', url(:<%= plural_model %>)
View
16 .../generators/templates/resource_controller/datamapper/app/views/%file_name%/show.html.haml
@@ -0,0 +1,16 @@
+%h1
+ <%= class_name %> controller, show action
+%p
+ Edit this file in
+ %tt
+ app/views/<%= file_name %>/show.html.erb
+<% for property in properties -%>
+%p
+ %b
+ <%= DataMapper::Inflection.humanize(property.field) %>:
+ =h @<%= singular_model %>.<%= property.getter %>
+<% end -%>
+
+= link_to 'Edit', url(:edit_<%= singular_model %>, @<%= singular_model %>)
+|
+= link_to 'Back', url(:<%= plural_model %>)
View
5 ...ml/lib/generators/templates/resource_controller/none/app/views/%file_name%/edit.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, edit action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/edit.html.haml
View
5 ...l/lib/generators/templates/resource_controller/none/app/views/%file_name%/index.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, index action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/index.html.haml
View
5 ...aml/lib/generators/templates/resource_controller/none/app/views/%file_name%/new.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, new action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/new.html.haml
View
5 ...ml/lib/generators/templates/resource_controller/none/app/views/%file_name%/show.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, show action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/show.html.haml
View
5 .../lib/generators/templates/resource_controller/sequel/app/views/%file_name%/edit.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, edit action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/edit.html.haml
View
5 ...lib/generators/templates/resource_controller/sequel/app/views/%file_name%/index.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, index action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/index.html.haml
View
5 ...l/lib/generators/templates/resource_controller/sequel/app/views/%file_name%/new.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, new action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/new.html.haml
View
5 .../lib/generators/templates/resource_controller/sequel/app/views/%file_name%/show.html.haml
@@ -0,0 +1,5 @@
+%h1 <%= class_name %> controller, show action
+
+%p
+ Edit this file in
+ %tt app/views/<%= file_name %>/show.html.haml
View
6 merb-haml/lib/merb-haml.rb
@@ -17,4 +17,10 @@ def symbolize_keys!
self
end
end
+
+ generators = File.join(File.dirname(__FILE__), 'generators')
+ Merb.add_generators generators / "resource_controller"
+ Merb.add_generators generators / "controller"
+ Merb.add_generators generators / "layout"
+
end

0 comments on commit e9f309e

Please sign in to comment.
Something went wrong with that request. Please try again.