hanami 1.3.5 → 2.0.0.alpha1

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 (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -41
  3. data/FEATURES.md +2 -12
  4. data/LICENSE.md +1 -1
  5. data/README.md +5 -8
  6. data/bin/hanami +6 -4
  7. data/hanami.gemspec +24 -28
  8. data/lib/hanami/application.rb +44 -176
  9. data/lib/hanami/boot.rb +6 -0
  10. data/lib/hanami/cli/commands/command.rb +21 -29
  11. data/lib/hanami/cli/commands/server.rb +63 -14
  12. data/lib/hanami/cli/commands.rb +5 -42
  13. data/lib/hanami/configuration/cookies.rb +24 -0
  14. data/lib/hanami/configuration/middleware.rb +8 -28
  15. data/lib/hanami/configuration/security.rb +141 -0
  16. data/lib/hanami/configuration/sessions.rb +50 -0
  17. data/lib/hanami/configuration.rb +181 -191
  18. data/lib/hanami/container.rb +107 -0
  19. data/lib/hanami/frameworks.rb +24 -18
  20. data/lib/hanami/routes.rb +17 -205
  21. data/lib/hanami/server.rb +5 -69
  22. data/lib/hanami/version.rb +3 -1
  23. data/lib/hanami.rb +39 -243
  24. metadata +36 -233
  25. data/lib/hanami/action/csrf_protection.rb +0 -211
  26. data/lib/hanami/action/routing_helpers.rb +0 -40
  27. data/lib/hanami/app.rb +0 -96
  28. data/lib/hanami/application_configuration.rb +0 -1495
  29. data/lib/hanami/application_name.rb +0 -108
  30. data/lib/hanami/application_namespace.rb +0 -14
  31. data/lib/hanami/assets/asset.rb +0 -72
  32. data/lib/hanami/assets/static.rb +0 -102
  33. data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
  34. data/lib/hanami/cli/commands/assets.rb +0 -16
  35. data/lib/hanami/cli/commands/console.rb +0 -95
  36. data/lib/hanami/cli/commands/db/apply.rb +0 -32
  37. data/lib/hanami/cli/commands/db/console.rb +0 -44
  38. data/lib/hanami/cli/commands/db/create.rb +0 -32
  39. data/lib/hanami/cli/commands/db/drop.rb +0 -32
  40. data/lib/hanami/cli/commands/db/migrate.rb +0 -39
  41. data/lib/hanami/cli/commands/db/prepare.rb +0 -32
  42. data/lib/hanami/cli/commands/db/rollback.rb +0 -59
  43. data/lib/hanami/cli/commands/db/version.rb +0 -32
  44. data/lib/hanami/cli/commands/db.rb +0 -32
  45. data/lib/hanami/cli/commands/destroy/action.rb +0 -137
  46. data/lib/hanami/cli/commands/destroy/app.rb +0 -159
  47. data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
  48. data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
  49. data/lib/hanami/cli/commands/destroy/model.rb +0 -84
  50. data/lib/hanami/cli/commands/destroy.rb +0 -26
  51. data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
  52. data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
  53. data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
  54. data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
  55. data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
  56. data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
  57. data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
  58. data/lib/hanami/cli/commands/generate/action.rb +0 -321
  59. data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
  60. data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
  61. data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
  62. data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
  63. data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
  64. data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
  65. data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
  66. data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
  67. data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
  68. data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
  69. data/lib/hanami/cli/commands/generate/app.rb +0 -243
  70. data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
  71. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
  72. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
  73. data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
  74. data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
  75. data/lib/hanami/cli/commands/generate/migration.rb +0 -41
  76. data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
  77. data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
  78. data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
  79. data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
  80. data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
  81. data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
  82. data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
  83. data/lib/hanami/cli/commands/generate/model.rb +0 -125
  84. data/lib/hanami/cli/commands/generate/secret.rb +0 -48
  85. data/lib/hanami/cli/commands/generate.rb +0 -28
  86. data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
  87. data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
  88. data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
  89. data/lib/hanami/cli/commands/new/Gemfile.erb +0 -57
  90. data/lib/hanami/cli/commands/new/README.md.erb +0 -33
  91. data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
  92. data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
  93. data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
  94. data/lib/hanami/cli/commands/new/gitignore.erb +0 -4
  95. data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -5
  96. data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
  97. data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
  98. data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
  99. data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
  100. data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
  101. data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
  102. data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
  103. data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
  104. data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
  105. data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
  106. data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
  107. data/lib/hanami/cli/commands/new.rb +0 -578
  108. data/lib/hanami/cli/commands/project.rb +0 -421
  109. data/lib/hanami/cli/commands/routes.rb +0 -21
  110. data/lib/hanami/cli/commands/templates.rb +0 -31
  111. data/lib/hanami/cli/commands/version.rb +0 -19
  112. data/lib/hanami/common_logger.rb +0 -109
  113. data/lib/hanami/components/app/assets.rb +0 -59
  114. data/lib/hanami/components/app/controller.rb +0 -74
  115. data/lib/hanami/components/app/routes.rb +0 -59
  116. data/lib/hanami/components/app/view.rb +0 -44
  117. data/lib/hanami/components/component.rb +0 -182
  118. data/lib/hanami/components/components.rb +0 -479
  119. data/lib/hanami/components/routes_inspector.rb +0 -72
  120. data/lib/hanami/components.rb +0 -156
  121. data/lib/hanami/config/cookies.rb +0 -69
  122. data/lib/hanami/config/framework_configuration.rb +0 -43
  123. data/lib/hanami/config/load_paths.rb +0 -46
  124. data/lib/hanami/config/mapper.rb +0 -47
  125. data/lib/hanami/config/routes.rb +0 -20
  126. data/lib/hanami/config/security.rb +0 -110
  127. data/lib/hanami/config/sessions.rb +0 -119
  128. data/lib/hanami/configuration/app.rb +0 -21
  129. data/lib/hanami/early_hints.rb +0 -129
  130. data/lib/hanami/env.rb +0 -69
  131. data/lib/hanami/environment.rb +0 -541
  132. data/lib/hanami/environment_application_configurations.rb +0 -37
  133. data/lib/hanami/hanamirc.rb +0 -169
  134. data/lib/hanami/mailer/glue.rb +0 -27
  135. data/lib/hanami/middleware_stack.rb +0 -172
  136. data/lib/hanami/rake_helper.rb +0 -78
  137. data/lib/hanami/rake_tasks.rb +0 -3
  138. data/lib/hanami/rendering_policy.rb +0 -94
  139. data/lib/hanami/routing/default.rb +0 -32
  140. data/lib/hanami/setup.rb +0 -3
  141. data/lib/hanami/static.rb +0 -63
  142. data/lib/hanami/templates/default.html.erb +0 -30
  143. data/lib/hanami/templates/welcome.html.erb +0 -52
  144. data/lib/hanami/views/default.rb +0 -37
  145. data/lib/hanami/views/default_template_finder.rb +0 -22
  146. data/lib/hanami/views/null_view.rb +0 -15
  147. data/lib/hanami/welcome.rb +0 -41
@@ -1,7 +0,0 @@
1
- module <%= app.classify %>
2
- module Views
3
- <%= beginning_module_definition %>
4
- <%= view_class_definition %>
5
- <%= ending_module_definition %>
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- require_relative '../../../spec_helper'
2
-
3
- describe <%= app.classify %>::Views::<%= classified_controller_name %>::<%= action.classify %> do
4
- let(:exposures) { Hash[format: :html] }
5
- let(:template) { Hanami::View::Template.new('<%= template %>') }
6
- let(:view) { <%= app.classify %>::Views::<%= classified_controller_name %>::<%= action.classify %>.new(template, exposures) }
7
- let(:rendered) { view.render }
8
-
9
- it 'exposes #format' do
10
- _(view.format).must_equal exposures.fetch(:format)
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- RSpec.describe <%= app.classify %>::Views::<%= classified_controller_name %>::<%= action.classify %>, type: :view do
2
- let(:exposures) { Hash[format: :html] }
3
- let(:template) { Hanami::View::Template.new('<%= template %>') }
4
- let(:view) { described_class.new(template, exposures) }
5
- let(:rendered) { view.render }
6
-
7
- it 'exposes #format' do
8
- expect(view.format).to eq exposures.fetch(:format)
9
- end
10
- end
@@ -1,321 +0,0 @@
1
- module Hanami
2
- class CLI
3
- module Commands
4
- module Generate
5
- # @since 1.1.0
6
- # @api private
7
- class Action < Command
8
- requires "environment"
9
-
10
- desc "Generate an action for app"
11
-
12
- example [
13
- "web home#index # Basic usage",
14
- "admin home#index # Generate for `admin` app",
15
- "web home#index --url=/ # Specify URL",
16
- "web sessions#destroy --method=GET # Specify HTTP method",
17
- "web books#create --skip-view # Skip view and template"
18
- ]
19
-
20
- argument :app, required: true, desc: "The application name (eg. `web`)"
21
- argument :action, required: true, desc: "The action name (eg. `home#index`)"
22
-
23
- option :url, desc: "The action URL"
24
- option :method, desc: "The action HTTP method"
25
- option :skip_view, type: :boolean, default: false, desc: "Skip view and template"
26
-
27
- # @since 1.1.0
28
- # @api private
29
- #
30
- # rubocop:disable Metrics/AbcSize
31
- # rubocop:disable Metrics/MethodLength
32
- def call(app:, action:, **options)
33
- *controller, action = controller_and_action_name(action)
34
- classified_controller_name = classified_controller(controller)
35
- http_method = route_http_method(action, options)
36
- context = Context.new(app: app, controller: controller, classified_controller_name: classified_controller_name, action: action, test: options.fetch(:test), http_method: http_method, options: options)
37
- context = context.with(template: project.template(context),
38
- action_class_definition: action_class_definition(context),
39
- view_class_definition: view_class_definition(context),
40
- beginning_module_definition: beginning_module_definition(context),
41
- ending_module_definition: ending_module_definition(context))
42
-
43
- assert_valid_app!(context)
44
- assert_valid_route_url!(context)
45
- assert_valid_route_http_method!(context)
46
-
47
- generate_action(context)
48
- generate_view(context)
49
- generate_template(context)
50
- generate_action_spec(context)
51
- generate_view_spec(context)
52
- insert_route(context)
53
- end
54
- # rubocop:enable Metrics/MethodLength
55
- # rubocop:enable Metrics/AbcSize
56
-
57
- private
58
-
59
- # @since 1.3.0
60
- # @api private
61
- def beginning_module_definition(context)
62
- length = context.classified_controller_name.split("::").size
63
- first_indentation = " " * 4
64
- indentation = first_indentation
65
- beginning_module_definition = ""
66
-
67
- context.classified_controller_name.split("::").each_with_index do |module_name, index|
68
- beginning_module_definition += "module #{module_name}".prepend(indentation)
69
- beginning_module_definition += "\n" unless length == index + 1
70
- indentation += " "
71
- end
72
- beginning_module_definition
73
- end
74
-
75
- # @since 1.3.0
76
- # @api private
77
- def ending_module_definition(context)
78
- length = context.classified_controller_name.split("::").size
79
- first_indentation = " " * 4
80
- indentation = first_indentation + " " * (length - 1)
81
- ending_module_definition = ""
82
-
83
- context.classified_controller_name.split("::").each_with_index do |_, index|
84
- ending_module_definition += "end".prepend(indentation)
85
- ending_module_definition += "\n" unless length == index + 1
86
- indentation = " " * (indentation.size - 2)
87
- end
88
- ending_module_definition
89
- end
90
-
91
- # @since 1.3.0
92
- # @api private
93
- def action_class_definition(context)
94
- body_line_position = 4
95
- view_class = [
96
- "class #{context.action.classify}",
97
- " include #{context.app.classify}::Action",
98
- "",
99
- " def call(params)",
100
- " end",
101
- "end"
102
- ]
103
- view_class.insert(body_line_position, " self.body = 'OK'") if skip_view?(context)
104
-
105
- add_indentation_to_class_definition(context, view_class)
106
- end
107
-
108
- # @since 1.3.0
109
- # @api private
110
- def view_class_definition(context)
111
- view_class = [
112
- "class #{context.action.classify}",
113
- " include #{context.app.classify}::View",
114
- "end"
115
- ]
116
-
117
- add_indentation_to_class_definition(context, view_class)
118
- end
119
-
120
- # @since 1.3.0
121
- # @api private
122
- def add_indentation_to_class_definition(context, view_content)
123
- length = context.classified_controller_name.split("::").size
124
- first_indentation = " " * 4
125
- indentation = first_indentation + " " * length * 2
126
-
127
- content = ""
128
- view_content.each do |line|
129
- next content += "\n" if line.empty?
130
- content += "#{line}\n".prepend(indentation)
131
- end
132
- content.chomp
133
- end
134
-
135
- # @since 1.1.0
136
- # @api private
137
- def controller_and_action_name(name)
138
- # FIXME: extract this regexp
139
- name.split(/#|\//)
140
- end
141
-
142
- # @since 1.1.0
143
- # @api private
144
- def assert_valid_app!(context)
145
- return if project.app?(context)
146
-
147
- existing_apps = project.apps.map { |name| "`#{name}'" }.join(' ')
148
- warn "`#{context.app}' is not a valid APP. Please specify one of: #{existing_apps}"
149
- exit(1)
150
- end
151
-
152
- # @since 1.1.0
153
- # @api private
154
- def assert_valid_route_url!(context)
155
- if context.options.key?(:url) && Utils::Blank.blank?(context.options[:url]) # rubocop:disable Style/GuardClause
156
- warn "`#{context.options[:url]}' is not a valid URL"
157
- exit(1)
158
- end
159
- end
160
-
161
- # @since 1.1.0
162
- # @api private
163
- def assert_valid_route_http_method!(context)
164
- unless Hanami::Routing::Route::VALID_HTTP_VERBS.include?(context.http_method.upcase) # rubocop:disable Style/GuardClause
165
- warn "`#{context.http_method.upcase}' is not a valid HTTP method. Please use one of: #{Hanami::Routing::Route::VALID_HTTP_VERBS.map { |verb| "`#{verb}'" }.join(' ')}"
166
- exit(1)
167
- end
168
- end
169
-
170
- # @since 1.1.0
171
- # @api private
172
- def generate_action(context)
173
- source = if skip_view?(context)
174
- templates.find("action_without_view.erb")
175
- else
176
- templates.find("action.erb")
177
- end
178
- destination = project.action(context)
179
-
180
- generate_file(source, destination, context)
181
- say(:create, destination)
182
- end
183
-
184
- # @since 1.1.0
185
- # @api private
186
- def generate_view(context)
187
- return if skip_view?(context)
188
-
189
- source = templates.find("view.erb")
190
- destination = project.view(context)
191
-
192
- generate_file(source, destination, context)
193
- say(:create, destination)
194
- end
195
-
196
- # @since 1.1.0
197
- # @api private
198
- def generate_template(context)
199
- return if skip_view?(context)
200
- destination = project.template(context)
201
-
202
- files.touch(destination)
203
- say(:create, destination)
204
- end
205
-
206
- # @since 1.1.0
207
- # @api private
208
- def generate_action_spec(context)
209
- source = templates.find("action_spec.#{context.test}.erb")
210
- destination = project.action_spec(context)
211
-
212
- generate_file(source, destination, context)
213
- say(:create, destination)
214
- end
215
-
216
- # @since 1.1.0
217
- # @api private
218
- def generate_view_spec(context)
219
- return if skip_view?(context)
220
-
221
- source = templates.find("view_spec.#{context.test}.erb")
222
- destination = project.view_spec(context)
223
-
224
- generate_file(source, destination, context)
225
- say(:create, destination)
226
- end
227
-
228
- # @since 1.1.0
229
- # @api private
230
- def insert_route(context)
231
- content = "#{context.http_method} '#{route_url(context)}', to: '#{route_endpoint(context)}'".downcase
232
- destination = project.app_routes(context)
233
-
234
- files.append(destination, content)
235
- say(:insert, destination)
236
- end
237
-
238
- # @since 1.1.0
239
- # @api private
240
- def route_http_method(action, options)
241
- options.fetch(:method) { route_resourceful_http_method(action) }
242
- end
243
-
244
- # @since 1.1.0
245
- # @api private
246
- def skip_view?(context)
247
- context.options.fetch(:skip_view, false)
248
- end
249
-
250
- # @since 1.1.0
251
- # @api private
252
- DEFAULT_HTTP_METHOD = 'GET'.freeze
253
-
254
- # @since 1.1.0
255
- # @api private
256
- RESOURCEFUL_HTTP_METHODS = {
257
- 'create' => 'POST',
258
- 'update' => 'PATCH',
259
- 'destroy' => 'DELETE'
260
- }.freeze
261
-
262
- # @since 1.1.0
263
- # @api private
264
- def route_resourceful_http_method(action)
265
- RESOURCEFUL_HTTP_METHODS.fetch(action, DEFAULT_HTTP_METHOD)
266
- end
267
-
268
- # @since 1.1.0
269
- # @api private
270
- def route_url(context)
271
- context.options.fetch(:url) { route_resourceful_url(context) }
272
- end
273
-
274
- # @since 1.1.0
275
- # @api private
276
- def route_resourceful_url(context)
277
- "/#{namespaced_controller(context)}#{route_resourceful_url_suffix(context)}"
278
- end
279
-
280
- # @since 1.1.0
281
- # @api private
282
- RESOURCEFUL_ROUTE_URL_SUFFIXES = {
283
- 'index' => '',
284
- 'new' => '/new',
285
- 'create' => '',
286
- 'edit' => '/:id/edit',
287
- 'update' => '/:id',
288
- 'show' => '/:id',
289
- 'destroy' => '/:id'
290
- }.freeze
291
-
292
- # @since 1.1.0
293
- # @api private
294
- def route_resourceful_url_suffix(context)
295
- RESOURCEFUL_ROUTE_URL_SUFFIXES.fetch(context.action) { "/#{context.action}" }
296
- end
297
-
298
- # @since 1.1.0
299
- # @api private
300
- def route_endpoint(context)
301
- "#{namespaced_controller(context)}##{context.action}"
302
- end
303
-
304
- # @since 1.1.0
305
- # @api private
306
- def classified_controller(controller)
307
- controller.
308
- map { |controller_name| Utils::String.new(controller_name).classify }.
309
- join("::")
310
- end
311
-
312
- # @since 1.1.0
313
- # @api private
314
- def namespaced_controller(context)
315
- context.controller.join("/")
316
- end
317
- end
318
- end
319
- end
320
- end
321
- end
@@ -1,313 +0,0 @@
1
- require 'hanami/helpers'
2
- require 'hanami/assets'
3
-
4
- module <%= app.classify %>
5
- class Application < Hanami::Application
6
- configure do
7
- ##
8
- # BASIC
9
- #
10
-
11
- # Define the root path of this application.
12
- # All paths specified in this configuration are relative to path below.
13
- #
14
- root __dir__
15
-
16
- # Relative load paths where this application will recursively load the
17
- # code.
18
- #
19
- # When you add new directories, remember to add them here.
20
- #
21
- load_paths << [
22
- 'controllers',
23
- 'views'
24
- ]
25
-
26
- # Handle exceptions with HTTP statuses (true) or don't catch them (false).
27
- # Defaults to true.
28
- # See: http://www.rubydoc.info/gems/hanami-controller/#Exceptions_management
29
- #
30
- # handle_exceptions true
31
-
32
- ##
33
- # HTTP
34
- #
35
-
36
- # Routes definitions for this application
37
- # See: http://www.rubydoc.info/gems/hanami-router#Usage
38
- #
39
- routes 'config/routes'
40
-
41
- # URI scheme used by the routing system to generate absolute URLs
42
- # Defaults to "http"
43
- #
44
- # scheme 'https'
45
-
46
- # URI host used by the routing system to generate absolute URLs
47
- # Defaults to "localhost"
48
- #
49
- # host 'example.org'
50
-
51
- # URI port used by the routing system to generate absolute URLs
52
- # Argument: An object coercible to integer, defaults to 80 if the scheme
53
- # is http and 443 if it's https
54
- #
55
- # This should only be configured if app listens to non-standard ports
56
- #
57
- # port 443
58
-
59
- # Enable cookies
60
- # Argument: boolean to toggle the feature
61
- # A Hash with options
62
- #
63
- # Options:
64
- # :domain - The domain (String - nil by default, not required)
65
- # :path - Restrict cookies to a relative URI
66
- # (String - nil by default)
67
- # :max_age - Cookies expiration expressed in seconds
68
- # (Integer - nil by default)
69
- # :secure - Restrict cookies to secure connections
70
- # (Boolean - Automatically true when using HTTPS)
71
- # See #scheme and #ssl?
72
- # :httponly - Prevent JavaScript access (Boolean - true by default)
73
- #
74
- # cookies true
75
- # or
76
- # cookies max_age: 300
77
-
78
- # Enable sessions
79
- # Argument: Symbol the Rack session adapter
80
- # A Hash with options
81
- #
82
- # See: http://www.rubydoc.info/gems/rack/Rack/Session/Cookie
83
- #
84
- # sessions :cookie, secret: ENV['<%= app.upcase %>_SESSIONS_SECRET']
85
-
86
- # Configure Rack middleware for this application
87
- #
88
- # middleware.use Rack::Protection
89
-
90
- # Default format for the requests that don't specify an HTTP_ACCEPT header
91
- # Argument: A symbol representation of a mime type, defaults to :html
92
- #
93
- # default_request_format :html
94
-
95
- # Default format for responses that don't consider the request format
96
- # Argument: A symbol representation of a mime type, defaults to :html
97
- #
98
- # default_response_format :html
99
-
100
- ##
101
- # TEMPLATES
102
- #
103
-
104
- # The layout to be used by all views
105
- #
106
- layout :application # It will load <%= app.classify %>::Views::ApplicationLayout
107
-
108
- # The relative path to templates
109
- #
110
- templates 'templates'
111
-
112
- ##
113
- # ASSETS
114
- #
115
- assets do
116
- # JavaScript compressor
117
- #
118
- # Supported engines:
119
- #
120
- # * :builtin
121
- # * :uglifier
122
- # * :yui
123
- # * :closure
124
- #
125
- # See: https://guides.hanamirb.org/assets/compressors
126
- #
127
- # In order to skip JavaScript compression comment the following line
128
- javascript_compressor :builtin
129
-
130
- # Stylesheet compressor
131
- #
132
- # Supported engines:
133
- #
134
- # * :builtin
135
- # * :yui
136
- # * :sass
137
- #
138
- # See: https://guides.hanamirb.org/assets/compressors
139
- #
140
- # In order to skip stylesheet compression comment the following line
141
- stylesheet_compressor :builtin
142
-
143
- # Specify sources for assets
144
- #
145
- sources << [
146
- 'assets'
147
- ]
148
- end
149
-
150
- ##
151
- # SECURITY
152
- #
153
-
154
- # X-Frame-Options is a HTTP header supported by modern browsers.
155
- # It determines if a web page can or cannot be included via <frame> and
156
- # <iframe> tags by untrusted domains.
157
- #
158
- # Web applications can send this header to prevent Clickjacking attacks.
159
- #
160
- # Read more at:
161
- #
162
- # * https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
163
- # * https://www.owasp.org/index.php/Clickjacking
164
- #
165
- security.x_frame_options 'DENY'
166
-
167
- # X-Content-Type-Options prevents browsers from interpreting files as
168
- # something else than declared by the content type in the HTTP headers.
169
- #
170
- # Read more at:
171
- #
172
- # * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-Content-Type-Options
173
- # * https://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx
174
- # * https://blogs.msdn.microsoft.com/ie/2008/09/02/ie8-security-part-vi-beta-2-update
175
- #
176
- security.x_content_type_options 'nosniff'
177
-
178
- # X-XSS-Protection is a HTTP header to determine the behavior of the
179
- # browser in case an XSS attack is detected.
180
- #
181
- # Read more at:
182
- #
183
- # * https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
184
- # * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-XSS-Protection
185
- #
186
- security.x_xss_protection '1; mode=block'
187
-
188
- # Content-Security-Policy (CSP) is a HTTP header supported by modern
189
- # browsers. It determines trusted sources of execution for dynamic
190
- # contents (JavaScript) or other web related assets: stylesheets, images,
191
- # fonts, plugins, etc.
192
- #
193
- # Web applications can send this header to mitigate Cross Site Scripting
194
- # (XSS) attacks.
195
- #
196
- # The default value allows images, scripts, AJAX, fonts and CSS from the
197
- # same origin, and does not allow any other resources to load (eg object,
198
- # frame, media, etc).
199
- #
200
- # Inline JavaScript is NOT allowed. To enable it, please use:
201
- # "script-src 'unsafe-inline'".
202
- #
203
- # Content Security Policy introduction:
204
- #
205
- # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/
206
- # * https://www.owasp.org/index.php/Content_Security_Policy
207
- # * https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29
208
- #
209
- # Inline and eval JavaScript risks:
210
- #
211
- # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful
212
- # * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#eval-too
213
- #
214
- # Content Security Policy usage:
215
- #
216
- # * http://content-security-policy.com/
217
- # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
218
- #
219
- # Content Security Policy references:
220
- #
221
- # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives
222
- #
223
- security.content_security_policy %{
224
- form-action 'self';
225
- frame-ancestors 'self';
226
- base-uri 'self';
227
- default-src 'none';
228
- script-src 'self';
229
- connect-src 'self';
230
- img-src 'self' https: data:;
231
- style-src 'self' 'unsafe-inline' https:;
232
- font-src 'self';
233
- object-src 'none';
234
- plugin-types application/pdf;
235
- child-src 'self';
236
- frame-src 'self';
237
- media-src 'self'
238
- }
239
-
240
- ##
241
- # FRAMEWORKS
242
- #
243
-
244
- # Configure the code that will yield each time <%= app.classify %>::Action is included
245
- # This is useful for sharing common functionality
246
- #
247
- # See: http://www.rubydoc.info/gems/hanami-controller#Configuration
248
- controller.prepare do
249
- # include MyAuthentication # included in all the actions
250
- # before :authenticate! # run an authentication before callback
251
- end
252
-
253
- # Configure the code that will yield each time <%= app.classify %>::View is included
254
- # This is useful for sharing common functionality
255
- #
256
- # See: http://www.rubydoc.info/gems/hanami-view#Configuration
257
- view.prepare do
258
- include Hanami::Helpers
259
- include <%= app.classify %>::Assets::Helpers
260
- end
261
- end
262
-
263
- ##
264
- # DEVELOPMENT
265
- #
266
- configure :development do
267
- # Don't handle exceptions, render the stack trace
268
- handle_exceptions false
269
- end
270
-
271
- ##
272
- # TEST
273
- #
274
- configure :test do
275
- # Don't handle exceptions, render the stack trace
276
- handle_exceptions false
277
- end
278
-
279
- ##
280
- # PRODUCTION
281
- #
282
- configure :production do
283
- # scheme 'https'
284
- # host 'example.org'
285
- # port 443
286
-
287
- assets do
288
- # Don't compile static assets in production mode (eg. Sass, ES6)
289
- #
290
- # See: http://www.rubydoc.info/gems/hanami-assets#Configuration
291
- compile false
292
-
293
- # Use fingerprint file name for asset paths
294
- #
295
- # See: https://guides.hanamirb.org/assets/overview
296
- fingerprint true
297
-
298
- # Content Delivery Network (CDN)
299
- #
300
- # See: https://guides.hanamirb.org/assets/content-delivery-network
301
- #
302
- # scheme 'https'
303
- # host 'cdn.example.org'
304
- # port 443
305
-
306
- # Subresource Integrity
307
- #
308
- # See: https://guides.hanamirb.org/assets/content-delivery-network/#subresource-integrity
309
- subresource_integrity :sha256
310
- end
311
- end
312
- end
313
- end
File without changes
@@ -1,7 +0,0 @@
1
- module <%= app.classify %>
2
- module Views
3
- class ApplicationLayout
4
- include <%= app.classify %>::Layout
5
- end
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe <%= app.classify %>::Views::ApplicationLayout do
4
- let(:layout) { <%= app.classify %>::Views::ApplicationLayout.new({ format: :html }, "contents") }
5
- let(:rendered) { layout.render }
6
-
7
- it 'contains application name' do
8
- _(rendered).must_include('<%= app.classify %>')
9
- end
10
- end