Hi! I cleaned up your code for you! #8

Open
wants to merge 1 commit into from
View
20 .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
View
2 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
View
18 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
View
2 lib/generators/mustache/controller/templates/view.rb.erb
@@ -1,3 +1,3 @@
class <%= singular_name.camelize %>::<%= @action.camelize %> < Mustache::Rails
-
+
end
View
8 lib/generators/mustache/install/templates/lib/mustache_rails.rb
@@ -77,23 +77,23 @@ 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
mustache[:yield] = content_for(:layout)
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
View
20 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
View
22 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
View
4 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
View
18 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
View
8 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
View
8 lib/mustache_rails.rb
@@ -77,23 +77,23 @@ 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
mustache[:yield] = content_for(:layout)
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