2012-04-25 21:17:49 +04:00
|
|
|
class RedminePluginControllerGenerator < Rails::Generators::NamedBase
|
|
|
|
source_root File.expand_path("../templates", __FILE__)
|
|
|
|
argument :controller, :type => :string
|
|
|
|
argument :actions, :type => :array, :default => [], :banner => "ACTION ACTION ..."
|
2008-09-05 14:31:06 +04:00
|
|
|
|
|
|
|
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
|
2012-04-01 16:41:55 +04:00
|
|
|
|
2012-04-25 21:17:49 +04:00
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
@plugin_name = file_name.underscore
|
2008-09-05 14:31:06 +04:00
|
|
|
@plugin_pretty_name = plugin_name.titleize
|
2012-04-25 21:17:49 +04:00
|
|
|
@plugin_path = "plugins/#{plugin_name}"
|
|
|
|
@controller_class = controller.camelize
|
2008-09-05 14:31:06 +04:00
|
|
|
end
|
2012-04-01 16:41:55 +04:00
|
|
|
|
2012-04-25 21:17:49 +04:00
|
|
|
def copy_templates
|
|
|
|
template 'controller.rb.erb', "#{plugin_path}/app/controllers/#{controller}_controller.rb"
|
|
|
|
template 'helper.rb.erb', "#{plugin_path}/app/helpers/#{controller}_helper.rb"
|
|
|
|
template 'functional_test.rb.erb', "#{plugin_path}/test/functional/#{controller}_controller_test.rb"
|
|
|
|
# View template for each action.
|
|
|
|
actions.each do |action|
|
|
|
|
path = "#{plugin_path}/app/views/#{controller}/#{action}.html.erb"
|
|
|
|
@action_name = action
|
|
|
|
template 'view.html.erb', path
|
2008-10-25 13:35:51 +04:00
|
|
|
end
|
|
|
|
end
|
2008-09-05 14:31:06 +04:00
|
|
|
end
|