Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
generator for partials, i am so lazy :)
- Loading branch information
Showing
7 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Description: | ||
Generating list,edit,save and show partials for tasks from TrstSysTask table, based on 'exe_id' value. | ||
Convention: | ||
base_path /app/views/trst_sys (change with --controller_path) | ||
partial_path base_path/xxx/yyy/zzz/_*.html.erb with "./script/generate task_partial xxx_yyy_zzz" | ||
or partial_path base_path/xxx/yyy/_zzz.html.erb with "./script/generate task_partial xxx_yyy_zzz --single" | ||
Example: | ||
"./script/generate task_partial db_sys_menu" => | ||
/app/views/trst_sys/db/sys/menu/_list.html.erb, _edit.html.rb .... | ||
"./script/generate task_partial db_sys_menu --single" => | ||
/app/views/trst_sys/db/sys/_menu.html.erb | ||
"./script/generate task_partial db_sys_menu --single --controller_path "other_path"" => | ||
/app/views/other_path/db/sys/_menu.html.erb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class TaskPartialGenerator < Rails::Generator::NamedBase | ||
default_options :single => false, :create => false, :controller_path => "trst_sys" | ||
|
||
def initialize(runtime_args, runtime_options = {}) | ||
super | ||
if TrstSysTask.find(:first, :conditions => ['exe_id = ?', @name ]).nil? | ||
logger.error("Task with exe_id='#{@name}' doesn't exists in trst_sys_tasks table ! | ||
Create a new record in table with exe_id='#{@name}' and try again ... | ||
or run with --create_record (if you are sure you didn't misspelled)") | ||
exit | ||
end unless options[:create] | ||
end | ||
|
||
def manifest | ||
record do |m| | ||
if options[:single] | ||
m.directory File.join("app/views/#{options[:controller_path]}",task_path) | ||
m.template( | ||
"single.html.erb", | ||
File.join("app/views/#{options[:controller_path]}",task_path,"_#{single_file_name}.html.erb")) | ||
else | ||
m.directory File.join("app/views/#{options[:controller_path]}",task_path) | ||
for action in task_views | ||
m.template( | ||
"#{action}.html.erb", | ||
File.join("app/views/#{options[:controller_path]}", task_path, "_#{action}.html.erb") | ||
) | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def banner | ||
"Usage: #{$0} task_partial some_task_exe_id" | ||
end | ||
|
||
def task_path | ||
file_name.gsub(/_/, "/") | ||
end | ||
|
||
def single_file_name | ||
file_name.split("_").last | ||
end | ||
|
||
def task_views | ||
%w[ edit list save show ] | ||
end | ||
|
||
def add_options!(opt) | ||
opt.separator '' | ||
opt.separator 'Options:' | ||
opt.on("--single", | ||
"Generate only one partial") { |v| options[:single] = v } | ||
opt.on("--create", | ||
"Force creating partials even without required task") { |v| options[:create] = v } | ||
opt.on("--controller_path", | ||
"Change default ('trst_sys') controller") { |v| options[:controller_path] = args[0] } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%# | ||
# To change this template, choose Tools | Templates | ||
# and open the template in the editor. | ||
%> | ||
<%= "edit" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%# | ||
# To change this template, choose Tools | Templates | ||
# and open the template in the editor. | ||
%> | ||
<%= "list" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%# | ||
# To change this template, choose Tools | Templates | ||
# and open the template in the editor. | ||
%> | ||
<%= "save" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%# | ||
# To change this template, choose Tools | Templates | ||
# and open the template in the editor. | ||
%> | ||
<%= "show" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%# | ||
# To change this template, choose Tools | Templates | ||
# and open the template in the editor. | ||
%> | ||
<%= "single.html" %> |