mdd 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,33 +44,36 @@ module Mdd
44
44
  def model
45
45
  case @relation.to_sym
46
46
  when :belongs_to
47
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
48
- "\n\tbelongs_to :#{@model2.singular_name}, :class_name => '#{@model2.klass}'\n\tattr_accessible :#{@model2.singular_name.foreign_key}"
47
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
48
+ ret = []
49
+ ret << "\n\tbelongs_to :#{@model2.singular_name}, :class_name => '#{@model2.klass}'"
50
+ ret << "\tattr_accessible :#{@model2.singular_name.foreign_key}"
51
+ ret.join("\n")
49
52
  end
50
53
  when :has_one
51
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
54
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
52
55
  "\n\thas_one :#{@model2.singular_name}, :class_name => '#{@model2.klass}'\n"
53
56
  end
54
57
  when :has_many
55
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
58
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
56
59
  "\n\thas_many :#{@model2.plural_name}, :class_name => '#{@model2.klass}'\n"
57
60
  end
58
61
  when :has_and_belongs_to_many
59
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
62
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
60
63
  "\n\thas_and_belongs_to_many :#{@model2.plural_name}, :join_table => :#{many_to_many_table_name}\n"
61
64
  end
62
- inject_into_class "app/models/#{@model2.space}/#{@model2.singular_name}.rb", @model2.klass.constantize do
65
+ inject_into_class "app/models/#{@model2.space}/#{@model2.singular_name}.rb", @model2.klass.classify.constantize do
63
66
  "\n\thas_and_belongs_to_many :#{@model1.plural_name}, :join_table => :#{many_to_many_table_name}\n"
64
67
  end
65
68
  when :nested_one
66
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
69
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
67
70
  # belongs_to
68
71
  # attr_accessible attributes
69
72
  # attr_nested_attributes
70
73
  "\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"
71
74
  end
72
75
  when :nested_many
73
- inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.constantize do
76
+ inject_into_class "app/models/#{@model1.space}/#{@model1.singular_name}.rb", @model1.klass.classify.constantize do
74
77
  # belongs_to
75
78
  # attr_accessible attributes
76
79
  # attr_nested_attributes
@@ -156,7 +156,7 @@ module Mdd
156
156
  def db_seeds
157
157
  if ask_question( "Create DB Seeds?")
158
158
  copy_file 'db/seeds/site.rb', 'db/seeds/site.rb'
159
- create_file 'db/seeds.rb'
159
+ create_file 'db/seeds.rb' unless File.exist?('db/seeds.rb')
160
160
  append_file 'db/seeds.rb' do
161
161
  "\nrequire File.expand_path( '../seeds/site', __FILE__ )\n"
162
162
  end
@@ -79,6 +79,32 @@ module Mdd
79
79
  end
80
80
  end
81
81
  end
82
+
83
+ def locales
84
+ destination = 'config/locales/mdwa_model_specific.en.yml'
85
+ inside Rails.root do
86
+ create_file destination unless File.exist?(destination)
87
+ append_file destination, "en:\n"
88
+ end
89
+
90
+ append_file destination, :after => "en:\n" do
91
+ lines = []
92
+ lines << " #{@model.plural_name}:"
93
+ lines << " create_success: \"#{@model.singular_name.humanize} created.\""
94
+ lines << " update_success: \"#{@model.singular_name.humanize} updated.\""
95
+ lines << " destroy_success: \"#{@model.singular_name.humanize} destroyed.\""
96
+ lines << " index_title: \"#{@model.plural_name.humanize}\""
97
+ lines << " show_title: \"#{@model.singular_name.humanize}\""
98
+ lines << " new_title: \"New #{@model.singular_name.humanize}\""
99
+ lines << " edit_title: \"Edit #{@model.singular_name.humanize}\""
100
+ @model.attributes.each do |attr|
101
+ lines << " index_#{attr.name}: \"#{attr.name.humanize}\""
102
+ lines << " show_#{attr.name}: \"#{attr.name.humanize}\""
103
+ end
104
+ lines << "\n"
105
+ lines.join("\n")
106
+ end
107
+ end
82
108
 
83
109
  def routes
84
110
  unless options.skip_interface
@@ -6,7 +6,7 @@
6
6
  <div class="inside">
7
7
  <%- @model.attributes.each do |attr| -%>
8
8
  <div class="field">
9
- <label><%%= t '<%= @model.plural_name %>.index_<%= attr.name %>' %></label>
9
+ <label><%%= t '<%= @model.plural_name %>.show_<%= attr.name %>' %></label>
10
10
  <span>
11
11
  <%- if !attr.references? -%>
12
12
  <%%= @<%= @model.singular_name %>.<%= attr.name %> %>
@@ -7,23 +7,25 @@ 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>||<model>:<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
14
14
  split = arg.split(':')
15
- self.type = split[1]
16
15
  self.name = split[0]
17
16
  self.reference = split[2]
18
17
  self.reference_type = split[3]
18
+ self.type = split[1] # type is the most important, so it's the last for override reasons
19
+
20
+ @raw_string = arg
19
21
  end
22
+
23
+ def raw
24
+ @raw_string
25
+ end
20
26
 
21
27
  def name=(value)
22
- if references? and !value.end_with?('_id')
23
- @name = "#{value.singularize}_id"
24
- else
25
- @name = value
26
- end
28
+ @name = value
27
29
  end
28
30
 
29
31
  def type=(value)
@@ -32,8 +34,11 @@ module Mdd
32
34
  else
33
35
  value_split = value.split(',')
34
36
  @type = Model.new( value_split.first ) # instance of model
35
- @type.specific_model_name = value_split.last if value_split.count > 1
37
+ @type.specific_model_name = value_split.last if value_split.count > 1
36
38
  raise "Invalid reference type" if @type.nil?
39
+
40
+ # rename attribute name if it's a belongs_to association
41
+ self.name = @type.singular_name.foreign_key if belongs_to?
37
42
  end
38
43
  end
39
44
 
data/lib/mdd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mdd
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
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.2
4
+ version: 2.0.3
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-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails