proscenium 0.10.0-x86_64-darwin → 0.11.0.pre.2-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +175 -39
- data/lib/proscenium/builder.rb +17 -11
- data/lib/proscenium/css_module/path.rb +31 -0
- data/lib/proscenium/css_module/transformer.rb +76 -0
- data/lib/proscenium/css_module.rb +6 -28
- data/lib/proscenium/ensure_loaded.rb +27 -0
- data/lib/proscenium/ext/proscenium +0 -0
- data/lib/proscenium/ext/proscenium.h +2 -1
- data/lib/proscenium/helper.rb +62 -0
- data/lib/proscenium/importer.rb +110 -0
- data/lib/proscenium/libs/react-manager/index.jsx +88 -0
- data/lib/proscenium/libs/react-manager/react.js +2 -0
- data/lib/proscenium/libs/test.js +1 -0
- data/lib/proscenium/middleware/base.rb +2 -2
- data/lib/proscenium/middleware/esbuild.rb +2 -4
- data/lib/proscenium/middleware/runtime.rb +18 -0
- data/lib/proscenium/middleware.rb +4 -1
- data/lib/proscenium/{side_load/monkey.rb → monkey.rb} +11 -15
- data/lib/proscenium/phlex/{resolve_css_modules.rb → css_modules.rb} +6 -20
- data/lib/proscenium/phlex/page.rb +2 -2
- data/lib/proscenium/phlex/react_component.rb +26 -27
- data/lib/proscenium/phlex.rb +10 -29
- data/lib/proscenium/railtie.rb +14 -26
- data/lib/proscenium/react_componentable.rb +94 -0
- data/lib/proscenium/resolver.rb +41 -0
- data/lib/proscenium/side_load.rb +13 -73
- data/lib/proscenium/source_path.rb +15 -0
- data/lib/proscenium/utils.rb +13 -0
- data/lib/proscenium/version.rb +1 -1
- data/lib/proscenium/view_component/css_modules.rb +11 -0
- data/lib/proscenium/view_component/react_component.rb +15 -15
- data/lib/proscenium/view_component/sideload.rb +4 -0
- data/lib/proscenium/view_component.rb +8 -38
- data/lib/proscenium.rb +23 -68
- metadata +21 -29
- data/lib/proscenium/componentable.rb +0 -63
- data/lib/proscenium/css_module/class_names_resolver.rb +0 -66
- data/lib/proscenium/css_module/resolver.rb +0 -76
- data/lib/proscenium/current.rb +0 -9
- data/lib/proscenium/phlex/component_concerns.rb +0 -9
- data/lib/proscenium/side_load/ensure_loaded.rb +0 -25
- data/lib/proscenium/side_load/helper.rb +0 -41
- data/lib/proscenium/view_component/tag_builder.rb +0 -23
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Proscenium
|
4
|
-
class CssModule::ClassNamesResolver
|
5
|
-
def initialize(class_names, phlex_path)
|
6
|
-
@class_names = class_names.split
|
7
|
-
@stylesheets = {}
|
8
|
-
@phlex_path = phlex_path.sub_ext('.module.css')
|
9
|
-
|
10
|
-
resolve_class_names
|
11
|
-
end
|
12
|
-
|
13
|
-
def class_names
|
14
|
-
@class_names.join(' ')
|
15
|
-
end
|
16
|
-
|
17
|
-
def stylesheets
|
18
|
-
@stylesheets.map { |_, values| values[:resolved_path] }
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def resolve_class_names
|
24
|
-
@class_names.map! do |class_name|
|
25
|
-
if class_name.include?('/')
|
26
|
-
if class_name.starts_with?('@')
|
27
|
-
# Scoped bare specifier (eg. "@scoped/package/lib/button@default").
|
28
|
-
_, path, name = class_name.split('@')
|
29
|
-
path = "@#{path}"
|
30
|
-
elsif class_name.starts_with?('/')
|
31
|
-
# Local path with leading slash.
|
32
|
-
path, name = class_name[1..].split('@')
|
33
|
-
else
|
34
|
-
# Bare specifier (eg. "mypackage/lib/button@default").
|
35
|
-
path, name = class_name.split('@')
|
36
|
-
end
|
37
|
-
|
38
|
-
path += '.module.css'
|
39
|
-
|
40
|
-
Utils.css_modularise_class_name name, digest: add_stylesheet(path)[:digest]
|
41
|
-
elsif class_name.starts_with?('@')
|
42
|
-
Utils.css_modularise_class_name class_name[1..],
|
43
|
-
digest: add_stylesheet(@phlex_path)[:digest]
|
44
|
-
else
|
45
|
-
class_name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def add_stylesheet(path)
|
51
|
-
return @stylesheets[path] if @stylesheets.key?(path)
|
52
|
-
|
53
|
-
resolved_path = Utils.resolve_path(path.to_s)
|
54
|
-
|
55
|
-
unless Rails.root.join(resolved_path[1..]).exist?
|
56
|
-
raise CssModule::StylesheetNotFound, resolved_path
|
57
|
-
end
|
58
|
-
|
59
|
-
# Note that the digest is based on the resolved (URL) path, not the original path.
|
60
|
-
@stylesheets[path] = {
|
61
|
-
resolved_path: resolved_path,
|
62
|
-
digest: Utils.digest(resolved_path)
|
63
|
-
}
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Proscenium
|
4
|
-
class CssModule::Resolver
|
5
|
-
attr_reader :side_loaded_paths
|
6
|
-
|
7
|
-
# @param path [Pathname] Absolute file system path to the Ruby file that will be side loaded.
|
8
|
-
def initialize(path, side_load: true, hash: nil)
|
9
|
-
raise ArgumentError, "'#{path}' must be a `Pathname`" unless path.is_a?(Pathname)
|
10
|
-
|
11
|
-
@path = path
|
12
|
-
@hash = hash
|
13
|
-
@css_module_path = path.sub_ext('.module.css')
|
14
|
-
@side_load = side_load
|
15
|
-
@side_loaded_paths = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
# Parses the given `content` for CSS modules names ('class' attributes beginning with '@'), and
|
19
|
-
# returns the content with said CSS Modules replaced with the compiled class names.
|
20
|
-
#
|
21
|
-
# Example:
|
22
|
-
# <div class="@my_css_module_name"></div>
|
23
|
-
def compile_class_names(content)
|
24
|
-
doc = Nokogiri::HTML::DocumentFragment.parse(content)
|
25
|
-
|
26
|
-
return content if (modules = doc.css('[class*="@"]')).empty?
|
27
|
-
|
28
|
-
modules.each do |ele|
|
29
|
-
classes = ele.classes.map { |cls| cls.starts_with?('@') ? class_names!(cls[1..]) : cls }
|
30
|
-
ele['class'] = classes.join(' ')
|
31
|
-
end
|
32
|
-
|
33
|
-
doc.to_html.html_safe
|
34
|
-
end
|
35
|
-
|
36
|
-
# Resolves the given CSS class names to CSS modules. This will also side load the stylesheet if
|
37
|
-
# it exists.
|
38
|
-
#
|
39
|
-
# @param names [String, Array]
|
40
|
-
# @returns [Array] of class names generated from the given CSS module `names`.
|
41
|
-
def class_names(*names)
|
42
|
-
side_load_css_module
|
43
|
-
Utils.css_modularise_class_names names, digest: @hash
|
44
|
-
end
|
45
|
-
|
46
|
-
# Like #class_names, but requires that the stylesheet exists.
|
47
|
-
#
|
48
|
-
# @param names [String, Array]
|
49
|
-
# @raises Proscenium::CssModule::NotFound if stylesheet does not exists.
|
50
|
-
# @see #class_names
|
51
|
-
def class_names!(...)
|
52
|
-
raise CssModule::StylesheetNotFound, @css_module_path unless @css_module_path.exist?
|
53
|
-
|
54
|
-
class_names(...)
|
55
|
-
end
|
56
|
-
|
57
|
-
def side_loaded?
|
58
|
-
@side_loaded_paths.present?
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def side_load_css_module
|
64
|
-
return if !@side_load || !Rails.application.config.proscenium.side_load
|
65
|
-
|
66
|
-
paths = SideLoad.append @path, { '.module.css' => :css }
|
67
|
-
|
68
|
-
@side_loaded_paths = if paths.empty?
|
69
|
-
nil
|
70
|
-
else
|
71
|
-
@hash = Utils.digest(paths[0])
|
72
|
-
paths
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/proscenium/current.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Proscenium::SideLoad
|
4
|
-
module EnsureLoaded
|
5
|
-
def self.included(child)
|
6
|
-
child.class_eval do
|
7
|
-
append_after_action do
|
8
|
-
if request.format.html? && Proscenium::Current.loaded
|
9
|
-
if Proscenium::Current.loaded[:js].present?
|
10
|
-
raise NotIncludedError, 'There are javascripts to be side loaded, but they have ' \
|
11
|
-
'not been included. Did you forget to add the ' \
|
12
|
-
'`#side_load_javascripts` helper in your views?'
|
13
|
-
end
|
14
|
-
|
15
|
-
if Proscenium::Current.loaded[:css].present?
|
16
|
-
raise NotIncludedError, 'There are stylesheets to be side loaded, but they have ' \
|
17
|
-
'notbeen included. Did you forget to add the ' \
|
18
|
-
'`#side_load_stylesheets` helper in your views?'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Proscenium
|
4
|
-
module SideLoad::Helper
|
5
|
-
def side_load_stylesheets(**options)
|
6
|
-
return unless Proscenium::Current.loaded
|
7
|
-
|
8
|
-
out = []
|
9
|
-
Proscenium::Current.loaded[:css].delete_if do |path|
|
10
|
-
out << stylesheet_link_tag(path, extname: false, **options)
|
11
|
-
end
|
12
|
-
out.join("\n").html_safe
|
13
|
-
end
|
14
|
-
|
15
|
-
def side_load_javascripts(**options) # rubocop:disable Metrics/AbcSize
|
16
|
-
return unless Proscenium::Current.loaded
|
17
|
-
|
18
|
-
out = []
|
19
|
-
paths = Proscenium::Current.loaded[:js]
|
20
|
-
|
21
|
-
if Rails.application.config.proscenium.code_splitting && paths.size > 1
|
22
|
-
public_path = Rails.public_path.to_s
|
23
|
-
paths_to_build = []
|
24
|
-
paths.delete_if { |x| paths_to_build << x.delete_prefix('/') }
|
25
|
-
|
26
|
-
result = Proscenium::Builder.build(paths_to_build.join(';'), base_url: request.base_url)
|
27
|
-
result.split(';').each do |x|
|
28
|
-
next if x.include?('public/assets/_asset_chunks/') || x.end_with?('.map')
|
29
|
-
|
30
|
-
out << javascript_include_tag(x.delete_prefix(public_path), extname: false, **options)
|
31
|
-
end
|
32
|
-
else
|
33
|
-
paths.delete_if do |x|
|
34
|
-
out << javascript_include_tag(x, extname: false, **options)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
out.join("\n").html_safe
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Proscenium::ViewComponent::TagBuilder < ActionView::Helpers::TagHelper::TagBuilder
|
4
|
-
def tag_options(options, escape = true) # rubocop:disable Style/OptionalBooleanParameter
|
5
|
-
super(css_module_option(options), escape)
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
|
-
def css_module_option(options)
|
11
|
-
return options if options.blank?
|
12
|
-
|
13
|
-
unless (css_module = options.delete(:css_module) || options.delete('css_module'))
|
14
|
-
return options
|
15
|
-
end
|
16
|
-
|
17
|
-
css_module = @view_context.css_module(css_module)
|
18
|
-
|
19
|
-
options.tap do |x|
|
20
|
-
x[:class] = "#{css_module} #{options.delete(:class) || options.delete('class')}".strip
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|