railsbuilder 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45d6b14d1a55a45a60dd93200ab4b6f9c74c55fd
4
- data.tar.gz: b588dd06cba0132e028012a1face9cbbf20b632c
3
+ metadata.gz: a6794f4c2e0e4f6403958c51e9c113ff42fad11b
4
+ data.tar.gz: 94b747e141aae1bd12754846aae778f87898cb55
5
5
  SHA512:
6
- metadata.gz: 88cf4b6d5956ec1d8b00351807ae78a4093482272a5095c0296d7d9aa106424212068acdf31ea29304a5514ee57b82e9793ae3c8636550c682d90b37e7815d5a
7
- data.tar.gz: 06a5c0a37cf73071b4fd286772d109ac314ff75ffbd8cec82424e3ad12e3c633d2ec63dbb0181aa5dc1f91e7fa26c686d925fa1b8b869a82e8e8d34e6cc5001f
6
+ metadata.gz: 6cefd11e1f458f8c37cd5c03d79d529e7873ab1030de80e7b429f1496a19150f9b58de20ba070ea6ed0ae94f5fd241aada91a7c0c69aef9b50d581bb3735018d
7
+ data.tar.gz: effe9db74ca5a0aa83399cddf5ceb20e1357e335484135ab90f864f51d0aab35b47cf6a4c70fb109888fbf6fd99b478ab841ee420ad77e667de398e34135c4f3
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/railsbuilder.rb CHANGED
@@ -6,10 +6,13 @@ require 'fileutils'
6
6
  require 'io/console'
7
7
  require 'lineparser'
8
8
  require 'rdiscount'
9
+ require 'yaml'
9
10
 
10
11
 
11
12
  class RailsBuilder
12
13
 
14
+ attr_accessor :notifications
15
+
13
16
  def initialize(filepath=nil)
14
17
 
15
18
  buffer = File.read File.expand_path(filepath) if filepath
@@ -31,17 +34,19 @@ class RailsBuilder
31
34
  ]
32
35
 
