mdd 2.0.1 → 2.0.2

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.
Files changed (28) hide show
  1. data/lib/generators/mdd/association/USAGE +1 -0
  2. data/lib/generators/mdd/association/association_generator.rb +21 -20
  3. data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/login_manifest.js +3 -1
  4. data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/system_manifest.js +1 -0
  5. data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/all_pages.js +4 -2
  6. data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/system_manifest.css +1 -2
  7. data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/backend.css.erb +7 -7
  8. data/lib/generators/mdd/sandbox/templates/app/assets/stylesheets/mdwa/template/template.css.erb +2 -4
  9. data/lib/generators/mdd/sandbox/templates/app/controllers/a/backend_controller.rb +0 -1
  10. data/lib/generators/mdd/scaffold/USAGE +15 -5
  11. data/lib/generators/mdd/scaffold/scaffold_generator.rb +21 -13
  12. data/lib/generators/mdd/scaffold/templates/controllers/ajax_controller.rb +9 -4
  13. data/lib/generators/mdd/scaffold/templates/controllers/controller.rb +5 -3
  14. data/lib/generators/mdd/scaffold/templates/db_migrate/migrate.rb +5 -4
  15. data/lib/generators/mdd/scaffold/templates/views/_form.html.erb +6 -5
  16. data/lib/generators/mdd/scaffold/templates/views/_form_fields.html.erb +30 -27
  17. data/lib/generators/mdd/scaffold/templates/views/_list.html.erb +17 -12
  18. data/lib/generators/mdd/scaffold/templates/views/create.js.erb +1 -1
  19. data/lib/generators/mdd/scaffold/templates/views/destroy.js.erb +1 -1
  20. data/lib/generators/mdd/scaffold/templates/views/index.html.erb +2 -2
  21. data/lib/generators/mdd/scaffold/templates/views/show.html.erb +18 -18
  22. data/lib/mdd.rb +4 -1
  23. data/lib/mdd/generators/model.rb +30 -4
  24. data/lib/mdd/generators/model_attribute.rb +5 -3
  25. data/lib/mdd/layout/helper.rb +7 -2
  26. data/lib/mdd/version.rb +1 -1
  27. metadata +2 -3
  28. data/lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/nested_form.js +0 -46
@@ -1,5 +1,6 @@
1
1
  Description:
2
2
  Generate migrations and models based on ActiveRecord association types.
3
+ Use the model class name.
3
4
 
4
5
  Example:
5
6
  rails g mdd:association Library has_many Books
@@ -21,6 +21,7 @@ module Mdd
21
21
 
22
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
23
  class_option :skip_rake_migrate, :desc => 'Skips rake db:migrate', :type => :boolean, :default => false
24
+ class_option :skip_migrations, :desc => 'Skips migration files', :type => :boolean, :default => false
24
25
  class_option :ask, :desc => 'Asks if the opposite should be generated.', :type => :boolean, :default => false
25
26
 
26
27
  def initialize(*args, &block)
@@ -38,26 +39,7 @@ module Mdd
38
39
  # active record generates join tables alphabetically
39
40
  @ordered_models = [@model1, @model2].sort! {|a,b| a.plural_name <=> b.plural_name}
40
41
  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
42
+
61
43
 
62
44
  def model
63
45
  case @relation.to_sym
@@ -97,6 +79,25 @@ module Mdd
97
79
  end
98
80
 
99
81
  end
82
+
83
+ def migrate
84
+ unless options.skip_migrations
85
+
86
+ @pending_migrations = true
87
+ case @relation.to_sym
88
+ when :belongs_to, :nested_one
89
+ @table = @model1
90
+ @field = @model2
91
+ migration_template 'migrate/one_field.rb', "db/migrate/add_#{@field.singular_name.foreign_key}_to_#{@table.plural_name}.rb"
92
+ when :has_and_belongs_to_many
93
+ migration_template 'migrate/many_to_many.rb', "db/migrate/create_#{many_to_many_table_name}.rb"
94
+ else
95
+ @pending_migrations = false
96
+ end
97
+
98
+ end
99
+
100
+ end
100
101
 
