railsbuilder 0.1.6 → 0.1.7
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 +4 -4
- checksums.yaml.gz.sig +2 -3
- data/lib/railsbuilder.rb +99 -30
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e53164476e19ca5d875a68d2fed6d91dbf6ca00
|
4
|
+
data.tar.gz: 7e12c6239b7748800ab509f0378e4f0f19f601f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfc24e298082046e9cb2a8c0eef8b6e5b8e7da3907138d93950a349954895bd19d91bf31b90b597b7b812591438a6b42c70277215c856698050bf98e2dff0757
|
7
|
+
data.tar.gz: 44ee196ba21efb7fa38dc9bdff0aaba2477ddc2e91f1a671f9c9d4dba2410ec284c445bfdb0374bbdf12d61eedda7a97be4434f7fba7b9fa44eb7033b9a5e018
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
�<r���d��ݜ�ְ��[�¿�Mz
|
2
|
-
��yC��X�5.&��' �>6?�0�DjY�Ke�%
|
3
|
-
�#"������&a��f�yP9�l_�^���� ��z_�(d��
|
4
1
|
&BY-��$�"���KU���+����Vt9�Ё�$��v:�MJ�̓�]'���d\u�n#!����I�V&5a�u)Ӄ�q�$��=�" �Bj���7mmF&��!7A23I�NZߔ)Ŕ����H:+%�nU�9" ��B}KB6蝗5���
|
2
|
+
�G�
|
3
|
+
����6�c#R����b�Yhk����O���H�폫���f�/3����Q�©���:�EN_k=�����%�h�t�ݧ���d���;w�>�2j�ཬ�G *�t�@�?
|
data/lib/railsbuilder.rb
CHANGED
@@ -9,8 +9,6 @@ require 'lineparser'
|
|
9
9
|
|
10
10
|
class RailsBuilder
|
11
11
|
|
12
|
-
attr_reader :to_h
|
13
|
-
|
14
12
|
def initialize(filepath=nil)
|
15
13
|
|
16
14
|
buffer = File.read File.expand_path(filepath) if filepath
|
@@ -24,37 +22,44 @@ class RailsBuilder
|
|
24
22
|
[:resource, 'model', :model],
|
25
23
|
[:model, ':class_name', :model_class],
|
26
24
|
[:resource, /controller \+ views/, :resource_cv],
|
27
|
-
[:resource_cv, /(\w+)
|
25
|
+
[:resource_cv, /(\w+)(?:\s+[av]{1,2})?/, :resource_cv_av],
|
28
26
|
[:all, /^\s*#/, :comment]
|
29
27
|
]
|
30
28
|
|
31
|
-
|
29
|
+
parse(patterns, buffer)
|
32
30
|
end
|
33
31
|
|
34
32
|
def build()
|
35
33
|
|
36
|
-
|
37
|
-
|
34
|
+
doc = self.to_doc.root
|
35
|
+
|
36
|
+
@app = app = doc.element('app/@app')
|
37
|
+
return unless app
|
38
|
+
|
39
|
+
app_path = doc.element('app_path/@app_path')
|
40
|
+
|
38
41
|
Dir.chdir app_path if app_path
|
39
42
|
|
40
|
-
unless File.exists?
|
43
|
+
unless File.exists? app then
|
41
44
|
|
42
|
-
command = 'rails new ' +
|
45
|
+
command = 'rails new ' + app
|
43
46
|
puts ":: preparing to execute shell command: `#{command}`"
|
44
47
|
puts 'Are you sure you want to build a new app? (Y/n)'
|
45
48
|
|
46
49
|
shell command
|
47
50
|
end
|
48
51
|
|
49
|
-
Dir.chdir
|
52
|
+
Dir.chdir app
|
50
53
|
|
51
54
|
# select the :resource records
|
52
|
-
root =
|
55
|
+
root = doc.element('root/@root')
|
56
|
+
|
57
|
+
routes = File.join('config','routes.rb')
|
53
58
|
|
54
59
|
if root then
|
55
60
|
|
56
61
|
# check if the config/routes.rb file needs updated
|
57
|
-
|
62
|
+
|
58
63
|
buffer = File.read routes
|
59
64
|
|
60
65
|
regex = / #( root 'welcome#index')/
|
@@ -66,31 +71,90 @@ class RailsBuilder
|
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
69
|
-
|
74
|
+
resources = doc.element('resources/@resources')
|
75
|
+
|
76
|
+
if resources then
|
77
|
+
|
78
|
+
buffer = File.read routes
|
79
|
+
|
80
|
+
if not buffer[/\n\s*resources :#{resources}/] then
|
81
|
+
|
82
|
+
puts ':: updating ' + routes
|
83
|
+
File.write routes, buffer.sub(/\n resources :\w+/,'')\
|
84
|
+
.sub(/ # resources :products/) \
|
85
|
+
{|x| x + "\n resources :#{resources}"}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
doc.xpath('resource').each do |node|
|
90
|
+
|
91
|
+
resource = node.attributes[:resource]
|
92
|
+
|
93
|
+
puts 'resource : ' + resource.inspect
|
94
|
+
next unless resource
|
95
|
+
|
96
|
+
controller = resource + '_controller.rb'
|
97
|
+
controller_file = File.join('app','controllers', controller)
|
70
98
|
|
71
|
-
|
72
|
-
resource = raw_resource[1][":resource"]
|
99
|
+
node.each do |child|
|
73
100
|
|
74
|
-
|
101
|
+
case child.name.to_sym
|
75
102
|
|
76
|
-
|
77
|
-
puts "it's a model"
|
78
|
-
when :resource_cv
|
103
|
+
when :model
|
79
104
|
|
80
|
-
|
81
|
-
|
82
|
-
|
105
|
+
# does the controller exitst?
|
106
|
+
|
107
|
+
unless File.exists? controller_file then
|
108
|
+
|
109
|
+
command = "rails g controller %s" % resource
|
110
|
+
puts ":: preparing to execute shell command: `#{command}`"
|
111
|
+
puts 'Are you sure you want to generate a controller? (Y/n)'
|
112
|
+
|
113
|
+
shell command
|
114
|
+
end
|
115
|
+
|
116
|
+
when :resource_cv
|
117
|
+
|
118
|
+
# fetch the action name
|
119
|
+
action = child.element 'resource_cv_av/@captures0'
|
120
|
+
|
121
|
+
if action then
|
122
|
+
|
123
|
+
page = action + '.html.erb'
|
124
|
+
view_file = File.join('app','views', resource, page)
|
125
|
+
|
126
|
+
# if the controller exists don't try to generate the view,
|
127
|
+
# instead add the entry to the controller file and
|
128
|
+
# create the view file
|
129
|
+
|
130
|
+
|
131
|
+
if File.exists? controller_file then
|
132
|
+
|
133
|
+
buffer = File.read controller_file
|
134
|
+
|
135
|
+
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
|
83
139
|
|
84
|
-
|
140
|
+
File.write view_file, ''
|
141
|
+
puts ':: created ' + page
|
85
142
|
|
86
|
-
|
87
|
-
puts ":: preparing to execute shell command: `#{command}`"
|
88
|
-
puts 'Are you sure you want to generate a controller action? (Y/n)'
|
143
|
+
else
|
89
144
|
|
90
|
-
|
91
|
-
end
|
145
|
+
unless File.exists? view_file then
|
92
146
|
|
93
|
-
|
147
|
+
command = "rails generate controller %s %s" % [resource, action]
|
148
|
+
puts ":: preparing to execute shell command: `#{command}`"
|
149
|
+
puts 'Are you sure you want to generate a controller action? (Y/n)'
|
150
|
+
|
151
|
+
shell command
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end # /case when
|
157
|
+
end # / child iterator
|
94
158
|
end
|
95
159
|
|
96
160
|
end
|
@@ -99,6 +163,10 @@ class RailsBuilder
|
|
99
163
|
File.write "#{@app}.cfg", @config
|
100
164
|
end
|
101
165
|
|
166
|
+
def to_doc()
|
167
|
+
Rexle.new(@lp.to_xml)
|
168
|
+
end
|
169
|
+
|
102
170
|
private
|
103
171
|
|
104
172
|
def parse(patterns, s=nil)
|
@@ -125,8 +193,9 @@ EOF
|
|
125
193
|
end
|
126
194
|
|
127
195
|
@config = s
|
128
|
-
|
129
|
-
|
196
|
+
@lp = LineParser.new(patterns)
|
197
|
+
@lp.parse s
|
198
|
+
|
130
199
|
end
|
131
200
|
|
132
201
|
def shell(command)
|
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.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
bNcCWso1cJhifoTCytPAyf9YVuyU4HjqC3eqx3p00NCg0VoELwMEkyhkpvYOGz2l
|
32
32
|
NSkTRB6yCN+xzQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-03-
|
34
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
metadata.gz.sig
CHANGED
Binary file
|