33
36
  parse(patterns, buffer.gsub(/^(\s{,5})#/,'\1;'))
37
+ @parent_path = Dir.pwd
38
+ @notifications = []
39
+
34
40
  end
35
41
 
36
42
  def build()
37
43
 
38
44
  doc = self.to_doc.root
39
-
45
+
40
46
  @app = app = doc.element('app/@app')
41
47
  return unless app
42
-
48
+
43
49
  app_path = doc.element('app_path/@app_path')
44
-
45
50
  Dir.chdir app_path if app_path
46
51
 
47
52
  unless File.exists? app then
@@ -51,6 +56,11 @@ class RailsBuilder
51
56
  puts 'Are you sure you want to build a new app? (Y/n)'
52
57
 
53
58
  shell command
59
+
60
+ trigger = "config: new app entry found which doesn't yet " \
61
+ + "exist as a file directory"
62
+ activity = "new Rails app created"
63
+ @notifications << [trigger,activity]
54
64
  end
55
65
 
56
66
  Dir.chdir app
@@ -69,9 +79,15 @@ class RailsBuilder
69
79
  regex = / #( root 'welcome#index')/
70
80
 
71
81
  if buffer[regex] or not buffer[/root '#{root}'/] then
82
+
72
83
  puts ':: updating ' + routes
73
84
  File.write routes, buffer.sub(regex, ' \1')\
74
85
  .sub(/'[^']+'/,"'" + root + "'")
86
+
87
+ trigger = "config: new root added or changed"
88
+ activity = "file: config/routes.rb modified"
89
+ data = /^\s*root\s+'#{root}'/
90
+ @notifications << [trigger, activity, data]
75
91
  end
76
92
  end
77
93
 
@@ -87,13 +103,19 @@ class RailsBuilder
87
103
  File.write routes, buffer.sub(/\n resources :\w+/,'')\
88
104
  .sub(/ # resources :products/) \
89
105
  {|x| x + "\n resources :#{resources}"}
106
+
107
+ trigger = "config: resources entry has been changed"
108
+ activity = "file: config/routes.rb modified"
109
+ data = /resources\s+:#{resources}/
110
+ @notifications << [trigger, activity, data]
90
111
  end
91
112
  end
92
113
 
93
114
  doc.xpath('resource').each do |node|
94
-
115
+
95
116
  resource = node.attributes[:resource]
96
117
 
118
+
97
119
  next unless resource
98
120
 
99
121
  controller = resource + '_controller.rb'
@@ -114,6 +136,10 @@ class RailsBuilder
114
136
  puts 'Are you sure you want to generate a controller? (Y/n)'
115
137
 
116
138
  shell command
139
+
140
+ trigger = "config: resources entry has been changed"
141
+ activity = "file: created app/controllers/posts_controller.rb"
142
+ @notifications << [trigger, activity]
117
143
  end
118
144
 
119
145
  # if the model fields are defined let's generate the model
@@ -135,15 +161,25 @@ class RailsBuilder
135
161
  r = shell command
136
162
  next if r == :abort
137
163
 
164
+ trigger = "config: a new model with associated entries has "
165
+ + "been created"
166
+ activity = "file: created app/models/#{class_name.downcase}.rb"
167
+ @notifications << [trigger, activity]
168
+
138
169
  # -- next command ---------------------
139
170
 
140
171
  command = "rake db:migrate"
141
172
 
142
173
  puts ":: preparing to execute shell command: `#{command}`"
143
- puts 'Are you sure you want to commit this ' \
174
+ puts 'Are you sure you want to commit this '
144
175
  + 'database operation? (Y/n)'
145
176
  shell command
146
177
 
178
+ trigger = "config: a new model with associated entries has "
179
+ + "been created"
180
+ activity = "database: created"
181
+ @notifications << [trigger, activity]
182
+
147
183
  when :resource_cv
148
184
 
149
185
  # fetch the action name
@@ -166,8 +202,15 @@ class RailsBuilder
166
202
  regex = /class \w+Controller < ApplicationController/
167
203
 
168
204
  unless File.exists? view_file then
205
+
169
206
  File.write view_file, ''
170
207
  puts ':: created ' + page
208
+
209
+ trigger = "config: the 1st action has been "\
210
+ + "created in the controller"
211
+ activity = "file: created " + view_file
212
+ @notifications << [trigger, activity]
213
+
171
214
  end
172
215
 
173
216
  child.elements.each do |av|
@@ -177,9 +220,16 @@ class RailsBuilder
177
220
  page = action + '.html.erb'
178
221
 
179
222
  unless buffer[/\bdef #{action}/] then
223
+
180
224
  buffer.sub!(regex) {|x| x + "\n def #{action}\n end\n" }
181
225
  File.write controller_file, buffer
182
226
  puts ':: updated ' + controller
227
+
228
+ trigger = "config: an action has been "\
229
+ + "created in the controller + views section"
230
+ activity = "file: updated " + controller_file
231
+ data = /def #{action}/
232
+ @notifications << [trigger, activity, data]
183
233
  end
184
234
 
185
235
  av_type = av.attributes[:captures1]
@@ -193,6 +243,12 @@ class RailsBuilder
193
243
  unless File.exists? view_file then
194
244
  File.write view_file, ''
195
245
  puts ':: created ' + page
246
+
247
+ trigger = "config: an action has been "\
248
+ + "created in the controller + views section"
249
+ activity = "file: updated " + controller_file
250
+ data = /def #{action}/
251
+ @notifications << [trigger, activity, data]
196
252
  end
197
253
 
198
254
  # does it contain a renderer? e.g. markdown
@@ -219,6 +275,12 @@ class RailsBuilder
219
275
  unless buffer[/#{html}/] then
220
276
  File.write view_file, html + "\n" + buffer
221
277
  puts ':: updated ' + view_file
278
+
279
+ trigger = "config: a rendering block has been "\
280
+ + "created or modified for an action"
281
+ activity = "file: updated " + view_file
282
+ data = /#{html}/
283
+ @notifications << [trigger, activity, data]
222
284
  end
223
285
  end
224
286
 
@@ -235,6 +297,14 @@ class RailsBuilder
235
297
  puts 'Are you sure you want to generate a ' \
236
298
  + 'controller action? (Y/n)'
237
299
  shell command
300
+
301
+ trigger = "config: a new action has been "\
302
+ + "created in the controller + views section for a "\
303
+ + "resource which doesn't have a model and the "\
304
+ + "controller file doesn't yet exist."
305
+ activity = "file: created " + controller_file
306
+ @notifications << [trigger, activity]
307
+
238
308
  end
239
309
  end
240
310
  end
@@ -243,6 +313,8 @@ class RailsBuilder
243
313
  end # / child iterator
244
314
  end
245
315
 
316
+ Dir.chdir @parent_path
317
+ @notifications.to_yaml
246
318
  end
247
319
 
248
320
  def save()
data.tar.gz.sig CHANGED
Binary file
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.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
@@ -1,4 +1,2 @@
1
- �U��$
2
- ���/:�m@/y�r1�Q9�-�6��;�o
3
- �w�j�n�6=)�Pl��1X0�d<#�H
4
- д�^^�
1
+ D)�dgݽzö�vz�+��t��8�{�7 �}�L-޾��<2��w�K���yr,��X�e�|�g��ٕS�!n-qtJ���I��ݗ�����V��؟�Ar��$��Z��Ł�_�D�(��xHI��12�*�[�g
2
+ ���_i��e��>