101
102
  def run_rake_db_migrate
102
103
  rake('db:migrate') if !options.skip_rake_migrate and @pending_migrations and yes? 'Run rake db:migrate?'
@@ -1,4 +1,6 @@
1
1
  // Login screen javascript files
2
2
  //
3
3
  //= require jquery
4
- //= require jquery_ujs
4
+ //= require jquery_ujs
5
+ //= require_tree ../jquery
6
+ //= require ./template/all_pages
@@ -5,4 +5,5 @@
5
5
  //= require jquery
6
6
  //= require jquery_ujs
7
7
  //= require_tree ../jquery
8
+ //= require jquery_nested_form
8
9
  //= require_tree ./template
@@ -13,7 +13,7 @@ $(function() {
13
13
 
14
14
  // notices fadeout
15
15
  $('a#system_notice_close, #system_notice').live('click', function() {
16
- $('#system_notice').fadeOut();
16
+ $('#system_notice').remove();
17
17
  });
18
18
 
19
19
  // ajax forms cancel button closes modal window
@@ -46,5 +46,7 @@ function defineOrder( form, action, id ) {
46
46
  }
47
47
 
48
48
  function deleteSystemNotice() {
49
- $('#system_notice').fadeOut('slow');
49
+ $('#system_notice').fadeOut('slow', function() {
50
+ $('#system_notice').remove();
51
+ });
50
52
  }
@@ -7,8 +7,7 @@
7
7
  *= require ./template/cssbase
8
8
  *= require ./template/template
9
9
  *= require ./template/grid
10
- *= require ./template/backend_base
10
+ *= require_tree ../jquery
11
11
  *= require ./template/backend
12
12
  *= require ./template/leftbar
13
- *= require_tree ../jquery
14
13
  */
@@ -83,7 +83,7 @@ div#logged_info {
83
83
  }
84
84
 
85
85
  div#logged_info a {
86
- color: #fff;
86
+ color: #fff;
87
87
  }
88
88
 
89
89
  div#logged_info .welcome, div#logged_info .logout {
@@ -209,8 +209,8 @@ div.inside {
209
209
  }
210
210
 
211
211
  #leftbar ul li {
212
- width: 100%;
213
- border-bottom: 1px solid #4A4A4A;
212
+ width: 100%;
213
+ border-bottom: 1px solid #4A4A4A;
214
214
  border-top: 1px solid #858585;
215
215
  list-style-type: none;
216
216
  margin: 0;
@@ -235,16 +235,16 @@ div.inside {
235
235
  }
236
236
 
237
237
  #leftbar ul.submenu {
238
- background: none repeat scroll 0 0 #555555;
238
+ background: none repeat scroll 0 0 #555555;
239
239
  box-shadow: 0 0 3px #333333 inset;
240
240
  }
241
241
 
242
242
  #leftbar ul.submenu li {
243
- border:none;
243
+ border:none;
244
244
  }
245
245
 
246
246
  #leftbar ul.submenu li a:hover {
247
- background: #5D5D5D !important
247
+ background: #5D5D5D !important
248
248
  }
249
249
 
250
250
  #leftbar ul li a span {
@@ -252,6 +252,6 @@ div.inside {
252
252
  }
253
253
 
254
254
  #leftbar ul.submenu li a span {
255
- margin:0;
255
+ margin:0;
256
256
  padding-left: 25px;
257
257
  }
