diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8f968 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Logs and databases # +###################### +*.log + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db diff --git a/LICENSE b/LICENSE index 2aad52f..7a95ba3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License Copyright (c) 2010 Michael Harrison mh@michaelharrison.ws - Paul Barry + Paul Barry Martin Gamsjaeger Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/lib/generators/mustache/controller/controller_generator.rb b/lib/generators/mustache/controller/controller_generator.rb index 7b46c61..8751a6a 100644 --- a/lib/generators/mustache/controller/controller_generator.rb +++ b/lib/generators/mustache/controller/controller_generator.rb @@ -5,34 +5,34 @@ class Mustache module Generators class ControllerGenerator < ::Rails::Generators::NamedBase extend TemplatePath - + argument :actions, :type => :array, :default => [], :banner => "action action" def create_view_files model_path = File.join(class_path, file_name) - + base_mustache_view_path = File.join("app/views", model_path) empty_directory base_mustache_view_path - + base_mustache_template_path = File.join("app/templates", model_path) empty_directory base_mustache_template_path - + actions.each do |action| @action = action mustache_view_path = File.join(base_mustache_view_path, "#{action}.rb") mustache_template_path = File.join(base_mustache_template_path, "#{action}.html.mustache") - + template "view.rb.erb", mustache_view_path - template "view.html.mustache.erb", mustache_template_path + template "view.html.mustache.erb", mustache_template_path end end - + protected - + # Methods not to be executed go here - + end end end \ No newline at end of file diff --git a/lib/generators/mustache/controller/templates/view.rb.erb b/lib/generators/mustache/controller/templates/view.rb.erb index 1a4287c..880cfbe 100644 --- a/lib/generators/mustache/controller/templates/view.rb.erb +++ b/lib/generators/mustache/controller/templates/view.rb.erb @@ -1,3 +1,3 @@ class <%= singular_name.camelize %>::<%= @action.camelize %> < Mustache::Rails - + end \ No newline at end of file diff --git a/lib/generators/mustache/install/templates/lib/mustache_rails.rb b/lib/generators/mustache/install/templates/lib/mustache_rails.rb index c7e906d..a6d403b 100644 --- a/lib/generators/mustache/install/templates/lib/mustache_rails.rb +++ b/lib/generators/mustache/install/templates/lib/mustache_rails.rb @@ -77,7 +77,7 @@ class TemplateHandler < ActionView::Template::Handler def compile(template) mustache_class = mustache_class_from_template(template) mustache_class.template_file = mustache_template_file(template) - + <<-MUSTACHE mustache = ::#{mustache_class}.new mustache.view = self @@ -85,15 +85,15 @@ def compile(template) mustache.context.update(local_assigns) variables = controller.instance_variable_names variables -= %w[@template] - + if controller.respond_to?(:protected_instance_variables) variables -= controller.protected_instance_variables end - + variables.each do |name| mustache.instance_variable_set(name, controller.instance_variable_get(name)) end - + # Declaring an +attr_reader+ for each instance variable in the # Mustache::Rails subclass makes them available to your templates. mustache.class.class_eval do diff --git a/lib/generators/mustache/scaffold/scaffold_generator.rb b/lib/generators/mustache/scaffold/scaffold_generator.rb index 54cec04..d7aa6d0 100644 --- a/lib/generators/mustache/scaffold/scaffold_generator.rb +++ b/lib/generators/mustache/scaffold/scaffold_generator.rb @@ -13,22 +13,22 @@ def copy_view_files views = available_views views.delete("index") if options[:singleton] - views.each do |view| - template "#{view}.rb.erb", + views.each do |view| + template "#{view}.rb.erb", File.join("app/views", controller_file_path, "#{view}.rb") - template "#{view}.html.mustache.erb", - File.join("app/templates", - controller_file_path, + template "#{view}.html.mustache.erb", + File.join("app/templates", + controller_file_path, "#{view}.html.mustache") end - template "_form.html.mustache.erb", - File.join("app/templates", - controller_file_path, + template "_form.html.mustache.erb", + File.join("app/templates", + controller_file_path, "_form.html.mustache") end - + private - + def available_views %w(index edit show new) end diff --git a/lib/generators/mustache/scaffold/templates/edit.rb.erb b/lib/generators/mustache/scaffold/templates/edit.rb.erb index 4b7ae93..fd7a50c 100644 --- a/lib/generators/mustache/scaffold/templates/edit.rb.erb +++ b/lib/generators/mustache/scaffold/templates/edit.rb.erb @@ -4,24 +4,24 @@ class <%= plural_name.camelize %>::Edit < Mustache::Rails def errors_display_div return "" unless <%= singular_name %>.errors.any? content_tag("div", :id=>"errorExplanation", :class=>"errorExplanation") do - content_tag("h2", error_header) + content_tag("ul") do + content_tag("h2", error_header) + content_tag("ul") do <%= singular_name %>.errors.full_messages.inject("") do |memo,msg| memo += content_tag("li", msg) end end end end - + def <%= singular_name %>_form_tag form_tag(update_path, :class => "<%= singular_name %>_form", :method => :put, :id => "edit_<%= singular_name %>_#{<%= singular_name %>.id}_form") end - + <% for attribute in attributes -%> def <%= attribute.name %>_label label :<%= singular_name %>, :<%= attribute.name %> end <%# TODO: Different fields for different attribute types -%> - + def <%= attribute.name %>_text_field text_field(:<%= singular_name %>, :<%= attribute.name %>, :id => "<%= attribute.name %>_text_field") end @@ -31,23 +31,23 @@ def <%= attribute.name %>_text_field def form_submit submit_tag "Update" end - + def show_path <%= singular_name %>_path(<%= singular_name %>) - end - + end + def index_path <%= plural_name %>_path end - + private - + def update_path <%= singular_name %>_path(<%= singular_name %>) end - + def error_header "u r dong it rong" end - + end \ No newline at end of file diff --git a/lib/generators/mustache/scaffold/templates/index.rb.erb b/lib/generators/mustache/scaffold/templates/index.rb.erb index 69bb380..a7cb4ce 100644 --- a/lib/generators/mustache/scaffold/templates/index.rb.erb +++ b/lib/generators/mustache/scaffold/templates/index.rb.erb @@ -3,7 +3,7 @@ class <%= plural_name.camelize %>::Index < Mustache::Rails def new_path new_<%= singular_name %>_path() end - + def listing <%= plural_name %>.collect do |record| { @@ -14,5 +14,5 @@ class <%= plural_name.camelize %>::Index < Mustache::Rails } end end - + end \ No newline at end of file diff --git a/lib/generators/mustache/scaffold/templates/new.rb.erb b/lib/generators/mustache/scaffold/templates/new.rb.erb index ed5e494..fa46118 100644 --- a/lib/generators/mustache/scaffold/templates/new.rb.erb +++ b/lib/generators/mustache/scaffold/templates/new.rb.erb @@ -4,24 +4,24 @@ class <%= plural_name.camelize %>::New < Mustache::Rails def errors_display_div return "" unless <%= singular_name %>.errors.any? content_tag("div", :id=>"errorExplanation", :class=>"errorExplanation") do - content_tag("h2", error_header) + content_tag("ul") do + content_tag("h2", error_header) + content_tag("ul") do <%= singular_name %>.errors.full_messages.inject("") do |memo,msg| memo += content_tag("li", msg) end end end end - + def <%= singular_name %>_form_tag form_tag(create_path, :class => "<%= singular_name %>_form", :id => "edit_<%= singular_name %>_#{<%= singular_name %>.id}_form") end - + <% for attribute in attributes -%> def <%= attribute.name %>_label label :<%= singular_name %>, :<%= attribute.name %> end <%# TODO: Different fields for different attribute types -%> - + def <%= attribute.name %>_text_field text_field(:<%= singular_name %>, :<%= attribute.name %>, :id => "<%= attribute.name %>_text_field") end @@ -32,19 +32,19 @@ def <%= attribute.name %>_text_field submit_tag "Create" end - + def index_path <%= plural_name %>_path end - + private - + def create_path <%= plural_name %>_path end - + def error_header "u r dong it rong" end - + end \ No newline at end of file diff --git a/lib/generators/mustache/scaffold/templates/show.rb.erb b/lib/generators/mustache/scaffold/templates/show.rb.erb index 8db0ddd..43bedae 100644 --- a/lib/generators/mustache/scaffold/templates/show.rb.erb +++ b/lib/generators/mustache/scaffold/templates/show.rb.erb @@ -1,18 +1,18 @@ class <%= plural_name.camelize %>::Show < Mustache::Rails - + <% for attribute in attributes -%> def <%= attribute.name %> <%= singular_name %>.<%= attribute.name %> end - + <% end -%> def edit_path edit_<%= singular_name %>_path(@<%= singular_name %>) end - + def index_path <%= plural_name %>_path end - + end \ No newline at end of file diff --git a/lib/mustache_rails.rb b/lib/mustache_rails.rb index 8be4a9d..620bedf 100644 --- a/lib/mustache_rails.rb +++ b/lib/mustache_rails.rb @@ -77,7 +77,7 @@ class TemplateHandler < ActionView::Template::Handler def compile(template) mustache_class = mustache_class_from_template(template) mustache_class.template_file = mustache_template_file(template) - + <<-MUSTACHE mustache = ::#{mustache_class}.new mustache.view = self @@ -85,15 +85,15 @@ def compile(template) mustache.context.update(local_assigns) variables = controller.instance_variable_names variables -= %w[@template] - + if controller.respond_to?(:protected_instance_variables) variables -= controller.protected_instance_variables end - + variables.each do |name| mustache.instance_variable_set(name, controller.instance_variable_get(name)) end - + # Declaring an +attr_reader+ for each instance variable in the # Mustache::Rails subclass makes them available to your templates. mustache.class.class_eval do