alex 0.0.1 → 0.0.2
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
- data/.gitignore +1 -0
- data/alex.gemspec +1 -1
- data/lib/alex/cli.rb +284 -14
- data/lib/alex/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc65721d61bb9b02b830c4c26e94414e7990dbee
|
4
|
+
data.tar.gz: 46f2a9b069eafb483310a7e87a3c2e6d7f57e203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe20558b804ffae8af1e4d711b262b018c390028ddc35d7853497896ba1be4a01b9bb7ab307e60bd2e8fa5cd6454898185ed967eb695f9bc7a4c1b39f989c582
|
7
|
+
data.tar.gz: 51117d1dc4ff0c516e05e476123c4134f983109e30ed0632da386fbdadcdb739c0817abf1c3be55875ed5b39595ce93034223e43fdc75f17ab49557ab8cba2d8
|
data/.gitignore
CHANGED
data/alex.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["juangesino@gmail.com"]
|
11
11
|
spec.summary = %q{Alex Command-line tool.}
|
12
12
|
spec.description = %q{Alex is a Ruby on Rails template generator. Alex asks the user some questions to generate the templates and then applies the template to the new app.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://rubygems.org/gems/alex"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/alex/cli.rb
CHANGED
@@ -24,27 +24,33 @@ module Alex
|
|
24
24
|
db = ask("Which do you use for production?\n\n[0] PostgreSQL (default)\n[1] SQLite\n[2] None\n\n")
|
25
25
|
db = 0 if db.blank?
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
puts "\nServer Type:\n"
|
28
|
+
server_type = ask("Which type of server are you building?\n\n[0] WebServer (default)\n[1] API\n[2] WebServer + API\n\n")
|
29
|
+
server_type = 0 if server_type.blank?
|
30
30
|
|
31
31
|
puts "\nDevise:\n"
|
32
|
-
if yes?("Would you like to install Devise?")
|
32
|
+
if yes?("Would you like to install Devise? (default: No)")
|
33
33
|
devise = true
|
34
34
|
|
35
35
|
devise_model_name = ask("What would you like the user model to be called? [user]")
|
36
36
|
devise_model_name = "user" if devise_model_name.blank?
|
37
37
|
|
38
|
-
if yes?("Would you like
|
38
|
+
if yes?("Would you like to generate views and controllers for #{devise_model_name}? (default: No)")
|
39
|
+
devise_model_scaffold = true
|
40
|
+
else
|
41
|
+
devise_model_scaffold = false
|
42
|
+
end
|
43
|
+
|
44
|
+
if yes?("Would you like Devise's views? (default: No)")
|
39
45
|
devise_views = true
|
40
46
|
else
|
41
47
|
devise_views = false
|
42
48
|
end
|
43
49
|
|
44
|
-
if yes?("Would you like to have UserRoles?")
|
50
|
+
if yes?("Would you like to have UserRoles? (default: No)")
|
45
51
|
user_roles = true
|
46
52
|
puts "\nCanCan:\n"
|
47
|
-
if yes?("Would you like to install CanCan to handle authorization?")
|
53
|
+
if yes?("Would you like to install CanCan to handle authorization? (default: No)")
|
48
54
|
cancan = true
|
49
55
|
else
|
50
56
|
cancan = false
|
@@ -54,7 +60,7 @@ module Alex
|
|
54
60
|
end
|
55
61
|
|
56
62
|
puts "\nActiveAdmin:\n"
|
57
|
-
if yes?("Would you like to install ActiveAdmin?")
|
63
|
+
if yes?("Would you like to install ActiveAdmin? (default: No)")
|
58
64
|
active_admin = true
|
59
65
|
else
|
60
66
|
active_admin = false
|
@@ -65,23 +71,43 @@ module Alex
|
|
65
71
|
end
|
66
72
|
|
67
73
|
puts "\nFigaro:\n"
|
68
|
-
if yes?("Would you like to install Figaro?")
|
74
|
+
if yes?("Would you like to install Figaro? (default: No)")
|
69
75
|
figaro = true
|
70
76
|
else
|
71
77
|
figaro = false
|
72
78
|
end
|
73
79
|
|
80
|
+
if server_type.to_i != 1 && yes?("\nCSS Frameworks:\nWould you like to install a CSS Frameworks? (default: No)")
|
81
|
+
css = true
|
82
|
+
css_fw = ask("Which CSS Framework would you like to use?\n\n[0] Bootstrap (default)\n[1] None\n\n")
|
83
|
+
# css_fw = ask("Which CSS Framework would you like to use?\n\n[0] Bootstrap (default)\n[1] MaterialAdmin\n[2] None\n\n")
|
84
|
+
css_fw = 0 if css_fw.blank?
|
85
|
+
else
|
86
|
+
css = false
|
87
|
+
end
|
88
|
+
|
89
|
+
if server_type.to_i != 1 && yes?("\nControllers:\nWould you like me to create a PagesController for your root page? (default: No)")
|
90
|
+
pages = true
|
91
|
+
else
|
92
|
+
pages = false
|
93
|
+
end
|
94
|
+
|
95
|
+
|
74
96
|
options = OpenStruct.new({
|
75
97
|
:appname => appname,
|
76
98
|
:db => db,
|
77
|
-
|
99
|
+
:server_type => server_type,
|
78
100
|
:devise => devise,
|
79
101
|
:devise_model_name => devise_model_name,
|
102
|
+
:devise_model_scaffold => devise_model_scaffold,
|
80
103
|
:devise_views => devise_views,
|
81
104
|
:user_roles => user_roles,
|
82
105
|
:cancan => cancan,
|
83
106
|
:active_admin => active_admin,
|
84
|
-
:figaro => figaro
|
107
|
+
:figaro => figaro,
|
108
|
+
:css => css,
|
109
|
+
:css_fw => css_fw,
|
110
|
+
:pages => pages
|
85
111
|
})
|
86
112
|
|
87
113
|
init_file = "gsub_file \"Gemfile\", \"gem \\'spring\\'\", \"\"\n"
|
@@ -93,6 +119,12 @@ module Alex
|
|
93
119
|
if options.devise_views
|
94
120
|
init_file = init_file + "generate \\'devise:views\\'\n"
|
95
121
|
end
|
122
|
+
|
123
|
+
if options.devise_model_scaffold
|
124
|
+
init_file = init_file + "generate(:scaffold_controller, \\'#{options.devise_model_name}\\')\n"
|
125
|
+
init_file = init_file + "insert_into_file \\'config/routes.rb\\', \"resources :users\\n\", after: \"devise_for :users\\n\" \n"
|
126
|
+
end
|
127
|
+
|
96
128
|
end
|
97
129
|
|
98
130
|
if options.user_roles
|
@@ -121,9 +153,7 @@ module Alex
|
|
121
153
|
init_file = init_file + "run \\'bundle exec figaro install\\'\n"
|
122
154
|
end
|
123
155
|
|
124
|
-
|
125
|
-
init_file = init_file + "git add: \\'.\\', commit: \\'-m \"initial commit\"\\'\n"
|
126
|
-
init_file = init_file + "gsub_file \"Gemfile\", \"gem \\'spring\\'\", \"\"\n"
|
156
|
+
|
127
157
|
|
128
158
|
if options.db.to_i == 0
|
129
159
|
template_file.puts("gsub_file 'Gemfile', \"gem \'sqlite3\'\", \"gem \'sqlite3\', group: :development\"\n")
|
@@ -134,9 +164,249 @@ module Alex
|
|
134
164
|
template_file.puts("gsub_file 'Gemfile', \"gem \'sqlite3\'\", \"gem \'sqlite3\', group: :development\"\n")
|
135
165
|
end
|
136
166
|
|
167
|
+
if options.pages
|
168
|
+
# Create the controller
|
169
|
+
init_file = init_file + "generate(:controller, \\'Pages\\',\\'index\\')\n"
|
170
|
+
# Define route
|
171
|
+
init_file = init_file + "gsub_file \\'config/routes.rb\\', \"get \\'pages/index\\'\", \"root \\'pages#index\\'\"\n"
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
if options.css
|
176
|
+
case options.css_fw.to_i
|
177
|
+
when 0
|
178
|
+
# Add Bootstrap CSS
|
179
|
+
# Download Bootstrap CSS
|
180
|
+
init_file = init_file + "run \\'wget -P vendor/assets/stylesheets/ https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\\'\n"
|
181
|
+
# Add CSS to application.css
|
182
|
+
init_file = init_file + "insert_into_file \\'app/assets/stylesheets/application.css\\', \\'*= require bootstrap.min\n\\', before: \"*/\\n\"\n"
|
183
|
+
# Download jQuery JS
|
184
|
+
# init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://code.jquery.com/jquery-2.1.4.min.js\\'\n"
|
185
|
+
# Add jQuery to application.js
|
186
|
+
# init_file = init_file + "append_file \\'app/assets/javascripts/application.js\\', \\'//= require jquery-2.1.4.min\\'\n"
|
187
|
+
# Download Bootstrap JS
|
188
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\\'\n"
|
189
|
+
# Add JS to application.js
|
190
|
+
init_file = init_file + "append_file \\'app/assets/javascripts/application.js\\', \\'//= require bootstrap.min\\'\n"
|
191
|
+
when 100
|
192
|
+
# Add MaterialAdmin Files
|
193
|
+
# Copy application.css
|
194
|
+
init_file = init_file + "run \\'wget -P app/assets/stylesheets/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/application.css\\'\n"
|
195
|
+
# Copy application.js
|
196
|
+
init_file = init_file + "run \\'wget -P app/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/application.js\\'\n"
|
197
|
+
# Copy fonts
|
198
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/FontAwesome.otf\\'\n"
|
199
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/fontawesome-webfont.eot\\'\n"
|
200
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/fontawesome-webfont.svg\\'\n"
|
201
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/fontawesome-webfont.ttf\\'\n"
|
202
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/fontawesome-webfont.woff\\'\n"
|
203
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/fontawesome-webfont.woff2\\'\n"
|
204
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/glyphicons-halflings-regular.eot\\'\n"
|
205
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/glyphicons-halflings-regular.svg\\'\n"
|
206
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/glyphicons-halflings-regular.ttf\\'\n"
|
207
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/glyphicons-halflings-regular.woff\\'\n"
|
208
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/glyphicons-halflings-regular.woff2\\'\n"
|
209
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/Material-Design-Iconic-Font.eot\\'\n"
|
210
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/Material-Design-Iconic-Font.svg\\'\n"
|
211
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/Material-Design-Iconic-Font.ttf\\'\n"
|
212
|
+
init_file = init_file + "run \\'wget -P vendor/assets/fonts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/fonts/Material-Design-Iconic-Font.woff\\'\n"
|
213
|
+
# Copy images
|
214
|
+
init_file = init_file + "run \\'wget -P vendor/assets/images/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/images/img16.jpg\\'\n"
|
215
|
+
# Copy JS
|
216
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/app.js\\'\n"
|
217
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/App.js\\'\n"
|
218
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/App.min.js\\'\n"
|
219
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppCard.js\\'\n"
|
220
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppForm.js\\'\n"
|
221
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppNavigation.js\\'\n"
|
222
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppNavSearch.js\\'\n"
|
223
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppOffcanvas.js\\'\n"
|
224
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/AppVendor.js\\'\n"
|
225
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/fotorama.js\\'\n"
|
226
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/headroom.min.js\\'\n"
|
227
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/jquery.fitvids.min.js\\'\n"
|
228
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/jquery.inview.js\\'\n"
|
229
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/jquery.nb2sb.min.js\\'\n"
|
230
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/jquery.scrollTo-1.4.6-min.js\\'\n"
|
231
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/jquery.tablesorter.min.js\\'\n"
|
232
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/materialPreloader-vanilla.js\\'\n"
|
233
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/particles.min.js\\'\n"
|
234
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/stellar.js\\'\n"
|
235
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/demo/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/demo/DemoUIMessages.js\\'\n"
|
236
|
+
init_file = init_file + "run \\'wget -P vendor/assets/javascripts/demo/ https://raw.githubusercontent.com/juangesino/alex/master/templates/MaterialAdmin/assets/javascripts/demo/Demo.js\\'\n"
|
237
|
+
|
238
|
+
# Copy CSS
|
239
|
+
# Copy LESS
|
240
|
+
# Copy views
|
241
|
+
else
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# init_file = init_file + "rake \\'db:migrate\\'\n"
|
246
|
+
# init_file = init_file + "git add: \\'.\\', commit: \\'-m \"Initial commit\"\\'\n"
|
247
|
+
|
137
248
|
template_file.puts("append_file '.gitignore', '.idea/'")
|
138
249
|
template_file.puts("git :init")
|
250
|
+
|
139
251
|
template_file.puts("create_file 'config/alex/init.rb', '#{init_file}'")
|
252
|
+
|
253
|
+
if options.server_type.to_i == 1 || options.server_type.to_i == 2
|
254
|
+
if options.devise && yes?("\nAPI:\nWould you like me to build the API auth? (default: No)")
|
255
|
+
### START API CONFIG (WITH AUTH)
|
256
|
+
template_file.puts(<<-'ALEXGEN'
|
257
|
+
append_file 'config/alex/init.rb', <<-'ALEX'
|
258
|
+
gsub_file 'app/controllers/application_controller.rb', "protect_from_forgery with: :exception", ""
|
259
|
+
|
260
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
|
261
|
+
protect_from_forgery with: :null_session
|
262
|
+
before_filter :add_allow_credentials_headers
|
263
|
+
|
264
|
+
def add_allow_credentials_headers
|
265
|
+
response.headers['Access-Control-Allow-Origin'] = request.headers['Origin'] || '*'
|
266
|
+
response.headers['Access-Control-Allow-Credentials'] = 'true'
|
267
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PUT, PATCH, OPTIONS'
|
268
|
+
end
|
269
|
+
|
270
|
+
def options
|
271
|
+
head :status => 200, :'Access-Control-Allow-Headers' => 'accept, content-type, authorization, User-App-Token'
|
272
|
+
end
|
273
|
+
RUBY
|
274
|
+
end
|
275
|
+
|
276
|
+
create_file 'app/controllers/api/v1/api_controller.rb'
|
277
|
+
|
278
|
+
append_file 'app/controllers/api/v1/api_controller.rb', <<-'RUBY'
|
279
|
+
module Api
|
280
|
+
module V1
|
281
|
+
class ApiController < ApplicationController
|
282
|
+
respond_to :json
|
283
|
+
protect_from_forgery with: :null_session
|
284
|
+
before_filter :check_token
|
285
|
+
skip_before_filter :check_token, :only => [:auth]
|
286
|
+
|
287
|
+
def current_user
|
288
|
+
@current_user
|
289
|
+
end
|
290
|
+
|
291
|
+
def check_auth
|
292
|
+
user = User.where(token: params[:token]).first
|
293
|
+
if user
|
294
|
+
respond_with @current_user
|
295
|
+
else
|
296
|
+
respond_with status: 402
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def auth
|
301
|
+
authenticate_or_request_with_http_basic do |username, password|
|
302
|
+
resource = User.find_by_email(username)
|
303
|
+
if resource && resource.valid_password?(password)
|
304
|
+
sign_in :user, resource
|
305
|
+
@current_user = resource
|
306
|
+
@current_user.token = Digest::MD5.hexdigest("#{DateTime.now}#{@current_user.email}")
|
307
|
+
@current_user.save
|
308
|
+
respond_with status: 200, token: @current_user.token, user: @current_user
|
309
|
+
else
|
310
|
+
respond_with status: 402
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def check_token
|
316
|
+
user = User.where(token: request.headers["User-App-Token"]).first
|
317
|
+
if user && request.headers["User-App-Token"]
|
318
|
+
@current_user = user
|
319
|
+
else
|
320
|
+
respond_with status: 402
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
RUBY
|
330
|
+
|
331
|
+
inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-'RUBY'
|
332
|
+
match '*any' => 'application#options', :via => [:options]
|
333
|
+
namespace :api, defaults: {format: 'json'} do
|
334
|
+
namespace :v1 do
|
335
|
+
# Auth
|
336
|
+
match "/auth" => "api#auth", via: [:get]
|
337
|
+
match "/check_auth" => "api#check_auth", via: [:get]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
RUBY
|
341
|
+
end
|
342
|
+
|
343
|
+
ALEX
|
344
|
+
ALEXGEN
|
345
|
+
)
|
346
|
+
### START API CONFIG (WITH AUTH)
|
347
|
+
else
|
348
|
+
### START API CONFIG (NO AUTH)
|
349
|
+
template_file.puts(<<-'ALEXGEN'
|
350
|
+
append_file 'config/alex/init.rb', <<-'ALEX'
|
351
|
+
gsub_file 'app/controllers/application_controller.rb', "protect_from_forgery with: :exception", ""
|
352
|
+
|
353
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
|
354
|
+
protect_from_forgery with: :null_session
|
355
|
+
before_filter :add_allow_credentials_headers
|
356
|
+
|
357
|
+
def add_allow_credentials_headers
|
358
|
+
response.headers['Access-Control-Allow-Origin'] = request.headers['Origin'] || '*'
|
359
|
+
response.headers['Access-Control-Allow-Credentials'] = 'true'
|
360
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PUT, PATCH, OPTIONS'
|
361
|
+
end
|
362
|
+
|
363
|
+
def options
|
364
|
+
head :status => 200, :'Access-Control-Allow-Headers' => 'accept, content-type, authorization, User-App-Token'
|
365
|
+
end
|
366
|
+
RUBY
|
367
|
+
end
|
368
|
+
|
369
|
+
create_file 'app/controllers/api/v1/api_controller.rb'
|
370
|
+
|
371
|
+
append_file 'app/controllers/api/v1/api_controller.rb', <<-'RUBY'
|
372
|
+
module Api
|
373
|
+
module V1
|
374
|
+
class ApiController < ApplicationController
|
375
|
+
respond_to :json
|
376
|
+
protect_from_forgery with: :null_session
|
377
|
+
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
RUBY
|
383
|
+
|
384
|
+
inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-'RUBY'
|
385
|
+
match '*any' => 'application#options', :via => [:options]
|
386
|
+
namespace :api, defaults: {format: 'json'} do
|
387
|
+
namespace :v1 do
|
388
|
+
|
389
|
+
end
|
390
|
+
end
|
391
|
+
RUBY
|
392
|
+
end
|
393
|
+
|
394
|
+
ALEX
|
395
|
+
ALEXGEN
|
396
|
+
)
|
397
|
+
### START API CONFIG (NO AUTH)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
template_file.puts(<<-'ALEXGEN'
|
403
|
+
append_file 'config/alex/init.rb', <<-'ALEX'
|
404
|
+
rake 'db:migrate'
|
405
|
+
git add '.', commit: '-m "Initial commit"'
|
406
|
+
ALEX
|
407
|
+
ALEXGEN
|
408
|
+
)
|
409
|
+
|
140
410
|
template_file.close
|
141
411
|
|
142
412
|
exec "rails new #{appname} -m .alex/#{appname}.rb"
|
data/lib/alex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan I. Gesino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- lib/alex/cli.rb
|
73
73
|
- lib/alex/version.rb
|
74
74
|
- templates/.keep
|
75
|
-
homepage:
|
75
|
+
homepage: https://rubygems.org/gems/alex
|
76
76
|
licenses:
|
77
77
|
- MIT
|
78
78
|
metadata: {}
|