@@ -85,14 +85,12 @@ a.remove span {
85
85
  /* nested_forms buttons */
86
86
  a.add_nested_fields {
87
87
  background: url( <%= asset_path 'mdwa/icons/add.png' %>) no-repeat scroll 0 50% padding-box transparent;
88
- padding: 0 0 0 19px;
88
+ padding: 0 0 0 20px;
89
89
  }
90
90
 
91
91
  a.remove_nested_fields {
92
92
  background: url(<%= asset_path 'mdwa/icons/remove-icon.png' %>) no-repeat scroll 0 50% padding-box transparent;
93
- padding: 0 0 0 19px;
94
- position: relative;
95
- top: 20px;
93
+ padding: 0 0 0 20px;
96
94
  }
97
95
 
98
96
  /* Rails errors */
@@ -3,7 +3,6 @@ class A::BackendController < ApplicationController
3
3
  before_filter :authenticate_a_user!
4
4
 
5
5
  check_authorization
6
- load_and_authorize_resource
7
6
 
8
7
  def current_ability
9
8
  @current_ability ||= Ability.new(current_user)
@@ -5,12 +5,8 @@ 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
-
12
8
  Example:
13
- It is equal to Rails scaffold if relations are not mentioned.
9
+ It behaves equally to Rails scaffold if relations are not mentioned.
14
10
  The relations syntax:
15
11
 
16
12
  - rails generate mdd:scaffold Product name:string initial_date:date category_id:category:name:belongs
@@ -55,3 +51,17 @@ Example:
55
51
  attr_accessible :name
56
52
  has_one :product_price
57
53
  ...
54
+
55
+
56
+ Restrictions:
57
+ 1. The database must be configured correctly as usual.
58
+ So, run rake db:create before start.
59
+
60
+ 2. For associations, you can use the mdd:association generator.
61
+ It generates several kinds of model relations.
62
+ Scaffold associations will fail for model associations with specific model names, for example:
63
+ rails g mdd:scaffold a/groups name:string --model=group
64
+ rails g mdd:scaffold a/projects name:string group:a/group:name:belongs_to
65
+ For that reason, you should use:
66
+ rails g mdd:scaffold a/projects name:string group:a/group,group:name:belongs_to
67
+
@@ -7,13 +7,14 @@ module Mdd
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
- attr_accessor :model, :create_nested_association
10
+ attr_accessor :model, :specific_model
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 :model, :desc => 'Use if model is different than the scaffold name. Format: "[namespace]/Model"', :type => :string
15
16
  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_migrations, :desc => 'Skips the generation of a new migration.', :type => :boolean, :default => false
17
18
  class_option :skip_timestamp, :desc => 'Skip timestamp generator on migration files.', :type => :boolean, :default => false
18
19
  class_option :skip_interface, :desc => 'Cretes only models, migrations and associations.', :type => :boolean, :default => false
19
20
  class_option :only_interface, :desc => 'Skips models, associations and migrations.', :type => :boolean, :default => false
@@ -22,11 +23,21 @@ module Mdd
22
23
 
23
24
  super
24
25
 
25
- @model = Generators::Model.new( scaffold_name )
26
+ @model = Generators::Model.new( scaffold_name )
26
27
 
27
28
  # model_name is not valid
28
29
  print_usage unless @model.valid?
29
30
 
31
+ # verifies specific model name
32
+ @specific_model = Generators::Model.new( options.model ) unless options.model.blank?
33
+ if !@specific_model.nil?
34
+ if !@specific_model.valid?
35
+ print_usage
36
+ else
37
+ @model.specific_model_name = @specific_model.raw
38
+ end
39
+ end
40
+
30
41
  # sets the model attributes
31
42
  attributes.each do |attribute|
32
43
  @model.add_attribute Generators::ModelAttribute.new( attribute )
@@ -43,8 +54,9 @@ module Mdd
43
54
 
44
55
  def model
45
56
  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"
57
+ model = @model.specific_model || @model
58
+ template 'models/module.rb', "app/models/#{model.space}.rb" if model.namespace?
59
+ template 'models/model.rb', "app/models/#{model.space}/#{model.singular_name}.rb"
48
60
  end
49
61
  end
50
62
 
@@ -76,25 +88,21 @@ module Mdd
76
88
  end
77
89
 
78
90
  def migration
79
- unless options.skip_migration or options.only_interface
91
+ unless options.skip_migrations or options.only_interface
80
92
  migration_template 'db_migrate/migrate.rb', "db/migrate/create_#{@model.plural_name}.rb"
81
93
  end
82
94
  end
83
95
 
84
96
  def associations
85
- unless options.skip_migration or options.only_interface
97
+ unless options.only_interface
86
98
  @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
99
+ generate "mdd:association #{@model.raw} #{attr.reference_type} #{attr.type.raw} #{'--skip_migrations' if options.skip_migrations} #{'--force' if options.force} --skip_rake_migrate --ask"
92
100
  end
93
101
  end
94
102
  end
95
103
 
96
104
  def run_rake_db_migrate
97
- unless options.skip_migration or options.only_interface
105
+ unless options.skip_migrations or options.only_interface
98
106
  rake('db:migrate') if yes? 'Run rake db:migrate?'
99
107
  end
100
108
  end
@@ -1,4 +1,6 @@
1
1
  class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
2
+
3
+ load_and_authorize_resource :class => "<%= @model.klass %>"
2
4
 
3
5
  def index
4
6
  @<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
@@ -17,16 +19,19 @@ class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'Appl
17
19
 
18
20
  def new
19
21
  @<%= @model.singular_name %> = <%= @model.klass %>.new
20
- render :layout => false
22
+ <%- @model.attributes.select {|a| a.nested_one?}.each do |attr| -%>
23
+ @<%= @model.singular_name %>.<%= attr.type.singular_name %> = <%= attr.type.klass %>.new
24
+ <%- end -%>
25
+ render :layout => false
21
26
  end
22
27
 
23
28
  def edit
24
29
  @<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
25
- render :layout => false
30
+ render :layout => false
26
31
  end
27
32
 
28
33
  def create
29
- @<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.object_name %>])
34
+ @<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.to_params %>])
30
35
  @system_notice = t('<%= @model.plural_name %>.create_success') if @<%= @model.singular_name %>.save
