Permalink
Browse files

add scaffold generator for haml / copy templates

  • Loading branch information...
1 parent ef1541c commit bfd85de5db2a5ad5e1d947959ea9bfe12a4c24d6 @labocho committed Dec 21, 2012
View
@@ -0,0 +1,4 @@
+---
+:include: ^(Rakefile|Gemfile|Capfile|Guardfile|config\.ru|.*\.(rb|erb|haml|yml|js|coffee|css|scss))$
+:exclude: ^(vendor/|public/|.*\.(eml)$)
+:force: false
View
@@ -104,6 +104,13 @@ def application_multiline(data, options = {})
EOS
# ====================
+# template
+# ====================
+
+rake "rails:templates:copy"
+directory(template_path + "generators", "lib/generators")
+
+# ====================
# git
# ====================
@@ -0,0 +1,8 @@
+Description:
+ Explain the generator
+
+Example:
+ rails generate scaffold Thing
+
+ This will create:
+ what/will/it/create
@@ -0,0 +1,10 @@
+require "rails/generators/erb/scaffold/scaffold_generator"
+
+class Haml::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
+ source_root File.expand_path('../templates', __FILE__)
+
+ protected
+ def handler
+ :haml
+ end
+end
@@ -0,0 +1,20 @@
+= form_for(@<%= singular_table_name %>, html: {class: "form-horizontal"}) do |f|
+ - if @<%= singular_table_name %>.errors.any?
+ %ul.alert.alert-error.validation-errors
+ - @<%= singular_table_name %>.errors.full_messages.each do |message|
+ %li= message
+
+ <%- attributes.each do |attribute| -%>
+ .control-group
+ = f.label :<%= attribute.name %>, class: "control-label"
+ .controls
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
+ <%- end -%>
+ .control-group
+ .controls
+ = f.submit class: "btn btn-primary"
+ - if @<%= singular_table_name %>.new_record?
+ %a.btn{href: <%= index_helper %>_path} Cancel
+ - else
+ %a.btn{href: <%= singular_table_name %>_path} Cancel
+
@@ -0,0 +1,3 @@
+%h1 Editing <%= singular_table_name %>
+
+= render 'form'
@@ -0,0 +1,20 @@
+%h1
+ = <%= singular_table_name.capitalize %>.model_name.human
+ .btn-group.pull-right
+ %a.btn{href: new_<%= singular_table_name %>_path} Add
+
+%table.table.table-bordered.table-striped
+ %thead
+ %tr
+ %th= <%= singular_table_name.capitalize %>.human_attribute_name :id
+ <%- attributes.each do |attribute| -%>
+ %th= <%= singular_table_name.capitalize %>.human_attribute_name :<%= attribute.name %>
+ <%- end -%>
+ %tbody
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
+ %tr
+ %td
+ %a{href: <%= singular_table_name %>_path(<%= singular_table_name %>)}= "##{<%= singular_table_name %>.id}"
+ <%- attributes.each do |attribute| -%>
+ %td= <%= singular_table_name %>.<%= attribute.name %>
+ <%- end -%>
@@ -0,0 +1,3 @@
+%h1 New <%= singular_table_name %>
+
+= render 'form'
@@ -0,0 +1,9 @@
+<%- attributes.each do |attribute| -%>
+%dl
+ %dt= <%= singular_table_name.capitalize %>.human_attribute_name :<%= attribute.name %>
+ %dd= @<%= singular_table_name %>.<%= attribute.name %>
+<%- end -%>
+
+%a.btn{href: edit_<%= singular_table_name %>_path} Edit
+%a.btn.btn-danger{href: <%= singular_table_name %>_path(@<%= singular_table_name %>), "data-method" => "delete", "data-confirm" => "Are you sure?"} Delete
+%a.btn{href: <%= index_helper %>_path} Back

0 comments on commit bfd85de

Please sign in to comment.