panda-core 0.9.2 → 0.9.3
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.
- checksums.yaml +4 -4
- data/lib/panda/core/engine.rb +18 -11
- data/lib/panda/core/module_registry.rb +93 -0
- data/lib/panda/core/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e7863be64e4e612a42759b596547772fdc8ea9f50d85dc57b6c879328cbb8fa
|
|
4
|
+
data.tar.gz: 14c99c7ad8e4dd48c69aecf9b958ab9201e77e5159affcdc3bba8bb5a6608998
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 337d68b1a7c03cedfdcea65f5978d13dc3cd6692d79188dc0132e4fb55a781d3b4c0991a23582e9fae585c88fa58ea314401f1a0cc5a9bc5059617d385536753
|
|
7
|
+
data.tar.gz: 5be39c37ddf7d54f51071bc2486fd33b81e1be1bc1176358c890180de86676ce7848d89b426ecad80663e7a72e371de164fb71b1a3bd82c44e6decd09519bf57
|
data/lib/panda/core/engine.rb
CHANGED
|
@@ -58,9 +58,10 @@ module Panda
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
# Static asset middleware for serving public files and JavaScript modules
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
# Must run before Propshaft to intercept /panda/* requests
|
|
62
|
+
initializer "panda.core.static_assets" do |app|
|
|
63
|
+
# Serve public assets (CSS, images, etc.)
|
|
64
|
+
app.config.middleware.insert_before Propshaft::Server, Rack::Static,
|
|
64
65
|
urls: ["/panda-core-assets"],
|
|
65
66
|
root: Panda::Core::Engine.root.join("public"),
|
|
66
67
|
header_rules: [
|
|
@@ -68,14 +69,9 @@ module Panda
|
|
|
68
69
|
[:all, {"Cache-Control" => Rails.env.development? ? "no-cache, no-store, must-revalidate" : "public, max-age=31536000"}]
|
|
69
70
|
]
|
|
70
71
|
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
app.config.middleware.
|
|
74
|
-
urls: ["/panda/core"],
|
|
75
|
-
root: Panda::Core::Engine.root.join("app/javascript"),
|
|
76
|
-
header_rules: [
|
|
77
|
-
[:all, {"Cache-Control" => Rails.env.development? ? "no-cache, no-store, must-revalidate" : "public, max-age=31536000"}]
|
|
78
|
-
]
|
|
72
|
+
# Use ModuleRegistry's custom middleware to serve JavaScript from all registered modules
|
|
73
|
+
# This middleware checks all modules and serves from the first matching location
|
|
74
|
+
app.config.middleware.insert_before Propshaft::Server, Panda::Core::ModuleRegistry::JavaScriptMiddleware
|
|
79
75
|
end
|
|
80
76
|
|
|
81
77
|
# Auto-compile CSS for test/development environments
|
|
@@ -125,3 +121,14 @@ module Panda
|
|
|
125
121
|
end
|
|
126
122
|
end
|
|
127
123
|
end
|
|
124
|
+
|
|
125
|
+
# Register Core module with ModuleRegistry for JavaScript serving
|
|
126
|
+
Panda::Core::ModuleRegistry.register(
|
|
127
|
+
gem_name: "panda-core",
|
|
128
|
+
engine: "Panda::Core::Engine",
|
|
129
|
+
paths: {
|
|
130
|
+
views: "app/views/panda/core/**/*.erb",
|
|
131
|
+
components: "app/components/panda/core/**/*.rb"
|
|
132
|
+
# JavaScript paths are auto-discovered from config/importmap.rb
|
|
133
|
+
}
|
|
134
|
+
)
|
|
@@ -277,6 +277,99 @@ module Panda
|
|
|
277
277
|
nil
|
|
278
278
|
end
|
|
279
279
|
end
|
|
280
|
+
|
|
281
|
+
# Custom Rack middleware to serve JavaScript modules from all registered Panda modules
|
|
282
|
+
#
|
|
283
|
+
# This middleware checks all registered modules' app/javascript/panda directories
|
|
284
|
+
# and serves the first matching file. This solves the problem of multiple Rack::Static
|
|
285
|
+
# instances blocking each other.
|
|
286
|
+
#
|
|
287
|
+
class JavaScriptMiddleware
|
|
288
|
+
def initialize(app)
|
|
289
|
+
@app = app
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def call(env)
|
|
293
|
+
request = Rack::Request.new(env)
|
|
294
|
+
path = request.path_info
|
|
295
|
+
|
|
296
|
+
# Only handle /panda/core/* and /panda/cms/* style JavaScript module requests
|
|
297
|
+
# Skip paths like /panda-core-assets/* (public assets handled by Rack::Static)
|
|
298
|
+
return @app.call(env) unless path.start_with?("/panda/")
|
|
299
|
+
|
|
300
|
+
# Strip /panda/ prefix to get relative path
|
|
301
|
+
# e.g., "/panda/cms/application.js" -> "cms/application.js"
|
|
302
|
+
relative_path = path.sub(%r{^/panda/}, "")
|
|
303
|
+
return @app.call(env) if relative_path.empty?
|
|
304
|
+
|
|
305
|
+
# Try to find the file in registered modules
|
|
306
|
+
file_path = find_javascript_file(relative_path)
|
|
307
|
+
|
|
308
|
+
if file_path && File.file?(file_path)
|
|
309
|
+
puts "[JavaScriptMiddleware] Serving: #{path} from #{file_path}"
|
|
310
|
+
serve_file(file_path, env)
|
|
311
|
+
else
|
|
312
|
+
puts "[JavaScriptMiddleware] Not found: #{path} (tried #{relative_path})"
|
|
313
|
+
@app.call(env)
|
|
314
|
+
end
|
|
315
|
+
rescue => e
|
|
316
|
+
# On error, log and pass to next middleware
|
|
317
|
+
puts "[JavaScriptMiddleware] Error: #{e.message}"
|
|
318
|
+
Rails.logger.error("[ModuleRegistry::JavaScriptMiddleware] Error: #{e.message}\n#{e.backtrace.join("\n")}") if defined?(Rails.logger)
|
|
319
|
+
@app.call(env)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
private
|
|
323
|
+
|
|
324
|
+
def find_javascript_file(relative_path)
|
|
325
|
+
# Check each registered module's JavaScript directory
|
|
326
|
+
ModuleRegistry.modules.each do |gem_name, info|
|
|
327
|
+
next unless ModuleRegistry.send(:engine_available?, info[:engine])
|
|
328
|
+
|
|
329
|
+
root = ModuleRegistry.send(:engine_root, info[:engine])
|
|
330
|
+
next unless root
|
|
331
|
+
|
|
332
|
+
# Check in app/javascript/panda/
|
|
333
|
+
candidate = root.join("app/javascript/panda", relative_path)
|
|
334
|
+
return candidate.to_s if candidate.exist? && candidate.file?
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
nil
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def serve_file(file_path, env)
|
|
341
|
+
# Read file content
|
|
342
|
+
content = File.read(file_path)
|
|
343
|
+
|
|
344
|
+
# Determine content type
|
|
345
|
+
content_type = case File.extname(file_path)
|
|
346
|
+
when ".js"
|
|
347
|
+
"application/javascript; charset=utf-8"
|
|
348
|
+
when ".json"
|
|
349
|
+
"application/json; charset=utf-8"
|
|
350
|
+
else
|
|
351
|
+
"text/plain; charset=utf-8"
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Determine cache control
|
|
355
|
+
cache_control = if Rails.env.development? || Rails.env.test?
|
|
356
|
+
"no-cache, no-store, must-revalidate"
|
|
357
|
+
else
|
|
358
|
+
"public, max-age=31536000"
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
# Return response
|
|
362
|
+
[
|
|
363
|
+
200,
|
|
364
|
+
{
|
|
365
|
+
"Content-Type" => content_type,
|
|
366
|
+
"Content-Length" => content.bytesize.to_s,
|
|
367
|
+
"Cache-Control" => cache_control
|
|
368
|
+
},
|
|
369
|
+
[content]
|
|
370
|
+
]
|
|
371
|
+
end
|
|
372
|
+
end
|
|
280
373
|
end
|
|
281
374
|
end
|
|
282
375
|
end
|
data/lib/panda/core/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: panda-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Otaina Limited
|
|
8
8
|
- James Inman
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2025-11-13 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: image_processing
|
|
@@ -529,6 +530,7 @@ metadata:
|
|
|
529
530
|
homepage_uri: https://github.com/tastybamboo/panda-core
|
|
530
531
|
source_code_uri: https://github.com/tastybamboo/panda-core
|
|
531
532
|
changelog_uri: https://github.com/tastybamboo/panda-core/blob/main/CHANGELOG.md
|
|
533
|
+
post_install_message:
|
|
532
534
|
rdoc_options: []
|
|
533
535
|
require_paths:
|
|
534
536
|
- lib
|
|
@@ -543,7 +545,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
543
545
|
- !ruby/object:Gem::Version
|
|
544
546
|
version: '0'
|
|
545
547
|
requirements: []
|
|
546
|
-
rubygems_version: 3.
|
|
548
|
+
rubygems_version: 3.5.22
|
|
549
|
+
signing_key:
|
|
547
550
|
specification_version: 4
|
|
548
551
|
summary: Core libraries and development tools for Tasty Bamboo projects
|
|
549
552
|
test_files: []
|