31
36
  # loads all <%= @model.plural_name %> to display in the list
32
37
  load_list
@@ -38,7 +43,7 @@ class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'Appl
38
43
 
39
44
  def update
40
45
  @<%= @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 %>])
46
+ @system_notice = t('<%= @model.plural_name %>.update_success') if @<%= @model.singular_name %>.update_attributes(params[:<%= @model.to_params %>])
42
47
 
43
48
  # loads all <%= @model.plural_name %> to display in the list
44
49
  load_list
@@ -1,7 +1,9 @@
1
1
  class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'ApplicationController' %>
2
+
3
+ load_and_authorize_resource :class => "<%= @model.klass %>"
2
4
 
3
5
  def index
4
- @<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
6
+ @<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page]
5
7
 
6
8
  respond_to do |format|
7
9
  format.html
@@ -20,9 +22,9 @@ class <%= @model.controller_name %>Controller < <%= @inherit_controller || 'Appl
20
22
 
21
23
  def new
22
24
  @<%= @model.singular_name %> = <%= @model.klass %>.new
23
- <%- @model.attributes.select {|a| a.nested_one?}.each do |attr| %>
25
+ <%- @model.attributes.select {|a| a.nested_one?}.each do |attr| -%>
24
26
  @<%= @model.singular_name %>.<%= attr.type.singular_name %> = <%= attr.type.klass %>.new
25
- <%- end %>
27
+ <%- end -%>
26
28
 
27
29
  respond_to do |format|
28
30
  format.html
@@ -2,11 +2,12 @@ class Create<%= @model.plural_name.camelize %> < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
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 %>
5
+ <%- @model.simple_attributes.each do |attr| -%>
6
+ t.<%= attr.migration_field %> :<%= attr.name %>
7
+ <%- end -%>
8
+ <%- unless options.skip_timestamps -%>
8
9
  t.timestamps
9
- <%- end %>
10
+ <%- end -%>
10
11
  end
11
12
  end
12
13
 
@@ -1,4 +1,4 @@
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| %>
1
+ <%%= <%= 'nested_' unless @model.attributes.select{|a| a.nested_many?}.count.zero? %>form_for(<%= @model.to_route_object('@') %><%= ', :remote => true, :html => {:class => :mdwa_ajax}' if options.ajax %>) do |f| %>
2
2
 
3
3
  <div id="mdwa_error">
4
4
  <%%= render '/template/mdwa/crud_error', :object => @<%= @model.singular_name %> %>
@@ -11,10 +11,11 @@
11
11
  </div>
12
12
 
13
13
  <div class="actions">
