proscenium 0.14.0-x86_64-linux → 0.15.0.beta.2-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -54
- data/lib/proscenium/builder.rb +62 -19
- data/lib/proscenium/core_ext/object/css_module_ivars.rb +19 -0
- data/lib/proscenium/css_module/rewriter.rb +28 -0
- data/lib/proscenium/css_module.rb +16 -1
- data/lib/proscenium/ensure_loaded.rb +6 -6
- data/lib/proscenium/ext/proscenium +0 -0
- data/lib/proscenium/ext/proscenium.h +16 -1
- data/lib/proscenium/helper.rb +23 -70
- data/lib/proscenium/importer.rb +2 -6
- data/lib/proscenium/libs/react-manager/index.jsx +56 -36
- data/lib/proscenium/log_subscriber.rb +14 -2
- data/lib/proscenium/middleware/esbuild.rb +2 -2
- data/lib/proscenium/monkey.rb +67 -32
- data/lib/proscenium/phlex/asset_inclusions.rb +4 -83
- data/lib/proscenium/phlex.rb +9 -1
- data/lib/proscenium/railtie.rb +17 -16
- data/lib/proscenium/react_componentable.rb +3 -3
- data/lib/proscenium/side_load.rb +122 -6
- data/lib/proscenium/version.rb +1 -1
- data/lib/proscenium/view_component.rb +7 -1
- data/lib/proscenium.rb +10 -0
- metadata +19 -3
data/lib/proscenium/side_load.rb
CHANGED
@@ -2,21 +2,137 @@
|
|
2
2
|
|
3
3
|
module Proscenium
|
4
4
|
class SideLoad
|
5
|
+
module Controller
|
6
|
+
def self.included(child)
|
7
|
+
child.class_eval do
|
8
|
+
class_attribute :sideload_assets_options
|
9
|
+
child.extend ClassMethods
|
10
|
+
|
11
|
+
append_after_action :capture_and_replace_proscenium_stylesheets,
|
12
|
+
:capture_and_replace_proscenium_javascripts,
|
13
|
+
if: -> { request.format.html? && !response.redirect? }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def sideload_assets(value)
|
19
|
+
self.sideload_assets_options = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture_and_replace_proscenium_stylesheets # rubocop:disable Metrics/*
|
24
|
+
return if response_body.first.blank? || !Proscenium::Importer.css_imported?
|
25
|
+
return unless response_body.first.include? '<!-- [PROSCENIUM_STYLESHEETS] -->'
|
26
|
+
|
27
|
+
imports = Proscenium::Importer.imported.dup
|
28
|
+
paths_to_build = []
|
29
|
+
Proscenium::Importer.each_stylesheet(delete: true) do |x, _|
|
30
|
+
paths_to_build << x.delete_prefix('/')
|
31
|
+
end
|
32
|
+
|
33
|
+
result = Proscenium::Builder.build_to_path(paths_to_build.join(';'),
|
34
|
+
base_url: helpers.request.base_url)
|
35
|
+
|
36
|
+
out = []
|
37
|
+
result.split(';').each do |x|
|
38
|
+
inpath, outpath = x.split('::')
|
39
|
+
inpath.prepend '/'
|
40
|
+
outpath.delete_prefix! 'public'
|
41
|
+
|
42
|
+
next unless imports.key?(inpath)
|
43
|
+
|
44
|
+
import = imports[inpath]
|
45
|
+
opts = import[:css].is_a?(Hash) ? import[:css] : {}
|
46
|
+
opts[:data] ||= {}
|
47
|
+
opts[:data][:original_href] = inpath
|
48
|
+
out << helpers.stylesheet_link_tag(outpath, extname: false, **opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
response_body.first.gsub! '<!-- [PROSCENIUM_STYLESHEETS] -->', out.join.html_safe
|
52
|
+
end
|
53
|
+
|
54
|
+
def capture_and_replace_proscenium_javascripts # rubocop:disable Metrics/*
|
55
|
+
return if response_body.first.blank? || !Proscenium::Importer.js_imported?
|
56
|
+
|
57
|
+
imports = Proscenium::Importer.imported.dup
|
58
|
+
paths_to_build = []
|
59
|
+
Proscenium::Importer.each_javascript(delete: true) do |x, _|
|
60
|
+
paths_to_build << x.delete_prefix('/')
|
61
|
+
end
|
62
|
+
|
63
|
+
result = Proscenium::Builder.build_to_path(paths_to_build.join(';'),
|
64
|
+
base_url: helpers.request.base_url)
|
65
|
+
|
66
|
+
if response_body.first.include? '<!-- [PROSCENIUM_JAVASCRIPTS] -->'
|
67
|
+
out = []
|
68
|
+
scripts = {}
|
69
|
+
result.split(';').each do |x|
|
70
|
+
inpath, outpath = x.split('::')
|
71
|
+
inpath.prepend '/'
|
72
|
+
outpath.delete_prefix! 'public'
|
73
|
+
|
74
|
+
next unless imports.key?(inpath)
|
75
|
+
|
76
|
+
if (import = imports[inpath]).delete(:lazy)
|
77
|
+
scripts[inpath] = import.merge(outpath: outpath)
|
78
|
+
else
|
79
|
+
opts = import[:js].is_a?(Hash) ? import[:js] : {}
|
80
|
+
out << helpers.javascript_include_tag(outpath, extname: false, **opts)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
response_body.first.gsub! '<!-- [PROSCENIUM_JAVASCRIPTS] -->', out.join.html_safe
|
85
|
+
end
|
86
|
+
|
87
|
+
return unless response_body.first.include? '<!-- [PROSCENIUM_LAZY_SCRIPTS] -->'
|
88
|
+
|
89
|
+
lazy_script = ''
|
90
|
+
if scripts.present?
|
91
|
+
lazy_script = helpers.content_tag 'script', type: 'application/json',
|
92
|
+
id: 'prosceniumLazyScripts' do
|
93
|
+
scripts.to_json.html_safe
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
response_body.first.gsub! '<!-- [PROSCENIUM_LAZY_SCRIPTS] -->', lazy_script
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
5
101
|
class << self
|
6
102
|
# Side loads the class, and its super classes that respond to `.source_path`.
|
7
103
|
#
|
8
|
-
#
|
9
|
-
# loaded.
|
10
|
-
# not be side loaded.
|
104
|
+
# Set the `abstract_class` class variable to true in any class, and it will not be side
|
105
|
+
# loaded.
|
11
106
|
#
|
12
107
|
# If the class responds to `.sideload`, it will be called instead of the regular side loading.
|
13
108
|
# You can use this to customise what is side loaded.
|
14
|
-
def sideload_inheritance_chain(obj)
|
15
|
-
return
|
109
|
+
def sideload_inheritance_chain(obj, options) # rubocop:disable Metrics/*
|
110
|
+
return unless Proscenium.config.side_load
|
111
|
+
|
112
|
+
options = {} if options.nil?
|
113
|
+
options = { js: options, css: options } unless options.is_a?(Hash)
|
114
|
+
|
115
|
+
unless obj.sideload_assets_options.nil?
|
116
|
+
tpl_options = obj.sideload_assets_options
|
117
|
+
options = if tpl_options.is_a?(Hash)
|
118
|
+
options.deep_merge tpl_options
|
119
|
+
else
|
120
|
+
{ js: tpl_options, css: tpl_options }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
%i[css js].each do |k|
|
125
|
+
options[k] = obj.instance_eval(&options[k]) if options[k].is_a?(Proc)
|
126
|
+
end
|
16
127
|
|
17
128
|
klass = obj.class
|
18
129
|
while klass.respond_to?(:source_path) && klass.source_path && !klass.abstract_class
|
19
|
-
klass.respond_to?(:sideload)
|
130
|
+
if klass.respond_to?(:sideload)
|
131
|
+
klass.sideload options
|
132
|
+
else
|
133
|
+
Importer.sideload klass.source_path, **options
|
134
|
+
end
|
135
|
+
|
20
136
|
klass = klass.superclass
|
21
137
|
end
|
22
138
|
end
|
data/lib/proscenium/version.rb
CHANGED
@@ -14,12 +14,14 @@ class Proscenium::ViewComponent < ViewComponent::Base
|
|
14
14
|
|
15
15
|
module Sideload
|
16
16
|
def before_render
|
17
|
-
Proscenium::SideLoad.sideload_inheritance_chain self
|
17
|
+
Proscenium::SideLoad.sideload_inheritance_chain self, controller.sideload_assets_options
|
18
18
|
|
19
19
|
super
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
class_attribute :sideload_assets_options
|
24
|
+
|
23
25
|
class << self
|
24
26
|
attr_accessor :abstract_class
|
25
27
|
|
@@ -28,5 +30,9 @@ class Proscenium::ViewComponent < ViewComponent::Base
|
|
28
30
|
|
29
31
|
super
|
30
32
|
end
|
33
|
+
|
34
|
+
def sideload_assets(value)
|
35
|
+
self.sideload_assets_options = value
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
data/lib/proscenium.rb
CHANGED
@@ -46,6 +46,16 @@ module Proscenium
|
|
46
46
|
"Path #{@path.inspect} cannot be resolved"
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
def config
|
52
|
+
@config ||= Railtie.config.proscenium
|
53
|
+
end
|
54
|
+
|
55
|
+
def cache
|
56
|
+
@cache ||= config.cache || ActiveSupport::Cache::NullStore.new
|
57
|
+
end
|
58
|
+
end
|
49
59
|
end
|
50
60
|
|
51
61
|
require 'proscenium/railtie'
|
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.
|
4
|
+
version: 0.15.0.beta.2
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - "<"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '8.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-next
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.0.1
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.0.1
|
81
95
|
description:
|
82
96
|
email:
|
83
97
|
- joel@developwithstyle.com
|
@@ -90,8 +104,10 @@ files:
|
|
90
104
|
- README.md
|
91
105
|
- lib/proscenium.rb
|
92
106
|
- lib/proscenium/builder.rb
|
107
|
+
- lib/proscenium/core_ext/object/css_module_ivars.rb
|
93
108
|
- lib/proscenium/css_module.rb
|
94
109
|
- lib/proscenium/css_module/path.rb
|
110
|
+
- lib/proscenium/css_module/rewriter.rb
|
95
111
|
- lib/proscenium/css_module/transformer.rb
|
96
112
|
- lib/proscenium/ensure_loaded.rb
|
97
113
|
- lib/proscenium/ext/proscenium
|
@@ -149,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
165
|
- !ruby/object:Gem::Version
|
150
166
|
version: '0'
|
151
167
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
168
|
+
rubygems_version: 3.5.5
|
153
169
|
signing_key:
|
154
170
|
specification_version: 4
|
155
171
|
summary: The engine powering your Rails frontend
|