proscenium 0.19.0.beta7 → 0.19.0.beta8

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: e9c86c8fc9ea5069434688a114679c39ea03b431af308efbe0b65360f0b5b935
4
- data.tar.gz: 4d74b86e4d0aed1651fdc369c4f830b1f85b9b33dad0d109905df3df9581dddc
3
+ metadata.gz: 5700515c91113e3ba65329d0a82f91cbf654850c6becd0e19908f9ab98a0678e
4
+ data.tar.gz: 02e282be2f438d9f875a1bc9ba508d57e99d5a05800d6b1e28f5c41a5ca25d4b
5
5
  SHA512:
6
- metadata.gz: c64c401d4ef4e70fedf4e6327177dc53645bcd540de6301f64edfb9020cf8686fe444377ea538ef9a09d2b0699229ab3a138f8704f006e89b5acfb0a39666355
7
- data.tar.gz: 249ae5d9c8fe4884b2ad5c7ab2712665522007f75ced0c2d56b4f6ee189e868c0e58122a4f96aade3b24443037b3977356595fd3881dc4fd107151e28c3c751d
6
+ metadata.gz: a2db492fc5134f0da0625c1489cd4ea8b38319af22c9d8a2d102bc4e33f7d27ed97bffe3e01fd12c252b6e11d26fbeba2c13b2d2ca74c7f57dc1e928ad9cf440
7
+ data.tar.gz: c72e8aa1325c4a6051bae850c9a798845ba8fc1dc492c018133738b267fade2228939fa69a5c517e0d0b700bc9718031b46774346458fb19647eba4da18e965b
@@ -85,7 +85,7 @@ module Proscenium
85
85
  end
86
86
 
87
87
  def build_to_string(path)
88
- ActiveSupport::Notifications.instrument('build_to_string.proscenium', identifier: path) do
88
+ ActiveSupport::Notifications.instrument('build.proscenium', identifier: path) do
89
89
  result = Request.build_to_string(path, @request_config)
90
90
 
91
91
  raise BuildError, result[:response] unless result[:success]
@@ -27,9 +27,9 @@ module Proscenium
27
27
  def css_module_string(name)
28
28
  if (path = Pathname.new(context.path).sub_ext('.module.css')).exist?
29
29
  tname = Transformer.new(path).class_name!(name, name.dup).first
30
- "Proscenium::CssModule::Name.new(:@#{name}, '#{tname}')"
30
+ "Proscenium::CssModule::Name.new(:@#{name}, '#{tname}', #{path})"
31
31
  else
32
- "Proscenium::CssModule::Name.new(:@#{name}, css_module(:#{name}))"
32
+ "Proscenium::CssModule::Name.new(:@#{name}, css_module(:#{name}), nil)"
33
33
  end
34
34
  end
35
35
  end
@@ -16,9 +16,12 @@ module Proscenium::CssModule
16
16
  end
17
17
 
18
18
  class Name
19
- def initialize(name, transform)
19
+ attr_reader :path
20
+
21
+ def initialize(name, transform, path = nil)
20
22
  @name = name
21
23
  @transform = transform
24
+ @path = path
22
25
  end
23
26
 
24
27
  def to_s
Binary file
@@ -24,17 +24,23 @@ module Proscenium
24
24
  # @param filepath [String] Absolute URL path (relative to Rails root) of the file to import.
25
25
  # Should be the actual asset file, eg. app.css, some/component.js.
26
26
  # @return [String|nil] the digest of the imported file path if a css module (*.module.css).
27
- def import(filepath = nil, **)
27
+ def import(filepath = nil, sideloaded: false, **)
28
28
  self.imported ||= {}
29
29
 
30
30
  filepath = "/node_modules/#{filepath}" if filepath.start_with?('@rubygems/')
31
31
  css_module = filepath.end_with?('.module.css')
32
32
 
33
33
  unless self.imported.key?(filepath)
