proscenium 0.10.0-arm64-darwin → 0.11.0.pre.1-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -39
  3. data/lib/proscenium/builder.rb +14 -10
  4. data/lib/proscenium/css_module/path.rb +31 -0
  5. data/lib/proscenium/css_module/transformer.rb +76 -0
  6. data/lib/proscenium/css_module.rb +6 -28
  7. data/lib/proscenium/ensure_loaded.rb +27 -0
  8. data/lib/proscenium/ext/proscenium +0 -0
  9. data/lib/proscenium/helper.rb +62 -0
  10. data/lib/proscenium/importer.rb +110 -0
  11. data/lib/proscenium/libs/react-manager/index.jsx +88 -0
  12. data/lib/proscenium/libs/react-manager/react.js +2 -0
  13. data/lib/proscenium/middleware/esbuild.rb +2 -4
  14. data/lib/proscenium/middleware.rb +2 -1
  15. data/lib/proscenium/{side_load/monkey.rb → monkey.rb} +11 -15
  16. data/lib/proscenium/phlex/{resolve_css_modules.rb → css_modules.rb} +6 -20
  17. data/lib/proscenium/phlex/page.rb +2 -2
  18. data/lib/proscenium/phlex/react_component.rb +26 -27
  19. data/lib/proscenium/phlex.rb +10 -29
  20. data/lib/proscenium/railtie.rb +14 -26
  21. data/lib/proscenium/react_componentable.rb +94 -0
  22. data/lib/proscenium/resolver.rb +37 -0
  23. data/lib/proscenium/side_load.rb +13 -73
  24. data/lib/proscenium/source_path.rb +15 -0
  25. data/lib/proscenium/utils.rb +13 -0
  26. data/lib/proscenium/version.rb +1 -1
  27. data/lib/proscenium/view_component/css_modules.rb +11 -0
  28. data/lib/proscenium/view_component/react_component.rb +15 -15
  29. data/lib/proscenium/view_component/sideload.rb +4 -0
  30. data/lib/proscenium/view_component.rb +8 -38
  31. data/lib/proscenium.rb +23 -68
  32. metadata +19 -29
  33. data/lib/proscenium/componentable.rb +0 -63
  34. data/lib/proscenium/css_module/class_names_resolver.rb +0 -66
  35. data/lib/proscenium/css_module/resolver.rb +0 -76
  36. data/lib/proscenium/current.rb +0 -9
  37. data/lib/proscenium/phlex/component_concerns.rb +0 -9
  38. data/lib/proscenium/side_load/ensure_loaded.rb +0 -25
  39. data/lib/proscenium/side_load/helper.rb +0 -41
  40. data/lib/proscenium/view_component/tag_builder.rb +0 -23
@@ -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
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/current_attributes'
4
-
5
- module Proscenium
6
- class Current < ActiveSupport::CurrentAttributes
7
- attribute :loaded
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Proscenium::Phlex::ComponentConcerns
4
- module CssModules
5
- extend ActiveSupport::Concern
6
- include Proscenium::CssModule
7
- include Proscenium::Phlex::ResolveCssModules
8
- end
9
- end
@@ -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