14
- <%- if !options.ajax %>
15
- <%%= link_to t('system.cancel_button'), <%= @model.object_name.pluralize %>_path, :class => :cancel %> <%- else %>
16
- <%%= link_to t('system.cancel_button'), '#', :class => :cancel %> <%- end %>
17
-
14
+ <%- if !options.ajax -%>
15
+ <%%= link_to t('system.cancel_button'), <%= @model.object_name.pluralize %>_path, :class => :cancel %>
16
+ <%- else -%>
17
+ <%%= link_to t('system.cancel_button'), '#', :class => :cancel %>
18
+ <%- end -%>
18
19
  <%%= f.submit :class => :button %>
19
20
  </div>
20
21
 
@@ -1,27 +1,30 @@
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
+ <%- @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 # unless -%>
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 # if -%>
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? -%>
21
+ <%%= ff.link_to_remove t('nested.remove') %>
22
+ <%- end -%>
23
+
24
+ <%% end %>
25
+ <%- unless attr.nested_one? -%>
26
+ <%%= f.link_to_add t('nested.add', :name => '<%= attr.type.singular_name %>'), :<%= attr.type.plural_name %> %>
27
+ <%- end -%>
28
+ </div>
29
+ <%- end # if -%>
30
+ <%- end # model.attributes.each -%>
@@ -2,32 +2,37 @@
2
2
  <thead>
3
3
  <th class="list_show"><%%= t 'system.index_id' %></th>
4
4
  <th class="list_edit"><%%= t 'system.index_edit' %></th>
5
- <%- @model.attributes.each do |attr| %>
5
+ <%- @model.attributes.each do |attr| -%>
6
6
  <th><%%= t '<%= @model.plural_name %>.index_<%= attr.name %>' %></th>
7
- <%- end %>
7
+ <%- end -%>
8
8
  <th class="list_remove"><%%= t 'system.index_remove' %></th>
9
9
  </thead>
10
10
  <%% @<%= @model.plural_name %>.each do |<%= @model.singular_name %>| %>
11
11
  <tr class="<%%= cycle 'odd_line', 'even_line' %>" >
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
12
  <td>
16
- <%- if !attr.references? %>
13
+ <%%= link_to <%= @model.singular_name %>.id, <%= @model.object_name %>_path(<%= @model.singular_name %>) <%= ", :class => 'lightbox various fancybox.ajax'" if options.ajax %> %>
14
+ </td>
15
+ <td>
16
+ <%%= link_to t('system.index_edit_label'), edit_<%= @model.object_name %>_path(<%= @model.singular_name %>) <%= ", :class => 'lightbox various fancybox.ajax'" if options.ajax %> %>
17
+ </td>
18
+ <%- @model.attributes.each do |attr| -%>
19
+ <td>
20
+ <%- if !attr.references? -%>
17
21
  <%%= <%= @model.singular_name %>.<%= attr.name %> %>
18
- <%- elsif attr.belongs_to? || attr.nested_one? %>
22
+ <%- elsif attr.belongs_to? || attr.nested_one? -%>
19
23
  <%%= <%= @model.singular_name %>.<%= attr.type.singular_name %>.<%= attr.reference %> %>
20
- <%- elsif attr.has_many? or attr.nested_many? %>
24
+ <%- elsif attr.has_many? or attr.nested_many? -%>
21
25
  <ul>
22
26
  <%% <%= @model.singular_name %>.<%= attr.type.plural_name %>.each do |<%= attr.type.singular_name %>| %>
23
27
  <li><%%= <%= attr.type.singular_name %>.<%= attr.reference %> %> </li>
24
28
  <%% end %>
25
29
  </ul>
26
- <%- end %>
30
+ <%- end -%>
27
31
  </td>
28
- <%- end %>
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>
32
+ <%- end -%>
33
+ <td>
34
+ <%%= link_to t('system.index_remove_label'), <%= @model.to_route_object %>, :method => :delete, <%= ':remote => true,' if options.ajax %> :data => {:confirm => t('system.index_confirm_deletion')} %>
35
+ </td>
31
36
  </tr>
32
37
  <%% end %>
33
38
  </table>
