lotusrb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/README.md +241 -311
  4. data/bin/lotus +4 -0
  5. data/lib/lotus/application.rb +111 -15
  6. data/lib/lotus/cli.rb +85 -0
  7. data/lib/lotus/commands/console.rb +62 -0
  8. data/lib/lotus/commands/new.rb +32 -0
  9. data/lib/lotus/commands/routes.rb +14 -0
  10. data/lib/lotus/commands/server.rb +65 -0
  11. data/lib/lotus/config/assets.rb +24 -10
  12. data/lib/lotus/config/configure.rb +17 -0
  13. data/lib/lotus/config/framework_configuration.rb +30 -0
  14. data/lib/lotus/config/load_paths.rb +1 -1
  15. data/lib/lotus/config/sessions.rb +97 -0
  16. data/lib/lotus/configuration.rb +698 -40
  17. data/lib/lotus/container.rb +30 -0
  18. data/lib/lotus/environment.rb +377 -0
  19. data/lib/lotus/frameworks.rb +17 -28
  20. data/lib/lotus/generators/abstract.rb +31 -0
  21. data/lib/lotus/generators/application/container/.gitkeep +1 -0
  22. data/lib/lotus/generators/application/container/Gemfile.tt +29 -0
  23. data/lib/lotus/generators/application/container/Rakefile.minitest.tt +10 -0
  24. data/lib/lotus/generators/application/container/config/.env.development.tt +2 -0
  25. data/lib/lotus/generators/application/container/config/.env.test.tt +2 -0
  26. data/lib/lotus/generators/application/container/config/.env.tt +1 -0
  27. data/lib/lotus/generators/application/container/config/environment.rb.tt +7 -0
  28. data/lib/lotus/generators/application/container/config.ru.tt +3 -0
  29. data/lib/lotus/generators/application/container/db/.gitkeep +1 -0
  30. data/lib/lotus/generators/application/container/features_helper.rb.tt +11 -0
  31. data/lib/lotus/generators/application/container/lib/app_name.rb.tt +31 -0
  32. data/lib/lotus/generators/application/container/lib/chirp/entities/.gitkeep +1 -0
  33. data/lib/lotus/generators/application/container/lib/chirp/repositories/.gitkeep +1 -0
  34. data/lib/lotus/generators/application/container/spec_helper.rb.tt +7 -0
  35. data/lib/lotus/generators/application/container.rb +70 -0
  36. data/lib/lotus/generators/slice/.gitkeep.tt +1 -0
  37. data/lib/lotus/generators/slice/action.rb.tt +8 -0
  38. data/lib/lotus/generators/slice/application.rb.tt +182 -0
  39. data/lib/lotus/generators/slice/config/mapping.rb.tt +10 -0
  40. data/lib/lotus/generators/slice/config/routes.rb.tt +8 -0
  41. data/lib/lotus/generators/slice/templates/application.html.erb +9 -0
  42. data/lib/lotus/generators/slice/templates/application.html.erb.tt +9 -0
  43. data/lib/lotus/generators/slice/templates/template.html.erb.tt +2 -0
  44. data/lib/lotus/generators/slice/view.rb.tt +5 -0
  45. data/lib/lotus/generators/slice/views/application_layout.rb.tt +7 -0
  46. data/lib/lotus/generators/slice.rb +103 -0
  47. data/lib/lotus/loader.rb +99 -19
  48. data/lib/lotus/middleware.rb +92 -9
  49. data/lib/lotus/rendering_policy.rb +42 -19
  50. data/lib/lotus/routing/default.rb +1 -1
  51. data/lib/lotus/setup.rb +5 -0
  52. data/lib/lotus/templates/welcome.html +49 -0
  53. data/lib/lotus/version.rb +1 -1
  54. data/lib/lotus/views/default.rb +13 -0
  55. data/lib/lotus/views/default_template_finder.rb +19 -0
  56. data/lib/lotus/welcome.rb +14 -0
  57. data/lib/lotus.rb +1 -0
  58. data/lotusrb.gemspec +9 -5
  59. metadata +122 -36
