hanami 1.3.1 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +110 -6
- data/FEATURES.md +9 -1
- data/LICENSE.md +1 -1
- data/README.md +4 -5
- data/hanami.gemspec +26 -30
- data/lib/hanami.rb +40 -243
- data/lib/hanami/application.rb +338 -174
- data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
- data/lib/hanami/application/container/boot/inflector.rb +7 -0
- data/lib/hanami/application/container/boot/logger.rb +8 -0
- data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
- data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
- data/lib/hanami/application/container/boot/settings.rb +7 -0
- data/lib/hanami/application/router.rb +59 -0
- data/lib/hanami/application/routing/middleware/stack.rb +89 -0
- data/lib/hanami/application/routing/resolver.rb +82 -0
- data/lib/hanami/application/routing/resolver/node.rb +50 -0
- data/lib/hanami/application/routing/resolver/trie.rb +59 -0
- data/lib/hanami/application/settings.rb +23 -0
- data/lib/hanami/application/settings/definition.rb +26 -0
- data/lib/hanami/application/settings/loader.rb +97 -0
- data/lib/hanami/application/settings/struct.rb +65 -0
- data/lib/hanami/boot.rb +5 -0
- data/lib/hanami/cli/application/cli.rb +40 -0
- data/lib/hanami/cli/application/command.rb +47 -0
- data/lib/hanami/cli/application/commands.rb +16 -0
- data/lib/hanami/cli/application/commands/console.rb +81 -0
- data/lib/hanami/cli/base_command.rb +48 -0
- data/lib/hanami/cli/commands.rb +6 -42
- data/lib/hanami/cli/commands/command.rb +20 -30
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/configuration.rb +248 -190
- data/lib/hanami/configuration/middleware.rb +8 -28
- data/lib/hanami/configuration/router.rb +50 -0
- data/lib/hanami/configuration/sessions.rb +50 -0
- data/lib/hanami/init.rb +5 -0
- data/lib/hanami/server.rb +5 -69
- data/lib/hanami/setup.rb +8 -2
- data/lib/hanami/slice.rb +138 -0
- data/lib/hanami/version.rb +3 -1
- data/lib/hanami/web/rack_logger.rb +96 -0
- metadata +84 -228
- data/bin/hanami +0 -6
- data/lib/hanami/action/csrf_protection.rb +0 -211
- data/lib/hanami/action/routing_helpers.rb +0 -40
- data/lib/hanami/app.rb +0 -96
- data/lib/hanami/application_configuration.rb +0 -1495
- data/lib/hanami/application_name.rb +0 -108
- data/lib/hanami/application_namespace.rb +0 -14
- data/lib/hanami/assets/asset.rb +0 -72
- data/lib/hanami/assets/static.rb +0 -102
- data/lib/hanami/cli/commands/assets.rb +0 -16
- data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
- data/lib/hanami/cli/commands/console.rb +0 -95
- data/lib/hanami/cli/commands/db.rb +0 -32
- data/lib/hanami/cli/commands/db/apply.rb +0 -32
- data/lib/hanami/cli/commands/db/console.rb +0 -44
- data/lib/hanami/cli/commands/db/create.rb +0 -32
- data/lib/hanami/cli/commands/db/drop.rb +0 -32
- data/lib/hanami/cli/commands/db/migrate.rb +0 -39
- data/lib/hanami/cli/commands/db/prepare.rb +0 -32
- data/lib/hanami/cli/commands/db/rollback.rb +0 -59
- data/lib/hanami/cli/commands/db/version.rb +0 -32
- data/lib/hanami/cli/commands/destroy.rb +0 -26
- data/lib/hanami/cli/commands/destroy/action.rb +0 -137
- data/lib/hanami/cli/commands/destroy/app.rb +0 -159
- data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
- data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
- data/lib/hanami/cli/commands/destroy/model.rb +0 -84
- data/lib/hanami/cli/commands/generate.rb +0 -28
- data/lib/hanami/cli/commands/generate/action.rb +0 -321
- data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
- data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
- data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
- data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app.rb +0 -243
- data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
- data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
- data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
- data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
- data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
- data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
- data/lib/hanami/cli/commands/generate/migration.rb +0 -41
- data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
- data/lib/hanami/cli/commands/generate/model.rb +0 -125
- data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
- data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
- data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/secret.rb +0 -48
- data/lib/hanami/cli/commands/new.rb +0 -578
- data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
- data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
- data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
- data/lib/hanami/cli/commands/new/README.md.erb +0 -33
- data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
- data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
- data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
- data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
- data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
- data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
- data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
- data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
- data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
- data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
- data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
- data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
- data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
- data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
- data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
- data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
- data/lib/hanami/cli/commands/project.rb +0 -421
- data/lib/hanami/cli/commands/routes.rb +0 -21
- data/lib/hanami/cli/commands/templates.rb +0 -31
- data/lib/hanami/cli/commands/version.rb +0 -19
- data/lib/hanami/common_logger.rb +0 -93
- data/lib/hanami/components.rb +0 -156
- data/lib/hanami/components/app/assets.rb +0 -59
- data/lib/hanami/components/app/controller.rb +0 -74
- data/lib/hanami/components/app/routes.rb +0 -59
- data/lib/hanami/components/app/view.rb +0 -44
- data/lib/hanami/components/component.rb +0 -182
- data/lib/hanami/components/components.rb +0 -479
- data/lib/hanami/components/routes_inspector.rb +0 -72
- data/lib/hanami/config/cookies.rb +0 -69
- data/lib/hanami/config/framework_configuration.rb +0 -43
- data/lib/hanami/config/load_paths.rb +0 -46
- data/lib/hanami/config/mapper.rb +0 -47
- data/lib/hanami/config/routes.rb +0 -20
- data/lib/hanami/config/security.rb +0 -110
- data/lib/hanami/config/sessions.rb +0 -103
- data/lib/hanami/configuration/app.rb +0 -18
- data/lib/hanami/early_hints.rb +0 -129
- data/lib/hanami/env.rb +0 -69
- data/lib/hanami/environment.rb +0 -513
- data/lib/hanami/environment_application_configurations.rb +0 -37
- data/lib/hanami/frameworks.rb +0 -22
- data/lib/hanami/hanamirc.rb +0 -169
- data/lib/hanami/mailer/glue.rb +0 -27
- data/lib/hanami/middleware_stack.rb +0 -172
- data/lib/hanami/rake_helper.rb +0 -78
- data/lib/hanami/rake_tasks.rb +0 -2
- data/lib/hanami/rendering_policy.rb +0 -95
- data/lib/hanami/routes.rb +0 -219
- data/lib/hanami/routing/default.rb +0 -32
- data/lib/hanami/static.rb +0 -63
- data/lib/hanami/templates/default.html.erb +0 -30
- data/lib/hanami/templates/welcome.html.erb +0 -52
- data/lib/hanami/views/default.rb +0 -37
- data/lib/hanami/views/default_template_finder.rb +0 -22
- data/lib/hanami/views/null_view.rb +0 -15
- data/lib/hanami/welcome.rb +0 -36
data/lib/hanami/rake_tasks.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'hanami/utils/class'
|
2
|
-
require 'hanami/views/default'
|
3
|
-
require 'hanami/views/null_view'
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
# Rendering policy
|
7
|
-
#
|
8
|
-
# @since 0.1.0
|
9
|
-
# @api private
|
10
|
-
class RenderingPolicy
|
11
|
-
# @api private
|
12
|
-
STATUS = 0
|
13
|
-
# @api private
|
14
|
-
HEADERS = 1
|
15
|
-
# @api private
|
16
|
-
BODY = 2
|
17
|
-
|
18
|
-
# @api private
|
19
|
-
HANAMI_ACTION = 'hanami.action'.freeze
|
20
|
-
# @api private
|
21
|
-
RACK_EXCEPTION = 'rack.exception'.freeze
|
22
|
-
|
23
|
-
# @api private
|
24
|
-
SUCCESSFUL_STATUSES = (200..201).freeze
|
25
|
-
# @api private
|
26
|
-
RENDERABLE_FORMATS = [:all, :html].freeze
|
27
|
-
# @api private
|
28
|
-
ERROR_STATUS = 500
|
29
|
-
|
30
|
-
# @api private
|
31
|
-
def initialize(configuration)
|
32
|
-
@controller_pattern = %r{#{ configuration.controller_pattern.gsub(/\%\{(controller|action)\}/) { "(?<#{ $1 }>(.*))" } }}
|
33
|
-
@configuration = configuration
|
34
|
-
end
|
35
|
-
|
36
|
-
# @api private
|
37
|
-
def render(env, response)
|
38
|
-
body = _render(env, response)
|
39
|
-
|
40
|
-
response[BODY] = Array(body) unless body.nil? || body.respond_to?(:each)
|
41
|
-
response
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
# @api private
|
46
|
-
def _render(env, response)
|
47
|
-
if action = renderable?(env)
|
48
|
-
_render_action(action, env, response) ||
|
49
|
-
_render_status_page(action, response)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# @api private
|
54
|
-
def _render_action(action, env, response)
|
55
|
-
begin
|
56
|
-
view_for(action, response).render(
|
57
|
-
action.exposures
|
58
|
-
)
|
59
|
-
rescue StandardError => e
|
60
|
-
env[RACK_EXCEPTION] = e
|
61
|
-
raise e unless @configuration.handle_exceptions
|
62
|
-
|
63
|
-
response[STATUS] = ERROR_STATUS
|
64
|
-
false
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# @api private
|
69
|
-
def _render_status_page(action, response)
|
70
|
-
if render_status_page?(action, response)
|
71
|
-
Hanami::Views::Default.render(@configuration.templates, response[STATUS], response: response, format: :html)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# @api private
|
76
|
-
def renderable?(env)
|
77
|
-
((action = env.delete(HANAMI_ACTION)) && action.renderable?) and action
|
78
|
-
end
|
79
|
-
|
80
|
-
# @api private
|
81
|
-
def render_status_page?(action, response)
|
82
|
-
RENDERABLE_FORMATS.include?(action.format) && !SUCCESSFUL_STATUSES.include?(response[STATUS])
|
83
|
-
end
|
84
|
-
|
85
|
-
# @api private
|
86
|
-
def view_for(action, response)
|
87
|
-
view = if response[BODY].respond_to?(:empty?) && response[BODY].empty?
|
88
|
-
captures = @controller_pattern.match(action.class.name)
|
89
|
-
Utils::Class.load(@configuration.view_pattern % { controller: captures[:controller], action: captures[:action] }, @configuration.namespace)
|
90
|
-
end
|
91
|
-
|
92
|
-
view || Views::NullView.new
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
data/lib/hanami/routes.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'hanami/utils/escape'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
# Routes factory
|
5
|
-
#
|
6
|
-
# A Hanami application has this factory instantiated by default and associated
|
7
|
-
# to the `Routes` constant, under the application namespace.
|
8
|
-
#
|
9
|
-
# @since 0.1.0
|
10
|
-
# @api private
|
11
|
-
class Routes
|
12
|
-
# Initialize the factory
|
13
|
-
#
|
14
|
-
# @param routes [Hanami::Router] a routes set
|
15
|
-
#
|
16
|
-
# @return [Hanami::Routes] the factory
|
17
|
-
#
|
18
|
-
# @since 0.1.0
|
19
|
-
# @api private
|
20
|
-
def initialize(routes)
|
21
|
-
@routes = routes
|
22
|
-
end
|
23
|
-
|
24
|
-
# Return a relative path for the given route name
|
25
|
-
#
|
26
|
-
# @param name [Symbol] the route name
|
27
|
-
# @param args [Array,nil] an optional set of arguments that is passed down
|
28
|
-
# to the wrapped route set.
|
29
|
-
#
|
30
|
-
# @return [Hanami::Utils::Escape::SafeString] the corresponding relative URL
|
31
|
-
#
|
32
|
-
# @raise Hanami::Routing::InvalidRouteException
|
33
|
-
#
|
34
|
-
# @since 0.1.0
|
35
|
-
#
|
36
|
-
# @see http://rdoc.info/gems/hanami-router/Hanami/Router#path-instance_method
|
37
|
-
#
|
38
|
-
# @example Basic example
|
39
|
-
# require 'hanami'
|
40
|
-
#
|
41
|
-
# module Web
|
42
|
-
# class Application < Hanami::Application
|
43
|
-
# configure do
|
44
|
-
# routes do
|
45
|
-
# get '/login', to: 'sessions#new', as: :login
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# Web.routes.path(:login)
|
52
|
-
# # => '/login'
|
53
|
-
#
|
54
|
-
# Web.routes.path(:login, return_to: '/dashboard')
|
55
|
-
# # => '/login?return_to=%2Fdashboard'
|
56
|
-
#
|
57
|
-
# @example Dynamic finders
|
58
|
-
# require 'hanami'
|
59
|
-
#
|
60
|
-
# module Web
|
61
|
-
# class Application < Hanami::Application
|
62
|
-
# configure do
|
63
|
-
# routes do
|
64
|
-
# get '/login', to: 'sessions#new', as: :login
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# Web.routes.login_path
|
71
|
-
# # => '/login'
|
72
|
-
#
|
73
|
-
# Web.routes.login_path(return_to: '/dashboard')
|
74
|
-
# # => '/login?return_to=%2Fdashboard'
|
75
|
-
def path(name, *args)
|
76
|
-
Utils::Escape::SafeString.new(@routes.path(name, *args))
|
77
|
-
end
|
78
|
-
|
79
|
-
# Return an absolute path for the given route name
|
80
|
-
#
|
81
|
-
# @param name [Symbol] the route name
|
82
|
-
# @param args [Array,nil] an optional set of arguments that is passed down
|
83
|
-
# to the wrapped route set.
|
84
|
-
#
|
85
|
-
# @return [Hanami::Utils::Escape::SafeString] the corresponding absolute URL
|
86
|
-
#
|
87
|
-
# @raise Hanami::Routing::InvalidRouteException
|
88
|
-
#
|
89
|
-
# @since 0.1.0
|
90
|
-
#
|
91
|
-
# @see http://rdoc.info/gems/hanami-router/Hanami/Router#url-instance_method
|
92
|
-
#
|
93
|
-
# @example Basic example
|
94
|
-
# require 'hanami'
|
95
|
-
#
|
96
|
-
# module Web
|
97
|
-
# class Application < Hanami::Application
|
98
|
-
# configure do
|
99
|
-
# routes do
|
100
|
-
# scheme 'https'
|
101
|
-
# host 'bookshelf.org'
|
102
|
-
#
|
103
|
-
# get '/login', to: 'sessions#new', as: :login
|
104
|
-
# end
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# Web.routes.url(:login)
|
110
|
-
# # => 'https://bookshelf.org/login'
|
111
|
-
#
|
112
|
-
# Web.routes.url(:login, return_to: '/dashboard')
|
113
|
-
# # => 'https://bookshelf.org/login?return_to=%2Fdashboard'
|
114
|
-
#
|
115
|
-
# @example Dynamic finders
|
116
|
-
# require 'hanami'
|
117
|
-
#
|
118
|
-
# module Web
|
119
|
-
# class Application < Hanami::Application
|
120
|
-
# configure do
|
121
|
-
# routes do
|
122
|
-
# scheme 'https'
|
123
|
-
# host 'bookshelf.org'
|
124
|
-
#
|
125
|
-
# get '/login', to: 'sessions#new', as: :login
|
126
|
-
# end
|
127
|
-
# end
|
128
|
-
# end
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# Web.routes.login_url
|
132
|
-
# # => 'https://bookshelf.org/login'
|
133
|
-
#
|
134
|
-
# Web.routes.login_url(return_to: '/dashboard')
|
135
|
-
# # => 'https://bookshelf.org/login?return_to=%2Fdashboard'
|
136
|
-
def url(name, *args)
|
137
|
-
Utils::Escape::SafeString.new(@routes.url(name, *args))
|
138
|
-
end
|
139
|
-
|
140
|
-
# Recognize a route from a Rack env.
|
141
|
-
#
|
142
|
-
# This method is designed for testing purposes
|
143
|
-
#
|
144
|
-
# @param env [Hash] a Rack env
|
145
|
-
#
|
146
|
-
# @return [Hanami::Routing::RecognizedRoute] the recognized route
|
147
|
-
#
|
148
|
-
# @since 0.8.0
|
149
|
-
#
|
150
|
-
# @see http://hanamirb.org/guides/routing/testing
|
151
|
-
#
|
152
|
-
# @example Path Generation
|
153
|
-
# # spec/web/routes_spec.rb
|
154
|
-
# RSpec.describe Web::Routes do
|
155
|
-
# it 'generates "/"' do
|
156
|
-
# actual = described_class.path(:root)
|
157
|
-
# expect(actual).to eq '/'
|
158
|
-
# end
|
159
|
-
#
|
160
|
-
# it 'generates "/books/23"' do
|
161
|
-
# actual = described_class.path(:book, id: 23)
|
162
|
-
# expect(actual).to eq '/books/23'
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
#
|
166
|
-
# @example Route Recognition
|
167
|
-
# # spec/web/routes_spec.rb
|
168
|
-
# RSpec.describe Web::Routes do
|
169
|
-
#
|
170
|
-
# # ...
|
171
|
-
#
|
172
|
-
# it 'recognizes "GET /"' do
|
173
|
-
# env = Rack::MockRequest.env_for('/')
|
174
|
-
# route = described_class.recognize(env)
|
175
|
-
#
|
176
|
-
# expect(route).to be_routable
|
177
|
-
#
|
178
|
-
# expect(route.path).to eq '/'
|
179
|
-
# expect(route.verb).to eq 'GET'
|
180
|
-
# expect(route.params).to eq({})
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# it 'recognizes "PATCH /books/23"' do
|
184
|
-
# env = Rack::MockRequest.env_for('/books/23', method: 'PATCH')
|
185
|
-
# route = described_class.recognize(env)
|
186
|
-
#
|
187
|
-
# expect(route).to be_routable
|
188
|
-
#
|
189
|
-
# expect(route.path).to eq '/books/23'
|
190
|
-
# expect(route.verb).to eq 'PATCH'
|
191
|
-
# expect(route.params).to eq(id: '23')
|
192
|
-
# end
|
193
|
-
#
|
194
|
-
# it 'does not recognize unknown route' do
|
195
|
-
# env = Rack::MockRequest.env_for('/foo')
|
196
|
-
# route = described_class.recognize(env)
|
197
|
-
#
|
198
|
-
# expect(route).to_not be_routable
|
199
|
-
# end
|
200
|
-
# end
|
201
|
-
def recognize(env)
|
202
|
-
@routes.recognize(env)
|
203
|
-
end
|
204
|
-
|
205
|
-
protected
|
206
|
-
|
207
|
-
# @since 0.3.0
|
208
|
-
# @api private
|
209
|
-
def method_missing(m, *args)
|
210
|
-
named_route, type = m.to_s.split(/\_(path|url)\z/)
|
211
|
-
|
212
|
-
if type
|
213
|
-
public_send(type, named_route.to_sym, *args)
|
214
|
-
else
|
215
|
-
super
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
# @api private
|
3
|
-
module Routing
|
4
|
-
# The default Rack application that responds when a resource cannot be found.
|
5
|
-
#
|
6
|
-
# @since 0.1.0
|
7
|
-
# @api private
|
8
|
-
class Default
|
9
|
-
# @api private
|
10
|
-
DEFAULT_CODE = 404
|
11
|
-
# @api private
|
12
|
-
DEFAULT_BODY = ['Not Found'].freeze
|
13
|
-
# @api private
|
14
|
-
CONTENT_TYPE = 'Content-Type'.freeze
|
15
|
-
|
16
|
-
# @api private
|
17
|
-
class NullAction
|
18
|
-
include Hanami::Action
|
19
|
-
|
20
|
-
# @api private
|
21
|
-
def call(env)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# @api private
|
26
|
-
def call(env)
|
27
|
-
action = NullAction.new.tap { |a| a.call(env) }
|
28
|
-
[ DEFAULT_CODE, {CONTENT_TYPE => action.content_type}, DEFAULT_BODY, action ]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/hanami/static.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rack/static"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
# Serve static assets in deployment environments (production, staging) where
|
7
|
-
# the stack doesn't include a web server.
|
8
|
-
#
|
9
|
-
# Web servers like Nginx are the ideal candidate to serve static assets.
|
10
|
-
# They are faster than Ruby application servers (eg. Puma) and they should be
|
11
|
-
# always preferred for this specific task.
|
12
|
-
#
|
13
|
-
# But there are some PaaS that don't allow to use web servers in front of Ruby
|
14
|
-
# web applications. A classical example is Heroku, which requires the web
|
15
|
-
# application to serve static assets.
|
16
|
-
#
|
17
|
-
# Hanami::Static is designed for this specific scenario.
|
18
|
-
#
|
19
|
-
# To enable it set the env variable `SERVE_STATIC_ASSETS` on `true`.
|
20
|
-
#
|
21
|
-
# NOTE: Please remember to precompile the assets at the deploy time with
|
22
|
-
# `bundle exec hanami assets precompile`.
|
23
|
-
#
|
24
|
-
# @since 0.6.0
|
25
|
-
# @api private
|
26
|
-
#
|
27
|
-
# @see http://www.rubydoc.info/gems/rack/Rack/Static
|
28
|
-
class Static < ::Rack::Static
|
29
|
-
# @since 0.8.0
|
30
|
-
# @api private
|
31
|
-
MAX_AGE = 60 * 60 * 24 * 365 # One year
|
32
|
-
|
33
|
-
# @since 0.8.0
|
34
|
-
# @api private
|
35
|
-
HEADER_RULES = [[:all, { "Cache-Control" => "public, max-age=#{MAX_AGE}" }]].freeze
|
36
|
-
|
37
|
-
# @since 0.8.0
|
38
|
-
# @api private
|
39
|
-
URL_PREFIX = "/"
|
40
|
-
|
41
|
-
# @since 0.6.0
|
42
|
-
# @api private
|
43
|
-
def initialize(app, root: Hanami.public_directory, header_rules: HEADER_RULES)
|
44
|
-
super(app, urls: _urls(root), root: root, header_rules: header_rules)
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# @since 0.8.0
|
50
|
-
# @api private
|
51
|
-
def _urls(root)
|
52
|
-
return [] unless root.exist?
|
53
|
-
|
54
|
-
asset_files = Pathname.glob(root.join("**", "*"))
|
55
|
-
.select(&:file?)
|
56
|
-
|
57
|
-
asset_files.each_with_object({}) do |path, result|
|
58
|
-
path = path.relative_path_from(root)
|
59
|
-
result["#{URL_PREFIX}#{path}"] = path
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title><%= title %></title>
|
5
|
-
<link rel="shortcut icon" type="image/x-icon" href="/assets/favicon.ico">
|
6
|
-
<style>
|
7
|
-
* { margin: 0; padding: 0; }
|
8
|
-
body { font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; color: #333; background-color: #ecf0f1; font-size: 16px; line-height: 24px; }
|
9
|
-
h2, h3 { margin: -20px; line-height: 100px; text-align: center; }
|
10
|
-
.logo { text-align: center; margin-top: 0.5em; }
|
11
|
-
h2 { font-size: 30px; }
|
12
|
-
h3 { font-size: 20px; line-height: 22px; color: #666; }
|
13
|
-
hr { margin: 2em; color: #ecf0f1; }
|
14
|
-
ul { text-align: center; }
|
15
|
-
li { display: inline; margin: 2em; line-height: 24px; list-style-type: none; vertical-align: text-top;}
|
16
|
-
p { margin-top: 60px; text-align: center; }
|
17
|
-
a { color: #333; padding: 1px; }
|
18
|
-
code { padding: .2em; background-color: #ecf0f1 }
|
19
|
-
#container { margin: 20% auto; padding: 24px; width: 75%; background-color: #fff; border: 1px solid #999; border-width: 1px; }
|
20
|
-
#content { margin: 30px 10px 0 10px; }
|
21
|
-
#footer { margin:0 auto 0; padding: 12px; width:700px; line-height: 24px; font-size: 12px; }
|
22
|
-
.bold { font-weight: bold; }
|
23
|
-
</style>
|
24
|
-
</head>
|
25
|
-
<body>
|
26
|
-
<div id="container">
|
27
|
-
<h2><%= title %></h2>
|
28
|
-
</div>
|
29
|
-
</body>
|
30
|
-
</html>
|