Permalink
Browse files

Added git files

  • Loading branch information...
A.K.M. Ashrafuzzaman
A.K.M. Ashrafuzzaman committed May 11, 2012
1 parent 7fee908 commit 9f7ad5e0f2f90c892d22faf3877df209b2464499
@@ -4,23 +4,60 @@ class NestedScaffoldGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
attr_accessor :pr, :r
def initialize(args, *options) #:nodoc:
super(args, *options)
parse_reources!
end
def copy_view_files
r_name, pr_name = file_name.split('/')
self.r, self.pr = Resource.new(r_name), Resource.new(pr_name)
available_views.each do |view|
filename = "#{view}.html.erb"
template "erb/#{filename}", File.join("app/views", r.plural_table_name, filename)
end
end
private
protected
def available_views
%w(show)
%w(index show new edit _form)
end
def parse_reources!
r_name = file_name.split(':')[0]
pr_name = file_name.split(':')[1]
@r ||= Resource.new(r_name)
@pr ||= Resource.new(pr_name)
#puts "R #{r_name}"
#puts "PR #{pr_name}"
end
def r
@r
end
def pr
@pr
end
def index_helper_path
uncountable? ? "#{pr_singular_r_plural}_index_path(@#{pr.singular_table_name}})" : "#{pr_singular_r_plural}_path(@#{pr.singular_table_name}})"
end
def edit_link_path
"edit_#{singular_path}"
end
def singular_path
"#{pr_singular_r_singular}_path"
end
def pr_singular_r_singular
"#{pr.singular_table_name}_#{r.singular_table_name}"
end
def pr_singular_r_plural
"#{pr.singular_table_name}_#{r.plural_table_name}"
end
end
unless Kernel.respond_to?(:require_relative)
@@ -1,18 +1,18 @@
<%%= form_for(@<%= singular_table_name %>) do |f| %>
<%% if @<%= singular_table_name %>.errors.any? %>
<%%= form_for [@<%= pr.singular_table_name %>, @<%= r.singular_table_name %>] do |f| %>
<%% if @<%= r.singular_table_name %>.errors.any? %>
<div id="error_explanation">
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
<h2><%%= pluralize(@<%= r.singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
<ul>
<%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
<%% @<%= r.singular_table_name %>.errors.full_messages.each do |msg| %>
<li><%%= msg %></li>
<%% end %>
</ul>
</div>
<%% end %>
<fieldset>
<legend><%%= <%= singular_table_name %>_form_title(@<%= singular_table_name %>) %></legend>
<legend><%%= <%= r.singular_table_name %>_form_title(@<%= r.singular_table_name %>) %></legend>
<ul>
<% attributes.each do |attribute| -%>
<li>
@@ -1,4 +1,4 @@
<%%= render 'form' %>
<%%= link_to 'Show', @<%= singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
<%%= link_to 'Show', @<%= r.singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper_path %> %>
@@ -1,4 +1,4 @@
<h1>Listing <%= plural_table_name %></h1>
<h1>Listing <%= r.plural_table_name %></h1>
<table>
<thead>
@@ -13,12 +13,12 @@
</thead>
<tbody>
<%%= content_tag_for(:tr, @<%= plural_table_name %>) do |<%= singular_table_name %>| %>
<%%= content_tag_for(:tr, @<%= r.plural_table_name %>) do |<%= r.singular_table_name %>| %>
<% attributes.each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<td><%%= <%= r.singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
<td><%%= link_to 'Show', <%= singular_path %>(@<%= pr.singular_table_name %>) %></td>
<td><%%= link_to 'Edit', <%= edit_link_path %>(@<%= pr.singular_table_name %>, <%= r.singular_table_name %>) %></td>
<td><%%= link_to 'Destroy', <%= singular_table_name %>, confirm: 'Are you sure?', method: :delete %></td>
<%% end %>
</tbody>

0 comments on commit 9f7ad5e

Please sign in to comment.