Permalink
Browse files

Added message generator

  • Loading branch information...
ashrafuzzaman committed Jun 7, 2012
1 parent 32cc26b commit 6173321c914495e8c0d394451ffa221afb2a2e56
View

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1,11 @@
A custom template generator
===========================
rails3 template for customizing generators
Nested scaffold
===========================
rails g nested_scaffold ParentModel:ChildModel properties_hash
Example:
rails g nested_scaffold Blog:Comment title:string body:text
@@ -0,0 +1,9 @@
Description:
This generates message partials for displaying messages/notifications
Example:
rails generate messages
This will create:
app/views/shared/_errors.erb.html
app/views/shared/_notifications.erb.html
@@ -0,0 +1,16 @@
class MessagesGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
def copy_view_files
available_views.each do |view|
filename = "#{view}.html.erb"
template "erb/#{filename}", File.join("app/views/shared", filename)
end
end
private
def available_views
%w(_errors _notifications)
end
end
@@ -0,0 +1,9 @@
<div class="alert-error alert">
<a class="close" href="#">&times;</a>
<h2><%%= t(:error_msg_title) %></h2>
<ul>
<%% model.errors.full_messages.uniq.each do |msg| %>
<li><%%= msg %></li>
<%% end %>
</ul>
</div>
@@ -0,0 +1,13 @@
<div class="alert-notify alert">
<a class="close" href="#">&times;</a>
<h2><%%= t(:notification_title) %></h2>
<ul>
<%% if message %>
<li><%%= msg %></li>
<%% else %>
<%% messages.each do |msg| %>
<li><%%= msg %></li>
<%% end %>
<%% end %>
</ul>
</div>
@@ -6,9 +6,9 @@ class NestedScaffoldGenerator < Rails::Generators::NamedBase
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
def initialize(args, *options) #:nodoc:
parse_reources!(args[0])
args[0] = r.name
super(args, *options)
parse_reources!
assign_names!(r.name)
end
def copy_view_files
@@ -27,21 +27,17 @@ def copy_controller
# route %{get "#{file_name}/#{action}"}
# end
#end
hook_for :template_engine, :test_framework, :as => :scaffold
# Invoke the helper using the controller name (pluralized)
hook_for :helper, :as => :scaffold do |invoked|
invoke invoked, [ controller_name ]
end
hook_for :test_framework, :messages, :as => :scaffold
protected
def available_views
%w(index show new edit _form)
end
def parse_reources!
pr_name, r_name = file_name.split(':')
def parse_reources!(name)
pr_name, r_name = name.split(':')
@r ||= Resource.new(r_name.downcase)
@pr ||= Resource.new(pr_name.downcase)
end

0 comments on commit 6173321

Please sign in to comment.