janela 0.3.0 → 0.4.1

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.
data/lib/janela/engine.rb CHANGED
@@ -24,7 +24,16 @@ module Janela
24
24
  # Janela's own layout links janela.css, and a host on Sprockets serves it
25
25
  # in production only if something declared it.
26
26
  initializer "janela.assets" do |app|
27
- app.config.assets.precompile << "janela.css" if app.config.respond_to?(:assets) && app.config.assets.respond_to?(:precompile)
27
+ if app.config.respond_to?(:assets) && app.config.assets.respond_to?(:precompile)
28
+ app.config.assets.precompile << "janela.css"
29
+ app.config.assets.precompile << "vitral.css"
30
+ end
31
+ end
32
+
33
+ # A host's route names are only known once its routes are drawn, which is
34
+ # lazy and happens again on every reload in development.
35
+ initializer "janela.host_routes" do |app|
36
+ app.config.after_routes_loaded { Janela::HostRoutes.define! }
28
37
  end
29
38
 
30
39
  initializer "janela.importmap", before: "importmap" do |app|
@@ -0,0 +1,37 @@
1
+ module Janela
2
+ # Route helpers the host application has and the engine does not, forwarded
3
+ # to the host.
4
+ #
5
+ # isolate_namespace points every route helper inside Janela's controllers at
6
+ # the engine's own routes, and a host's ApplicationController runs there,
7
+ # because Janela's controllers inherit it. So an authentication redirect, a
8
+ # rescue_from or an after_action that names one of the host's own routes
9
+ # raises where it would work anywhere else in the application (ADR 022).
10
+ #
11
+ # Only names the engine does not define are forwarded, so the engine's own
12
+ # routes can never be shadowed by a host's. main_app stays the unambiguous
13
+ # way to say either.
14
+ module HostRoutes
15
+ def self.define!(host: Rails.application.routes, engine: Janela::Engine.routes)
16
+ # Routes reload in development, so a name that has gone is removed
17
+ # rather than left behind pointing at nothing.
18
+ instance_methods(false).each { |method| remove_method(method) }
19
+
20
+ forwarded(host: host, engine: engine).each do |name|
21
+ define_method(name) do |*args, **options, &block|
22
+ main_app.public_send(name, *args, **options, &block)
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.forwarded(host: Rails.application.routes, engine: Janela::Engine.routes)
28
+ # Route loading is lazy, so a call before anything else has drawn the
29
+ # host's routes would otherwise see an empty set rather than an error
30
+ # (issue #37). This does not recurse: define! runs from
31
+ # after_routes_loaded, by which point the reloader has already marked
32
+ # itself loaded.
33
+ Rails.application.reload_routes_unless_loaded
34
+ host.named_routes.helper_names - engine.named_routes.helper_names
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Janela
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/janela.rb CHANGED
@@ -10,6 +10,7 @@ require "janela/definition"
10
10
  require "janela/measure"
11
11
  require "janela/dimension"
12
12
  require "janela/doctor"
13
+ require "janela/host_routes"
13
14
 
14
15
  module Janela
15
16
  class Error < StandardError; end
@@ -24,6 +25,12 @@ module Janela
24
25
  # and authorisation apply to dashboards with no configuration.
25
26
  mattr_accessor :parent_controller, default: "ApplicationController"
26
27
 
28
+ # The stylesheet Janela's own pages load on top of janela.css. Nil means the
29
+ # structural one only, which is what a host that has its own look wants. The
30
+ # gem ships "vitral". A host's own pages are untouched either way: they load
31
+ # whatever that host's layout says (ADR 023).
32
+ mattr_accessor :theme, default: nil
33
+
27
34
  # Checks janela:doctor should not report, by the name it prints beside each
28
35
  # finding. A check that is a false alarm for one application stays a false
29
36
  # alarm, and that is a judgement made once at boot, which is what a setting
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janela
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Killeen
@@ -99,7 +99,9 @@ files:
99
99
  - app/assets/javascripts/janela/chart_controller.js
100
100
  - app/assets/javascripts/janela/frame_controller.js
101
101
  - app/assets/javascripts/janela/vendor/chart.js
102
+ - app/assets/javascripts/janela/vitral_controller.js
102
103
  - app/assets/stylesheets/janela.css
104
+ - app/assets/stylesheets/vitral.css
103
105
  - app/controllers/janela/application_controller.rb
104
106
  - app/controllers/janela/frames_controller.rb
105
107
  - app/controllers/janela/panes_controller.rb
@@ -155,13 +157,19 @@ files:
155
157
  - docs/decisions/019-a-created-frame-asks-the-host-who-owns-it.md
156
158
  - docs/decisions/020-formatting-belongs-to-the-measure.md
157
159
  - docs/decisions/021-a-check-has-a-name-a-host-can-silence.md
160
+ - docs/decisions/022-host-route-helpers-work-inside-the-engine.md
161
+ - docs/decisions/023-vitral-is-a-theme-not-the-stylesheet.md
162
+ - docs/decisions/024-selecting-more-than-one-value.md
163
+ - docs/decisions/025-janela-bounds-what-a-filter-can-ask-for.md
158
164
  - docs/decisions/INDEX.md
159
165
  - docs/multi-tenancy.md
166
+ - docs/naming.md
160
167
  - lib/janela.rb
161
168
  - lib/janela/definition.rb
162
169
  - lib/janela/dimension.rb
163
170
  - lib/janela/doctor.rb
164
171
  - lib/janela/engine.rb
172
+ - lib/janela/host_routes.rb
165
173
  - lib/janela/measure.rb
166
174
  - lib/janela/model.rb
167
175
  - lib/janela/version.rb
@@ -175,19 +183,6 @@ metadata:
175
183
  changelog_uri: https://github.com/retail-tasker/janela/blob/main/CHANGELOG.md
176
184
  bug_tracker_uri: https://github.com/retail-tasker/janela/issues
177
185
  rubygems_mfa_required: 'true'
178
- post_install_message: |
179
- Janela 0.3.0 needs two things from you. Run the migrations, because the
180
- mount root now serves an index of frames:
181
-
182
- bin/rails janela:install:migrations && bin/rails db:migrate
183
-
184
- Then rename the Stimulus controller you register, the helper that wraps
185
- your panes, and a few constants.
186
-
187
- Steps: UPGRADING.md in this gem, or
188
- https://github.com/retail-tasker/janela/blob/main/UPGRADING.md
189
-
190
- Then run: bin/rails janela:doctor
191
186
  rdoc_options: []
192
187
  require_paths:
193
188
  - lib