diff --git a/app.rb b/app.rb index 0d5781c..e048cf7 100644 --- a/app.rb +++ b/app.rb @@ -305,6 +305,14 @@ module Maptool erb :index, locals: { logged_in: logged_in?, user: session[:user], revision: REVISION } end + # Map legend + symbol browser. A view, not a static public/ page, so it + # gets the same versioned importmap as the map: as a static page it + # imported /js/icons.js and /vendor/mdi/mdi.mjs unversioned, and a + # browser still holding an older copy of either rendered no symbols. + get "/symbols.html" do + erb :symbols, layout: false + end + # A share to the installed app normally never reaches the server: the # service worker (public/sw.js) takes the POST, parks the files and # opens the app. Only lands here if no worker is running yet — back to diff --git a/test/test_app.rb b/test/test_app.rb index 9b92c23..64ba897 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -47,6 +47,18 @@ class AppTest < Minitest::Test end end + # The legend page imports app and vendor modules too: it must get the + # same versioned importmap, and stay light (auto-darkening washed out its + # color swatches on a tablet). + def test_symbols_page_has_the_versioned_importmap_and_a_light_color_scheme + response = request.get("/symbols.html") + assert_equal 200, response.status + assert_match(%r{"/vendor/mdi/mdi\.mjs":\s*"/vendor/mdi/mdi\.mjs\?v=\d+"}, response.body) + assert_match(%r{"/js/icons\.js":\s*"/js/icons\.js\?v=\d+"}, response.body) + assert_includes response.body, '' + assert_operator response.body.index("importmap"), :<, response.body.index(' diff --git a/views/layout.erb b/views/layout.erb index cedc19d..5178600 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -27,54 +27,7 @@ - <%# Every app module and every vendored module they import is versioned - (ASSET_VERSION, a fresh value per deploy): map.js and the rest import - each other — and /vendor modules — by plain path, and an import map - remaps those paths to a versioned URL, so a deploy busts all of them - without touching any import statement. A vendored module that changes - with the app (mdi.mjs gaining an icon) can't be left cached while the - module importing it is fresh. Static files are also revalidated - (static_cache_control in app.rb) as a backstop for anything loaded - some other way. Must come before the module script below: the - importmap has to be parsed first. %> - + <%= erb :importmap, layout: false %> diff --git a/public/symbols.html b/views/symbols.erb similarity index 90% rename from public/symbols.html rename to views/symbols.erb index 3053964..4b62656 100644 --- a/public/symbols.html +++ b/views/symbols.erb @@ -3,11 +3,13 @@ + <%# Light only: without this, Android/Chrome auto-darkening repaints the + page dark and washes out the legend swatches. %> + MapTool legend