data/README.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  A complete web framework for Ruby
4
4
 
5
+ ## Frameworks
6
+
7
+ Lotus combines together small but yet powerful frameworks:
8
+
9
+ * [**Lotus::Utils**](https://github.com/lotus/utils) - Ruby core extentions and class utilities
10
+ * [**Lotus::Router**](https://github.com/lotus/router) - Rack compatible HTTP router for Ruby
11
+ * [**Lotus::Validations**](https://github.com/lotus/validations) - Validation mixin for Ruby objects
12
+ * [**Lotus::Model**](https://github.com/lotus/model) - Persistence with entities, repositories and data mapper
13
+ * [**Lotus::View**](https://github.com/lotus/view) - Presentation with a separation between views and templates
14
+ * [**Lotus::Controller**](https://github.com/lotus/controller) - Full featured, fast and testable actions for Rack
15
+
16
+ All those components are designed to be used independently from each other or to work together in a Lotus application.
17
+ If your aren't familiar with them, please take time to go through their READMEs.
18
+
5
19
  ## Status
6
20
 
7
21
  [![Gem Version](https://badge.fury.io/rb/lotusrb.png)](http://badge.fury.io/rb/lotusrb)
@@ -26,324 +40,101 @@ __Lotus__ supports Ruby (MRI) 2+
26
40
 
27
41
  ## Installation
28
42
 
29
- Add this line to your application's Gemfile:
30
-
31
- ```ruby
32
- gem 'lotusrb'
33
- ```
34
-
35
- And then execute:
36
-
37
43
  ```shell
38
- $ bundle
44
+ % gem install lotusrb
39
45
  ```
40
46
 
41
- Or install it yourself as:
47
+ ## Usage
42
48
 
43
49
  ```shell
44
- $ gem install lotusrb
50
+ % lotus new bookshelf
51
+ % cd bookshelf && bundle
52
+ % bundle exec lotus server # visit http://localhost:2300
45
53
  ```
46
54
 
47
- ## Usage
48
-
49
- Lotus combines the power and the flexibility of all its [frameworks](https://github.com/lotus).
50
- It uses [Lotus::Router](https://github.com/lotus/router) and [Lotus::Controller](https://github.com/lotus/controller) for routing and controller layer, respectively.
51
- While [Lotus::View](https://github.com/lotus/view) it's used for the presentational logic.
52
-
53
- **If you're not familiar with those libraries, please read their READMEs first.**
55
+ ## Architectures
54
56
 
55
- ### Architecture
57
+ Lotus is a modular web framework.
58
+ It scales from **single file HTTP endpoints** to **multiple applications in the same Ruby process**.
56
59
 
57
- Unlike the other Ruby web frameworks, it has a flexible conventions for the code structure.
60
+ Unlike other Ruby web frameworks, Lotus has **flexible conventions for code structure**.
58
61
  Developers can arrange the layout of their projects as they prefer.
59
62
  There is a suggested architecture that can be easily changed with a few settings.
60
63
 
61
- Based on the experience on dozens of projects, Lotus encourages the use of Ruby namespaces.
62
- In this way, growing code bases can be split without effort, avoiding monolithic applications.
63
-
64
- Lotus has a smart **mechanism of duplication of its frameworks**, that allows multiple copy of a framework and multiple applications to run in the **same Ruby process**.
65
- In other words, even small Lotus applications are ready to be split in separated deliverables, but they can safely coexist in the same heap space.
64
+ Lotus encourages the use of Ruby namespaces. This is based on the experience of working on dozens of projects.
65
+ By using Ruby namespaces, as your code grows it can be split with less effort. In other words, Lotus is providing gentle guidance for **avoid monolithic applications**.
66
66
 
67
- For instance, when a `Bookshelf::Application` is loaded, `Lotus::View` and `Lotus::Controller` are duplicated as `Bookshelf::View` and `Bookshelf::Controller`, in order to make their configurations completely indepentend from `Backend::Application` thay may live in the same Ruby process.
68
- So that, developers SHOULD include `Bookshelf::Controller` instead of `Lotus::Controller`.
69
-
70
- #### One file application
71
-
72
- ```ruby
73
- # config.ru
74
- require 'lotus'
75
-
76
- module OneFile
77
- class Application < Lotus::Application
78
- configure do
79
- routes do
80
- get '/', to: 'home#index'
81
- end
82
- end
83
- end
67
+ Lotus has a smart **mechanism of duplication of its frameworks**.
68
+ It allows multiple copies of the framework and multiple applications to run in the **same Ruby process**.
69
+ In other words, Lotus applications are ready to be split into smaller parts but these parts can coexist in the same heap space.
84
70
 
85
- module Controllers::Home
86
- include OneFile::Controller
71
+ All this adaptability can be helpful to bend the framework for your advanced needs, but we recognize the need of a guidance in standard architectures.
72
+ For this reason Lotus is shipped with code generators.
87
73
 
88
- action 'Index' do
89
- def call(params)
90
- end
91
- end
92
- end
93
74
 
94
- module Views::Home
95
- class Index
96
- include OneFile::View
75
+ ### _Container_ architecture
97
76
 
98
- def render
99
- 'Hello'
100
- end
101
- end
102
- end
103
- end
77
+ **TL;DR: Develop your application like a gem. Implement use cases in `lib/`. Use one or more Lotus applications in `apps/`.**
104
78
 
105
- run OneFile::Application.new
106
- ```
79
+ This is the default architecture.
80
+ When your are about to start a new project use it.
107
81
 
108
- When the application is instantiated, it will also create `OneFile::Controllers` and `OneFile::Views` namespace, to incentivize the modularization of the resources.
109
- Also, note how similar are the names of the action and of the view: `OneFile::Controllers::Home::Index` and `OneFile::Views::Home::Index`.
110
- **This naming system is a Lotus convention and MUST be followed, or otherwise configured**.
82
+ The core of this architecture lives in `lib/`, where developers should build features **independently from the delivery mechanism**.
111
83
 
112
- #### Microservices architecture
84
+ Imagine you are building a personal finance application, and you have a feature called _"register expense"_. This functionality involves `Money` and `Expense` Ruby objects and the need of persisting data into a database. You can have those classes living in `lib/pocket/money.rb` and `lib/pocket/expense.rb` and use [Lotus::Model](https://github.com/lotus/model) to persist them.
113
85
 
114
- ```
115
- test/fixtures/microservices
116
- ├── apps
117
- │   ├── backend
118
- │   │   ├── application.rb Backend::Application
119
- │   │   ├── controllers
120
- │   │   │   └── sessions.rb Backend::Controllers::Sessions::New, Create & Destroy
121
- │   │   ├── public
122
- │   │   │   ├── favicon.ico
123
- │   │   │   ├── fonts
124
- │   │   │   │   └── cabin-medium.woff
125
- │   │   │   ├── images
126
- │   │   │   │   └── application.jpg
127
- │   │   │   ├── javascripts
128
- │   │   │   │   └── application.js
129
- │   │   │   └── stylesheets
130
- │   │   │   └── application.css
131
- │   │   ├── templates
132
- │   │   │   ├── backend.html.erb
133
- │   │   │   └── sessions
134
- │   │   │   └── new.html.erb
135
- │   │   └── views
136
- │   │   ├── backend_layout.rb Backend::Views::BackendLayout
137
- │   │   └── sessions
138
- │   │   ├── create.rb Backend::Views::Sessions::Create
139
- │   │   ├── destroy.rb Backend::Views::Sessions::Destroy
140
- │   │   └── new.rb Backend::Views::Sessions::New
141
- │   └── frontend
142
- │   ├── application.rb Frontend::Application
143
- │   ├── assets
144
- │   │   ├── favicon.ico
145
- │   │   ├── fonts
146
- │   │   │   └── cabin-medium.woff
147
- │   │   ├── images
148
- │   │   │   └── application.jpg
149
- │   │   ├── javascripts
150
- │   │   │   └── application.js
151
- │   │   └── stylesheets
152
- │   │   └── application.css
153
- │   ├── controllers
154
- │   │   └── sessions
155
- │   │   ├── create.rb Frontend::Controllers::Sessions::Create
156
- │   │   ├── destroy.rb Frontend::Controllers::Sessions::Destroy
157
- │   │   └── new.rb Frontend::Controllers::Sessions::New
158
- │   ├── templates
159
- │   │   ├── frontend.html.erb
160
- │   │   └── sessions
161
- │   │   └── new.html.erb
162
- │   └── views
163
- │   ├── application_layout.rb Frontend::Views::ApplicationLayout
164
- │   └── sessions
165
- │      ├── create.rb Frontend::Views::Sessions::Create
166
- │      ├── destroy.rb Frontend::Views::Sessions::Destroy
167
- │      └── new.rb Frontend::Views::Sessions::New
168
- └── config.ru
169
- ```
86
+ It's based on a few simple concepts: **use cases** and **applications**.
87
+ Use cases (features) should be implemented in `lib/` with a combination of pure objects and the needed Ruby gems.
88
+ One or more Lotus applications live in `apps/`. They are isolated each other, and depend only on the code in `lib/`.
170
89
 
171
- As you can see, the code can be organized as you prefer. For instance, all the sessions actions for the backend are grouped in the same file,
172
- while they're split in the case of the frontend app.
90
+ Each of them should serve for only one purpose: user facing web application, administrative backend, JSON API, metrics dashboard, etc.
173
91
 
174
- **This because Lotus doesn't have namespace-to-filename conventions, and doesn't have autoload paths.**
175
- During the boot time it **recursively preloads all the classes from the specified directories.**
92
+ This architecture has important advantages:
176
93
 
177
- ```ruby
178
- # apps/backend/application.rb
179
- require 'lotus'
94
+ * **Code reusability.** You can consume a feature from the Web UI or from a HTTP API. Each one can be different Lotus application or simple Rack based endpoints.
95
+ * **Decoupled components.** The core of your application depends only on a few gems and it doesn't need to worry about the Web/HTTP/Console/Background jobs.
96
+ * **Applications are built like a gem**, this ease the process of package them and share between projects, without the need of carry a lot of dependencies.
97
+ * **Avoid monoliths**. Each Lotus application under `apps/` is a candidate for later on extraction into a separated [_microservice_](http://martinfowler.com/articles/microservices.html).
180
98
 
181
- module Backend
182
- class Application < Lotus::Application
183
- configure do
184
- load_paths << [
185
- 'controllers',
186
- 'views'
187
- ]
99
+ The last point is crucial. In the early days of a new project is really convenient to build and deploy all the code together.
100
+ But as the time passes, it can become nearly impossible to extract sets of cohesive functionalities into separated deliverables.
101
+ Lotus helps to plan those things ahead of time, but without the burden that is required by those choices, because it support multiple applications natively.
188
102
 
189
- layout :backend
103
+ Here's the name _**container**_: a Lotus _"shell"_ that can run multiple micro applications in the same process.
190
104
 
191
- routes do
192
- resource :sessions, only: [:new, :create, :destroy]
193
- end
194
- end
195
- end
196
- end
197
-
198
- # All code under apps/backend/{controllers,views} will be loaded
199
- ```
200
-
201
- ```ruby
202
- # config.ru
203
- require_relative 'apps/frontend/application'
204
- require_relative 'apps/backend/application'
205
-
206
- run Lotus::Router.new {
207
- mount Backend::Application, at: '/backend'
208
- mount Frontend::Application, at: '/'
209
- }
210
-
211
- # We use an instance of Lotus::Router to mount two Lotus applications
212
- ```
213
-
214
- #### Modulized application
215
-
216
- ```
217
- test/fixtures/furnitures
218
- ├── app
219
- │   ├── controllers
220
- │   │   └── furnitures
221
- │   │   └── catalog_controller.rb Furnitures::CatalogController::Index
222
- │   ├── templates
223
- │   │   ├── application.html.erb
224
- │   │   └── furnitures
225
- │   │   └── catalog
226
- │   │   └── index.html.erb
227
- │   └── views
228
- │   ├── application_layout.rb Furnitures::Views::ApplicationLayout
229
- │   └── furnitures
230
- │   └── catalog
231
- │   └── index.rb Furnitures::Catalog::Index
232
- ├── application.rb Furnitures::Application
233
- └── public
234
- ├── favicon.ico
235
- ├── fonts
236
- │   └── cabin-medium.woff
237
- ├── images
238
- │   └── application.jpg
239
- ├── javascripts
240
- │   └── application.js
241
- └── stylesheets
242
- └── application.css
243
- ```
244
-
245
- You may have noticed a different naming structure here, it's easily achieved with a few settings.
246
-
247
- ```ruby
248
- # application.rb
249
- require 'lotus'
250
-
251
- module Furnitures
252
- class Application < Lotus::Application
253
- configure do
254
- layout :application
255
- routes do
256
- get '/', to: 'catalog#index'
257
- end
258
-
259
- load_paths << 'app'
260
-
261
- controller_pattern "%{controller}Controller::%{action}"
262
- view_pattern "%{controller}::%{action}"
263
- end
264
- end
265
- end
266
- ```
267
-
268
- The patterns above, are indicating to Lotus the name structure that we want to use for our application.
269
- The main actor of the HTTP layer is an action. Actions are classes grouped logically in the same module called controller.
270
-
271
- For an incoming `GET` request to `/`, the router will look for a `CatalogController` with an `Index` action.
272
- Once the action will be called, the control will pass to the view. Here the application will look for a `Catalog` module with an `Index` view.
273
-
274
- **That two patters are interpolated at the runtime, with the controller/action informations passed by the router.**
275
-
276
- #### Top level architecture
277
-
278
- ```
279
- test/fixtures/information_tech
280
- ├── app
281
- │   ├── controllers
282
- │   │   └── hardware_controller.rb HardwareController::Index
283
- │   ├── templates
284
- │   │   ├── app.html.erb
285
- │   │   └── hardware
286
- │   │      └── index.html.erb
287
- │   └── views
288
- │   ├── app_layout.rb AppLayout
289
- │   └── hardware
290
- │       └── index.rb Hardware::Index
291
- ├── application.rb InformationTech::Application
292
- ├── config
293
- │   └── routes.rb
294
- └── public
295
- ├── favicon.ico
296
- ├── fonts
297
- │   └── cabin-medium.woff
298
- ├── images
299
- │   └── application.jpg
300
- ├── javascripts
301
- │   └── application.js
302
- └── stylesheets
303
- └── application.css
105
+ ```shell
106
+ % lotus new pocket --arch=container
107
+ % lotus new pocket # --arch=container is the default
304
108
  ```
305
109
 
306
- While this architecture is technically possible, it's discouraged, because it pollutes the global namespace and it makes hard to split in several deliverables, once the code base will be big enough.
307
-
308
- ```ruby
309
- # application.rb
310
- require 'lotus'
311
-
312
- module InformationTech
313
- class Application < Lotus::Application
314
- configure do
315
- namespace Object
110
+ Read more about this [architecture](https://github.com/lotus/lotus/wiki/Container-architecture).
316
111
 
317
- controller_pattern '%{controller}Controller::%{action}'
318
- view_pattern '%{controller}::%{action}'
112
+ ### _Application_ architecture
319
113
 
320
- layout :app
114
+ _upcoming_
321
115
 
322
- load_paths << 'app'
323
- routes 'config/routes'
324
- end
325
- end
326
- end
116
+ ### _Micro_ architecture
327
117
 
328
- # We use Object, because it's the top level Ruby namespace.
329
- ```
118
+ _upcoming_
330
119
 
331
- ### Conventions
120
+ ## Conventions
332
121
 
333
- * Lotus expects that controllers, actions and views to have a specific pattern (see Configuration for customizations)
122
+ * Lotus expects controllers, actions and views to have a specific pattern (see [Configuration](#configuration) for customizations)
334
123
  * All the commands must be run from the root of the project. If this requirement cannot be satisfied, please hardcode the path with `Configuration#root`.
335
124
  * The template name must reflect the name of the corresponding view: `Bookshelf::Views::Dashboard::Index` for `dashboard/index.html.erb`.
336
125
  * All the static files are served by the internal Rack middleware stack.
337
126
  * The application expects to find static files under `public/` (see `Configuration#assets`)
338
127
  * If the public folder doesn't exist, it doesn't serve static files.
339
128
 
340
- ### Non-Conventions
129
+ ## Non-Conventions
341
130
 
342
131
  * The application structure can be organized according to developer needs.
343
132
  * No file-to-name convention: modules and classes can live in one or multiple files.
344
- * No autoloading paths. They must be explicitely configured.
133
+ * No autoloading paths. They must be explicitly configured.
345
134
 
346
- ### Configuration
135
+ ## Configuration
136
+
137
+ <a name="configuration"></a>
347
138
 
348
139
  A Lotus application can be configured with a DSL that determines its behavior.
349
140
 
@@ -353,24 +144,32 @@ require 'lotus'
353
144
  module Bookshelf
354
145
  class Application < Lotus::Application
355
146
  configure do
147
+ ########################
148
+ # BASIC CONFIGURATIONS #
149
+ ########################
150
+
356
151
  # Determines the root of the application (optional)
357
152
  # Argument: String, Pathname, defaults to Dir.pwd
358
153
  #
359
- root 'path/to/root'
360
-
361
- # The Ruby namespace where to lookup for actions and views (optional)
362
- # Argument: Module, Class, defaults to the application module (eg. Bookshelf)
363
- #
364
- namespace Object
154
+ root 'path/to/root' # or __root__
365
155
 
366
156
  # The relative load paths where the application will recursively load the code (mandatory)
367
157
  # Argument: String, Array<String>, defaults to empty set
368
158
  #
369
159
  load_paths << [
370
- 'app/controllers',
371
- 'app/views'
160
+ 'controllers',
161
+ 'views'
372
162
  ]
373
163
 
164
+ # Handle exceptions with HTTP statuses (true) or don't catch them (false)
165
+ # Argument: boolean, defaults to true
166
+ #
167
+ handle_exceptions true
168
+
169
+ #######################
170
+ # HTTP CONFIGURATIONS #
171
+ #######################
172
+
374
173
  # The route set (mandatory)
375
174
  # Argument: Proc with the routes definition
376
175
  #
@@ -383,62 +182,193 @@ module Bookshelf
383
182
  #
384
183
  routes 'config/routes'
385
184
 
386
- # The layout to be used by all the views (optional)
387
- # Argument: A Symbol that indicates the name, default to nil
185
+ # URI scheme used by the routing system to generate absolute URLs (optional)
186
+ # Argument: A string, default to "http"
388
187
  #
389
- layout :application # Will look for Bookshelf::Views::ApplicationLayout
188
+ scheme 'https'
390
189
 
391
- # The relative path where to find the templates (optional)
392
- # Argument: A string with the relative path, default to the root of the app
190
+ # URI host used by the routing system to generate absolute URLs (optional)
191
+ # Argument: A string, default to "localhost"
192
+ #
193
+ host 'bookshelf.org'
194
+
195
+ # URI port used by the routing system to generate absolute URLs (optional)
196
+ # Argument: An object coercible to integer, default to 80 if the scheme is http and 443 if it's https
197
+ # This SHOULD be configured only in case the application listens to that non standard ports
198
+ #
199
+ port 2323
200
+
201
+ # Toggle cookies (optional)
202
+ # Argument: A [`TrueClass`, `FalseClass`], default to `FalseClass`.
203
+ #
204
+ cookies true
205
+
206
+ # Toggle sessions (optional)
207
+ # Argument: Symbol the Rack session adapter
208
+ # A Hash with options
393
209
  #
394
- templates 'app/templates'
210
+ sessions :cookie, secret: ENV['SESSIONS_SECRET']
395
211
 
396
212
  # Default format for the requests that don't specify an HTTP_ACCEPT header (optional)
397
213
  # Argument: A symbol representation of a mime type, default to :html
398
214
  #
399
215
  default_format :json
400
216
 
401
- # URI scheme used by the routing system to generate absoule URLs (optional)
402
- # Argument: A string, default to "http"
217
+ # Rack middleware configuration (optional)
403
218
  #
404
- scheme 'https'
219
+ middleware.use Rack::Protection
405
220
 
406
- # URI host used by the routing system to generate absoule URLs (optional)
407
- # Argument: A string, default to "localhost"
221
+ # HTTP Body parsers (optional)
222
+ # Parse non GET responses body for a specific mime type
223
+ # Argument: Symbol, which represent the format of the mime type (only `:json` is supported)
224
+ # Object, the parser
408
225
  #
409
- host 'bookshelf.org'
226
+ body_parsers :json, MyXMLParser.new
227
+
228
+ ###########################
229
+ # DATABASE CONFIGURATIONS #
230
+ ###########################
231
+
232
+ # Configure a database adapter (optional)
233
+ # Argument: A Hash with the settings
234
+ # type: Symbol, :file_system, :memory and :sql
235
+ # uri: String, 'file:///db/bookshelf'
236
+ # 'memory://localhost/bookshelf'
237
+ # 'sqlite:memory:'
238
+ # 'sqlite://db/bookshelf.db'
239
+ # 'postgres://localhost/bookshelf'
240
+ # 'mysql://localhost/bookshelf'
241
+ #
242
+ adapter type: :file_system, uri: ENV['DATABASE_URL']
410
243
 
411
- # URI port used by the routing system to generate absoule URLs (optional)
412
- # Argument: An object coercible to integer, default to 80 if the scheme is http and 443 if it's https
413
- # This SHOULD be configured only in case the application listens to that non standard ports
244
+ # Configure a database mapping (optional)
245
+ # Argument: Proc
414
246
  #
415
- port 2323
247
+ mapping do
248
+ collection :users do
249
+ entity User
250
+ repository UserRepository
251
+
252
+ attribute :id, Integer
253
+ attribute :name, String
254
+ end
255
+ end
416
256
 
417
- # The name pattern to find controller and actions (optional)
418
- # Argument: A string, it must contain "%{controller}" and %{action}
419
- # Default to "Controllers::%{controller}::%{action}"
257
+ # Configure a database mapping (optional, alternative usage)
258
+ # Argument: A relative path where to find the mapping definitions
420
259
  #
421
- controller_pattern '%{controller}Controller::%{action}'
260
+ mapping 'config/mapping'
422
261
 
423
- # The name pattern to find views (optional)
424
- # Argument: A string, it must contain "%{controller}" and %{action}
425
- # Default to "Views::%{controller}::%{action}"
262
+ ############################
263
+ # TEMPLATES CONFIGURATIONS #
264
+ ############################
265
+
266
+ # The layout to be used by all the views (optional)
267
+ # Argument: A Symbol that indicates the name, default to nil
268
+ #
269
+ layout :application # Will look for Bookshelf::Views::ApplicationLayout
270
+
271
+ # The relative path where to find the templates (optional)
272
+ # Argument: A string with the relative path, default to the root of the app
273
+ #
274
+ templates 'templates'
275
+
276
+ #########################
277
+ # ASSETS CONFIGURATIONS #
278
+ #########################
279
+
280
+ # Specify sources for assets (optional)
281
+ # Argument: String, Array<String>, defaults to 'public'
282
+ #
283
+ assets << [
284
+ 'public',
285
+ 'vendor/assets'
286
+ ]
287
+
288
+ # Enabling serving assets (optional)
289
+ # Argument: boolean, defaults to false
290
+ #
291
+ serve_assets true
292
+
293
+ #############################
294
+ # FRAMEWORKS CONFIGURATIONS #
295
+ #############################
296
+
297
+ # Low level configuration for Lotus::View (optional)
298
+ # The given block will be yielded every time `Lotus::View` is included.
299
+ # This is helpful to share logic between views
300
+ # See the related documentation
301
+ # Argument: Proc
426
302
  #
427
- view_pattern '%{controller}Views::%{action}'
303
+ view.prepare do
304
+ include MyCustomRoutingHelpers # included by all the views
305
+ end
306
+
307
+ # Low level configuration for Lotus::Controller (optional)
308
+ # Argument: Proc
309
+ controller.prepare do
310
+ include Authentication # included by all the actions
311
+ before :authenticate! # run auth logic before each action
312
+ end
313
+ end
314
+
315
+ ###############################
316
+ # ENVIRONMENTS CONFIGURATIONS #
317
+ ###############################
318
+
319
+ configure :development do
320
+ # override the general configuration only for the development environment
321
+ handle_exceptions false
322
+ serve_assets true
323
+ end
324
+
325
+ configure :test do
326
+ # override the general configuration only for the test environment
327
+ host 'test.host'
428
328
  end
429
329
  end
430
330
  end
431
331
  ```
432
332
 
433
- ## The future
333
+ ## Command line
334
+
335
+ Lotus provides a few command line utilities:
336
+
337
+ ### Server
434
338
 
435
- Lotus uses different approaches for web development with Ruby, for this reason, it needs to reach a certain code maturity degree.
436
- It will improved by collecting the feedback of real world applications.
339
+ It looks at the `config.ru` file in the root of the application, and starts the Rack server defined in your `Gemfile` (eg. puma, thin, unicorn). It defaults to WEBRick.
437
340
 
438
- Also, it still lacks of features like: live reloading, multiple environments, code generators, cli, etc..
439
- Please get involved with the project.
341
+ It supports **code reloading** feature by default, useful for development purposes.
342
+
343
+ ```shell
344
+ % bundle exec lotus server
345
+ ```
346
+
347
+ ### Console
348
+
349
+ It starts a REPL, by using the engine defined in your `Gemfile`. It defaults to IRb. **Run it from the root of the application**.
350
+
351
+ ```shell
352
+ % bundle exec lotus console
353
+ ```
440
354
 
441
- Thank you.
355
+ It supports **code reloading** via the `reload!` command.
356
+
357
+ ### Routes
358
+
359
+ It prints the routes defined by the Lotus application(s).
360
+
361
+ ```shell
362
+ % bundle exec lotus routes
363
+ ```
364
+
365
+ ### Version
366
+
367
+ It prints the current Lotus version.
368
+
369
+ ```shell
370
+ % bundle exec lotus version
371
+ ```
442
372
 
443
373
  ## Contributing
444
374
 
data/bin/lotus ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lotus/cli'
4
+ Lotus::Cli.start