mdd 1.1.0 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/views/template/mdwa/_crud_error.html.erb +11 -0
- data/app/views/template/mdwa/_notice.html.erb +0 -4
- data/lib/generators/mdd/.DS_Store +0 -0
- data/lib/generators/mdd/association/USAGE +21 -0
- data/lib/generators/mdd/association/association_generator.rb +153 -0
- data/lib/generators/mdd/association/templates/.DS_Store +0 -0
- data/lib/generators/mdd/association/templates/migrate/many_to_many.rb +8 -0
- data/lib/generators/mdd/association/templates/migrate/one_field.rb +13 -0
- data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/all_pages.js +3 -0
- data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/clicable_title.js +2 -2
- data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/login/login.css +2 -4
- data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/.DS_Store +0 -0
- data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/backend_base.css.erb +6 -1
- data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/template.css.erb +3 -3
- data/lib/generators/mdd/sandbox/templates/config/locales/mdwa.en.yml +5 -1
- data/lib/generators/mdd/scaffold/USAGE +49 -1
- data/lib/generators/mdd/scaffold/scaffold_generator.rb +56 -56
- data/lib/generators/mdd/scaffold/templates/controllers/ajax_controller.rb +15 -15
- data/lib/generators/mdd/scaffold/templates/controllers/controller.rb +17 -14
- data/lib/generators/mdd/scaffold/templates/db_migrate/.DS_Store +0 -0
- data/lib/generators/mdd/scaffold/templates/db_migrate/migrate.rb +7 -8
- data/lib/generators/mdd/scaffold/templates/models/model.rb +2 -6
- data/lib/generators/mdd/scaffold/templates/models/module.rb +1 -1
- data/lib/generators/mdd/scaffold/templates/views/_form.html.erb +7 -22
- data/lib/generators/mdd/scaffold/templates/views/_form_fields.html.erb +27 -0
- data/lib/generators/mdd/scaffold/templates/views/_list.html.erb +25 -10
- data/lib/generators/mdd/scaffold/templates/views/create.js.erb +7 -2
- data/lib/generators/mdd/scaffold/templates/views/destroy.js.erb +2 -1
- data/lib/generators/mdd/scaffold/templates/views/edit.html.erb +2 -2
- data/lib/generators/mdd/scaffold/templates/views/index.html.erb +5 -5
- data/lib/generators/mdd/scaffold/templates/views/index.js.erb +1 -1
- data/lib/generators/mdd/scaffold/templates/views/new.html.erb +2 -2
- data/lib/generators/mdd/scaffold/templates/views/show.html.erb +26 -0
- data/lib/mdd.rb +2 -1
- data/lib/mdd/generators/model.rb +71 -0
- data/lib/mdd/generators/model_attribute.rb +54 -10
- data/lib/mdd/version.rb +1 -1
- metadata +14 -3
- data/lib/generators/mdd/scaffold/templates/views/update.js.erb +0 -2
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Description:
|
2
|
+
Generate migrations and models based on ActiveRecord association types.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails g mdd:association Library has_many Books
|
6
|
+
|
7
|
+
rails g mdd:association Book belongs_to Library --with-opposite
|
8
|
+
Generates the first example as the opposite
|
9
|
+
|
10
|
+
rails g mdd:association Company nested_one Address
|
11
|
+
Creates address_id in migration and belongs_to :address and accepts_nested_attrs in Company model
|
12
|
+
Creates has_one :company in Address model if opposite requested
|
13
|
+
|
14
|
+
rails g mdd:association Sale nested_many SaleItem
|
15
|
+
Creates sale_id and belongs_to in SaleItem
|
16
|
+
Creates has_many and accepts_nested_attrs in Sale
|
17
|
+
|
18
|
+
rails g mdd:association User has_and_belongs_to_many Project
|
19
|
+
Creates the join table projects_users
|
20
|
+
Creates has_and_belongs_to_many association in both models
|
21
|
+
The generated code indicates the join_table parameter, because often users have many to many associations and may be inheritance involved.
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
|
6
|
+
module Mdd
|
7
|
+
module Generators
|
8
|
+
class AssociationGenerator < Rails::Generators::Base
|
9
|
+
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
|
12
|
+
ACCEPTED_RELATIONS = [:has_many, :belongs_to, :has_and_belongs_to_many, :nested_many, :nested_one, :has_one]
|
13
|
+
|
14
|
+
source_root File.expand_path("../templates", __FILE__)
|
15
|
+
|
16
|
+
attr_accessor :model1, :attribute, :model2, :pending_migrations
|
17
|
+
|
18
|
+
argument :model1, :type => :string, :banner => "First part of relation"
|
19
|
+
argument :relation, :type => :string, :banner => "has_many, belongs, has_one, nested_many, nested_one..."
|
20
|
+
argument :model2, :type => :string, :banner => "Second part of relation"
|
21
|
+
|
22
|
+
class_option :with_opposite, :desc => 'Generate the opposite relation too. For example, the oposite of belongs_to is has_many.', :type => :boolean, :default => false
|
23
|
+
class_option :skip_rake_migrate, :desc => 'Skips rake db:migrate', :type => :boolean, :default => false
|
24
|
+
class_option :ask, :desc => 'Asks if the opposite should be generated.', :type => :boolean, :default => false
|
25
|
+
|
26
|
+
def initialize(*args, &block)
|
27
|
+
|
28
|
+
super
|
29
|
+
|
30
|
+
@model1 = Generators::Model.new( model1 )
|
31
|
+
@model2 = Generators::Model.new( model2 )
|
32
|
+
|
33
|
+
# validation
|
34
|
+
print_usage unless @model1.valid?
|
35
|
+
print_usage unless @model2.valid?
|
36
|
+
print_usage unless ACCEPTED_RELATIONS.include? @relation.to_sym
|
37
|
+
|
38
|
+
# active record generates join tables alphabetically
|
39
|
+
@ordered_models = [@model1, @model2].sort! {|a,b| a.plural_name <=> b.plural_name}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def migrate
|
44
|
+
@pending_migrations = true
|
45
|
+
case @relation.to_sym
|
46
|
+
when :belongs_to, :nested_one
|
47
|
+
@table = @model1
|
48
|
+
@field = @model2
|
49
|
+
migration_template 'migrate/one_field.rb', "db/migrate/add_#{@field.singular_name.foreign_key}_to_#{@table.plural_name}.rb"
|
50
|
+
when :nested_many
|
51
|
+
@table = @model2
|
52
|
+
@field = @model1
|
53
|
+
migration_template 'migrate/one_field.rb', "db/migrate/add_#{@field.singular_name.foreign_key}_to_#{@table.plural_name}.rb"
|
54
|
+
when :has_and_belongs_to_many
|
55
|
+
migration_template 'migrate/many_to_many.rb', "db/migrate/create_#{many_to_many_table_name}.rb"
|
56
|
+
else
|
57
|
+
@pending_migrations = false
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def model
|
63
|
+
case @relation.to_sym
|
64
|
+
when :belongs_to
|
65
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
66
|
+
"\n\tbelongs_to :#{@model2.singular_name}, :class_name => '#{@model2.klass}'\n\tattr_accessible :#{@model2.singular_name.foreign_key}"
|
67
|
+
end
|
68
|
+
when :has_one
|
69
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
70
|
+
"\n\thas_one :#{@model2.singular_name}, :class_name => '#{@model2.klass}'\n"
|
71
|
+
end
|
72
|
+
when :has_many
|
73
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
74
|
+
"\n\thas_many :#{@model2.plural_name}, :class_name => '#{@model2.klass}'\n"
|
75
|
+
end
|
76
|
+
when :has_and_belongs_to_many
|
77
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
78
|
+
"\n\thas_and_belongs_to_many :#{@model2.plural_name}, :join_table => :#{many_to_many_table_name}\n"
|
79
|
+
end
|
80
|
+
inject_into_class "app/models/#{@model2.space}/#{@model2.singular_name}.rb", @model2.klass.constantize do
|
81
|
+
"\n\thas_and_belongs_to_many :#{@model1.plural_name}, :join_table => :#{many_to_many_table_name}\n"
|
82
|
+
end
|
83
|
+
when :nested_one
|
84
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
85
|
+
# belongs_to
|
86
|
+
# attr_accessible attributes
|
87
|
+
# attr_nested_attributes
|
88
|
+
"\n\tbelongs_to :#{@model2.singular_name}, :class_name => '#{@model2.klass}'\n\tattr_accessible :#{@model2.singular_name}_attributes, :#{@model2.singular_name.foreign_key}\n\taccepts_nested_attributes_for :#{@model2.singular_name}, :allow_destroy => true\n"
|
89
|
+
end
|
90
|
+
when :nested_many
|
91
|
+
inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
|
92
|
+
# belongs_to
|
93
|
+
# attr_accessible attributes
|
94
|
+
# attr_nested_attributes
|
95
|
+
"\n\thas_many :#{@model2.plural_name}, :class_name => '#{@model2.klass}', :dependent => :destroy\n\tattr_accessible :#{@model2.plural_name}_attributes\n\taccepts_nested_attributes_for :#{@model2.plural_name}, :allow_destroy => true\n"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
def run_rake_db_migrate
|
102
|
+
rake('db:migrate') if !options.skip_rake_migrate and @pending_migrations and yes? 'Run rake db:migrate?'
|
103
|
+
end
|
104
|
+
|
105
|
+
def opposite
|
106
|
+
|
107
|
+
if options.with_opposite or options.ask
|
108
|
+
# belongs_to
|
109
|
+
if @relation == 'belongs_to' and (options.with_opposite or ( options.ask and yes?("#{@model1.name} belongs to #{@model2.singular_name}. Create has_many association?") ))
|
110
|
+
generate "mdd:association #{@model2.raw} has_many #{@model1.raw} #{'--force' if options.force}"
|
111
|
+
end
|
112
|
+
|
113
|
+
# has_many
|
114
|
+
if @relation == 'has_many' and (options.with_opposite or ( options.ask and yes?("#{@model1.name} has many #{@model2.plural_name}. Create belongs_to association?") ))
|
115
|
+
generate "mdd:association #{@model2.raw} belongs_to #{@model1.raw} #{'--force' if options.force}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# has_one
|
119
|
+
if @relation == 'has_one' and (options.with_opposite or ( options.ask and yes?("#{@model1.name} has one #{@model2.singular_name}. Create belongs_to association?") ))
|
120
|
+
generate "mdd:association #{@model2.raw} belongs_to #{@model1.raw} #{'--force' if options.force}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# nested_many
|
124
|
+
if @relation == 'nested_many' and (options.with_opposite or ( options.ask and yes?("#{@model1.name} has many (nested) with #{@model2.plural_name}. Create belongs_to association?") ))
|
125
|
+
generate "mdd:association #{@model2.raw} belongs_to #{@model1.raw} #{'--force' if options.force}"
|
126
|
+
end
|
127
|
+
|
128
|
+
# nested_one
|
129
|
+
if @relation == 'nested_one' and (options.with_opposite or ( options.ask and yes?("#{@model1.name} belongs nested to #{@model2.singular_name}. Create has_one association?") ))
|
130
|
+
generate "mdd:association #{@model2.raw} has_one #{@model1.raw} #{'--force' if options.force}"
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Implement the required interface for Rails::Generators::Migration.
|
137
|
+
def self.next_migration_number(dirname)
|
138
|
+
if ActiveRecord::Base.timestamped_migrations
|
139
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S").to_s
|
140
|
+
else
|
141
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
def many_to_many_table_name
|
147
|
+
"#{@ordered_models.first.plural_name}_#{@ordered_models.last.plural_name}"
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
Binary file
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class Create<%= @ordered_models.first.plural_name.camelize %><%= @ordered_models.last.plural_name.camelize %> < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :<%= @ordered_models.first.plural_name %>_<%= @ordered_models.last.plural_name %>, :id => false do |t|
|
5
|
+
t.references :<%= @ordered_models.first.singular_name %>, :<%= @ordered_models.last.singular_name %>
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Add<%= @field.singular_name.foreign_key.camelize %>To<%= @table.plural_name.camelize %> < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
add_column :<%= @table.plural_name %>, :<%= @field.singular_name.foreign_key %>, :integer
|
5
|
+
add_index :<%= @table.plural_name %>, :<%= @field.singular_name.foreign_key %>
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_column :<%= @table.plural_name %>, :<%= @field.singular_name.foreign_key %>
|
10
|
+
remove_index :<%= @table.plural_name %>, :<%= @field.singular_name.foreign_key %>
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/clicable_title.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
$(function() {
|
2
|
-
$.each($('.
|
2
|
+
$.each($('.clicable_title'), function(index, value) {
|
3
3
|
if($(this).val() == '')
|
4
4
|
$(this).val($(this).attr('title'));
|
5
5
|
});
|
6
|
-
$('.
|
6
|
+
$('.clicable_title').live({
|
7
7
|
blur: function() {
|
8
8
|
if($(this).val() == '') $(this).val($(this).attr('title'));
|
9
9
|
},
|
@@ -104,12 +104,10 @@ div.actions .button {
|
|
104
104
|
box-shadow: 0 0 1px #AAAAAA;
|
105
105
|
cursor: pointer;
|
106
106
|
float: right;
|
107
|
-
|
107
|
+
font-size: 15px;
|
108
|
+
padding: 5px 10px;
|
108
109
|
text-shadow: 0 0 1px #FFFFFF;
|
109
110
|
width: 100px;
|
110
|
-
|
111
|
-
font-size: 15px;
|
112
|
-
padding: 10px;
|
113
111
|
}
|
114
112
|
|
115
113
|
div.actions .button:hover {
|
Binary file
|
data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/backend_base.css.erb
CHANGED
@@ -25,7 +25,8 @@ div.field label {
|
|
25
25
|
div.field input[type="text"],
|
26
26
|
div.field input[type="email"],
|
27
27
|
div.field input[type="number"],
|
28
|
-
div.field input[type="password"]
|
28
|
+
div.field input[type="password"],
|
29
|
+
div.field textarea {
|
29
30
|
border: 1px solid #888;
|
30
31
|
padding: 4px;
|
31
32
|
font-size: 13px;
|
@@ -40,6 +41,10 @@ div.field input[type="password"]:hover {
|
|
40
41
|
box-shadow: 0 0 2px #999;
|
41
42
|
}
|
42
43
|
|
44
|
+
div.field textarea {
|
45
|
+
height: 100px;
|
46
|
+
}
|
47
|
+
|
43
48
|
div.actions {
|
44
49
|
text-align:center;
|
45
50
|
margin: 20px 0;
|
data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/template.css.erb
CHANGED
@@ -102,7 +102,7 @@ a.remove_nested_fields {
|
|
102
102
|
display: table;
|
103
103
|
}
|
104
104
|
|
105
|
-
|
105
|
+
.mdwa_error {
|
106
106
|
width: 450px;
|
107
107
|
border: 2px solid red;
|
108
108
|
padding: 7px;
|
@@ -111,7 +111,7 @@ a.remove_nested_fields {
|
|
111
111
|
background-color: #f0f0f0;
|
112
112
|
}
|
113
113
|
|
114
|
-
|
114
|
+
.mdwa_error h2 {
|
115
115
|
text-align: left;
|
116
116
|
font-weight: bold;
|
117
117
|
padding: 5px 5px 5px 15px;
|
@@ -122,7 +122,7 @@ a.remove_nested_fields {
|
|
122
122
|
color: #fff;
|
123
123
|
}
|
124
124
|
|
125
|
-
|
125
|
+
.mdwa_error ul li {
|
126
126
|
font-size: 12px;
|
127
127
|
list-style: square;
|
128
128
|
}
|
@@ -5,5 +5,53 @@ Description:
|
|
5
5
|
All list have pagination with will_paginate gem.
|
6
6
|
Referenced models also have their relations configured in models and views.
|
7
7
|
|
8
|
+
Restriction:
|
9
|
+
The database must be configured correctly as usual.
|
10
|
+
So, run rake db:create before start.
|
11
|
+
|
8
12
|
Example:
|
9
|
-
|
13
|
+
It is equal to Rails scaffold if relations are not mentioned.
|
14
|
+
The relations syntax:
|
15
|
+
|
16
|
+
- rails generate mdd:scaffold Product name:string initial_date:date category_id:category:name:belongs
|
17
|
+
# model product.rb
|
18
|
+
class Product < ActiveRecord::Base
|
19
|
+
attr_accessible :name, :initial_date, :category_id
|
20
|
+
belongs_to :category
|
21
|
+
...
|
22
|
+
|
23
|
+
- rails generate mdd:scaffold Category name:string products:product:name:has_many
|
24
|
+
# model product.rb
|
25
|
+
class Product < ActiveRecord::Base
|
26
|
+
attr_accessible :name
|
27
|
+
has_many :products
|
28
|
+
...
|
29
|
+
|
30
|
+
- rails generate mdd:scaffold Product name:string category:category:name:nested_many
|
31
|
+
# model product.rb
|
32
|
+
class Product < ActiveRecord::Base
|
33
|
+
attr_accessible :name, :categories_attributes
|
34
|
+
has_many :categories
|
35
|
+
accepts_nested_attributes_for :categories, :allow_destroy => true
|
36
|
+
...
|
37
|
+
|
38
|
+
- rails generate mdd:scaffold Company name:string address:address:name:nested_one
|
39
|
+
class Company < ActiveRecord::Base
|
40
|
+
attr_accessible :name, :address_attributes
|
41
|
+
belongs_to :address
|
42
|
+
accepts_nested_attributes_for :address, :allow_destroy => true
|
43
|
+
...
|
44
|
+
|
45
|
+
- rails generate mdd:scaffold User name:string projects:projects:name:has_and_belongs_to_many
|
46
|
+
rails generate mdd:scaffold Project name:string users:user:name:has_and_belongs_to_many
|
47
|
+
Class User < ActiveRecord::Base
|
48
|
+
has_and_belongs_to_many :projects
|
49
|
+
Class User < ActiveRecord::Base
|
50
|
+
has_and_belongs_to_many :users
|
51
|
+
|
52
|
+
- rails generate mdd:scaffold Product name:string product_price:productPrice:name:has_one
|
53
|
+
# model product.rb
|
54
|
+
class Product < ActiveRecord::Base
|
55
|
+
attr_accessible :name
|
56
|
+
has_one :product_price
|
57
|
+
...
|
@@ -7,99 +7,99 @@ module Mdd
|
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :model, :create_nested_association
|
11
11
|
|
12
12
|
argument :scaffold_name, :type => :string, :banner => "[namespace]/Model"
|
13
13
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
14
14
|
|
15
|
-
class_option :
|
16
|
-
class_option :
|
15
|
+
class_option :ajax, :desc => 'Generates modal forms and AJAX submits.', :type => :boolean, :default => false
|
16
|
+
class_option :skip_migration, :desc => 'Skips the generation of a new migration.', :type => :boolean, :default => false
|
17
|
+
class_option :skip_timestamp, :desc => 'Skip timestamp generator on migration files.', :type => :boolean, :default => false
|
18
|
+
class_option :skip_interface, :desc => 'Cretes only models, migrations and associations.', :type => :boolean, :default => false
|
19
|
+
class_option :only_interface, :desc => 'Skips models, associations and migrations.', :type => :boolean, :default => false
|
17
20
|
|
18
21
|
def initialize(*args, &block)
|
19
22
|
|
20
23
|
super
|
21
24
|
|
22
|
-
|
23
|
-
@namespace = ''
|
24
|
-
@namespace = scaffold_name.split('/').first.camelize if scaffold_name.split('/').count > 1
|
25
|
-
@model_name = scaffold_name.split('/').last.singularize.camelize
|
25
|
+
@model = Generators::Model.new( scaffold_name )
|
26
26
|
|
27
27
|
# model_name is not valid
|
28
|
-
print_usage unless @
|
28
|
+
print_usage unless @model.valid?
|
29
29
|
|
30
30
|
# sets the model attributes
|
31
|
-
@model_attributes = []
|
32
31
|
attributes.each do |attribute|
|
33
|
-
@
|
32
|
+
@model.add_attribute Generators::ModelAttribute.new( attribute )
|
34
33
|
end
|
34
|
+
|
35
35
|
end
|
36
36
|
|
37
37
|
def controller
|
38
|
-
|
39
|
-
|
38
|
+
unless options.skip_interface
|
39
|
+
@inherit_controller = 'A::BackendController' if @model.space == 'a'
|
40
|
+
template "controllers/#{'ajax_' if options.ajax}controller.rb", "app/controllers/#{@model.space}/#{@model.plural_name}_controller.rb"
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def model
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def migration
|
48
|
-
unless options.skip_migration
|
49
|
-
migration_template 'db_migrate/migrate.rb', "db/migrate/create_#{plural_name}.rb"
|
45
|
+
unless options.only_interface
|
46
|
+
template 'models/module.rb', "app/models/#{@model.space}.rb" if @model.namespace?
|
47
|
+
template 'models/model.rb', "app/models/#{@model.space}/#{@model.singular_name}.rb"
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
51
|
def views
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
template 'views/
|
63
|
-
|
64
|
-
|
52
|
+
unless options.skip_interface
|
53
|
+
template 'views/edit.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/edit.html.erb"
|
54
|
+
template 'views/index.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/index.html.erb"
|
55
|
+
template 'views/index.js.erb', "app/views/#{@model.space}/#{@model.plural_name}/index.js.erb"
|
56
|
+
template 'views/new.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/new.html.erb"
|
57
|
+
template 'views/show.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/show.html.erb"
|
58
|
+
template 'views/_form.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/_form.html.erb"
|
59
|
+
template 'views/_form_fields.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/_form_fields.html.erb"
|
60
|
+
template 'views/_list.html.erb', "app/views/#{@model.space}/#{@model.plural_name}/_#{@model.plural_name}.html.erb"
|
61
|
+
|
62
|
+
if options.ajax
|
63
|
+
#create and update are the same
|
64
|
+
template 'views/create.js.erb', "app/views/#{@model.space}/#{@model.plural_name}/create.js.erb"
|
65
|
+
template 'views/create.js.erb', "app/views/#{@model.space}/#{@model.plural_name}/update.js.erb"
|
66
|
+
template 'views/destroy.js.erb', "app/views/#{@model.space}/#{@model.plural_name}/destroy.js.erb"
|
67
|
+
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
71
|
def routes
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def run_rake_db_migrate
|
74
|
-
rake('db:migrate') if yes? 'Run rake db:migrate?'
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def singular_name
|
80
|
-
@model_name.underscore
|
81
|
-
end
|
82
|
-
|
83
|
-
def plural_name
|
84
|
-
@model_name.underscore.pluralize
|
72
|
+
unless options.skip_interface
|
73
|
+
route "resources :#{@model.plural_name}" unless @model.namespace?
|
74
|
+
route "namespace :#{@model.space} do resources :#{@model.plural_name} end" if @model.namespace?
|
85
75
|
end
|
76
|
+
end
|
86
77
|
|
87
|
-
|
88
|
-
|
78
|
+
def migration
|
79
|
+
unless options.skip_migration or options.only_interface
|
80
|
+
migration_template 'db_migrate/migrate.rb', "db/migrate/create_#{@model.plural_name}.rb"
|
89
81
|
end
|
82
|
+
end
|
90
83
|
|
91
|
-
|
92
|
-
|
93
|
-
|
84
|
+
def associations
|
85
|
+
unless options.skip_migration or options.only_interface
|
86
|
+
@model.attributes.select{ |a| a.references? }.each do |attr|
|
87
|
+
# if attr.belongs_to? or attr.nested_one? or attr.has_one?
|
88
|
+
generate "mdd:association #{@model.raw} #{attr.reference_type} #{attr.type.raw} #{'--force' if options.force} --skip_rake_migrate --ask"
|
89
|
+
# else
|
90
|
+
# generate "mdd:association #{attr.type.raw} #{attr.reference_type} #{@model.raw} #{'--force' if options.force} --skip_rake_migrate --ask"
|
91
|
+
# end
|
92
|
+
end
|
94
93
|
end
|
94
|
+
end
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
def run_rake_db_migrate
|
97
|
+
unless options.skip_migration or options.only_interface
|
98
|
+
rake('db:migrate') if yes? 'Run rake db:migrate?'
|
98
99
|
end
|
100
|
+
end
|
99
101
|
|
100
|
-
|
101
|
-
!namespace.blank?
|
102
|
-
end
|
102
|
+
private
|
103
103
|
|
104
104
|
# Sets Rails migration timestamp
|
105
105
|
def self.next_migration_number(dirname) #:nodoc:
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
|
2
2
|
|
3
3
|
def index
|
4
|
-
@<%= plural_name %> = <%=
|
4
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
|
5
5
|
|
6
6
|
respond_to do |format|
|
7
7
|
format.html
|
@@ -11,24 +11,24 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
11
11
|
|
12
12
|
|
13
13
|
def show
|
14
|
-
@<%= singular_name %> = <%=
|
14
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
15
15
|
render :layout => false
|
16
16
|
end
|
17
17
|
|
18
18
|
def new
|
19
|
-
@<%= singular_name %> = <%=
|
19
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new
|
20
20
|
render :layout => false
|
21
21
|
end
|
22
22
|
|
23
23
|
def edit
|
24
|
-
@<%= singular_name %> = <%=
|
24
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
25
25
|
render :layout => false
|
26
26
|
end
|
27
27
|
|
28
28
|
def create
|
29
|
-
@<%= singular_name %> = <%=
|
30
|
-
@<%= singular_name %>.save
|
31
|
-
# loads all <%= plural_name %> to display in the list
|
29
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.object_name %>])
|
30
|
+
@system_notice = t('<%= @model.plural_name %>.create_success') if @<%= @model.singular_name %>.save
|
31
|
+
# loads all <%= @model.plural_name %> to display in the list
|
32
32
|
load_list
|
33
33
|
|
34
34
|
respond_to do |format|
|
@@ -37,10 +37,10 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def update
|
40
|
-
@<%= singular_name %> = <%=
|
41
|
-
@<%= singular_name %>.update_attributes(params[:<%=
|
40
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
41
|
+
@system_notice = t('<%= @model.plural_name %>.update_success') if @<%= @model.singular_name %>.update_attributes(params[:<%= @model.object_name %>])
|
42
42
|
|
43
|
-
# loads all <%= plural_name %> to display in the list
|
43
|
+
# loads all <%= @model.plural_name %> to display in the list
|
44
44
|
load_list
|
45
45
|
|
46
46
|
respond_to do |format|
|
@@ -49,10 +49,10 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def destroy
|
52
|
-
@<%= singular_name %> = <%=
|
53
|
-
@<%= singular_name %>.destroy
|
52
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
53
|
+
@system_notice = t('<%= @model.plural_name %>.destroy_success') if @<%= @model.singular_name %>.destroy
|
54
54
|
|
55
|
-
# loads all <%= plural_name %> to display in the list
|
55
|
+
# loads all <%= @model.plural_name %> to display in the list
|
56
56
|
load_list
|
57
57
|
|
58
58
|
respond_to do |format|
|
@@ -62,7 +62,7 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
62
62
|
|
63
63
|
private
|
64
64
|
def load_list
|
65
|
-
@<%= plural_name %> = <%=
|
65
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => 1
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
|
2
2
|
|
3
3
|
def index
|
4
|
-
@<%= plural_name %> = <%=
|
4
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
|
5
5
|
|
6
6
|
respond_to do |format|
|
7
7
|
format.html
|
@@ -11,7 +11,7 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
11
11
|
|
12
12
|
|
13
13
|
def show
|
14
|
-
@<%= singular_name %> = <%=
|
14
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
15
15
|
|
16
16
|
respond_to do |format|
|
17
17
|
format.html
|
@@ -19,7 +19,10 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def new
|
22
|
-
@<%= singular_name %> = <%=
|
22
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new
|
23
|
+
<%- @model.attributes.select {|a| a.nested_one?}.each do |attr| %>
|
24
|
+
@<%= @model.singular_name %>.<%= attr.type.singular_name %> = <%= attr.type.klass %>.new
|
25
|
+
<%- end %>
|
23
26
|
|
24
27
|
respond_to do |format|
|
25
28
|
format.html
|
@@ -27,15 +30,15 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def edit
|
30
|
-
@<%= singular_name %> = <%=
|
33
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
31
34
|
end
|
32
35
|
|
33
36
|
def create
|
34
|
-
@<%= singular_name %> = <%=
|
37
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.object_name %>])
|
35
38
|
|
36
39
|
respond_to do |format|
|
37
|
-
if @<%= singular_name %>.save
|
38
|
-
format.html { redirect_to <%=
|
40
|
+
if @<%= @model.singular_name %>.save
|
41
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.create_success') }
|
39
42
|
else
|
40
43
|
format.html { render action: "new" }
|
41
44
|
end
|
@@ -43,11 +46,11 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
43
46
|
end
|
44
47
|
|
45
48
|
def update
|
46
|
-
@<%= singular_name %> = <%=
|
49
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
47
50
|
|
48
51
|
respond_to do |format|
|
49
|
-
if @<%= singular_name %>.update_attributes(params[:<%=
|
50
|
-
format.html { redirect_to <%=
|
52
|
+
if @<%= @model.singular_name %>.update_attributes(params[:<%= @model.object_name %>])
|
53
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.update_success') }
|
51
54
|
else
|
52
55
|
format.html { render action: "edit" }
|
53
56
|
end
|
@@ -55,12 +58,12 @@ class <%= namespace_scope %><%= plural_name.camelize %>Controller < <%= @inherit
|
|
55
58
|
end
|
56
59
|
|
57
60
|
def destroy
|
58
|
-
@<%= singular_name %> = <%=
|
61
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
59
62
|
|
60
|
-
@<%= singular_name %>.destroy
|
63
|
+
@<%= @model.singular_name %>.destroy
|
61
64
|
|
62
65
|
respond_to do |format|
|
63
|
-
format.html { redirect_to <%=
|
66
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: t('<%= @model.plural_name %>.destroy_success') }
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
Binary file
|
@@ -1,18 +1,17 @@
|
|
1
|
-
class Create<%= plural_name.camelize %> < ActiveRecord::Migration
|
1
|
+
class Create<%= @model.plural_name.camelize %> < ActiveRecord::Migration
|
2
2
|
|
3
3
|
def self.up
|
4
|
-
create_table :<%= plural_name %> do |t|
|
5
|
-
<%- @
|
6
|
-
t.<%= attr.migration_field %> :<%= attr.name %>
|
7
|
-
<%-
|
8
|
-
|
9
|
-
add_index <%= indexed_attributes.collect {|m| ":" + m.name }.join(', ') %>
|
4
|
+
create_table :<%= @model.plural_name %> do |t|
|
5
|
+
<%- @model.simple_attributes.each do |attr| %>
|
6
|
+
t.<%= attr.migration_field %> :<%= attr.name %><%- end %>
|
7
|
+
<%- unless options.skip_timestamp %>
|
8
|
+
t.timestamps
|
10
9
|
<%- end %>
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.down
|
15
|
-
drop_table :<%= plural_name %>
|
14
|
+
drop_table :<%= @model.plural_name %>
|
16
15
|
end
|
17
16
|
|
18
17
|
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= @model.klass %> < ActiveRecord::Base
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
<%- @model_attributes.select {|m| m.references? }.each do |attr| %>
|
6
|
-
belongs_to :<%= attr.type %>
|
7
|
-
<%- end %>
|
3
|
+
attr_accessible <%= @model.simple_attributes.collect {|a| ":" + a.name }.join(', ') %>
|
8
4
|
|
9
5
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module <%= @namespace
|
1
|
+
module <%= @model.namespace %>
|
2
2
|
end
|
@@ -1,33 +1,18 @@
|
|
1
|
-
<%%= form_for(@<%= singular_name %><%= ', :remote => true, :class => :mdwa_ajax' if options.ajax %>) do |f| %>
|
2
|
-
|
3
|
-
<%- unless options.ajax %>
|
4
|
-
<%% if @<%= singular_name %>.errors.any? %>
|
5
|
-
<div id="error_explanation">
|
6
|
-
<h2><%%= pluralize(@<%= singular_name %>.errors.count, t('system.error')) %> :</h2>
|
7
|
-
|
8
|
-
<ul>
|
9
|
-
<%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
|
10
|
-
<li><%%= msg %></li>
|
11
|
-
<%% end %>
|
12
|
-
</ul>
|
13
|
-
</div>
|
14
|
-
<%% end %>
|
15
|
-
<%- end %>
|
1
|
+
<%%= <%= 'nested_' unless @model.attributes.select{|a| a.nested_many?}.count.zero? %>form_for(@<%= @model.singular_name %><%= ', :remote => true, :html => {:class => :mdwa_ajax}' if options.ajax %>) do |f| %>
|
16
2
|
|
3
|
+
<div id="mdwa_error">
|
4
|
+
<%%= render '/template/mdwa/crud_error', :object => @<%= @model.singular_name %> %>
|
5
|
+
</div>
|
6
|
+
|
17
7
|
<div class="yui3-g">
|
18
8
|
<div class="yui3-u">
|
19
|
-
|
20
|
-
<div class="field">
|
21
|
-
<%%= f.label :<%= attr.name %> %>
|
22
|
-
<%= attr.form_field %>
|
23
|
-
</div>
|
24
|
-
<%- end %>
|
9
|
+
<%%= render 'form_fields', :f => f %>
|
25
10
|
</div>
|
26
11
|
</div>
|
27
12
|
|
28
13
|
<div class="actions">
|
29
14
|
<%- if !options.ajax %>
|
30
|
-
<%%= link_to t('system.cancel_button'), <%=
|
15
|
+
<%%= link_to t('system.cancel_button'), <%= @model.object_name.pluralize %>_path, :class => :cancel %> <%- else %>
|
31
16
|
<%%= link_to t('system.cancel_button'), '#', :class => :cancel %> <%- end %>
|
32
17
|
|
33
18
|
<%%= f.submit :class => :button %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%- @model.attributes.each do |attr| %>
|
2
|
+
<%- unless attr.references? %>
|
3
|
+
<div class="field">
|
4
|
+
<%%= f.label :<%= attr.name %> %>
|
5
|
+
<%%= f.<%= attr.form_field %> :<%= attr.name %> %>
|
6
|
+
</div>
|
7
|
+
<%- end %>
|
8
|
+
<%- if attr.belongs_to? %>
|
9
|
+
<div class="field">
|
10
|
+
<%%= f.label :<%= attr.name %> %>
|
11
|
+
<%%= f.select :<%= attr.name %>,
|
12
|
+
options_for_select( <%= attr.type.klass %>.order('<%= attr.reference %> ASC').collect{ |c| [c.<%= attr.reference %>, c.id] }, f.object.<%= attr.name %> ),
|
13
|
+
:prompt => '-- Select --' %>
|
14
|
+
</div>
|
15
|
+
<%- end %>
|
16
|
+
<%- if attr.nested? %>
|
17
|
+
<div class="nested">
|
18
|
+
<%%= f.fields_for :<%= (attr.nested_many?) ? attr.type.plural_name : attr.type.singular_name %> do |ff| %>
|
19
|
+
<%%= render '<%= attr.type.space %>/<%= attr.type.plural_name %>/form_fields', :f => ff %>
|
20
|
+
<%- unless attr.nested_one? %><%%= ff.link_to_remove t('nested.remove') %><%- end %>
|
21
|
+
<%% end %>
|
22
|
+
<%- unless attr.nested_one? %>
|
23
|
+
<%%= f.link_to_add t('nested.add', :name => '<%= attr.type.singular_name %>'), :<%= attr.type.plural_name %> %>
|
24
|
+
<%- end %>
|
25
|
+
</div>
|
26
|
+
<%- end %>
|
27
|
+
<%- end %>
|
@@ -1,20 +1,35 @@
|
|
1
1
|
<table class="list">
|
2
2
|
<thead>
|
3
|
-
<th><%%= t 'system.index_id' %></th>
|
4
|
-
|
5
|
-
|
3
|
+
<th class="list_show"><%%= t 'system.index_id' %></th>
|
4
|
+
<th class="list_edit"><%%= t 'system.index_edit' %></th>
|
5
|
+
<%- @model.attributes.each do |attr| %>
|
6
|
+
<th><%%= t '<%= @model.plural_name %>.index_<%= attr.name %>' %></th>
|
6
7
|
<%- end %>
|
7
|
-
<th><%%= t 'system.index_remove' %></th>
|
8
|
+
<th class="list_remove"><%%= t 'system.index_remove' %></th>
|
8
9
|
</thead>
|
9
|
-
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
10
|
+
<%% @<%= @model.plural_name %>.each do |<%= @model.singular_name %>| %>
|
10
11
|
<tr class="<%%= cycle 'odd_line', 'even_line' %>" >
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
<td><%%= link_to <%= @model.singular_name %>.id, <%= @model.object_name %>_path(<%= @model.singular_name %>) <%= ", :class => 'lightbox various fancybox.ajax'" if options.ajax %> %></td>
|
13
|
+
<td><%%= link_to 'Edit', edit_<%= @model.object_name %>_path(<%= @model.singular_name %>) <%= ", :class => 'lightbox various fancybox.ajax'" if options.ajax %> %></td>
|
14
|
+
<%- @model.attributes.each do |attr| %>
|
15
|
+
<td>
|
16
|
+
<%- if !attr.references? %>
|
17
|
+
<%%= <%= @model.singular_name %>.<%= attr.name %> %>
|
18
|
+
<%- elsif attr.belongs_to? || attr.nested_one? %>
|
19
|
+
<%%= <%= @model.singular_name %>.<%= attr.type.singular_name %>.<%= attr.reference %> %>
|
20
|
+
<%- elsif attr.has_many? or attr.nested_many? %>
|
21
|
+
<ul>
|
22
|
+
<%% <%= @model.singular_name %>.<%= attr.type.plural_name %>.each do |<%= attr.type.singular_name %>| %>
|
23
|
+
<li><%%= <%= attr.type.singular_name %>.<%= attr.reference %> %> </li>
|
24
|
+
<%% end %>
|
25
|
+
</ul>
|
26
|
+
<%- end %>
|
27
|
+
</td>
|
14
28
|
<%- end %>
|
15
|
-
|
29
|
+
|
30
|
+
<td><%%= link_to t('system.index_remove_label'), <%= @model.singular_name %>, :method => :delete, <%= ':remote => true,' if options.ajax %> :data => {:confirm => t('system.index_confirm_deletion')} %></td>
|
16
31
|
</tr>
|
17
32
|
<%% end %>
|
18
33
|
</table>
|
19
34
|
|
20
|
-
<%%= pagination_footer @<%= plural_name %> %>
|
35
|
+
<%%= pagination_footer @<%= @model.plural_name %> %>
|
@@ -1,2 +1,7 @@
|
|
1
|
-
|
2
|
-
$("
|
1
|
+
<%% if @<%= @model.singular_name %>.errors.any? %>
|
2
|
+
$("#mdwa_error").html("<%%= escape_javascript( render '/template/mdwa/crud_error', :object => @<%= @model.singular_name %> )%>");
|
3
|
+
<%% else %>
|
4
|
+
$.fancybox.close(true);
|
5
|
+
$("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render :partial => '<%= @model.plural_name %>' )%>");
|
6
|
+
$('body').append("<%%= escape_javascript( render '/template/mdwa/notice', :notice => @system_notice )%>");
|
7
|
+
<%% end %>
|
@@ -1 +1,2 @@
|
|
1
|
-
$("#<%= plural_name %>_list").html("<%%= escape_javascript( render :partial => '<%= plural_name %>' )%>");
|
1
|
+
$("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render :partial => '<%= @model.plural_name %>' )%>");
|
2
|
+
$('body').append("<%%= escape_javascript( render '/template/mdwa/notice', :notice => @system_notice )%>");
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<div id="<%= plural_name %>_edit" class="mdwa_edit">
|
1
|
+
<div id="<%= @model.plural_name %>_edit" class="mdwa_edit">
|
2
2
|
<div class="page_header">
|
3
|
-
<h1><%%= t('<%= plural_name %>.edit_title') %></h1>
|
3
|
+
<h1><%%= t('<%= @model.plural_name %>.edit_title') %></h1>
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="inside">
|
@@ -1,16 +1,16 @@
|
|
1
|
-
<div id="<%= plural_name %>_index" class="mdwa_index">
|
1
|
+
<div id="<%= @model.plural_name %>_index" class="mdwa_index">
|
2
2
|
<div class="page_header">
|
3
|
-
<h1><%%= t '<%= plural_name %>.index_title' %></h1>
|
3
|
+
<h1><%%= t '<%= @model.plural_name %>.index_title' %></h1>
|
4
4
|
<%- if options.ajax %>
|
5
5
|
<div class="page_header_right_tab">
|
6
|
-
<%%= link_to t('system.add_by_ajax', :name => '<%= singular_name.humanize %>'), new_<%=
|
6
|
+
<%%= link_to t('system.add_by_ajax', :name => '<%= @model.singular_name.humanize %>'), new_<%= @model.object_name %>_path, :class => 'lightbox various fancybox.ajax' %>
|
7
7
|
</div>
|
8
8
|
<%- end %>
|
9
9
|
</div>
|
10
10
|
|
11
11
|
<div class="inside">
|
12
|
-
<div id="<%= plural_name %>_list">
|
13
|
-
<%%= render '<%= plural_name %>' %>
|
12
|
+
<div id="<%= @model.plural_name %>_list">
|
13
|
+
<%%= render '<%= @model.plural_name %>' %>
|
14
14
|
</div>
|
15
15
|
</div>
|
16
16
|
</div>
|
@@ -1 +1 @@
|
|
1
|
-
$("#<%= plural_name %>_list").html("<%%= escape_javascript( render :partial => "<%= plural_name %>" )%>");
|
1
|
+
$("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render :partial => "<%= @model.plural_name %>" )%>");
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<div id="<%= plural_name %>_new" class="mdwa_new">
|
1
|
+
<div id="<%= @model.plural_name %>_new" class="mdwa_new">
|
2
2
|
<div class="page_header">
|
3
|
-
<h1><%%= t('<%= plural_name %>.new_title') %></h1>
|
3
|
+
<h1><%%= t('<%= @model.plural_name %>.new_title') %></h1>
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="inside">
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<div id="<%= @model.plural_name %>_show" class="mdwa_show">
|
2
|
+
<div class="page_header">
|
3
|
+
<h1><%%= t('<%= @model.plural_name %>.show_title') %></h1>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div class="inside">
|
7
|
+
<%- @model.attributes.each do |attr| %>
|
8
|
+
<div class="field">
|
9
|
+
<label><%%= t '<%= @model.plural_name %>.index_<%= attr.name %>' %></label>
|
10
|
+
<span>
|
11
|
+
<%- if !attr.references? %>
|
12
|
+
<%%= @<%= @model.singular_name %>.<%= attr.name %> %>
|
13
|
+
<%- elsif attr.belongs_to? || attr.nested_one? %>
|
14
|
+
<%%= @<%= @model.singular_name %>.<%= attr.type.singular_name %>.<%= attr.reference %> %>
|
15
|
+
<%- elsif attr.has_many? or attr.nested_many? %>
|
16
|
+
<ul>
|
17
|
+
<%% @<%= @model.singular_name %>.<%= attr.type.plural_name %>.each do |<%= attr.type.singular_name %>| %>
|
18
|
+
<li><%%= <%= attr.type.singular_name %>.<%= attr.reference %> %> </li>
|
19
|
+
<%% end %>
|
20
|
+
</ul>
|
21
|
+
<%- end %>
|
22
|
+
</span>
|
23
|
+
</div>
|
24
|
+
<%- end %>
|
25
|
+
</div>
|
26
|
+
</div>
|
data/lib/mdd.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Mdd
|
2
|
+
module Generators
|
3
|
+
class Model
|
4
|
+
|
5
|
+
attr_accessor :name, :namespace, :attributes
|
6
|
+
|
7
|
+
# Sets the variables by the string
|
8
|
+
# Format: <namespace>/<model>, the namespace is optional.
|
9
|
+
def initialize( arg )
|
10
|
+
|
11
|
+
self.namespace = '' # prevents unitialized variable errors
|
12
|
+
self.namespace = arg.split('/').first.camelize if arg.split('/').count > 1
|
13
|
+
self.name = arg.split('/').last.singularize.camelize
|
14
|
+
|
15
|
+
self.attributes = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
name.underscore =~ /^[a-z][a-z0-9_\/]+$/
|
20
|
+
end
|
21
|
+
|
22
|
+
def klass
|
23
|
+
namespace_scope + name
|
24
|
+
end
|
25
|
+
|
26
|
+
def controller_name
|
27
|
+
namespace_scope + name.pluralize
|
28
|
+
end
|
29
|
+
|
30
|
+
def object_name
|
31
|
+
space + '_' + singular_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def raw
|
35
|
+
klass.underscore
|
36
|
+
end
|
37
|
+
|
38
|
+
def singular_name
|
39
|
+
name.underscore
|
40
|
+
end
|
41
|
+
|
42
|
+
def plural_name
|
43
|
+
name.underscore.pluralize
|
44
|
+
end
|
45
|
+
|
46
|
+
def namespace?
|
47
|
+
!namespace.blank?
|
48
|
+
end
|
49
|
+
|
50
|
+
def space
|
51
|
+
namespace.underscore
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_attribute(model_attribute)
|
55
|
+
self.attributes << model_attribute
|
56
|
+
model_attribute.model = self
|
57
|
+
end
|
58
|
+
|
59
|
+
def simple_attributes
|
60
|
+
attributes.select{ |a| !a.references? }
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def namespace_scope
|
65
|
+
return "#{namespace}::" if namespace?
|
66
|
+
return ''
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -2,10 +2,12 @@ module Mdd
|
|
2
2
|
module Generators
|
3
3
|
|
4
4
|
class ModelAttribute
|
5
|
-
attr_accessor :name, :type, :reference, :reference_type
|
5
|
+
attr_accessor :name, :type, :reference, :reference_type, :model
|
6
6
|
|
7
7
|
STATIC_TYPES = [:boolean, :date, :datetime, :decimal, :float, :integer, :string, :text, :time, :timestamp, :file]
|
8
8
|
|
9
|
+
# Sets the attributes variables
|
10
|
+
# Format: <name>:<type>:<reference>:<reference_type>
|
9
11
|
def initialize( arg )
|
10
12
|
|
11
13
|
# sets the variables by the string
|
@@ -14,11 +16,6 @@ module Mdd
|
|
14
16
|
self.name = split[0]
|
15
17
|
self.reference = split[2]
|
16
18
|
self.reference_type = split[3]
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def references?
|
21
|
-
!STATIC_TYPES.include?(self.type.to_sym)
|
22
19
|
end
|
23
20
|
|
24
21
|
def name=(value)
|
@@ -29,8 +26,26 @@ module Mdd
|
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
29
|
+
def type=(value)
|
30
|
+
if STATIC_TYPES.include?( value.to_sym )
|
31
|
+
@type = value
|
32
|
+
else
|
33
|
+
@type = Model.new value # instance of model
|
34
|
+
raise "Invalid reference type" if @type.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def reference=(value)
|
39
|
+
@reference = value
|
40
|
+
@reference = 'id' if value.blank?
|
41
|
+
end
|
42
|
+
|
43
|
+
def reference_type=(value)
|
44
|
+
@reference_type = value.underscore unless value.blank?
|
45
|
+
end
|
46
|
+
|
32
47
|
def migration_field
|
33
|
-
@migration_field ||= case self.type.to_sym
|
48
|
+
@migration_field ||= case self.type.to_s.to_sym
|
34
49
|
when :string, :file then 'string'
|
35
50
|
when :boolean then 'boolean'
|
36
51
|
when :date then 'date'
|
@@ -45,7 +60,7 @@ module Mdd
|
|
45
60
|
end
|
46
61
|
|
47
62
|
def form_field
|
48
|
-
@form_field ||= case self.type.to_sym
|
63
|
+
@form_field ||= case self.type.to_s.to_sym
|
49
64
|
when :integer then 'number_field'
|
50
65
|
when :float, :decimal then 'text_field'
|
51
66
|
when :file then 'file_field'
|
@@ -57,10 +72,39 @@ module Mdd
|
|
57
72
|
else
|
58
73
|
'text_field'
|
59
74
|
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def belongs_to?
|
78
|
+
return (reference_type == 'belongs_to')
|
79
|
+
end
|
80
|
+
|
81
|
+
def has_many?
|
82
|
+
return (reference_type == 'has_many')
|
83
|
+
end
|
84
|
+
|
85
|
+
def nested_many?
|
86
|
+
return (reference_type == 'nested_many')
|
87
|
+
end
|
88
|
+
|
89
|
+
def nested?
|
90
|
+
nested_many? || nested_one?
|
91
|
+
end
|
60
92
|
|
61
|
-
|
93
|
+
def nested_one?
|
94
|
+
return (reference_type == 'nested_one')
|
95
|
+
end
|
96
|
+
|
97
|
+
def has_one?
|
98
|
+
return (reference_type == 'has_one')
|
99
|
+
end
|
100
|
+
|
101
|
+
def has_and_belongs_to_many?
|
102
|
+
return (reference_type == 'has_and_belongs_and_to_many')
|
103
|
+
end
|
104
|
+
|
105
|
+
def references?
|
106
|
+
!STATIC_TYPES.include?(self.type.to_s.to_sym)
|
62
107
|
end
|
63
|
-
|
64
108
|
end
|
65
109
|
|
66
110
|
end
|
data/lib/mdd/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '2.0'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -122,9 +122,16 @@ files:
|
|
122
122
|
- Rakefile
|
123
123
|
- app/helpers/mdd_helper.rb
|
124
124
|
- app/views/template/mdwa/_autocomplete_tag.html.erb
|
125
|
+
- app/views/template/mdwa/_crud_error.html.erb
|
125
126
|
- app/views/template/mdwa/_login_text.html.erb
|
126
127
|
- app/views/template/mdwa/_notice.html.erb
|
127
128
|
- lib/generators/.DS_Store
|
129
|
+
- lib/generators/mdd/.DS_Store
|
130
|
+
- lib/generators/mdd/association/USAGE
|
131
|
+
- lib/generators/mdd/association/association_generator.rb
|
132
|
+
- lib/generators/mdd/association/templates/.DS_Store
|
133
|
+
- lib/generators/mdd/association/templates/migrate/many_to_many.rb
|
134
|
+
- lib/generators/mdd/association/templates/migrate/one_field.rb
|
128
135
|
- lib/generators/mdd/sandbox/USAGE
|
129
136
|
- lib/generators/mdd/sandbox/sandbox_generator.rb
|
130
137
|
- lib/generators/mdd/sandbox/templates/app/assets/images/.DS_Store
|
@@ -187,6 +194,7 @@ files:
|
|
187
194
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/login_manifest.css
|
188
195
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/public_manifest.css
|
189
196
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/system_manifest.css
|
197
|
+
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/.DS_Store
|
190
198
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/backend.css.erb
|
191
199
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/backend_base.css.erb
|
192
200
|
- lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/cssbase.css
|
@@ -244,10 +252,12 @@ files:
|
|
244
252
|
- lib/generators/mdd/scaffold/templates/.DS_Store
|
245
253
|
- lib/generators/mdd/scaffold/templates/controllers/ajax_controller.rb
|
246
254
|
- lib/generators/mdd/scaffold/templates/controllers/controller.rb
|
255
|
+
- lib/generators/mdd/scaffold/templates/db_migrate/.DS_Store
|
247
256
|
- lib/generators/mdd/scaffold/templates/db_migrate/migrate.rb
|
248
257
|
- lib/generators/mdd/scaffold/templates/models/model.rb
|
249
258
|
- lib/generators/mdd/scaffold/templates/models/module.rb
|
250
259
|
- lib/generators/mdd/scaffold/templates/views/_form.html.erb
|
260
|
+
- lib/generators/mdd/scaffold/templates/views/_form_fields.html.erb
|
251
261
|
- lib/generators/mdd/scaffold/templates/views/_list.html.erb
|
252
262
|
- lib/generators/mdd/scaffold/templates/views/create.js.erb
|
253
263
|
- lib/generators/mdd/scaffold/templates/views/destroy.js.erb
|
@@ -255,9 +265,10 @@ files:
|
|
255
265
|
- lib/generators/mdd/scaffold/templates/views/index.html.erb
|
256
266
|
- lib/generators/mdd/scaffold/templates/views/index.js.erb
|
257
267
|
- lib/generators/mdd/scaffold/templates/views/new.html.erb
|
258
|
-
- lib/generators/mdd/scaffold/templates/views/
|
268
|
+
- lib/generators/mdd/scaffold/templates/views/show.html.erb
|
259
269
|
- lib/mdd.rb
|
260
270
|
- lib/mdd/.DS_Store
|
271
|
+
- lib/mdd/generators/model.rb
|
261
272
|
- lib/mdd/generators/model_attribute.rb
|
262
273
|
- lib/mdd/layout/base.rb
|
263
274
|
- lib/mdd/layout/helper.rb
|