brut 0.0.20 → 0.0.21

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/brut/back_end/seed_data.rb +19 -2
  4. data/lib/brut/back_end/sidekiq/middlewares/server.rb +2 -1
  5. data/lib/brut/back_end/sidekiq/middlewares.rb +2 -1
  6. data/lib/brut/back_end/sidekiq.rb +2 -1
  7. data/lib/brut/back_end/validator.rb +5 -1
  8. data/lib/brut/back_end.rb +4 -2
  9. data/lib/brut/cli.rb +4 -3
  10. data/lib/brut/factory_bot.rb +0 -5
  11. data/lib/brut/framework/app.rb +70 -5
  12. data/lib/brut/framework/config.rb +5 -3
  13. data/lib/brut/framework/container.rb +3 -2
  14. data/lib/brut/framework/errors.rb +12 -4
  15. data/lib/brut/framework/mcp.rb +62 -1
  16. data/lib/brut/framework/project_environment.rb +6 -2
  17. data/lib/brut/framework.rb +1 -1
  18. data/lib/brut/front_end/component.rb +35 -12
  19. data/lib/brut/front_end/components/constraint_violations.rb +1 -1
  20. data/lib/brut/front_end/components/form_tag.rb +1 -1
  21. data/lib/brut/front_end/components/inputs/csrf_token.rb +1 -1
  22. data/lib/brut/front_end/components/inputs/text_field.rb +1 -1
  23. data/lib/brut/front_end/components/time_tag.rb +1 -1
  24. data/lib/brut/front_end/layout.rb +16 -0
  25. data/lib/brut/front_end/page.rb +51 -26
  26. data/lib/brut/front_end/routing.rb +5 -1
  27. data/lib/brut/front_end.rb +4 -13
  28. data/lib/brut/i18n/base_methods.rb +37 -3
  29. data/lib/brut/i18n/for_back_end.rb +3 -0
  30. data/lib/brut/i18n/for_cli.rb +3 -0
  31. data/lib/brut/i18n/http_accept_language.rb +47 -0
  32. data/lib/brut/instrumentation/open_telemetry.rb +25 -0
  33. data/lib/brut/instrumentation.rb +3 -5
  34. data/lib/brut/sinatra_helpers.rb +1 -0
  35. data/lib/brut/spec_support/component_support.rb +18 -4
  36. data/lib/brut/spec_support/e2e_support.rb +1 -1
  37. data/lib/brut/spec_support/general_support.rb +3 -0
  38. data/lib/brut/spec_support/handler_support.rb +6 -1
  39. data/lib/brut/spec_support/matcher.rb +1 -0
  40. data/lib/brut/spec_support/matchers/be_page_for.rb +1 -0
  41. data/lib/brut/spec_support/matchers/have_html_attribute.rb +1 -0
  42. data/lib/brut/spec_support/matchers/have_i18n_string.rb +2 -5
  43. data/lib/brut/spec_support/matchers/have_link_to.rb +1 -0
  44. data/lib/brut/spec_support/matchers/have_redirected_to.rb +1 -0
  45. data/lib/brut/spec_support/matchers/have_rendered.rb +1 -0
  46. data/lib/brut/spec_support/matchers/have_returned_rack_response.rb +44 -0
  47. data/lib/brut/spec_support.rb +1 -1
  48. data/lib/brut/version.rb +1 -1
  49. data/lib/brut.rb +5 -4
  50. metadata +2 -9
  51. data/doc-src/architecture.md +0 -102
  52. data/doc-src/assets.md +0 -98
  53. data/doc-src/forms.md +0 -214
  54. data/doc-src/handlers.md +0 -83
  55. data/doc-src/javascript.md +0 -265
  56. data/doc-src/keyword-injection.md +0 -183
  57. data/doc-src/pages.md +0 -210
  58. data/doc-src/route-hooks.md +0 -59
@@ -1,59 +0,0 @@
1
- # Route and Page Hooks
2
-
3
- Route and page hooks allow you to perform logic or redirect the visitor before a page is rendered or action handled.
4
-
5
- ## Route Hooks
6
-
7
- Route hooks are objects that are run before or after a request has been handled. They are useful for setting up cross-cutting code
8
- that you don't want to have inside a page or handler.
9
-
10
- To use one, call either {Brut::Framework::App.before} or {Brut::Framework::App.after}, passing it the *name* of a class to use as the
11
- hook (i.e. a `String`).
12
-
13
- Then, implement that class, extending {Brut::FrontEnd::RouteHook}, and provide either {Brut::FrontEnd::RouteHook#before} or {Brut::FrontEnd::RouteHook#after}. As discussed in {file:doc-src/keyword-injection.md Keyword Injection}, your hook can be passed some managed values to allow it to work.
14
-
15
- In general, a hook will allow the request to continue or not, but using one of the following methods as the return value:
16
-
17
- * {Brut::FrontEnd::HandlingResults#redirect_to} to redirect the user instead of rendering the page or handling the request.
18
- * {Brut::FrontEnd::HandlingResults#http_status} to return an HTTP status instead of rendering the page or handling the request.
19
- * {Brut::FrontEnd::RouteHook#continue} to proceed with the request.
20
-
21
- ## Page Hooks
22
-
23
- Sometimes, the behavior you want to manage before a page is rendered is specific to a page and not cross-cutting. Because a page
24
- exepcts to render HTML, you cannot easily put such code in your page class.
25
-
26
- If you implement {Brut::FrontEnd::Page#before_render}, you can skip page rendering entirely and redirect the user or send an error. A
27
- good example of this would be a set of admin pages where the logged-in site visitor must possess some roles in order to see the page.
28
-
29
- A page hook expects one of these return values:
30
-
31
- * `URI` - redirect the visitor instead of rendering the page.
32
- * {Brut::FrontEnd::HttpStatus} - Send the browser this status code instead of rendering the page.
33
- * Anything else - render the page as normal
34
-
35
- Thus, the lifecycle of a page is:
36
-
37
- 1. "Before" Route Hooks
38
- 2. Page Initializer, injected as described in {file:doc-src/keyword-injection.md}
39
- 3. Page's `before_render`, called with no arguments.
40
- 4. Page's ERB generates HTML
41
- 5. "After" Route Hooks
42
-
43
- ## Handler Hooks
44
-
45
- Like page hooks, handler hooks are called before handling logic. Implement `before_handle`. It's arguments must be a subset of the
46
- arguments passed to `handle`. Thus, any value needed by `before_handle` must be declared as a keyword argument to `handle` as well.
47
-
48
- If `before_handle` returns `nil`, `handle` is then called. Otherwise, `handle` is skipped and the return value of `before_handle` is
49
- interpreted as the return value of `handle`. See {Brut::FrontEnd::Handler#handle}.
50
-
51
- This makes the lifecycle of a handler as such:
52
-
53
- 1. "Before" Route Hooks
54
- 2. Handler Initializer, called with no argument.
55
- 3. Handler's `handle!`, injected with arguments as described in {file:doc-src/keyword-injections.md}
56
- 1. `handle!` calls `before_handle`, passing the arguments in.
57
- 2. `handle!` calls `handle`, passing the arguments in.
58
- 4. "After" Route Hooks
59
-