@@ -2,6 +2,6 @@
2
2
  $("#mdwa_error").html("<%%= escape_javascript( render '/template/mdwa/crud_error', :object => @<%= @model.singular_name %> )%>");
3
3
  <%% else %>
4
4
  $.fancybox.close(true);
5
- $("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render :partial => '<%= @model.plural_name %>' )%>");
5
+ $("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render '<%= @model.plural_name %>' )%>");
6
6
  $('body').append("<%%= escape_javascript( render '/template/mdwa/notice', :notice => @system_notice )%>");
7
7
  <%% end %>
@@ -1,2 +1,2 @@
1
- $("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render :partial => '<%= @model.plural_name %>' )%>");
1
+ $("#<%= @model.plural_name %>_list").html("<%%= escape_javascript( render '<%= @model.plural_name %>' )%>");
2
2
  $('body').append("<%%= escape_javascript( render '/template/mdwa/notice', :notice => @system_notice )%>");
@@ -1,11 +1,11 @@
1
1
  <div id="<%= @model.plural_name %>_index" class="mdwa_index">
2
2
  <div class="page_header">
3
3
  <h1><%%= t '<%= @model.plural_name %>.index_title' %></h1>
4
- <%- if options.ajax %>
4
+ <%- if options.ajax -%>
5
5
  <div class="page_header_right_tab">
6
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
- <%- end %>
8
+ <%- end -%>
9
9
  </div>
10
10
 
11
11
  <div class="inside">
@@ -4,23 +4,23 @@
4
4
  </div>
5
5
 
6
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 %>
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
25
  </div>
26
26
  </div>
data/lib/mdd.rb CHANGED
@@ -17,4 +17,7 @@ module Mdd
17
17
  end
18
18
 
19
19
  # include the layout selector in ApplicationController
20
- ActionController::Base.send :include, Mdd::Layout::Helper
20
+ ActionController::Base.send :include, Mdd::Layout::Helper
21
+ ActiveSupport.on_load(:action_controller) do
22
+ helper_method "current_page"
23
+ end
@@ -2,7 +2,7 @@ module Mdd
2
2
  module Generators
3
3
  class Model
4
4
 
5
- attr_accessor :name, :namespace, :attributes
5
+ attr_accessor :name, :namespace, :attributes, :specific_model_name
6
6
 
7
7
  # Sets the variables by the string
8
8
  # Format: <namespace>/<model>, the namespace is optional.
@@ -10,17 +10,30 @@ module Mdd
10
10
 
11
11
  self.namespace = '' # prevents unitialized variable errors
12
12
  self.namespace = arg.split('/').first.camelize if arg.split('/').count > 1
13
- self.name = arg.split('/').last.singularize.camelize
13
+ self.name = arg.split('/').last.singularize.camelize
14
14
 
15
- self.attributes = []
15
+ self.attributes = []
16
16
  end
17
17
 
18
18
  def valid?
19
19
  name.underscore =~ /^[a-z][a-z0-9_\/]+$/
20
20
  end
21
+
22
+ def specific?
23
+ !specific_model_name.blank?
24
+ end
25
+
26
+ def specific_model
27
+ return Model.new( specific_model_name ) if specific?
28
+ return nil
29
+ end
21
30
 
22
31
  def klass
23
- namespace_scope + name
32
+ if !specific?
33
+ return (namespace_scope + name)
34
+ else
35
+ return specific_model.klass
36
+ end
24
37
  end
25
38
 
26
39
  def controller_name
@@ -30,6 +43,19 @@ module Mdd
30
43
  def object_name
31
44
  space + '_' + singular_name
32
45
  end
46
+
47
+ def to_params
48
+ if !specific?
49
+ return object_name
50
+ else
51
+ return singular_name
52
+ end
53
+ end
54
+
55
+ def to_route_object(prefix = '')
56
+ return "#{prefix}#{singular_name}" if !specific? or !namespace?
57
+ return "[ :#{space}, #{prefix}#{singular_name}]" if specific? and namespace?
58
+ end
33
59
 
34
60
  def raw
35
61
  klass.underscore