34
- # ActiveSupport::Notifications.instrument('sideload.proscenium', identifier: value)
35
-
36
- self.imported[filepath] = { ** }
37
- self.imported[filepath][:digest] = Utils.digest(filepath) if css_module
34
+ if sideloaded
35
+ ActiveSupport::Notifications.instrument 'sideload.proscenium', identifier: filepath,
36
+ sideloaded: do
37
+ self.imported[filepath] = { ** }
38
+ self.imported[filepath][:digest] = Utils.digest(filepath) if css_module
39
+ end
40
+ else
41
+ self.imported[filepath] = { ** }
42
+ self.imported[filepath][:digest] = Utils.digest(filepath) if css_module
43
+ end
38
44
  end
39
45
 
40
46
  css_module ? self.imported[filepath][:digest] : nil
@@ -72,12 +78,17 @@ module Proscenium
72
78
  end
73
79
 
74
80
  def sideload_css(filepath, **)
75
- _sideload(filepath, CSS_EXTENSIONS, **)
81
+ _sideload(filepath, ['.css'], **)
82
+ end
83
+
84
+ def sideload_css_module(filepath, **)
85
+ _sideload(filepath, ['.module.css'], **)
76
86
  end
77
87
 
78
88
  # @param filepath [Pathname] Absolute file system path of the Ruby file to sideload.
79
89
  # @param extensions [Array<String>] Supported file extensions to sideload.
80
90
  # @param options [Hash] Options to pass to `import`.
91
+ # @return [Array<String>] The imported file paths.
81
92
  # @raise [ArgumentError] if `filepath` is not an absolute file system path.
82
93
  private def _sideload(filepath, extensions, **options) # rubocop:disable Style/AccessModifierDeclarations
83
94
  return unless Proscenium.config.side_load
@@ -86,13 +97,18 @@ module Proscenium
86
97
  raise ArgumentError, "`filepath` (#{filepath}) must be a `Pathname`, and an absolute path"
87
98
  end
88
99
 
100
+ # Ensures extensions with more than one dot are handled correctly.
89
101
  filepath = filepath.sub_ext('')
90
102
 
103
+ sideloaded = []
104
+
91
105
  extensions.find do |x|
92
106
  if (fp = filepath.sub_ext(x)).exist?
93
- import(Resolver.resolve(fp.to_s), sideloaded: true, **options)
107
+ sideloaded << import(Resolver.resolve(fp.to_s), sideloaded: filepath, **options)
94
108
  end
95
109
  end
110
+
111
+ sideloaded
96
112
  end
97
113
 
98
114
  def each_stylesheet(delete: false)
@@ -5,17 +5,32 @@ require 'active_support/log_subscriber'
5
5
  module Proscenium
6
6
  class LogSubscriber < ActiveSupport::LogSubscriber
7
7
  def sideload(event)
8
+ path = event.payload[:identifier]
9
+ sideloaded = event.payload[:sideloaded]
10
+ sideloaded = sideloaded.relative_path_from(Rails.root) if sideloaded.is_a?(Pathname)
11
+
12
+ info do
13
+ msg = " #{color('[Proscenium]', nil, bold: true)} Sideloading #{path}"
14
+ sideloaded.is_a?(Pathname) ? msg << " from #{sideloaded}" : msg
15
+ end
16
+ end
17
+
18
+ def build(event)
19
+ path = event.payload[:identifier]
20
+ path = CGI.unescape(path) if path.start_with?(/https?%3A%2F%2F/)
21
+
8
22
  info do
9
- " [Proscenium] Side loaded #{event.payload[:identifier]}"
23
+ message = "#{color('[Proscenium]', nil, bold: true)} Building /#{path}"
24
+ message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
10
25
  end
11
26
  end
12
27
 
13
- def build_to_string(event)
28
+ def resolve(event)
14
29
  path = event.payload[:identifier]
15
30
  path = CGI.unescape(path) if path.start_with?(/https?%3A%2F%2F/)
