lotusrb 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d28819002e6d575706d772613ca8acbc42888d1
4
- data.tar.gz: 177882c7445b20f85c2b28fe97b9203bd2ee89e0
3
+ metadata.gz: 74fd948b607c701d1250dc47afc23b7aa1162f7c
4
+ data.tar.gz: c8785125081fc134d26b79e278679cafa3b35133
5
5
  SHA512:
6
- metadata.gz: 81f9b224f32e558aef69409bef59569d583c23bbdcad5a27b18e19237110bb092585b9172a8e8c4e62411c537121f5a1aba6b2a0da69ceaf394b22b11539417b
7
- data.tar.gz: 13fbb08851dd26c62f7a89a055318d53f2f034a5b25f179e146f1085f3ef6768e68848c79f82cc65af0a6df617f9f18430542ea5fc53209796aa03654b8a06f7
6
+ metadata.gz: c8e7ad9a91a5ebc28557a55bcb320fe96986f36822499be4abe127e038bb06afa17c3e4c4767c04687ec4e55d2f44a77fb50fe81b763d344dc0d8ddb3e55ac53
7
+ data.tar.gz: a4e96da94c3d7f60f88fd719e02f692b86a919f2a56dbb6a173a1e528089cccfad0b344dcf365eb3b0f1ee857e77dde5918c4b0d46c2b8c534dc187b5d85f748
File without changes
data/README.md CHANGED
@@ -1,29 +1,457 @@
1
- # Lotusrb
1
+ # Lotus
2
2
 
