lotusrb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -0
- data/README.md +241 -311
- data/bin/lotus +4 -0
- data/lib/lotus/application.rb +111 -15
- data/lib/lotus/cli.rb +85 -0
- data/lib/lotus/commands/console.rb +62 -0
- data/lib/lotus/commands/new.rb +32 -0
- data/lib/lotus/commands/routes.rb +14 -0
- data/lib/lotus/commands/server.rb +65 -0
- data/lib/lotus/config/assets.rb +24 -10
- data/lib/lotus/config/configure.rb +17 -0
- data/lib/lotus/config/framework_configuration.rb +30 -0
- data/lib/lotus/config/load_paths.rb +1 -1
- data/lib/lotus/config/sessions.rb +97 -0
- data/lib/lotus/configuration.rb +698 -40
- data/lib/lotus/container.rb +30 -0
- data/lib/lotus/environment.rb +377 -0
- data/lib/lotus/frameworks.rb +17 -28
- data/lib/lotus/generators/abstract.rb +31 -0
- data/lib/lotus/generators/application/container/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +29 -0
- data/lib/lotus/generators/application/container/Rakefile.minitest.tt +10 -0
- data/lib/lotus/generators/application/container/config/.env.development.tt +2 -0
- data/lib/lotus/generators/application/container/config/.env.test.tt +2 -0
- data/lib/lotus/generators/application/container/config/.env.tt +1 -0
- data/lib/lotus/generators/application/container/config/environment.rb.tt +7 -0
- data/lib/lotus/generators/application/container/config.ru.tt +3 -0
- data/lib/lotus/generators/application/container/db/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/features_helper.rb.tt +11 -0
- data/lib/lotus/generators/application/container/lib/app_name.rb.tt +31 -0
- data/lib/lotus/generators/application/container/lib/chirp/entities/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/lib/chirp/repositories/.gitkeep +1 -0
- data/lib/lotus/generators/application/container/spec_helper.rb.tt +7 -0
- data/lib/lotus/generators/application/container.rb +70 -0
- data/lib/lotus/generators/slice/.gitkeep.tt +1 -0
- data/lib/lotus/generators/slice/action.rb.tt +8 -0
- data/lib/lotus/generators/slice/application.rb.tt +182 -0
- data/lib/lotus/generators/slice/config/mapping.rb.tt +10 -0
- data/lib/lotus/generators/slice/config/routes.rb.tt +8 -0
- data/lib/lotus/generators/slice/templates/application.html.erb +9 -0
- data/lib/lotus/generators/slice/templates/application.html.erb.tt +9 -0
- data/lib/lotus/generators/slice/templates/template.html.erb.tt +2 -0
- data/lib/lotus/generators/slice/view.rb.tt +5 -0
- data/lib/lotus/generators/slice/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/slice.rb +103 -0
- data/lib/lotus/loader.rb +99 -19
- data/lib/lotus/middleware.rb +92 -9
- data/lib/lotus/rendering_policy.rb +42 -19
- data/lib/lotus/routing/default.rb +1 -1
- data/lib/lotus/setup.rb +5 -0
- data/lib/lotus/templates/welcome.html +49 -0
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/views/default.rb +13 -0
- data/lib/lotus/views/default_template_finder.rb +19 -0
- data/lib/lotus/welcome.rb +14 -0
- data/lib/lotus.rb +1 -0
- data/lotusrb.gemspec +9 -5
- metadata +122 -36
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'thread'
|
2
|
+
require 'lotus/router'
|
3
|
+
|
4
|
+
module Lotus
|
5
|
+
class Container
|
6
|
+
attr_reader :routes
|
7
|
+
|
8
|
+
def self.configure(&blk)
|
9
|
+
Mutex.new.synchronize { @@configuration = blk }
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
Mutex.new.synchronize do
|
14
|
+
assert_configuration_presence!
|
15
|
+
@routes = Lotus::Router.new(&@@configuration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
@routes.call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def assert_configuration_presence!
|
25
|
+
unless self.class.class_variable_defined?(:@@configuration)
|
26
|
+
raise ArgumentError.new("#{ self.class } doesn't have any application mounted.")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,377 @@
|
|
1
|
+
require 'thread'
|
2
|
+
require 'pathname'
|
3
|
+
require 'dotenv'
|
4
|
+
require 'lotus/utils/hash'
|
5
|
+
|
6
|
+
module Lotus
|
7
|
+
# Define and expose information about the Lotus environment.
|
8
|
+
#
|
9
|
+
# @since 0.1.0
|
10
|
+
# @api private
|
11
|
+
class Environment
|
12
|
+
# Standard Rack ENV key
|
13
|
+
#
|
14
|
+
# @since 0.1.0
|
15
|
+
# @api private
|
16
|
+
RACK_ENV = 'RACK_ENV'.freeze
|
17
|
+
|
18
|
+
# Standard Lotus ENV key
|
19
|
+
#
|
20
|
+
# @since 0.1.0
|
21
|
+
# @api private
|
22
|
+
LOTUS_ENV = 'LOTUS_ENV'.freeze
|
23
|
+
|
24
|
+
# Default Lotus environment
|
25
|
+
#
|
26
|
+
# @since 0.1.0
|
27
|
+
# @api private
|
28
|
+
DEFAULT_ENV = 'development'.freeze
|
29
|
+
|
30
|
+
# Default `.env` file name
|
31
|
+
#
|
32
|
+
# @since 0.2.0
|
33
|
+
# @api private
|
34
|
+
DEFAULT_DOTENV = '.env'.freeze
|
35
|
+
|
36
|
+
# Default `.env` per environment file name
|
37
|
+
#
|
38
|
+
# @since 0.2.0
|
39
|
+
# @api private
|
40
|
+
DEFAULT_DOTENV_ENV = '.env.%s'.freeze
|
41
|
+
|
42
|
+
# Default configuration directory under application root
|
43
|
+
#
|
44
|
+
# @since 0.2.0
|
45
|
+
# @api private
|
46
|
+
DEFAULT_CONFIG = 'config'.freeze
|
47
|
+
|
48
|
+
# Standard Lotus host ENV key
|
49
|
+
#
|
50
|
+
# @since 0.1.0
|
51
|
+
# @api private
|
52
|
+
LOTUS_HOST = 'LOTUS_HOST'.freeze
|
53
|
+
|
54
|
+
# Default HTTP host
|
55
|
+
#
|
56
|
+
# @since 0.1.0
|
57
|
+
# @api private
|
58
|
+
DEFAULT_HOST = 'localhost'.freeze
|
59
|
+
|
60
|
+
# Default IP address listen
|
61
|
+
#
|
62
|
+
# @since 0.1.0
|
63
|
+
# @api private
|
64
|
+
LISTEN_ALL_HOST = '0.0.0.0'.freeze
|
65
|
+
|
66
|
+
# Standard Lotus port ENV key
|
67
|
+
#
|
68
|
+
# @since 0.1.0
|
69
|
+
# @api private
|
70
|
+
LOTUS_PORT = 'LOTUS_PORT'.freeze
|
71
|
+
|
72
|
+
# Default Lotus HTTP port
|
73
|
+
#
|
74
|
+
# @since 0.1.0
|
75
|
+
# @api private
|
76
|
+
DEFAULT_PORT = 2300
|
77
|
+
|
78
|
+
# Default Rack configuration file
|
79
|
+
#
|
80
|
+
# @since 0.2.0
|
81
|
+
# @api private
|
82
|
+
DEFAULT_RACKUP = 'config.ru'.freeze
|
83
|
+
|
84
|
+
# Default environment configuration file
|
85
|
+
#
|
86
|
+
# @since 0.2.0
|
87
|
+
# @api private
|
88
|
+
DEFAULT_ENVIRONMENT_CONFIG = 'environment'.freeze
|
89
|
+
|
90
|
+
# Code reloading per environment
|
91
|
+
#
|
92
|
+
# @since 0.2.0
|
93
|
+
# @api private
|
94
|
+
CODE_RELOADING = { 'development' => true }.freeze
|
95
|
+
|
96
|
+
# Initialize a Lotus environment
|
97
|
+
#
|
98
|
+
# It accepts an optional set of configurations from the CLI commands.
|
99
|
+
# Those settings override the defaults defined by this object.
|
100
|
+
#
|
101
|
+
# When initialized, it sets standard `ENV` variables for Rack and Lotus,
|
102
|
+
# such as `RACK_ENV` and `LOTUS_ENV`.
|
103
|
+
#
|
104
|
+
# It also evaluates configuration from `.env` and `.env.<environment>`
|
105
|
+
# located under the config directory. All the settings in those files will
|
106
|
+
# be exported as `ENV` variables.
|
107
|
+
#
|
108
|
+
# The format of those `.env` files is compatible with `dotenv` and `foreman`
|
109
|
+
# gems.
|
110
|
+
#
|
111
|
+
# @param options [Hash] override default options for various environment
|
112
|
+
# attributes
|
113
|
+
#
|
114
|
+
# @return [Lotus::Environment] the environment
|
115
|
+
#
|
116
|
+
# @see Lotus::Commands::Console
|
117
|
+
# @see Lotus::Commands::Routes
|
118
|
+
# @see Lotus::Commands::Server
|
119
|
+
# @see Lotus::Environment#config
|
120
|
+
#
|
121
|
+
# @example Define ENV variables from .env
|
122
|
+
#
|
123
|
+
# # % tree config/
|
124
|
+
# # config
|
125
|
+
# # ├── .env
|
126
|
+
# # ├── .env.development
|
127
|
+
# # └── environment.rb
|
128
|
+
#
|
129
|
+
# # % cat config/.env
|
130
|
+
# # FOO="bar"
|
131
|
+
# # XYZ="yes"
|
132
|
+
#
|
133
|
+
# # % cat config/.env.development
|
134
|
+
# # FOO="ok"
|
135
|
+
#
|
136
|
+
# require 'lotus/environment'
|
137
|
+
#
|
138
|
+
# env = Lotus::Environment.new
|
139
|
+
# env.environment # => "development"
|
140
|
+
#
|
141
|
+
# # Framework defined ENV vars
|
142
|
+
# ENV['LOTUS_ENV'] # => "development"
|
143
|
+
# ENV['RACK_ENV'] # => "development"
|
144
|
+
#
|
145
|
+
# ENV['LOTUS_HOST'] # => "localhost"
|
146
|
+
# ENV['LOTUS_PORT'] # => "2300"
|
147
|
+
#
|
148
|
+
# # User defined ENV vars
|
149
|
+
# ENV['FOO'] # => "ok"
|
150
|
+
# ENV['XYZ'] # => "yes"
|
151
|
+
#
|
152
|
+
# # Lotus::Environment evaluates `.env` first as master configuration.
|
153
|
+
# # Then it evaluates `.env.development` because the current environment
|
154
|
+
# # is "development". The settings defined in this last file override
|
155
|
+
# # the one defined in the parent (eg `FOO` is overwritten). All the
|
156
|
+
# # other settings (eg `XYZ`) will be left untouched.
|
157
|
+
def initialize(options = {})
|
158
|
+
@options = Utils::Hash.new(options).symbolize!.freeze
|
159
|
+
@mutex = Mutex.new
|
160
|
+
@mutex.synchronize { set_env_vars! }
|
161
|
+
end
|
162
|
+
|
163
|
+
# The current environment
|
164
|
+
#
|
165
|
+
# In order to decide the value, it looks up to the following `ENV` vars:
|
166
|
+
#
|
167
|
+
# * LOTUS_ENV
|
168
|
+
# * RACK_ENV
|
169
|
+
#
|
170
|
+
# If those are missing it falls back to the defalt one: `"development"`.
|
171
|
+
#
|
172
|
+
# @return [String] the current environment
|
173
|
+
#
|
174
|
+
# @since 0.1.0
|
175
|
+
#
|
176
|
+
# @see Lotus::Environment::DEFAULT_ENV
|
177
|
+
def environment
|
178
|
+
@environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV
|
179
|
+
end
|
180
|
+
|
181
|
+
# A set of Bundler groups
|
182
|
+
#
|
183
|
+
# @return [Array] A set of groups
|
184
|
+
#
|
185
|
+
# @since 0.2.0
|
186
|
+
# @api private
|
187
|
+
#
|
188
|
+
# @see http://bundler.io/v1.7/groups.html
|
189
|
+
def bundler_groups
|
190
|
+
[environment]
|
191
|
+
end
|
192
|
+
|
193
|
+
# Application's root
|
194
|
+
#
|
195
|
+
# It defaults to the current working directory.
|
196
|
+
# Lotus assumes that all the commands are executed from there.
|
197
|
+
#
|
198
|
+
# @return [Pathname] application's root
|
199
|
+
#
|
200
|
+
# @since 0.2.0
|
201
|
+
def root
|
202
|
+
@root ||= Pathname.new(Dir.pwd)
|
203
|
+
end
|
204
|
+
|
205
|
+
# Application's config directory
|
206
|
+
#
|
207
|
+
# It's the application where all the configurations are stored.
|
208
|
+
#
|
209
|
+
# In order to decide the value, it looks up the following sources:
|
210
|
+
#
|
211
|
+
# * CLI option `config`
|
212
|
+
#
|
213
|
+
# If those are missing it falls back to the default one: `"config/"`.
|
214
|
+
#
|
215
|
+
# When a relative path is given via CLI option, it assumes to be located
|
216
|
+
# under application's root. If absolute path, it will be used as it is.
|
217
|
+
#
|
218
|
+
# @return [Pathname] the config directory
|
219
|
+
#
|
220
|
+
# @since 0.2.0
|
221
|
+
#
|
222
|
+
# @see Lotus::Environment::DEFAULT_CONFIG
|
223
|
+
# @see Lotus::Environment#root
|
224
|
+
def config
|
225
|
+
@config ||= root.join(@options.fetch(:config) { DEFAULT_CONFIG })
|
226
|
+
end
|
227
|
+
|
228
|
+
# The HTTP host name
|
229
|
+
#
|
230
|
+
# In order to decide the value, it looks up the following sources:
|
231
|
+
#
|
232
|
+
# * CLI option `host`
|
233
|
+
# * LOTUS_HOST ENV var
|
234
|
+
#
|
235
|
+
# If those are missing it falls back to the following defaults:
|
236
|
+
#
|
237
|
+
# * `"localhost"` for development
|
238
|
+
# * `"0.0.0.0"` for all the other environments
|
239
|
+
#
|
240
|
+
# @return [String] the HTTP host name
|
241
|
+
#
|
242
|
+
# @since 0.1.0
|
243
|
+
#
|
244
|
+
# @see Lotus::Environment::DEFAULT_HOST
|
245
|
+
# @see Lotus::Environment::LISTEN_ALL_HOST
|
246
|
+
def host
|
247
|
+
@host ||= @options.fetch(:host) {
|
248
|
+
ENV[LOTUS_HOST] || default_host
|
249
|
+
}
|
250
|
+
end
|
251
|
+
|
252
|
+
# The HTTP port
|
253
|
+
#
|
254
|
+
# In order to decide the value, it looks up the following sources:
|
255
|
+
#
|
256
|
+
# * CLI option `port`
|
257
|
+
# * LOTUS_PORT ENV var
|
258
|
+
#
|
259
|
+
# If those are missing it falls back to the default one: `2300`.
|
260
|
+
#
|
261
|
+
# @return [Integer] the default port
|
262
|
+
#
|
263
|
+
# @since 0.1.0
|
264
|
+
#
|
265
|
+
# @see Lotus::Environment::DEFAULT_PORT
|
266
|
+
def port
|
267
|
+
@port ||= @options.fetch(:port) { ENV[LOTUS_PORT] || DEFAULT_PORT }.to_i
|
268
|
+
end
|
269
|
+
|
270
|
+
# Path to the Rack configuration file
|
271
|
+
#
|
272
|
+
# In order to decide the value, it looks up the following sources:
|
273
|
+
#
|
274
|
+
# * CLI option `rackup`
|
275
|
+
#
|
276
|
+
# If those are missing it falls back to the default one: `"config.ru"`.
|
277
|
+
#
|
278
|
+
# When a relative path is given via CLI option, it assumes to be located
|
279
|
+
# under application's root. If absolute path, it will be used as it is.
|
280
|
+
#
|
281
|
+
# @return [Pathname] path to the Rack configuration file
|
282
|
+
#
|
283
|
+
# @since 0.2.0
|
284
|
+
def rackup
|
285
|
+
root.join(@options.fetch(:rackup) { DEFAULT_RACKUP })
|
286
|
+
end
|
287
|
+
|
288
|
+
# Path to environment configuration file.
|
289
|
+
#
|
290
|
+
# In order to decide the value, it looks up the following sources:
|
291
|
+
#
|
292
|
+
# * CLI option `environment`
|
293
|
+
#
|
294
|
+
# If those are missing it falls back to the default one:
|
295
|
+
# `"config/environment.rb"`.
|
296
|
+
#
|
297
|
+
# When a relative path is given via CLI option, it assumes to be located
|
298
|
+
# under application's root. If absolute path, it will be used as it is.
|
299
|
+
#
|
300
|
+
# @return [Pathname] path to applications
|
301
|
+
#
|
302
|
+
# @since 0.1.0
|
303
|
+
#
|
304
|
+
# @see Lotus::Environment::DEFAULT_ENVIRONMENT_CONFIG
|
305
|
+
def env_config
|
306
|
+
root.join(@options.fetch(:environment) { config.join(DEFAULT_ENVIRONMENT_CONFIG) })
|
307
|
+
end
|
308
|
+
|
309
|
+
# Determine if activate code reloading for the current environment while
|
310
|
+
# running the server.
|
311
|
+
#
|
312
|
+
# In order to decide the value, it looks up the following sources:
|
313
|
+
#
|
314
|
+
# * CLI option `code_reloading`
|
315
|
+
#
|
316
|
+
# If those are missing it falls back to the following defaults:
|
317
|
+
#
|
318
|
+
# * true for development
|
319
|
+
# * false for all the other environments
|
320
|
+
#
|
321
|
+
# @return [TrueClass,FalseClass] the result of the check
|
322
|
+
#
|
323
|
+
# @since 0.2.0
|
324
|
+
#
|
325
|
+
# @see Lotus::Commands::Server
|
326
|
+
# @see Lotus::Environment::CODE_RELOADING
|
327
|
+
def code_reloading?
|
328
|
+
@options.fetch(:code_reloading) { !!CODE_RELOADING[environment] }
|
329
|
+
end
|
330
|
+
|
331
|
+
# Serialize the most relevant settings into a Hash
|
332
|
+
#
|
333
|
+
# @return [Lotus::Utils::Hash]
|
334
|
+
#
|
335
|
+
# @since 0.1.0
|
336
|
+
# @api private
|
337
|
+
def to_options
|
338
|
+
@options.merge(
|
339
|
+
environment: environment,
|
340
|
+
env_config: env_config,
|
341
|
+
rackup: rackup,
|
342
|
+
host: host,
|
343
|
+
port: port
|
344
|
+
)
|
345
|
+
end
|
346
|
+
|
347
|
+
private
|
348
|
+
|
349
|
+
# @since 0.1.0
|
350
|
+
# @api private
|
351
|
+
def set_env_vars!
|
352
|
+
set_lotus_env_vars!
|
353
|
+
set_application_env_vars!
|
354
|
+
end
|
355
|
+
|
356
|
+
# @since 0.2.0
|
357
|
+
# @api private
|
358
|
+
def set_lotus_env_vars!
|
359
|
+
ENV[LOTUS_ENV] = ENV[RACK_ENV] = environment
|
360
|
+
ENV[LOTUS_HOST] = host
|
361
|
+
ENV[LOTUS_PORT] = port.to_s
|
362
|
+
end
|
363
|
+
|
364
|
+
# @since 0.2.0
|
365
|
+
# @api private
|
366
|
+
def set_application_env_vars!
|
367
|
+
Dotenv.load config.join(DEFAULT_DOTENV)
|
368
|
+
Dotenv.overload config.join(DEFAULT_DOTENV_ENV % environment)
|
369
|
+
end
|
370
|
+
|
371
|
+
# @since 0.1.0
|
372
|
+
# @api private
|
373
|
+
def default_host
|
374
|
+
environment == DEFAULT_ENV ? DEFAULT_HOST : LISTEN_ALL_HOST
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
data/lib/lotus/frameworks.rb
CHANGED
@@ -1,38 +1,27 @@
|
|
1
1
|
require 'lotus/router'
|
2
|
-
require 'lotus/controller'
|
3
2
|
require 'lotus/view'
|
3
|
+
require 'lotus/controller'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# module Rack
|
11
|
-
# protected
|
12
|
-
# def response
|
13
|
-
# [super, self].flatten
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# Lotus::Action::Rack.class_eval do
|
21
|
-
# include Lotus::Frameworks::Action::Rack
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# ..but it doesn't work and I want to ship it!
|
25
|
-
|
26
|
-
Lotus::Action::Rack.class_eval do
|
27
|
-
DEFAULT_RESPONSE_CODE = 200
|
28
|
-
DEFAULT_RESPONSE_BODY = []
|
5
|
+
module Lotus
|
6
|
+
module Frameworks
|
7
|
+
module Action
|
8
|
+
module Rack
|
9
|
+
ENV_KEY = 'lotus.action'.freeze
|
29
10
|
|
30
|
-
|
31
|
-
|
32
|
-
|
11
|
+
protected
|
12
|
+
def finish
|
13
|
+
super
|
14
|
+
@_env[ENV_KEY] = self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
33
18
|
end
|
34
19
|
end
|
35
20
|
|
21
|
+
Lotus::Action::Rack.class_eval do
|
22
|
+
prepend Lotus::Frameworks::Action::Rack
|
23
|
+
end
|
24
|
+
|
36
25
|
Lotus::Action.class_eval do
|
37
26
|
def to_rendering
|
38
27
|
exposures.merge(format: format)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module Lotus
|
4
|
+
module Generators
|
5
|
+
# Abstract super class for generators
|
6
|
+
#
|
7
|
+
# @abstract
|
8
|
+
# @since 0.2.0
|
9
|
+
class Abstract < SimpleDelegator
|
10
|
+
# Initialize a generator
|
11
|
+
#
|
12
|
+
# @param command [Thor] a Thor instance that comes from Lotus::Cli
|
13
|
+
#
|
14
|
+
# @since 0.2.0
|
15
|
+
# @api private
|
16
|
+
def initialize(command)
|
17
|
+
super(command)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Start the generator
|
21
|
+
#
|
22
|
+
# @raise [NotImplementedError]
|
23
|
+
#
|
24
|
+
# @abstract
|
25
|
+
# @since 0.2.0
|
26
|
+
def start
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,29 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'bundler'
|
4
|
+
gem 'rake'
|
5
|
+
|
6
|
+
<%- if config[:lotus_head] -%>
|
7
|
+
gem 'lotus-utils', require: false, github: 'lotus/utils'
|
8
|
+
gem 'lotus-router', require: false, github: 'lotus/router'
|
9
|
+
gem 'lotus-validations', require: false, github: 'lotus/validations'
|
10
|
+
gem 'lotus-controller', require: false, github: 'lotus/controller'
|
11
|
+
gem 'lotus-view', require: false, github: 'lotus/view'
|
12
|
+
gem 'lotus-model', require: false, github: 'lotus/model'
|
13
|
+
gem 'lotusrb', github: 'lotus/lotus'
|
14
|
+
<%- else -%>
|
15
|
+
gem 'lotusrb', '<%= Lotus::VERSION %>'
|
16
|
+
gem 'lotus-model', '<%= config[:lotus_model_version] %>'
|
17
|
+
<%- end -%>
|
18
|
+
|
19
|
+
group :test do
|
20
|
+
<%- if config[:test] == 'rspec' -%>
|
21
|
+
<%- else -%>
|
22
|
+
gem 'minitest'
|
23
|
+
<%- end -%>
|
24
|
+
gem 'capybara'
|
25
|
+
end
|
26
|
+
|
27
|
+
group :production do
|
28
|
+
# gem 'puma'
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Define ENV variables
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'lotus/model'
|
2
|
+
Dir["#{ __dir__ }/**/*.rb"].each { |file| require_relative file }
|
3
|
+
|
4
|
+
Lotus::Model.configure do
|
5
|
+
# Database adapter
|
6
|
+
#
|
7
|
+
# Available options:
|
8
|
+
#
|
9
|
+
# * Memory adapter
|
10
|
+
# adapter type: :memory, uri: 'memory://localhost/<%= config[:app_name] %>_development'
|
11
|
+
#
|
12
|
+
# * SQL adapter
|
13
|
+
# adapter type: :sql, uri: 'sqlite://db/<%= config[:app_name] %>_development.db'
|
14
|
+
# adapter type: :sql, uri: 'postgres://localhost/<%= config[:app_name] %>_development'
|
15
|
+
# adapter type: :sql, uri: 'mysql://localhost/<%= config[:app_name] %>_development'
|
16
|
+
#
|
17
|
+
adapter type: :file_system, uri: ENV['<%= config[:app_name].upcase %>_DATABASE_URL']
|
18
|
+
|
19
|
+
##
|
20
|
+
# Database mapping
|
21
|
+
#
|
22
|
+
mapping do
|
23
|
+
# collection :users do
|
24
|
+
# entity User
|
25
|
+
# repository UserRepository
|
26
|
+
#
|
27
|
+
# attribute :id, Integer
|
28
|
+
# attribute :name, String
|
29
|
+
# end
|
30
|
+
end
|
31
|
+
end.load!
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'lotus/generators/abstract'
|
2
|
+
require 'lotus/generators/slice'
|
3
|
+
|
4
|
+
module Lotus
|
5
|
+
module Generators
|
6
|
+
module Application
|
7
|
+
class Container < Abstract
|
8
|
+
def initialize(command)
|
9
|
+
super
|
10
|
+
|
11
|
+
@slice_generator = Slice.new(command)
|
12
|
+
@lotus_head = options.fetch(:lotus_head)
|
13
|
+
@lotus_model_version = '~> 0.2'
|
14
|
+
|
15
|
+
cli.class.source_root(source)
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
opts = {
|
20
|
+
app_name: app_name,
|
21
|
+
lotus_head: @lotus_head,
|
22
|
+
lotus_model_version: @lotus_model_version
|
23
|
+
}
|
24
|
+
|
25
|
+
templates = {
|
26
|
+
'Gemfile.tt' => 'Gemfile',
|
27
|
+
'config.ru.tt' => 'config.ru',
|
28
|
+
'config/environment.rb.tt' => 'config/environment.rb',
|
29
|
+
'config/.env.tt' => 'config/.env',
|
30
|
+
'config/.env.development.tt' => 'config/.env.development',
|
31
|
+
'config/.env.test.tt' => 'config/.env.test',
|
32
|
+
'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
|
33
|
+
}
|
34
|
+
|
35
|
+
empty_directories = [
|
36
|
+
"db",
|
37
|
+
"lib/#{ app_name }/entities",
|
38
|
+
"lib/#{ app_name }/repositories"
|
39
|
+
]
|
40
|
+
|
41
|
+
case options[:test]
|
42
|
+
when 'rspec'
|
43
|
+
else # minitest (default)
|
44
|
+
templates.merge!(
|
45
|
+
'Rakefile.minitest.tt' => 'Rakefile',
|
46
|
+
'spec_helper.rb.tt' => 'spec/spec_helper.rb',
|
47
|
+
'features_helper.rb.tt' => 'spec/features_helper.rb'
|
48
|
+
)
|
49
|
+
|
50
|
+
empty_directories << [
|
51
|
+
"spec/#{ app_name }/entities",
|
52
|
+
"spec/#{ app_name }/repositories"
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
templates.each do |src, dst|
|
57
|
+
cli.template(source.join(src), target.join(dst), opts)
|
58
|
+
end
|
59
|
+
|
60
|
+
empty_directories.flatten.each do |dir|
|
61
|
+
gitkeep = '.gitkeep'
|
62
|
+
cli.template(source.join(gitkeep), target.join(dir, gitkeep), opts)
|
63
|
+
end
|
64
|
+
|
65
|
+
@slice_generator.start
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|