oa_angular_setup 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/generators/oa_angular_setup/install_generator.rb +16 -0
- data/lib/generators/templates/oa_angular_setup_initializer.rb +24 -0
- data/lib/oa_angular_setup/initialize_angular.rb +420 -0
- data/lib/oa_angular_setup/version.rb +3 -0
- data/lib/oa_angular_setup.rb +41 -0
- data/lib/tasks/oa_angular_setup.rake +16 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96ee39082d3740903d1372209ed3a6bc60261d49
|
4
|
+
data.tar.gz: 9de1f74bf4e600d44e709ea866799e192560e8a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28cfadf7cca21ad4b834c26e44e4a0d8ea61228600b182fccc27e313c73d4caf4d6f85c28bdc10f9847a1276a6be52cd2383390d0c38306d1d3a704c4f8d7bae
|
7
|
+
data.tar.gz: c6f0162f6b31331878bbb776fb10afba8bcd93175bd29bc406f5173b3e763d5269863335cbb0c2a9fc3c39b4721e1e1453042b2394e22a6f2b8685604e0783ca
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module OaAngularSetup
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
desc "Creates OaAngularSetup initializer for your application"
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template "oa_angular_setup_initializer.rb", "config/initializers/oa_angular_setup.rb"
|
11
|
+
|
12
|
+
puts "Install complete! Checkout 'config/initializers/oa_angular_setup.rb' to edit the configuration for oa_angular_setup."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
OaAngularSetup.configure do |config|
|
2
|
+
# Set the options to what makes sense for you
|
3
|
+
|
4
|
+
#Name of your app (default: 'App')
|
5
|
+
config.app_name = 'App'
|
6
|
+
|
7
|
+
#Create app.js file true/false (default: true)
|
8
|
+
config.create_app_js = true
|
9
|
+
|
10
|
+
#Create factories true/false (default: true)
|
11
|
+
config.create_factories = true
|
12
|
+
|
13
|
+
#Create controllers true/false (default: true)
|
14
|
+
config.create_controllers = true
|
15
|
+
|
16
|
+
#The URL where the gem can find your swagger documentation (default: "http://localhost:3000/api/swagger_doc")
|
17
|
+
config.swagger_doc_url = "http://localhost:3000/api/swagger_doc"
|
18
|
+
|
19
|
+
#The Destination where the files will be created, starting from your Rails.root . (default: "/public/angular/")
|
20
|
+
config.destination = "/public/angular/"
|
21
|
+
|
22
|
+
#Download and implement swagger-ui true/false (default: true)
|
23
|
+
config.add_swaggger_ui = true
|
24
|
+
end
|
@@ -0,0 +1,420 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'rails'
|
4
|
+
class AngularInitializer
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
config = OaAngularSetup.configuration
|
8
|
+
@app_name = config.app_name
|
9
|
+
@factory_name = "#{@app_name}Services"
|
10
|
+
@create_factories = config.create_factories
|
11
|
+
@create_app_js = config.create_app_js
|
12
|
+
@create_controllers = config.create_controllers
|
13
|
+
@url = config.swagger_doc_url
|
14
|
+
@destination = "#{Rails.root}#{config.destination}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_angular
|
18
|
+
#add in swagger ui
|
19
|
+
if OaAngularSetup.configuration.add_swaggger_ui
|
20
|
+
if !File.exists?("#{Rails.root}/public/api/docs/")
|
21
|
+
#get files and move into place
|
22
|
+
Dir.mkdir("#{Rails.root}/public/api") unless File.exists?("#{Rails.root}/public/api")
|
23
|
+
system "npm install swagger-ui" unless File.exists?("#{Rails.root}/node_modules/swagger-ui/")
|
24
|
+
system "cp -R #{Rails.root}/node_modules/swagger-ui/dist #{Rails.root}/public/api/docs"
|
25
|
+
|
26
|
+
#replace dummy url
|
27
|
+
file_name = "#{Rails.root}/public/api/docs/index.html"
|
28
|
+
text = File.read(file_name)
|
29
|
+
new_contents = text.gsub('http://petstore.swagger.io/v2/swagger.json', @url)
|
30
|
+
File.open(file_name, "w") {|file| file.puts new_contents }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
mechanize = Mechanize.new
|
37
|
+
page = mechanize.get(@url)
|
38
|
+
body = JSON.parse(page.body)
|
39
|
+
app_bodies = {}
|
40
|
+
|
41
|
+
body["apis"].each do |api|
|
42
|
+
model = api["path"].split('.')[0]
|
43
|
+
api_page = mechanize.get(@url + model)
|
44
|
+
api_body = JSON.parse(api_page.body)
|
45
|
+
app_bodies[model] = api_body["apis"]
|
46
|
+
|
47
|
+
update_factory(api_body["apis"], model, @factory_name) if @create_factories
|
48
|
+
update_controllers(api_body["apis"], model, @app_name) if @create_controllers
|
49
|
+
end
|
50
|
+
update_app_js(app_bodies) if @create_app_js
|
51
|
+
|
52
|
+
write_backups
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_backups
|
56
|
+
Dir.mkdir("#{@destination}backups/") unless File.exists?("#{@destination}backups/")
|
57
|
+
if @create_factories
|
58
|
+
Dir.mkdir("#{@destination}backups/factories/") unless File.exists?("#{@destination}backups/factories/")
|
59
|
+
FileUtils.cp_r "#{@destination}factories/.", "#{@destination}backups/factories/"
|
60
|
+
end
|
61
|
+
if @create_factories
|
62
|
+
Dir.mkdir("#{@destination}backups/controllers/") unless File.exists?("#{@destination}backups/controllers/")
|
63
|
+
FileUtils.cp_r "#{@destination}controllers/.", "#{@destination}backups/controllers/"
|
64
|
+
end
|
65
|
+
if @create_app_js
|
66
|
+
FileUtils.cp "#{@destination}#{@app_name}.js", "#{@destination}backups/#{@app_name}.js"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def run
|
71
|
+
Dir.mkdir("#{@destination}") unless File.exists?("#{@destination}")
|
72
|
+
mechanize = Mechanize.new
|
73
|
+
page = mechanize.get(@url)
|
74
|
+
body = JSON.parse(page.body)
|
75
|
+
|
76
|
+
if @create_app_js
|
77
|
+
app_js_file = File.open("#{@destination}#{@app_name}.js", 'w')
|
78
|
+
if @create_factories
|
79
|
+
app_js_file.write("var #{@app_name} = angular.module('#{@app_name}', ['ngRoute', '#{@factory_name}']); \n")
|
80
|
+
else
|
81
|
+
app_js_file.write("var #{@app_name} = angular.module('#{@app_name}', ['ngRoute']); \n")
|
82
|
+
end
|
83
|
+
app_js_file.write("\n ");
|
84
|
+
app_js_file.write("#{@app_name}.config(['$routeProvider', function($routeProvider) { \n");
|
85
|
+
app_js_file.write(" $routeProvider.\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
body["apis"].each do |api|
|
89
|
+
model = api["path"].split('.')[0]
|
90
|
+
api_page = mechanize.get(@url + model)
|
91
|
+
api_body = JSON.parse(api_page.body)
|
92
|
+
|
93
|
+
write_factories(api_body["apis"], model, @factory_name) if @create_factories
|
94
|
+
write_app_js(api_body["apis"], model, app_js_file) if @create_app_js
|
95
|
+
write_controllers(api_body["apis"], model, @app_name) if @create_controllers
|
96
|
+
end
|
97
|
+
|
98
|
+
if @create_app_js
|
99
|
+
app_js_file.write(" otherwise({ \n")
|
100
|
+
app_js_file.write(" redirectTo: '/' \n")
|
101
|
+
app_js_file.write(" }); \n")
|
102
|
+
app_js_file.write("}]); \n")
|
103
|
+
if @create_factories
|
104
|
+
app_js_file.write("\n")
|
105
|
+
app_js_file.write("var #{@factory_name} = angular.module('#{@factory_name}', ['ngResource']); \n")
|
106
|
+
end
|
107
|
+
app_js_file.close
|
108
|
+
end
|
109
|
+
write_backups
|
110
|
+
end
|
111
|
+
|
112
|
+
def output_to_angular(outfile_or_string, method, path)
|
113
|
+
string = ""
|
114
|
+
# assuming only called for PUT and GET methods
|
115
|
+
if method == 'GET'
|
116
|
+
command = 'show'
|
117
|
+
elsif method == 'PUT'
|
118
|
+
command = 'update'
|
119
|
+
else
|
120
|
+
puts "problem. method not GET or PUT"
|
121
|
+
return
|
122
|
+
end
|
123
|
+
if path.include?("id")
|
124
|
+
ep_path = path.split('/')
|
125
|
+
if ep_path[4].nil?
|
126
|
+
string += " #{command}: {method:'#{method}'}"
|
127
|
+
else
|
128
|
+
action = ep_path[4].split(".")[0]
|
129
|
+
if method == 'GET'
|
130
|
+
string += " #{action}: {method:'#{method}', isArray:true, params:{action:'#{action}'}}"
|
131
|
+
else
|
132
|
+
string += " #{action}: {method:'#{method}', params:{action:'#{action}'}}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
else
|
136
|
+
string += " query: {method:'#{method}', isArray:true}"
|
137
|
+
end
|
138
|
+
if outfile_or_string.is_a?(File)
|
139
|
+
outfile_or_string.write(string)
|
140
|
+
else
|
141
|
+
return string
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def write_factories(apis, model, name)
|
146
|
+
Dir.mkdir("#{@destination}factories") unless File.exists?("#{@destination}factories")
|
147
|
+
|
148
|
+
fh1 = name + ".factory('"
|
149
|
+
fh2 = "', ['$resource', function($resource){\n"
|
150
|
+
output = []
|
151
|
+
fname = "#{@destination}factories/" + model.gsub("/","") + "_factory.js"
|
152
|
+
output_string = fh1 + model.gsub("/","").chomp('s').capitalize + fh2
|
153
|
+
output_string += " return $resource('api/v1" + model + "/:id/:action', {}, { \n"
|
154
|
+
|
155
|
+
apis.each do |endpoint|
|
156
|
+
endpoint["operations"].each do |op|
|
157
|
+
string = write_factory(endpoint, op)
|
158
|
+
string = " // #{op['summary']} \n"+string
|
159
|
+
output.push(string)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
output_string += output.join(",\n")
|
164
|
+
output_string += "\n });\n"
|
165
|
+
output_string += "}]);\n"
|
166
|
+
|
167
|
+
outfile = File.open(fname, 'w')
|
168
|
+
outfile.write(output_string)
|
169
|
+
outfile.close
|
170
|
+
end
|
171
|
+
|
172
|
+
def write_app_js(apis, model_name, outfile)
|
173
|
+
model = model_name.delete('/')
|
174
|
+
apis.each do |endpoint|
|
175
|
+
endpoint["operations"].each do |op|
|
176
|
+
case op["method"]
|
177
|
+
when /GET/
|
178
|
+
ep_path = endpoint["path"].split('/')
|
179
|
+
if ep_path[4].nil?
|
180
|
+
if endpoint["path"].include?("id")
|
181
|
+
outfile.write(" when('/#{model}/:id', { \n")
|
182
|
+
outfile.write(" template@url: '/angular/templates/#{model}/show.html', \n")
|
183
|
+
outfile.write(" controller: '#{model.capitalize}ShowCtrl' \n")
|
184
|
+
else
|
185
|
+
ctrl = 'index'
|
186
|
+
outfile.write(" when('/#{model}', { \n")
|
187
|
+
outfile.write(" template@url: '/angular/templates/#{model}/index.html',\n")
|
188
|
+
outfile.write(" controller: '#{model.capitalize}IndexCtrl' \n")
|
189
|
+
end
|
190
|
+
outfile.write(" }). \n")
|
191
|
+
end
|
192
|
+
when /PUT/
|
193
|
+
ep_path = endpoint["path"].split('/')
|
194
|
+
if ep_path[4].nil?
|
195
|
+
outfile.write(" when('/#{model}/:id/edit', { \n")
|
196
|
+
outfile.write(" template@url: '/angular/templates/#{model}/edit.html', \n")
|
197
|
+
outfile.write(" controller: '#{model.capitalize}EditCtrl' \n")
|
198
|
+
outfile.write(" }). \n")
|
199
|
+
end
|
200
|
+
when /POST/
|
201
|
+
outfile.write(" when('/#{model}/new', { \n")
|
202
|
+
outfile.write(" template@url: '/angular/templates/#{model}/new.html', \n")
|
203
|
+
outfile.write(" controller: '#{model.capitalize}NewCtrl' \n")
|
204
|
+
outfile.write(" }). \n")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def write_controllers(apis, model_name, app_name)
|
211
|
+
Dir.mkdir("#{@destination}controllers") unless File.exists?("#{@destination}controllers")
|
212
|
+
model = model_name.delete('/')
|
213
|
+
output = []
|
214
|
+
apis.each do |endpoint|
|
215
|
+
endpoint["operations"].each do |op|
|
216
|
+
string,controller_title = write_controller(model, endpoint, op)
|
217
|
+
output.push(string)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
outfile = File.open("#{@destination}controllers/#{model}_controllers.js", 'w')
|
221
|
+
outfile.write(output.join)
|
222
|
+
outfile.close
|
223
|
+
end
|
224
|
+
|
225
|
+
def update_factory(apis, model, name)
|
226
|
+
Dir.mkdir("#{@destination}factories") unless File.exists?("#{@destination}factories")
|
227
|
+
|
228
|
+
fh1 = name + ".factory('"
|
229
|
+
fh2 = "', ['$resource', function($resource){\n"
|
230
|
+
fname = "#{@destination}factories/" + model.gsub("/","") + "_factory.js"
|
231
|
+
# backup_contents = File.read("#{@destination}backups/factories/" + model.gsub("/","") + "_factory.js").split("\n")
|
232
|
+
file_contents = File.read(fname)
|
233
|
+
file_contents_lines = file_contents.split("\n")
|
234
|
+
first_lines = file_contents_lines.shift(2)
|
235
|
+
output_string = first_lines.join("\n")+"\n"
|
236
|
+
file_contents_lines.pop(2) #drop last two closing lines so they arent added twice
|
237
|
+
paths = file_contents.scan(/\n\s*(\w*?):/i).flatten
|
238
|
+
|
239
|
+
output = []
|
240
|
+
file_contents_lines.each_with_index do |line, index|
|
241
|
+
output.push(line.chomp(","))
|
242
|
+
end
|
243
|
+
|
244
|
+
apis.each do |endpoint|
|
245
|
+
endpoint["operations"].each do |op|
|
246
|
+
string = write_factory(endpoint, op)
|
247
|
+
next if output.include?(string)
|
248
|
+
next if(paths.include?(string.split(":")[0]))
|
249
|
+
string = " // #{op['summary']} \n"+string
|
250
|
+
output.push(string)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
output_string += output.join(",\n")
|
255
|
+
output_string += "\n });\n"
|
256
|
+
output_string += "}]);\n"
|
257
|
+
|
258
|
+
outfile = File.open(fname, 'w')
|
259
|
+
outfile.write(output_string)
|
260
|
+
outfile.close
|
261
|
+
end
|
262
|
+
|
263
|
+
def write_controller(model, endpoint, op)
|
264
|
+
string = ""
|
265
|
+
controller_title = ""
|
266
|
+
service = model.chomp('s').capitalize
|
267
|
+
ep_path = endpoint["path"].split('/')
|
268
|
+
case op["method"]
|
269
|
+
when /GET/
|
270
|
+
if ep_path[4].nil?
|
271
|
+
if endpoint["path"].include?("id")
|
272
|
+
controller_title = "#{model.capitalize}ShowCtrl"
|
273
|
+
string += "angular.module('#{@app_name}').controller('#{controller_title}', ['$scope', '$routeParams', '#{service}', function ($scope, $routeParams, #{service}) { \n"
|
274
|
+
string += " $scope.id = $routeParams.id; \n"
|
275
|
+
string += "}]); \n"
|
276
|
+
string += " \n"
|
277
|
+
else
|
278
|
+
controller_title = "#{model.capitalize}IndexCtrl"
|
279
|
+
string += "angular.module('#{@app_name}').controller('#{controller_title}', ['$scope', '#{service}', function ($scope, #{service}) { \n"
|
280
|
+
string += " $scope.#{model} = #{service}.query(); \n"
|
281
|
+
string += "}]); \n"
|
282
|
+
string += " \n"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
when /PUT/
|
286
|
+
if ep_path[4].nil?
|
287
|
+
controller_title = "#{model.capitalize}EditCtrl"
|
288
|
+
string += "angular.module('#{@app_name}').controller('#{controller_title}', ['$scope', '$routeParams', '#{service}', function ($scope, $routeParams, #{service}) { \n"
|
289
|
+
string += " $scope.id = $routeParams.id; \n"
|
290
|
+
string += "}]); \n"
|
291
|
+
string += " \n"
|
292
|
+
end
|
293
|
+
when /POST/
|
294
|
+
controller_title = "#{model.capitalize}NewCtrl"
|
295
|
+
string += "angular.module('#{@app_name}').controller('#{controller_title}', ['$scope', '#{service}', function ($scope, #{service}) { \n"
|
296
|
+
string += "}]); \n"
|
297
|
+
string += " \n"
|
298
|
+
end
|
299
|
+
|
300
|
+
return string, controller_title
|
301
|
+
end
|
302
|
+
|
303
|
+
def write_factory(endpoint, op)
|
304
|
+
string = ""
|
305
|
+
case op["method"]
|
306
|
+
when /GET/
|
307
|
+
string = output_to_angular(string, op["method"], endpoint["path"])
|
308
|
+
when /PUT/
|
309
|
+
string = output_to_angular(string, op["method"], endpoint["path"])
|
310
|
+
when /POST/
|
311
|
+
string = " create: {method:'POST'}"
|
312
|
+
when /DELETE/
|
313
|
+
string = " destroy: {method:'DELETE'}"
|
314
|
+
end
|
315
|
+
|
316
|
+
return string
|
317
|
+
end
|
318
|
+
|
319
|
+
def update_controllers(apis, model_name, app_name)
|
320
|
+
Dir.mkdir("#{@destination}controllers") unless File.exists?("#{@destination}controllers")
|
321
|
+
output, edited_controller_titles = [], []
|
322
|
+
model = model_name.delete('/')
|
323
|
+
file_contents = File.read("#{@destination}controllers/#{model}_controllers.js")
|
324
|
+
controller_names = file_contents.scan(/controller\('(.*?)'/im).flatten
|
325
|
+
controllers = file_contents.scan(/angular.module.*?}\]\);/im)
|
326
|
+
|
327
|
+
controllers.each do |controller|
|
328
|
+
output.push(controller+" \n \n")
|
329
|
+
end
|
330
|
+
|
331
|
+
apis.each do |endpoint|
|
332
|
+
endpoint["operations"].each do |op|
|
333
|
+
string,controller_title = write_controller(model, endpoint, op)
|
334
|
+
|
335
|
+
output.push(string) unless controller_names.include?(controller_title)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
outfile = File.open("#{@destination}controllers/#{model}_controllers.js", 'w')
|
339
|
+
outfile.write(output.join)
|
340
|
+
outfile.close
|
341
|
+
end
|
342
|
+
|
343
|
+
def update_app_js(apis)
|
344
|
+
output, edited_routes = [],[]
|
345
|
+
file_contents = File.read("#{@destination}#{@app_name}.js")
|
346
|
+
routes = file_contents.scan(/when\(.*?}\)\./im)
|
347
|
+
route_paths = file_contents.scan(/when\('(.*?)'/im).flatten
|
348
|
+
|
349
|
+
if @create_app_js
|
350
|
+
if @create_factories
|
351
|
+
output.push("var #{@app_name} = angular.module('#{@app_name}', ['ngRoute', '#{@factory_name}']); \n")
|
352
|
+
else
|
353
|
+
output.push("var #{@app_name} = angular.module('#{@app_name}', ['ngRoute']); \n")
|
354
|
+
end
|
355
|
+
output.push("\n #{@app_name}.config(['$routeProvider', function($routeProvider) { \n $routeProvider.\n");
|
356
|
+
end
|
357
|
+
|
358
|
+
routes.each_with_index do |route, index|
|
359
|
+
output.push(" #{route} \n ")
|
360
|
+
end
|
361
|
+
|
362
|
+
apis.each do |model_name, model_api|
|
363
|
+
model = model_name.delete('/')
|
364
|
+
model_api.each do |endpoint|
|
365
|
+
endpoint["operations"].each do |op|
|
366
|
+
string , route_path = "",""
|
367
|
+
case op["method"]
|
368
|
+
when /GET/
|
369
|
+
ep_path = endpoint["path"].split('/')
|
370
|
+
if ep_path[4].nil?
|
371
|
+
if endpoint["path"].include?("id")
|
372
|
+
route_path = "/#{model}/:id"
|
373
|
+
string += " when('#{route_path}', { \n"
|
374
|
+
string += " template@url: '/angular/templates/#{model}/show.html', \n"
|
375
|
+
string += " controller: '#{model.capitalize}ShowCtrl' \n"
|
376
|
+
else
|
377
|
+
ctrl = 'index'
|
378
|
+
route_path = "/#{model}"
|
379
|
+
string += " when('#{route_path}', { \n"
|
380
|
+
string += " template@url: '/angular/templates/#{model}/index.html',\n"
|
381
|
+
string += " controller: '#{model.capitalize}IndexCtrl' \n"
|
382
|
+
end
|
383
|
+
string += " }). \n"
|
384
|
+
end
|
385
|
+
when /PUT/
|
386
|
+
ep_path = endpoint["path"].split('/')
|
387
|
+
if ep_path[4].nil?
|
388
|
+
route_path = "/#{model}/:id/edit"
|
389
|
+
string += " when('#{route_path}', { \n"
|
390
|
+
string += " template@url: '/angular/templates/#{model}/edit.html', \n"
|
391
|
+
string += " controller: '#{model.capitalize}EditCtrl' \n"
|
392
|
+
string += " }). \n"
|
393
|
+
end
|
394
|
+
when /POST/
|
395
|
+
route_path = "/#{model}/new"
|
396
|
+
string += " when('#{route_path}', { \n"
|
397
|
+
string += " template@url: '/angular/templates/#{model}/new.html', \n"
|
398
|
+
string += " controller: '#{model.capitalize}NewCtrl' \n"
|
399
|
+
string += " }). \n"
|
400
|
+
end
|
401
|
+
output.push(string) unless route_paths.include?(route_path)
|
402
|
+
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
output.push(" otherwise({ \n")
|
407
|
+
output.push(" redirectTo: '/' \n")
|
408
|
+
output.push(" }); \n")
|
409
|
+
output.push("}]); \n")
|
410
|
+
if @create_factories
|
411
|
+
output.push("\n")
|
412
|
+
output.push("var #{@factory_name} = angular.module('#{@factory_name}', ['ngResource']); \n")
|
413
|
+
end
|
414
|
+
app_js_file = File.open("#{@destination}#{@app_name}.js", 'w')
|
415
|
+
app_js_file.write(output.join)
|
416
|
+
app_js_file.close
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "oa_angular_setup/version"
|
2
|
+
require "oa_angular_setup/initialize_angular"
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module OaAngularSetup
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class Configuration
|
20
|
+
attr_accessor :app_name, :create_factories, :create_app_js,
|
21
|
+
:create_controllers, :swagger_doc_url, :destination, :add_swaggger_ui
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@app_name = 'App'
|
25
|
+
@create_factories = true
|
26
|
+
@create_app_js = true
|
27
|
+
@create_controllers = true
|
28
|
+
@add_swaggger_ui = true
|
29
|
+
@swagger_doc_url = "http://localhost:3000/api/swagger_doc"
|
30
|
+
@destination = "/public/angular/"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Rails
|
35
|
+
class Railtie < ::Rails::Railtie
|
36
|
+
rake_tasks do
|
37
|
+
load "tasks/oa_angular_setup.rake"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "oa_angular_setup/initialize_angular"
|
2
|
+
|
3
|
+
namespace :oa_angular_setup do
|
4
|
+
|
5
|
+
desc 'Create angular server'
|
6
|
+
task :create => :environment do
|
7
|
+
initializer = AngularInitializer.new
|
8
|
+
initializer.run
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Create angular server'
|
12
|
+
task :update => :environment do
|
13
|
+
initializer = AngularInitializer.new
|
14
|
+
initializer.update
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oa_angular_setup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark VanArsdale
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A gem to setup angular factories
|
56
|
+
email:
|
57
|
+
- mark@openarc.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/generators/oa_angular_setup/install_generator.rb
|
63
|
+
- lib/generators/templates/oa_angular_setup_initializer.rb
|
64
|
+
- lib/oa_angular_setup.rb
|
65
|
+
- lib/oa_angular_setup/initialize_angular.rb
|
66
|
+
- lib/oa_angular_setup/version.rb
|
67
|
+
- lib/tasks/oa_angular_setup.rake
|
68
|
+
homepage: https://github.com/openarcllc/oa_angular_setup
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.5.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: A gem to setup angular factories
|
92
|
+
test_files: []
|