3
- TODO: Write a gem description
3
+ A complete web framework for Ruby
4
+
5
+ ## Status
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/lotusrb.png)](http://badge.fury.io/rb/lotusrb)
8
+ [![Build Status](https://secure.travis-ci.org/lotus/lotus.png?branch=master)](http://travis-ci.org/lotus/lotus?branch=master)
9
+ [![Coverage](https://coveralls.io/repos/lotus/lotus/badge.png?branch=master)](https://coveralls.io/r/lotus/lotus)
10
+ [![Code Climate](https://codeclimate.com/github/lotus/lotus.png)](https://codeclimate.com/github/lotus/lotus)
11
+ [![Dependencies](https://gemnasium.com/lotus/lotus.png)](https://gemnasium.com/lotus/lotus)
12
+ [![Inline docs](http://inch-ci.org/github/lotus/lotus.png)](http://inch-ci.org/github/lotus/lotus)
13
+
14
+ ## Contact
15
+
16
+ * Home page: http://lotusrb.org
17
+ * Mailing List: http://lotusrb.org/mailing-list
18
+ * API Doc: http://rdoc.info/gems/lotusrb
19
+ * Bugs/Issues: https://github.com/lotus/lotus/issues
20
+ * Support: http://stackoverflow.com/questions/tagged/lotus-ruby
21
+ * Chat: https://gitter.im/lotus/chat
22
+
23
+ ## Rubies
24
+
25
+ __Lotus__ supports Ruby (MRI) 2+
4
26
 
5
27
  ## Installation
6
28
 
7
29
  Add this line to your application's Gemfile:
8
30
 
9
- gem 'lotusrb'
31
+ ```ruby
32
+ gem 'lotusrb'
33
+ ```
10
34
 
11
35
  And then execute:
12
36
 
13
- $ bundle
37
+ ```shell
38
+ $ bundle
39
+ ```
14
40
 
15
41
  Or install it yourself as:
16
42
 
17
- $ gem install lotusrb
43
+ ```shell
44
+ $ gem install lotusrb
45
+ ```
18
46
 
19
47
  ## Usage
20
48
 
21
- TODO: Write usage instructions here
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.**
54
+
55
+ ### Architecture
56
+
57
+ Unlike the other Ruby web frameworks, it has a flexible conventions for the code structure.
58
+ Developers can arrange the layout of their projects as they prefer.
59
+ There is a suggested architecture that can be easily changed with a few settings.
60
+
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.
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
84
+
85
+ module Controllers::Home
86
+ include OneFile::Controller
87
+
88
+ action 'Index' do
89
+ def call(params)
90
+ end
91
+ end
92
+ end
93
+
94
+ module Views::Home
95
+ class Index
96
+ include OneFile::View
97
+
98
+ def render
99
+ 'Hello'
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ run OneFile::Application.new
106
+ ```
107
+
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**.
111
+
112
+ #### Microservices architecture
113
+
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
+ ```
170
+
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.
173
+
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.**
176
+
177
+ ```ruby
178
+ # apps/backend/application.rb
179
+ require 'lotus'
180
+
181
+ module Backend
182
+ class Application < Lotus::Application
183
+ configure do
184
+ load_paths << [
185
+ 'controllers',
186
+ 'views'
187
+ ]
188
+
189
+ layout :backend
190
+
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
304
+ ```
305
+
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
316
+
317
+ controller_pattern '%{controller}Controller::%{action}'
318
+ view_pattern '%{controller}::%{action}'
319
+
320
+ layout :app
321
+
322
+ load_paths << 'app'
323
+ routes 'config/routes'
324
+ end
325
+ end
326
+ end
327
+
328
+ # We use Object, because it's the top level Ruby namespace.
329
+ ```
330
+
331
+ ### Conventions
332
+
333
+ * Lotus expects that controllers, actions and views to have a specific pattern (see Configuration for customizations)
334
+ * 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
+ * The template name must reflect the name of the corresponding view: `Bookshelf::Views::Dashboard::Index` for `dashboard/index.html.erb`.
336
+ * All the static files are served by the internal Rack middleware stack.
337
+ * The application expects to find static files under `public/` (see `Configuration#assets`)
338
+ * If the public folder doesn't exist, it doesn't serve static files.
339
+
340
+ ### Non-Conventions
341
+
342
+ * The application structure can be organized according to developer needs.
343
+ * No file-to-name convention: modules and classes can live in one or multiple files.
344
+ * No autoloading paths. They must be explicitely configured.
345
+
346
+ ### Configuration
347
+
348
+ A Lotus application can be configured with a DSL that determines its behavior.
349
+
350
+ ```ruby
351
+ require 'lotus'
352
+
353
+ module Bookshelf
354
+ class Application < Lotus::Application
355
+ configure do
356
+ # Determines the root of the application (optional)
357
+ # Argument: String, Pathname, defaults to Dir.pwd
358
+ #
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
365
+
366
+ # The relative load paths where the application will recursively load the code (mandatory)
367
+ # Argument: String, Array<String>, defaults to empty set
368
+ #
369
+ load_paths << [
370
+ 'app/controllers',
371
+ 'app/views'
372
+ ]
373
+
374
+ # The route set (mandatory)
375
+ # Argument: Proc with the routes definition
376
+ #
377
+ routes do
378
+ get '/', to: 'home#index'
379
+ end
380
+
381
+ # The route set (mandatory) (alternative usage)
382
+ # Argument: A relative path where to find the routes definition
383
+ #
384
+ routes 'config/routes'
385
+
386
+ # The layout to be used by all the views (optional)
387
+ # Argument: A Symbol that indicates the name, default to nil
388
+ #
389
+ layout :application # Will look for Bookshelf::Views::ApplicationLayout
390
+
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
393
+ #
394
+ templates 'app/templates'
395
+
396
+ # Default format for the requests that don't specify an HTTP_ACCEPT header (optional)
397
+ # Argument: A symbol representation of a mime type, default to :html
398
+ #
399
+ default_format :json
400
+
401
+ # URI scheme used by the routing system to generate absoule URLs (optional)
402
+ # Argument: A string, default to "http"
403
+ #
404
+ scheme 'https'
405
+
406
+ # URI host used by the routing system to generate absoule URLs (optional)
407
+ # Argument: A string, default to "localhost"
408
+ #
409
+ host 'bookshelf.org'
410
+
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
414
+ #
415
+ port 2323
416
+
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}"
420
+ #
421
+ controller_pattern '%{controller}Controller::%{action}'
422
+
423
+ # The name pattern to find views (optional)
424
+ # Argument: A string, it must contain "%{controller}" and %{action}
425
+ # Default to "Views::%{controller}::%{action}"
426
+ #
427
+ view_pattern '%{controller}Views::%{action}'
428
+ end
429
+ end
430
+ end
431
+ ```
432
+
433
+ ## The future
434
+
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.
437
+
438
+ Also, it still lacks of features like: live reloading, multiple environments, code generators, cli, etc..
439
+ Please get involved with the project.
440
+
441
+ Thank you.
22
442
 
23
443
  ## Contributing
24
444
 
25
- 1. Fork it ( http://github.com/<my-github-username>/lotusrb/fork )
445
+ 1. Fork it ( https://github.com/lotus/lotus/fork )
26
446
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
447
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
448
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
449
+ 5. Create a new Pull Request
450
+
451
+ ## Versioning
452
+
453
+ __Lotus__ uses [Semantic Versioning 2.0.0](http://semver.org)
454
+
455
+ ## Copyright
456
+
457
+ Copyright 2014 Luca Guidi – Released under MIT License