16
31
 
17
32
  info do
18
- message = " #{color('[Proscenium]', nil, bold: true)} Building (to string) #{path}"
33
+ message = " #{color('[Proscenium]', nil, bold: true)} Resolving #{path}"
19
34
  message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
20
35
  end
21
36
  end
@@ -24,7 +24,7 @@ module Proscenium
24
24
 
25
25
  def after_template
26
26
  self.class.resolved_css_module_paths.each do |path|
27
- Proscenium::Importer.import path
27
+ Proscenium::Importer.import path, sideloaded: true
28
28
  end
29
29
 
30
30
  super
@@ -46,7 +46,6 @@ module Proscenium
46
46
  class_methods do
47
47
  def sideload(options)
48
48
  Importer.import manager, **options, js: { type: 'module' }
49
- Importer.sideload source_path, lazy: true, **options
50
49
  end
51
50
  end
52
51
 
@@ -86,13 +86,14 @@ module Proscenium
86
86
  end
87
87
 
88
88
  class << self
89
- # Side loads the class, and its super classes that respond to `.source_path`.
89
+ # Side loads assets for the class, and its super classes that respond to `.source_path`, which
90
+ # should return a Pathname of the class source file.
90
91
  #
91
92
  # Set the `abstract_class` class variable to true in any class, and it will not be side
92
93
  # loaded.
93
94
  #
94
- # If the class responds to `.sideload`, it will be called instead of the regular side loading.
95
- # You can use this to customise what is side loaded.
95
+ # If the class responds to `.sideload`, it will be called after the regular side loading. You
96
+ # can use this to customise what is side loaded.
96
97
  def sideload_inheritance_chain(obj, options)
97
98
  return unless Proscenium.config.side_load
98
99
 
@@ -116,18 +117,28 @@ module Proscenium
116
117
 
117
118
  klass = obj.class
118
119
  while klass.respond_to?(:source_path) && klass.source_path && !klass.abstract_class
119
- if klass.respond_to?(:sideload)
120
- klass.sideload options
121
- elsif options[:css] == false
120
+ if options[:css] == false
122
121
  Importer.sideload klass.source_path, **options
123
122
  else
124
123
  Importer.sideload_js klass.source_path, **options
125
124
  css_imports << klass.source_path
126
125
  end
127
126
 
127
+ klass.sideload options if klass.respond_to?(:sideload)
128
+
128
129
  klass = klass.superclass
129
130
  end
130
131
 
132
+ # All regular CSS files (*.css) are ancestrally sideloaded. However, the first CSS module
133
+ # in the ancestry is also sideloaded in addition to the regular CSS files. This is because
134
+ # the CSS module digest will be different for each file, so we only sideload the first CSS
135
+ # module.
136
+ css_imports.each do |it|
137
+ break if Importer.sideload_css_module(it, **options).present?
138
+ end
139
+
140
+ # Sideload regular CSS files in reverse order.
141
+ #
131
142
  # The reason why we sideload CSS after JS is because the order of CSS is important.
132
143
  # Basically, the layout should be loaded before the view so that CSS cascading works in the
133
144
  # right direction.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.19.0.beta7'
4
+ VERSION = '0.19.0.beta8'
5
5
  end
data/lib/proscenium.rb CHANGED
@@ -1,12 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require 'zeitwerk'
4
-
5
- # loader = Zeitwerk::Loader.for_gem
6
- # loader.inflector.inflect 'ui' => 'UI'
7
- # loader.ignore "#{__dir__}/proscenium/ext"
8
- # loader.ignore "#{__dir__}/proscenium/libs"
9
- # loader.setup
3
+ require 'active_support'
10
4
 
11
5
  module Proscenium
12
6
  extend ActiveSupport::Autoload
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proscenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0.beta7
4
+ version: 0.19.0.beta8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-31 00:00:00.000000000 Z
11
+ date: 2025-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport