proscenium 0.9.1-x86_64-linux → 0.11.0.pre.1-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +423 -63
  3. data/lib/proscenium/builder.rb +126 -0
  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/ext/proscenium.h +19 -12
  10. data/lib/proscenium/helper.rb +62 -0
  11. data/lib/proscenium/importer.rb +110 -0
  12. data/lib/proscenium/libs/react-manager/index.jsx +88 -0
  13. data/lib/proscenium/libs/react-manager/react.js +2 -0
  14. data/lib/proscenium/libs/stimulus-loading.js +83 -0
  15. data/lib/proscenium/log_subscriber.rb +1 -2
  16. data/lib/proscenium/middleware/base.rb +1 -1
  17. data/lib/proscenium/middleware/esbuild.rb +3 -5
  18. data/lib/proscenium/middleware.rb +7 -1
  19. data/lib/proscenium/{side_load/monkey.rb → monkey.rb} +16 -12
  20. data/lib/proscenium/phlex/{resolve_css_modules.rb → css_modules.rb} +6 -20
  21. data/lib/proscenium/phlex/page.rb +2 -2
  22. data/lib/proscenium/phlex/react_component.rb +27 -64
  23. data/lib/proscenium/phlex.rb +10 -29
  24. data/lib/proscenium/railtie.rb +20 -22
  25. data/lib/proscenium/react_componentable.rb +94 -0
  26. data/lib/proscenium/resolver.rb +37 -0
  27. data/lib/proscenium/side_load.rb +13 -72
  28. data/lib/proscenium/source_path.rb +15 -0
  29. data/lib/proscenium/utils.rb +13 -0
  30. data/lib/proscenium/version.rb +1 -1
  31. data/lib/proscenium/view_component/css_modules.rb +11 -0
  32. data/lib/proscenium/view_component/react_component.rb +15 -28
  33. data/lib/proscenium/view_component/sideload.rb +4 -0
  34. data/lib/proscenium/view_component.rb +8 -31
  35. data/lib/proscenium.rb +24 -68
  36. metadata +21 -58
  37. data/lib/proscenium/css_module/class_names_resolver.rb +0 -66
  38. data/lib/proscenium/css_module/resolver.rb +0 -76
  39. data/lib/proscenium/current.rb +0 -9
  40. data/lib/proscenium/esbuild/golib.rb +0 -97
  41. data/lib/proscenium/esbuild.rb +0 -32
  42. data/lib/proscenium/phlex/component_concerns.rb +0 -27
  43. data/lib/proscenium/side_load/ensure_loaded.rb +0 -25
  44. data/lib/proscenium/side_load/helper.rb +0 -25
  45. data/lib/proscenium/view_component/tag_builder.rb +0 -23
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ffi'
4
- require 'oj'
5
-
6
- module Proscenium
7
- class Esbuild::Golib
8
- class Result < FFI::Struct
9
- layout :success, :bool,
10
- :response, :string
11
- end
12
-
13
- module Request
14
- extend FFI::Library
15
- ffi_lib Pathname.new(__dir__).join('../ext/proscenium').to_s
16
-
17
- enum :environment, [:development, 1, :test, :production]
18
-
19
- attach_function :build, [
20
- :string, # path or entry point
21
- :string, # root
22
- :string, # base URL of the Rails app. eg. https://example.com
23
- :environment, # Rails environment as a Symbol
24
- :string, # path to import map, relative to root
25
- :bool # debugging enabled?
26
- ], Result.by_value
27
-
28
- attach_function :resolve, [
29
- :string, # path or entry point
30
- :string, # root
31
- :environment, # Rails environment as a Symbol
32
- :string # path to import map, relative to root
33
- ], Result.by_value
34
- end
35
-
36
- class BuildError < StandardError
37
- attr_reader :error, :path
38
-
39
- def initialize(path, error)
40
- error = Oj.load(error, mode: :strict).deep_transform_keys(&:underscore)
41
-
42
- super "Failed to build '#{path}' -- #{error['text']}"
43
- end
44
- end
45
-
46
- class ResolveError < StandardError
47
- attr_reader :error_msg, :path
48
-
49
- def initialize(path, error_msg)
50
- super "Failed to resolve '#{path}' -- #{error_msg}"
51
- end
52
- end
53
-
54
- def initialize(root: nil, base_url: nil)
55
- @root = root || Rails.root
56
- @base_url = base_url
57
- end
58
-
59
- def self.resolve(path)
60
- new.resolve(path)
61
- end
62
-
63
- def self.build(path)
64
- new.build(path)
65
- end
66
-
67
- def build(path)
68
- result = Request.build(path, @root.to_s, @base_url, Rails.env.to_sym, import_map,
69
- Rails.env.development?)
70
- raise BuildError.new(path, result[:response]) unless result[:success]
71
-
72
- result[:response]
73
- end
74
-
75
- def resolve(path)
76
- result = Request.resolve(path, @root.to_s, Rails.env.to_sym, import_map)
77
- raise ResolveError.new(path, result[:response]) unless result[:success]
78
-
79
- result[:response]
80
- end
81
-
82
- private
83
-
84
- def import_map
85
- return unless (path = Rails.root&.join('config'))
86
-
87
- if (json = path.join('import_map.json')).exist?
88
- return json.relative_path_from(@root).to_s
89
- end
90
- if (js = path.join('import_map.js')).exist?
91
- return js.relative_path_from(@root).to_s
92
- end
93
-
94
- nil
95
- end
96
- end
97
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Proscenium
4
- class Esbuild
5
- class CompileError < StandardError; end
6
-
7
- extend ActiveSupport::Autoload
8
-
9
- autoload :Golib
10
-
11
- def self.build(...)
12
- new(...).build
13
- end
14
-
15
- def initialize(path, root:, base_url:)
16
- @path = path
17
- @root = root
18
- @base_url = base_url
19
- end
20
-
21
- def build
22
- Proscenium::Esbuild::Golib.new(root: @root, base_url: @base_url).build(@path)
23
- end
24
-
25
- private
26
-
27
- def cache_query_string
28
- q = Proscenium.config.cache_query_string
29
- q ? "--cache-query-string #{q}" : nil
30
- end
31
- end
32
- end
@@ -1,27 +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
-
9
- # class_methods do
10
- # # FIXME: Still needed?
11
- # def path
12
- # pp name, super
13
- # pp Module.const_source_location(name).first
14
-
15
- # name && Pathname.new(Module.const_source_location(name).first)
16
- # rescue NameError
17
- # nil
18
- # end
19
- # end
20
-
21
- private
22
-
23
- def path
24
- self.class.path
25
- end
26
- end
27
- 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 Proscenium::Current.loaded
9
- if Proscenium::Current.loaded[:js].present?
10
- raise NotIncludedError, 'There are javascripts to be side loaded, but they have not ' \
11
- '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 not ' \
17
- 'been 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,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Proscenium
4
- module SideLoad::Helper
5
- def side_load_stylesheets
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)
11
- end
12
- out.join("\n").html_safe
13
- end
14
-
15
- def side_load_javascripts(**options)
16
- return unless Proscenium::Current.loaded
17
-
18
- out = []
19
- Proscenium::Current.loaded[:js].delete_if do |path|
20
- out << javascript_include_tag(path, extname: false, **options)
21
- end
22
- out.join("\n").html_safe
23
- end
24
- end
25
- 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