@@ -7,7 +7,7 @@ module Mdd
7
7
  STATIC_TYPES = [:boolean, :date, :datetime, :decimal, :float, :integer, :string, :text, :time, :timestamp, :file]
8
8
 
9
9
  # Sets the attributes variables
10
- # Format: <name>:<type>:<reference>:<reference_type>
10
+ # Format: <name>:<type>||<model>:<reference>:<reference_type>
11
11
  def initialize( arg )
12
12
 
13
13
  # sets the variables by the string
@@ -20,7 +20,7 @@ module Mdd
20
20
 
21
21
  def name=(value)
22
22
  if references? and !value.end_with?('_id')
23
- @name = "#{value}_id"
23
+ @name = "#{value.singularize}_id"
24
24
  else
25
25
  @name = value
26
26
  end
@@ -30,7 +30,9 @@ module Mdd
30
30
  if STATIC_TYPES.include?( value.to_sym )
31
31
  @type = value
32
32
  else
33
- @type = Model.new value # instance of model
33
+ value_split = value.split(',')
34
+ @type = Model.new( value_split.first ) # instance of model
35
+ @type.specific_model_name = value_split.last if value_split.count > 1
34
36
  raise "Invalid reference type" if @type.nil?
35
37
  end
36
38
  end
@@ -12,8 +12,13 @@ module Mdd
12
12
  module ClassMethods
13
13
  def select_layout
14
14
  Base.select_layout "#{request.path_parameters[:controller]}##{request.path_parameters[:action]}"
15
- end
16
- end
15
+ end
16
+
17
+ def current_page
18
+ "#{request.path_parameters[:controller].gsub('/', '_').underscore}_#{request.path_parameters[:action].underscore}"
19
+ end
20
+
21
+ end
17
22
  end
18
23
 
19
24
  end
data/lib/mdd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mdd
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
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: 2.0.1
4
+ version: 2.0.2
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-26 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -183,7 +183,6 @@ files:
183
183
  - lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/ajaxloader.js
184
184
  - lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/all_pages.js
185
185
  - lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/clicable_title.js
186
- - lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/nested_form.js
187
186
  - lib/generators/mdd/sandbox/templates/app/assets/javascripts/mdwa/template/pagination.js
188
187
  - lib/generators/mdd/sandbox/templates/app/assets/stylesheets/.DS_Store
189
188
  - lib/generators/mdd/sandbox/templates/app/assets/stylesheets/jquery/.DS_Store
@@ -1,46 +0,0 @@
1
- $(function() {
2
- $('form a.add_nested_fields').live('click', function() {
3
- // Setup
4
- var assoc = $(this).attr('data-association'); // Name of child
5
- var content = $('#' + assoc + '_fields_blueprint').html(); // Fields template
6
-
7
- // Make the context correct by replacing new_<parents> with the generated ID
8
- // of each of the parent objects
9
- var context = ($(this).closest('.fields').find('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
10
-
11
- // context will be something like this for a brand new form:
12
- // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105]
13
- // or for an edit form:
14
- // project[tasks_attributes][0][assignments_attributes][1]
15
- if(context) {
16
- var parent_names = context.match(/[a-z_]+_attributes/g) || [];
17
- var parent_ids = context.match(/[0-9]+/g);
18
-
19
- for(i = 0; i < parent_names.length; i++) {
20
- if(parent_ids[i]) {
21
- content = content.replace(
22
- new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
23
- '$1[' + parent_ids[i] + ']'
24
- )
25
- }
26
- }
27
- }
28
-
29
- // Make a unique ID for the new child
30
- var regexp = new RegExp('new_' + assoc, 'g');
31
- var new_id = new Date().getTime();
32
- content = content.replace(regexp, new_id);
33
-
34
- $(this).before(content);
35
- return false;
36
- });
37
-
38
- $('form a.remove_nested_fields').live('click', function() {
39
- var hidden_field = $(this).prev('input[type=hidden]')[0];
40
- if(hidden_field) {
41
- hidden_field.value = '1';
42
- }
43
- $(this).closest('.fields').hide();
44
- return false;
45
- });
46
- });