railsbuilder 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e53164476e19ca5d875a68d2fed6d91dbf6ca00
4
- data.tar.gz: 7e12c6239b7748800ab509f0378e4f0f19f601f1
3
+ metadata.gz: 311649e88f84c35d430a4b1f24cdca457f92ecd6
4
+ data.tar.gz: 535b72090974228bc0a3cc7a1e68557e8162ef4a
5
5
  SHA512:
6
- metadata.gz: dfc24e298082046e9cb2a8c0eef8b6e5b8e7da3907138d93950a349954895bd19d91bf31b90b597b7b812591438a6b42c70277215c856698050bf98e2dff0757
7
- data.tar.gz: 44ee196ba21efb7fa38dc9bdff0aaba2477ddc2e91f1a671f9c9d4dba2410ec284c445bfdb0374bbdf12d61eedda7a97be4434f7fba7b9fa44eb7033b9a5e018
6
+ metadata.gz: da3f71bd78cffccd22fb2ec0ee035aa3d9da638801b6bb9f1cdae08b271652f52df491f800eae8f2c3dca40efb5ddd48920bc33414603887f2167bc005e5a977
7
+ data.tar.gz: 23e16e223972febb71b427bad4ecaddd0cb610c7e20c3d841871e723f66948eb43cf76ae8a69d80226f67b2d9d3269dcee505f27283b5cd94459466c20065c46
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/railsbuilder.rb CHANGED
@@ -21,6 +21,7 @@ class RailsBuilder
21
21
  [:root, ':resource', :resource],
22
22
  [:resource, 'model', :model],
23
23
  [:model, ':class_name', :model_class],
24
+ [:model_class, /(\w+):\s*(string|text)/, :class_attribute],
24
25
  [:resource, /controller \+ views/, :resource_cv],
25
26
  [:resource_cv, /(\w+)(?:\s+[av]{1,2})?/, :resource_cv_av],
26
27
  [:all, /^\s*#/, :comment]
@@ -71,7 +72,8 @@ class RailsBuilder
71
72
  end
72
73
  end
73
74
 
74
- resources = doc.element('resources/@resources')
75
+ resources = doc.element('resources/@resources')
76
+ puts 'resources :' + resources.inspect
75
77
 
76
78
  if resources then
77
79
 
@@ -90,7 +92,6 @@ class RailsBuilder
90
92
 
91
93
  resource = node.attributes[:resource]
92
94
 
93
- puts 'resource : ' + resource.inspect
94
95
  next unless resource
95
96
 
96
97
  controller = resource + '_controller.rb'
@@ -113,6 +114,28 @@ class RailsBuilder
113
114
  shell command
114
115
  end
115
116
 
117
+ # if the model fields are defined let's generate the model
118
+ model = child.element('model_class')
119
+
120
+ class_name = model.attributes[:class_name]
121
+ attributes = model.xpath('.').map {|x| x.attributes.values}
122
+ s = class_name + ' ' + attributes.map{|x| x.join ':'}.join(' ')
123
+
124
+ command = "rails generate model %s" % s
125
+ puts ":: preparing to execute shell command: `#{command}`"
126
+ puts 'Are you sure you want to generate a model? (Y/n)'
127
+
128
+ shell command
129
+
130
+ # -- next command ---------------------
131
+
132
+ command = "rake db:migrate"
133
+
134
+ puts ":: preparing to execute shell command: `#{command}`"
135
+ puts 'Are you sure you want to commit this database operation? (Y/n)'
136
+
137
+ shell command
138
+
116
139
  when :resource_cv
117
140
 
118
141
  # fetch the action name
@@ -122,7 +145,7 @@ class RailsBuilder
122
145
 
123
146
  page = action + '.html.erb'
124
147
  view_file = File.join('app','views', resource, page)
125
-
148
+
126
149
  # if the controller exists don't try to generate the view,
127
150
  # instead add the entry to the controller file and
128
151
  # create the view file
@@ -133,12 +156,24 @@ class RailsBuilder
133
156
  buffer = File.read controller_file
134
157
 
135
158
  regex = /class \w+Controller < ApplicationController/
136
- buffer.sub!(regex) {|x| x + "\n\n def new\n end\n" }
137
- File.write controller_file, buffer
138
- puts ':: updated ' + controller
139
-
140
- File.write view_file, ''
141
- puts ':: created ' + page
159
+
160
+ unless File.exists? view_file then
161
+ File.write view_file, ''
162
+ puts ':: created ' + page
163
+ end
164
+
165
+ child.elements.each do |av|
166
+
167
+ action = av.attributes[:captures0]
168
+ next unless action
169
+ page = action + '.html.erb'
170
+
171
+ unless buffer[/\bdef #{action}/] then
172
+ buffer.sub!(regex) {|x| x + "\n def #{action}\n end\n" }
173
+ File.write controller_file, buffer
174
+ puts ':: updated ' + controller
175
+ end
176
+ end
142
177
 
143
178
  else
144
179
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railsbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ���d�#>��8��qX�xK�;,�}<D<��"�<�1���2P��<r����U�{S�,�(>�x��p����5DiBl�&x�cyb��@����A�:� ����ɉ4q��
2
- iZw���?j{�:����r�W�>���)~u��]^��<��ld��>ɺkYY�7�w��u��Z�ͩ�W�H��u�J�}e�z�v�hC��,�.(� ���3��|,]`�R�n�Ipl��I���E7��h�b���
1
+ <*!�&Mҁ��+��TlvI�Xd�O4%B���,���?�����q ����bݫD"Wo'~�'�pѺ��(a_�,*�vW��=�b~���̥t��5LhSzŪB�h��> ���Q7Ǽ=�Á.ۃmz��v��"Yaaw�>lh{v��P;�&>�368t��{��Nmelk)�[����;���`��$wpi/R����R��b�H�[��"�ʿ<�d
2
+ e���g���]+\�H{R���W