lotusrb 0.1.0 → 0.2.0

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.
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
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,8 @@
1
+ module <%= config[:classified_slice_name] %>::Controllers::Home
2
+ class Index
3
+ include <%= config[:classified_slice_name] %>::Action
4
+
5
+ def call(params)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,182 @@
1
+ module <%= config[:classified_slice_name] %>
2
+ class Application < Lotus::Application
3
+ configure do
4
+ ##
5
+ # BASIC
6
+ #
7
+
8
+ # Define the root path of this application.
9
+ # All the paths specified in this configuration are relative to this one.
10
+ #
11
+ root __dir__
12
+
13
+ # Relative load paths where this application will recursively load the code.
14
+ # Remember to add directories here when you create new.
15
+ #
16
+ load_paths << [
17
+ 'controllers',
18
+ 'views'
19
+ ]
20
+
21
+ # Handle exceptions with HTTP statuses (true) or don't catch them (false).
22
+ # Defaults to true.
23
+ # See: http://www.rubydoc.info/gems/lotus-controller/#Exceptions_management
24
+ #
25
+ # handle_exceptions true
26
+
27
+ ##
28
+ # HTTP
29
+ #
30
+
31
+ # Routes definitions for this application
32
+ # See: http://www.rubydoc.info/gems/lotus-router#Usage
33
+ #
34
+ routes 'config/routes'
35
+
36
+ # URI scheme used by the routing system to generate absolute URLs
37
+ # Defaults to "http"
38
+ #
39
+ # scheme 'https'
40
+
41
+ # URI host used by the routing system to generate absolute URLs
42
+ # Defaults to "localhost"
43
+ #
44
+ # host 'example.org'
45
+
46
+ # URI port used by the routing system to generate absolute URLs
47
+ # Argument: An object coercible to integer, default to 80 if the scheme is http and 443 if it's https
48
+ # This SHOULD be configured only in case the application listens to that non standard ports
49
+ #
50
+ # port 443
51
+
52
+ # Enable cookies
53
+ #
54
+ # cookies true
55
+
56
+ # Enable sessions
57
+ # Argument: Symbol the Rack session adapter
58
+ # A Hash with options
59
+ #
60
+ # See: http://www.rubydoc.info/gems/rack/Rack/Session/Cookie
61
+ #
62
+ # sessions :cookie, secret: ENV['<%= config[:upcase_slice_name] %>_SESSIONS_SECRET']
63
+
64
+ # Configure Rack middleware for this application
65
+ #
66
+ # middleware.use Rack::Protection
67
+
68
+ # Default format for the requests that don't specify an HTTP_ACCEPT header
69
+ # Argument: A symbol representation of a mime type, default to :html
70
+ #
71
+ # default_format :html
72
+
73
+ # HTTP Body parsers
74
+ # Parse non GET responses body for a specific mime type
75
+ # Argument: Symbol, which represent the format of the mime type (only `:json` is supported)
76
+ # Object, the parser
77
+ #
78
+ # body_parsers :json
79
+
80
+ ##
81
+ # DATABASE
82
+ #
83
+
84
+ # Configure a database adapter
85
+ # Argument: A Hash with the settings
86
+ # type: Symbol, :file_system, :memory and :sql
87
+ # uri: String, 'file:///db/bookshelf'
88
+ # 'memory://localhost/bookshelf'
89
+ # 'sqlite:memory:'
90
+ # 'sqlite://db/bookshelf.db'
91
+ # 'postgres://localhost/bookshelf'
92
+ # 'mysql://localhost/bookshelf'
93
+ #
94
+ # adapter type: :file_system, uri: ENV['<%= config[:upcase_slice_name] %>_DATABASE_URL']
95
+
96
+ # Configure a database mapping
97
+ # See: http://www.rubydoc.info/gems/lotus-model#Data_Mapper
98
+ #
99
+ # mapping 'config/mapping'
100
+
101
+ ##
102
+ # TEMPLATES
103
+ #
104
+
105
+ # The layout to be used by all the views
106
+ #
107
+ layout :application # It will load <%= config[:classified_slice_name] %>::Views::ApplicationLayout
108
+
109
+ # The relative path where to find the templates
110
+ #
111
+ # templates 'templates'
112
+
113
+ ##
114
+ # ASSETS
115
+ #
116
+
117
+ # Specify sources for assets
118
+ # The directory `public/` is added by default
119
+ #
120
+ # assets << [
121
+ # 'vendor/javascripts'
122
+ # ]
123
+
124
+ # Enabling serving assets
125
+ # Defaults to false
126
+ #
127
+ # serve_assets false
128
+
129
+ ##
130
+ # FRAMEWORKS
131
+ #
132
+
133
+ # Configure the code to be yielded each time <%= config[:classified_slice_name] %>::Action will be included
134
+ # This is useful for share common functionalities
135
+ #
136
+ # See: http://www.rubydoc.info/gems/lotus-controller#Configuration
137
+ controller.prepare do
138
+ # include MyAuthentication # included in all the actions
139
+ # before :authenticate! # run an authentication before callback
140
+ end
141
+
142
+ # Configure the code to be yielded each time <%= config[:classified_slice_name] %>::View will be included
143
+ # This is useful for share common functionalities
144
+ #
145
+ # See: http://www.rubydoc.info/gems/lotus-view#Configuration
146
+ view.prepare do
147
+ # include MyRoutingHelpers # included in all the views
148
+ end
149
+ end
150
+
151
+ ##
152
+ # DEVELOPMENT
153
+ #
154
+ configure :development do
155
+ # Don't handle exceptions, render the stack trace
156
+ handle_exceptions false
157
+
158
+ # Serve static assets during development
159
+ serve_assets true
160
+ end
161
+
162
+ ##
163
+ # TEST
164
+ #
165
+ configure :test do
166
+ # Don't handle exceptions, render the stack trace
167
+ handle_exceptions false
168
+
169
+ # Serve static assets during development
170
+ serve_assets true
171
+ end
172
+
173
+ ##
174
+ # PRODUCTION
175
+ #
176
+ configure :production do
177
+ # scheme 'https'
178
+ # host 'example.org'
179
+ # port 443
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,10 @@
1
+ # Configure your database mapping here
2
+ # See: http://www.rubydoc.info/gems/lotus-model/#Usage
3
+ #
4
+ # collection :users do
5
+ # entity User
6
+ # repository UserRepository
7
+ #
8
+ # attribute :id, Integer
9
+ # attribute :name, String
10
+ # end
@@ -0,0 +1,8 @@
1
+ # Configure your routes here
2
+ # See: http://www.rubydoc.info/gems/lotus-router/#Usage
3
+ #
4
+ #
5
+ #
6
+ # This route will look for `<%= config[:classified_slice_name] %>::Controllers::Home::Index` action in `apps/<%= config[:slice_name] %>/controllers/home/index.rb`.
7
+ # Please, uncomment the following line to have a working example.
8
+ # get '/', to: 'home#index'
@@ -0,0 +1,9 @@
1
+ <!doctype HTML>
2
+ <html>
3
+ <head>
4
+ <title>Chirp!</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <!doctype HTML>
2
+ <html>
3
+ <head>
4
+ <title><%= config[:classified_slice_name] %></title>
5
+ </head>
6
+ <body>
7
+ <%%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Welcome to Lotus!</h1>
2
+ <h3>This template is rendered by <code><%= config[:classified_slice_name] %>::Views::Home::Index</code> and it's available at: <code>apps/<%= config[:slice_name] %>/templates/home/index.html.erb</code></h3>
@@ -0,0 +1,5 @@
1
+ module <%= config[:classified_slice_name] %>::Views::Home
2
+ class Index
3
+ include <%= config[:classified_slice_name] %>::View
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module <%= config[:classified_slice_name] %>
2
+ module Views
3
+ class ApplicationLayout
4
+ include <%= config[:classified_slice_name] %>::Layout
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,103 @@
1
+ require 'securerandom'
2
+ require 'lotus/generators/abstract'
3
+ require 'lotus/utils/string'
4
+
5
+ module Lotus
6
+ module Generators
7
+ class Slice < Abstract
8
+ def initialize(command)
9
+ super
10
+
11
+ @slice_name = options.fetch(:application)
12
+ @upcase_slice_name = @slice_name.upcase
13
+ @classified_slice_name = Utils::String.new(@slice_name).classify
14
+
15
+ @source = Pathname.new(::File.dirname(__FILE__) + '/../generators/slice')
16
+ @target = target.join('apps', @slice_name)
17
+
18
+ @slice_base_url = options.fetch(:application_base_url)
19
+
20
+ cli.class.source_root(@source)
21
+ end
22
+
23
+ def start
24
+ opts = {
25
+ slice_name: @slice_name,
26
+ upcase_slice_name: @upcase_slice_name,
27
+ classified_slice_name: @classified_slice_name,
28
+ slice_base_url: @slice_base_url
29
+ }
30
+
31
+ templates = {
32
+ 'application.rb.tt' => 'application.rb',
33
+ 'config/routes.rb.tt' => 'config/routes.rb',
34
+ 'config/mapping.rb.tt' => 'config/mapping.rb',
35
+ 'action.rb.tt' => 'controllers/home/index.rb',
36
+ 'views/application_layout.rb.tt' => 'views/application_layout.rb',
37
+ 'templates/application.html.erb.tt' => 'templates/application.html.erb',
38
+ 'view.rb.tt' => 'views/home/index.rb',
39
+ 'templates/template.html.erb.tt' => 'templates/home/index.html.erb',
40
+ }
41
+
42
+ empty_directories = [
43
+ "public/javascripts",
44
+ "public/stylesheets"
45
+ ]
46
+
47
+ case options[:test]
48
+ when 'rspec'
49
+ else # minitest (default)
50
+ empty_directories << [
51
+ "../../spec/#{ opts[:slice_name] }/features",
52
+ "../../spec/#{ opts[:slice_name] }/controllers",
53
+ "../../spec/#{ opts[:slice_name] }/views"
54
+ ]
55
+ end
56
+
57
+ ##
58
+ # config/environment.rb
59
+ #
60
+
61
+ # Add "require_relative '../apps/web/application'"
62
+ cli.gsub_file target.join('config/environment.rb'), /require_relative (.*)/ do |match|
63
+ match << "\nrequire_relative '../apps/#{ opts[:slice_name] }/application'"
64
+ end
65
+
66
+ # Mount slice inside "Lotus::Container.configure"
67
+ cli.gsub_file target.join('config/environment.rb'), /(mount (.*)|Lotus::Container.configure do)/ do |match|
68
+ match << "\n mount #{ opts[:classified_slice_name] }::Application, at: '#{ opts[:slice_base_url] }'"
69
+ end
70
+
71
+ ##
72
+ # Per environment .env
73
+ #
74
+ ['development', 'test'].each do |environment|
75
+ # Add WEB_DATABASE_URL="file:///db/web_development"
76
+ cli.append_to_file target.join("config/.env.#{ environment }") do
77
+ %(#{ opts[:upcase_slice_name] }_DATABASE_URL="file:///db/#{ opts[:slice_name] }_#{ environment }"\n)
78
+ end
79
+
80
+ # Add WEB_SESSIONS_SECRET="abc123" (random hex)
81
+ cli.append_to_file target.join("config/.env.#{ environment }") do
82
+ %(#{ opts[:upcase_slice_name] }_SESSIONS_SECRET="#{ SecureRandom.hex(32) }"\n)
83
+ end
84
+ end
85
+
86
+ ##
87
+ # New files
88
+ #
89
+ templates.each do |src, dst|
90
+ cli.template(@source.join(src), @target.join(dst), opts)
91
+ end
92
+
93
+ ##
94
+ # Empty directories
95
+ #
96
+ empty_directories.flatten.each do |dir|
97
+ gitkeep = '.gitkeep'
98
+ cli.template(@source.join(gitkeep), @target.join(dir, gitkeep), opts)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
data/lib/lotus/loader.rb CHANGED
@@ -3,6 +3,8 @@ require 'lotus/utils/kernel'
3
3
  require 'lotus/utils/string'
4
4
  require 'lotus/routes'
5
5
  require 'lotus/routing/default'
6
+ require 'lotus/action/cookies'
7
+ require 'lotus/action/session'
6
8
 
7
9
  module Lotus
8
10
  # Load an application
@@ -20,9 +22,10 @@ module Lotus
20
22
  def load!
21
23
  @mutex.synchronize do
22
24
  load_configuration!
25
+ configure_frameworks!
26
+ load_configuration_load_paths!
27
+ load_rack!
23
28
  load_frameworks!
24
- load_application!
25
- finalize!
26
29
  end
27
30
  end
28
31
 
@@ -33,34 +36,109 @@ module Lotus
33
36
  configuration.load!(application_module)
34
37
  end
35
38
 
36
- def load_frameworks!
39
+ def configure_frameworks!
40
+ _configure_model_framework! if defined?(Lotus::Model)
41
+ _configure_controller_framework!
42
+ _configure_view_framework!
43
+ end
44
+
45
+ def _configure_controller_framework!
37
46
  config = configuration
47
+ unless namespace.const_defined?('Controller')
48
+ controller = Lotus::Controller.duplicate(namespace) do
49
+ handle_exceptions config.handle_exceptions
50
+ default_format config.default_format
38
51
 
39
- unless application_module.const_defined?('Controller')
40
- controller = Lotus::Controller.duplicate(application_module) do
41
- default_format config.default_format
52
+ prepare { include Lotus::Action::Cookies } if config.cookies
53
+ prepare { include Lotus::Action::Session } if config.sessions.enabled?
54
+
55
+ config.controller.__apply(self)
42
56
  end
43
57
 
44
- application_module.const_set('Controller', controller)
58
+ namespace.const_set('Controller', controller)
45
59
  end
60
+ end
46
61
 
47
- unless application_module.const_defined?('View')
48
- view = Lotus::View.duplicate(application_module) do
62
+ def _configure_view_framework!
63
+ config = configuration
64
+ unless namespace.const_defined?('View')
65
+ view = Lotus::View.duplicate(namespace) do
49
66
  root config.templates
50
67
  layout config.layout
68
+
69
+ config.view.__apply(self)
51
70
  end
52
71
 
53
- application_module.const_set('View', view)
72
+ namespace.const_set('View', view)
73
+ end
74
+ end
75
+
76
+ def _configure_model_framework!
77
+ config = configuration
78
+ if _lotus_model_loaded? && !application_module.const_defined?('Model')
79
+ model = Lotus::Model.duplicate(application_module) do
80
+ adapter(config.adapter) if config.adapter
81
+ mapping(&config.mapping) if config.mapping
82
+
83
+ config.model.__apply(self)
84
+ end
85
+
86
+ application_module.const_set('Model', model)
87
+ end
88
+ end
89
+
90
+
91
+ def load_frameworks!
92
+ _load_view_framework!
93
+ _load_model_framework!
94
+ end
95
+
96
+ def _load_view_framework!
97
+ namespace.module_eval %{
98
+ #{ namespace }::View.load!
99
+ }
100
+ end
101
+
102
+ def _load_model_framework!
103
+ return unless _load_model_framework?
104
+
105
+ application_module.module_eval %{
106
+ #{ application_module }::Model.load!
107
+ }
108
+ end
109
+
110
+ def _load_model_framework?
111
+ if _lotus_model_loaded? && application_module.const_defined?('Model')
112
+ model = application_module.const_get('Model')
113
+ model.configuration.adapter
54
114
  end
55
115
  end
56
116
 
57
- def load_application!
117
+ def _lotus_model_loaded?
118
+ defined?(Lotus::Model)
119
+ end
120
+
121
+ def load_configuration_load_paths!
58
122
  configuration.load_paths.load!(configuration.root)
59
- namespace = configuration.namespace || application_module
123
+ end
60
124
 
125
+ def load_rack!
126
+ return if application.is_a?(Class)
127
+ _assign_rendering_policy!
128
+ _assign_rack_routes!
129
+ _load_rack_middleware!
130
+ _assign_routes_to_application_module!
131
+ end
132
+
133
+ def _assign_rendering_policy!
134
+ application.renderer = RenderingPolicy.new(configuration)
135
+ end
136
+
137
+ def _assign_rack_routes!
61
138
  resolver = Lotus::Routing::EndpointResolver.new(pattern: configuration.controller_pattern, namespace: namespace)
62
139
  default_app = Lotus::Routing::Default.new
63
140
  application.routes = Lotus::Router.new(
141
+ parsers: configuration.body_parsers,
64
142
  resolver: resolver,
65
143
  default_app: default_app,
66
144
  scheme: configuration.scheme,
@@ -68,25 +146,27 @@ module Lotus
68
146
  port: configuration.port,
69
147
  &configuration.routes
70
148
  )
149
+ end
71
150
 
72
- application.middleware # preload
151
+ def _load_rack_middleware!
152
+ configuration.middleware.load!(application, namespace)
73
153
  end
74
154
 
75
- def finalize!
155
+ def _assign_routes_to_application_module!
76
156
  unless application_module.const_defined?('Routes')
77
157
  routes = Lotus::Routes.new(application.routes)
78
158
  application_module.const_set('Routes', routes)
79
159
  end
80
-
81
- application_module.module_eval %{
82
- #{ application_module }::View.load!
83
- }
84
160
  end
85
161
 
86
162
  def application_module
87
163
  @application_module ||= Utils::Class.load!(
88
- Utils::String.new(application.class).namespace
164
+ Utils::String.new(application.name).namespace
89
165
  )
90
166
  end
167
+
168
+ def namespace
169
+ configuration.namespace || application_module
170
+ end
91
171
  end
92
172
  end
@@ -6,7 +6,7 @@ module Lotus
6
6
  class Middleware
7
7
  # Instantiate a middleware stack
8
8
  #
9
- # @param application [Lotus::Application] the application
9
+ # @param configuration [Lotus::Configuration] the application's configuration
10
10
  #
11
11
  # @return [Lotus::Middleware] the new stack
12
12
  #
@@ -14,16 +14,29 @@ module Lotus
14
14
  # @api private
15
15
  #
16
16
  # @see Lotus::Configuration
17
- # @see http://rdoc.info/gems/rack/Rack/Builder
18
- def initialize(application)
19
- configuration = application.configuration
20
- routes = application.routes
17
+ def initialize(configuration)
18
+ @stack = []
19
+ @configuration = configuration
20
+ end
21
21
 
22
+ # Load the middleware stack
23
+ #
24
+ # @param application [Lotus::Application] the application loading the middleware
25
+ #
26
+ # @return [Lotus::Middleware] the loaded middleware stack
27
+ #
28
+ # @since 0.2.0
29
+ # @api private
30
+ #
31
+ # @see http://rdoc.info/gems/rack/Rack/Builder
32
+ def load!(application, namespace)
33
+ @namespace = namespace
22
34
  @builder = ::Rack::Builder.new
23
- @builder.use Rack::Static,
24
- urls: configuration.assets.entries,
25
- root: configuration.assets
26
- @builder.run routes
35
+ load_default_stack(application)
36
+ @stack.each { |m, args, block| @builder.use load_middleware(m), *args, &block }
37
+ @builder.run application.routes
38
+
39
+ self
27
40
  end
28
41
 
29
42
  # Process a request.
@@ -38,5 +51,75 @@ module Lotus
38
51
  def call(env)
39
52
  @builder.call(env)
40
53
  end
54
+
55
+ # Add a middleware to the stack.
56
+ #
57
+ # @param middleware [Object] a Rack middleware
58
+ # @param *args [Array] optional arguments to pass to the Rack middleware
59
+ # @param &blk [Proc] an optional block to pass to the Rack middleware
60
+ #
61
+ # @return [Array] the middleware that was added
62
+ #
63
+ # @since 0.2.0
64
+ def use(middleware, *args, &blk)
65
+ @stack << [middleware, args, blk]
66
+ end
67
+
68
+ # @api private
69
+ # @since 0.2.0
70
+ def load_middleware(middleware)
71
+ case middleware
72
+ when String
73
+ @namespace.const_get(middleware)
74
+ else
75
+ middleware
76
+ end
77
+ end
78
+
79
+ # @api private
80
+ # @since 0.2.0
81
+ def load_default_stack(application)
82
+ @default_stack_loaded ||= begin
83
+ _load_session_middleware
84
+ _load_asset_middlewares
85
+ _load_default_welcome_page_for(application)
86
+ use Rack::MethodOverride
87
+
88
+ true
89
+ end
90
+ end
91
+
92
+ # Default welcome page
93
+ #
94
+ # @api private
95
+ # @since 0.2.0
96
+ def _load_default_welcome_page_for(application)
97
+ unless application.routes.defined?
98
+ require 'lotus/welcome'
99
+ use Lotus::Welcome
100
+ end
101
+ end
102
+
103
+ # Add session middleware
104
+ #
105
+ # @api private
106
+ # @since 0.2.0
107
+ def _load_session_middleware
108
+ if @configuration.sessions.enabled?
109
+ use(*@configuration.sessions.middleware)
110
+ end
111
+ end
112
+
113
+ # Add asset middlewares
114
+ #
115
+ # @api private
116
+ # #since 0.2.0
117
+ def _load_asset_middlewares
118
+ if @configuration.serve_assets
119
+ @configuration.assets.entries.each do |path, children|
120
+ use Rack::Static, urls: children, root: path
121
+ end
122
+ end
123
+ end
41
124
  end
42
125
  end