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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08a72a419dd702e8cc8cde2bfea476a283a17280499bb16de53b554ebaf7406c'
4
- data.tar.gz: 4cf2468a51ed77691ab280b2cfb4b0345a2449e4bb61a36560b286cecb311cac
3
+ metadata.gz: 3e7863be64e4e612a42759b596547772fdc8ea9f50d85dc57b6c879328cbb8fa
4
+ data.tar.gz: 14c99c7ad8e4dd48c69aecf9b958ab9201e77e5159affcdc3bba8bb5a6608998
5
5
  SHA512:
6
- metadata.gz: d8ebe8e076e53a063dc0f7ab565c6b12c299a6765cdd7e9c446716a5de191070ea2da46a75167f384ab4ee5c2fa91753543625e2cbc64f58a9f962725be39042
7
- data.tar.gz: c7d7d8932c8eea8b767343e27a4ce23ac0206c40df9acd6557b5734b2684f16080a2586fc99a63d62b0b548427dd35cf4603219e2d9938f3d704d873da818a39
6
+ metadata.gz: 337d68b1a7c03cedfdcea65f5978d13dc3cd6692d79188dc0132e4fb55a781d3b4c0991a23582e9fae585c88fa58ea314401f1a0cc5a9bc5059617d385536753
7
+ data.tar.gz: 5be39c37ddf7d54f51071bc2486fd33b81e1be1bc1176358c890180de86676ce7848d89b426ecad80663e7a72e371de164fb71b1a3bd82c44e6decd09519bf57
@@ -58,9 +58,10 @@ module Panda
58
58
  end
59
59
 
60
60
  # Static asset middleware for serving public files and JavaScript modules
61
- initializer "panda.core.static_assets", before: :build_middleware_stack do |app|
62
- # Make files in public available to the main app (e.g. /panda-core-assets/panda-logo.png)
63
- app.config.middleware.use Rack::Static,
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
- # Make JavaScript files available for importmap
72
- # Serve from app/javascript with proper MIME types
73
- app.config.middleware.use Rack::Static,
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Panda
4
4
  module Core
5
- VERSION = "0.9.2"
5
+ VERSION = "0.9.3"
6
6
  end
7
7
  end
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.2
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: 1980-01-02 00:00:00.000000000 Z
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.6.9
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: []