Skip to content

Commit 1cf27f7

Browse files
committed
Demo 4: Multi-store, cada tienda su propia PWA
- Manifest personalizado por store con ERB (nombre, logo) - Cache nombrado por subdominio para facilitar debugging - Renombrar service-worker.js a .js.erb para habilitar ERB - Helper current_store disponible para Rails::PwaController
1 parent 8f67218 commit 1cf27f7

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
module ApplicationHelper
2+
# Disponible en todas las vistas, incluyendo las de Rails::PwaController
3+
# que NO hereda de nuestro ApplicationController.
4+
def current_store
5+
Current.store || Store.find_by(subdomain: request.subdomain)
6+
end
7+
28
def order_status_border_class(status)
39
case status.to_s
410
when "open" then "border-amber-300"

app/views/pwa/manifest.json.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
<%# Personalizado por store %>
12
{
2-
"name": "May Store",
3-
"short_name": "MayStore",
3+
"name": "<%= current_store&.name || 'May Store' %>",
4+
"short_name": "<%= current_store&.name&.truncate(12) || 'MayStore' %>",
45
"icons": [
56
{
6-
"src": "/icon.png",
7+
"src": "<%= current_store&.logo_url || '/icon.png' %>",
78
"type": "image/png",
89
"sizes": "512x512"
910
},
1011
{
11-
"src": "/icon.png",
12+
"src": "<%= current_store&.logo_url || '/icon.png' %>",
1213
"type": "image/png",
1314
"sizes": "512x512",
1415
"purpose": "maskable"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const CACHE_NAME = "may-store-v1"
1+
// Cache nombrado por store para facilitar debugging
2+
const CACHE_NAME = "may-store-<%= current_store&.subdomain || 'public' %>-v1"
23

34
// 1. Install: pre-cachear la pagina offline
45
self.addEventListener("install", (event) => {

0 commit comments

Comments
 (0)