Merged rails-3.2 branch.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9528 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -2,4 +2,4 @@ Description:
|
||||
Generates a plugin model.
|
||||
|
||||
Examples:
|
||||
./script/generate redmine_plugin_model MyPlugin pool title:string question:text
|
||||
./script/generate redmine_plugin_model meetings pool
|
||||
|
||||
@@ -1,45 +1,19 @@
|
||||
require 'rails_generator/base'
|
||||
require 'rails_generator/generators/components/model/model_generator'
|
||||
class RedminePluginModelGenerator < Rails::Generators::NamedBase
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
argument :model, :type => :string
|
||||
|
||||
class RedminePluginModelGenerator < ModelGenerator
|
||||
attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name
|
||||
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
|
||||
|
||||
def initialize(runtime_args, runtime_options = {})
|
||||
runtime_args = runtime_args.dup
|
||||
usage if runtime_args.empty?
|
||||
@plugin_name = "redmine_" + runtime_args.shift.underscore
|
||||
def initialize(*args)
|
||||
super
|
||||
@plugin_name = file_name.underscore
|
||||
@plugin_pretty_name = plugin_name.titleize
|
||||
@plugin_path = "vendor/plugins/#{plugin_name}"
|
||||
super(runtime_args, runtime_options)
|
||||
@plugin_path = "plugins/#{plugin_name}"
|
||||
@model_class = model.camelize
|
||||
end
|
||||
|
||||
def destination_root
|
||||
File.join(Rails.root, plugin_path)
|
||||
end
|
||||
|
||||
def manifest
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions class_path, class_name, "#{class_name}Test"
|
||||
|
||||
# Model, test, and fixture directories.
|
||||
m.directory File.join('app/models', class_path)
|
||||
m.directory File.join('test/unit', class_path)
|
||||
m.directory File.join('test/fixtures', class_path)
|
||||
|
||||
# Model class, unit test, and fixtures.
|
||||
m.template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb")
|
||||
m.template 'unit_test.rb.erb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
||||
|
||||
unless options[:skip_fixture]
|
||||
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
||||
end
|
||||
|
||||
unless options[:skip_migration]
|
||||
m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
|
||||
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
||||
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
end
|
||||
end
|
||||
def copy_templates
|
||||
template 'model.rb.erb', "#{plugin_path}/app/models/#{model}.rb"
|
||||
template 'unit_test.rb.erb', "#{plugin_path}/test/unit/#{model}_test.rb"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
one:
|
||||
id: 1
|
||||
<% for attribute in attributes -%>
|
||||
<%= attribute.name %>: <%= attribute.default %>
|
||||
<% end -%>
|
||||
two:
|
||||
id: 2
|
||||
<% for attribute in attributes -%>
|
||||
<%= attribute.name %>: <%= attribute.default %>
|
||||
<% end -%>
|
||||
@@ -1,13 +0,0 @@
|
||||
class <%= migration_name %> < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :<%= table_name %> do |t|
|
||||
<% for attribute in attributes -%>
|
||||
t.column :<%= attribute.name %>, :<%= attribute.type %>
|
||||
<% end -%>
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :<%= table_name %>
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,3 @@
|
||||
class <%= class_name %> < ActiveRecord::Base
|
||||
class <%= @model_class %> < ActiveRecord::Base
|
||||
unloadable
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class <%= class_name %>Test < ActiveSupport::TestCase
|
||||
fixtures :<%= table_name %>
|
||||
class <%= @model_class %>Test < ActiveSupport::TestCase
|
||||
|
||||
# Replace this with your real tests.
|
||||
def test_truth
|
||||
|
||||
Reference in New Issue
Block a user