From 80cd16372ce1776e5d6af87b2dc7be8205fa1513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 1 Jul 2009 18:33:22 +0200 Subject: Added scaffold views to scaffold controller. --- .../generators/erb/scaffold/scaffold_generator.rb | 42 ++++++++++++++++++++++ .../erb/scaffold/templates/edit.html.erb | 18 ++++++++++ .../erb/scaffold/templates/index.html.erb | 24 +++++++++++++ .../erb/scaffold/templates/layout.html.erb | 17 +++++++++ .../generators/erb/scaffold/templates/new.html.erb | 17 +++++++++ .../erb/scaffold/templates/show.html.erb | 10 ++++++ 6 files changed, 128 insertions(+) create mode 100644 railties/lib/generators/erb/scaffold/scaffold_generator.rb create mode 100644 railties/lib/generators/erb/scaffold/templates/edit.html.erb create mode 100644 railties/lib/generators/erb/scaffold/templates/index.html.erb create mode 100644 railties/lib/generators/erb/scaffold/templates/layout.html.erb create mode 100644 railties/lib/generators/erb/scaffold/templates/new.html.erb create mode 100644 railties/lib/generators/erb/scaffold/templates/show.html.erb (limited to 'railties/lib/generators/erb') diff --git a/railties/lib/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/generators/erb/scaffold/scaffold_generator.rb new file mode 100644 index 0000000000..c89af042b7 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/scaffold_generator.rb @@ -0,0 +1,42 @@ +require 'generators/erb' + +module Erb + module Generators + class ScaffoldGenerator < Base + include Rails::Generators::ControllerNamedBase + + argument :attributes, :type => :hash, :default => {}, :banner => "field:type field:type" + class_option :singleton, :type => :boolean, :desc => "Supply to skip index action" + + # TODO Spec me + def copy_index_file + return if options[:singleton] + copy_view :index + end + + def copy_edit_file + copy_view :edit + end + + def copy_show_file + copy_view :show + end + + def copy_new_file + copy_view :new + end + + # TODO invoke_if? + def copy_layout_file + template "layout.html.erb", File.join("app", "views", "layouts", controller_class_path, "#{controller_file_name}.html.erb") + end + + protected + + def copy_view(view) + template "#{view}.html.erb", File.join("app", "views", controller_file_path, "#{view}.html.erb") + end + + end + end +end diff --git a/railties/lib/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/generators/erb/scaffold/templates/edit.html.erb new file mode 100644 index 0000000000..cca1d61c68 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/edit.html.erb @@ -0,0 +1,18 @@ +

Editing <%= singular_name %>

+ +<%% form_for(@<%= singular_name %>) do |f| %> + <%%= f.error_messages %> + +<% for attribute in attributes -%> +

+ <%%= f.label :<%= attribute.name %> %>
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> +

+<% end -%> +

+ <%%= f.submit 'Update' %> +

+<%% end %> + +<%%= link_to 'Show', @<%= singular_name %> %> | +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file diff --git a/railties/lib/generators/erb/scaffold/templates/index.html.erb b/railties/lib/generators/erb/scaffold/templates/index.html.erb new file mode 100644 index 0000000000..427ff81e03 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/index.html.erb @@ -0,0 +1,24 @@ +

Listing <%= plural_name %>

+ + + +<% for attribute in attributes -%> + +<% end -%> + + +<%% @<%= plural_name %>.each do |<%= singular_name %>| %> + +<% for attribute in attributes -%> + +<% end -%> + + + + +<%% end %> +
<%= attribute.human_name %>
<%%=h <%= singular_name %>.<%= attribute.name %> %><%%= link_to 'Show', <%= singular_name %> %><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %> diff --git a/railties/lib/generators/erb/scaffold/templates/layout.html.erb b/railties/lib/generators/erb/scaffold/templates/layout.html.erb new file mode 100644 index 0000000000..ebc97f8130 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/layout.html.erb @@ -0,0 +1,17 @@ + + + + + + <%= controller_class_name %>: <%%= controller.action_name %> + <%%= stylesheet_link_tag 'scaffold' %> + + + +

<%%= flash[:notice] %>

+ +<%%= yield %> + + + diff --git a/railties/lib/generators/erb/scaffold/templates/new.html.erb b/railties/lib/generators/erb/scaffold/templates/new.html.erb new file mode 100644 index 0000000000..96c89fc50e --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/new.html.erb @@ -0,0 +1,17 @@ +

New <%= singular_name %>

+ +<%% form_for(@<%= singular_name %>) do |f| %> + <%%= f.error_messages %> + +<% for attribute in attributes -%> +

+ <%%= f.label :<%= attribute.name %> %>
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> +

+<% end -%> +

+ <%%= f.submit 'Create' %> +

+<%% end %> + +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file diff --git a/railties/lib/generators/erb/scaffold/templates/show.html.erb b/railties/lib/generators/erb/scaffold/templates/show.html.erb new file mode 100644 index 0000000000..adecaf70c6 --- /dev/null +++ b/railties/lib/generators/erb/scaffold/templates/show.html.erb @@ -0,0 +1,10 @@ +<% for attribute in attributes -%> +

+ <%= attribute.column.human_name %>: + <%%=h @<%= singular_name %>.<%= attribute.name %> %> +

+ +<% end -%> + +<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> | +<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file -- cgit v1.2.3