proscenium 0.11.0.pre.13-arm64-darwin → 0.13.0-arm64-darwin
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 +4 -4
- data/README.md +66 -1
- data/lib/proscenium/css_module.rb +14 -2
- data/lib/proscenium/ext/proscenium +0 -0
- data/lib/proscenium/helper.rb +18 -5
- data/lib/proscenium/importer.rb +13 -2
- data/lib/proscenium/phlex/asset_inclusions.rb +96 -0
- data/lib/proscenium/phlex.rb +1 -9
- data/lib/proscenium/railtie.rb +2 -2
- data/lib/proscenium/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 504d8ab4fde95d64a7800b7406ac1cb5e9de3757277729bd64f84a80a89d0363
|
4
|
+
data.tar.gz: 9dac30d044bac3f9c3c8b6a82721072dbe58a540a36d6538cc3ae29eea31a2ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b828294555e4ed9a3f9875785d09193266b7de9d07cbda5bf3cafe06eff2e3825600dbf6539821c6ffd8f792aba3305b877c174c2337fca6563c7cc9bb6a2849
|
7
|
+
data.tar.gz: 37e577a37203199fdf55eb560521e0f1b5f47ad854ee19f147ab372792a6811a4eef86ea8faa7ddd9a6330b31c7d40ddbd0f90e7804044e31fa205eef1fa4ad9
|
data/README.md
CHANGED
@@ -46,7 +46,8 @@ Proscenium treats your client-side code as first class citizens of your Rails ap
|
|
46
46
|
- [ViewComponent Support](#viewcomponent-support)
|
47
47
|
- [Cache Busting](#cache-busting)
|
48
48
|
- [rjs is back!](#rjs-is-back)
|
49
|
-
- [
|
49
|
+
- [Resolution](#resolution)
|
50
|
+
- [Assets from Rails Engines](#assets-from-rails-engines)
|
50
51
|
- [Thanks](#thanks)
|
51
52
|
- [Development](#development)
|
52
53
|
|
@@ -227,6 +228,42 @@ import utils from '/lib/utils'
|
|
227
228
|
import constants from './constants'
|
228
229
|
```
|
229
230
|
|
231
|
+
```css /app/views/layouts/application.css
|
232
|
+
@import '/lib/reset';
|
233
|
+
```
|
234
|
+
|
235
|
+
```css /lib/reset.css
|
236
|
+
body {
|
237
|
+
/* some styles... */
|
238
|
+
}
|
239
|
+
```
|
240
|
+
|
241
|
+
### Unbundling
|
242
|
+
|
243
|
+
Sometimes you don't want to bundle an import. For example, you want to ensure that only one instance of React is loaded. In this cases, you can use the `unbundle` prefix
|
244
|
+
|
245
|
+
```js
|
246
|
+
import React from 'unbundle:react'
|
247
|
+
```
|
248
|
+
|
249
|
+
This only works any bare and local imports.
|
250
|
+
|
251
|
+
You can also use the `unbundle` prefix in your import map, which ensures that all imports of a particular path is always unbundled:
|
252
|
+
|
253
|
+
```json
|
254
|
+
{
|
255
|
+
"imports": {
|
256
|
+
"react": "unbundle:react"
|
257
|
+
}
|
258
|
+
}
|
259
|
+
```
|
260
|
+
|
261
|
+
Then just import as normal:
|
262
|
+
|
263
|
+
```js
|
264
|
+
import React from 'react'
|
265
|
+
```
|
266
|
+
|
230
267
|
## Import Maps
|
231
268
|
|
232
269
|
> **[WIP]**
|
@@ -515,6 +552,13 @@ css_module 'mypackage/button@big_button'
|
|
515
552
|
# => "big_button"
|
516
553
|
```
|
517
554
|
|
555
|
+
`css_module` also accepts a `path` keyword argument, which allows you to specify the path to the CSS
|
556
|
+
file. Note that this will use the given path for all class names passed to that instance of `css_module`.
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
css_module :my_module_name, path: Rails.root.join('app/components/button.css')
|
560
|
+
```
|
561
|
+
|
518
562
|
#### In your JavaScript
|
519
563
|
|
520
564
|
Importing a CSS module from JS will automatically append the stylesheet to the document's head. And the result of the import will be an object of CSS class to module names.
|
@@ -634,6 +678,27 @@ class MyView < Proscenium::Phlex
|
|
634
678
|
end
|
635
679
|
```
|
636
680
|
|
681
|
+
In your layouts, include `Proscenium::Phlex::AssetInclusions`, and call the `include_assets` helper.
|
682
|
+
|
683
|
+
```ruby
|
684
|
+
class ApplicationLayout < Proscenium::Phlex
|
685
|
+
include Proscenium::Phlex::AssetInclusions
|
686
|
+
|
687
|
+
def template(&)
|
688
|
+
doctype
|
689
|
+
html do
|
690
|
+
head do
|
691
|
+
title { 'My Awesome App' }
|
692
|
+
include_assets
|
693
|
+
end
|
694
|
+
body(&)
|
695
|
+
end
|
696
|
+
end
|
697
|
+
end
|
698
|
+
```
|
699
|
+
|
700
|
+
You can specifically include CCS and JS assets using the `include_stylesheets` and `include_javascripts` helpers, allowing you to control where they are included in the HTML.
|
701
|
+
|
637
702
|
### Side-loading
|
638
703
|
|
639
704
|
Any Phlex class that inherits `Proscenium::Phlex` will automatically be [side-loaded](#side-loading).
|
@@ -18,8 +18,20 @@ module Proscenium::CssModule
|
|
18
18
|
# Accepts one or more CSS class names, and transforms them into CSS module names.
|
19
19
|
#
|
20
20
|
# @param name [String,Symbol,Array<String,Symbol>]
|
21
|
-
|
22
|
-
|
21
|
+
# @param path [Pathname] the path to the CSS module file to use for the transformation.
|
22
|
+
# @return [String] the transformed CSS module names concatenated as a string.
|
23
|
+
def css_module(*names, path: nil)
|
24
|
+
transformer = path.nil? ? cssm : Transformer.new(path)
|
25
|
+
transformer.class_names(*names, require_prefix: false).map { |name, _| name }.join(' ')
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param name [String,Symbol,Array<String,Symbol>]
|
29
|
+
# @param path [Pathname] the path to the CSS file to use for the transformation.
|
30
|
+
# @return [String] the transformed CSS module names concatenated as a string.
|
31
|
+
def class_names(*names, path: nil)
|
32
|
+
names = names.flatten.compact
|
33
|
+
transformer = path.nil? ? cssm : Transformer.new(path)
|
34
|
+
transformer.class_names(*names).map { |name, _| name }.join(' ') unless names.empty?
|
23
35
|
end
|
24
36
|
|
25
37
|
private
|
Binary file
|
data/lib/proscenium/helper.rb
CHANGED
@@ -20,11 +20,24 @@ module Proscenium
|
|
20
20
|
#
|
21
21
|
# @see CssModule::Transformer#class_names
|
22
22
|
# @param name [String,Symbol,Array<String,Symbol>]
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# @param path [Pathname] the path to the CSS module file to use for the transformation.
|
24
|
+
# @return [String] the transformed CSS module names concatenated as a string.
|
25
|
+
def css_module(*names, path: nil)
|
26
|
+
path ||= Pathname.new(@lookup_context.find(@virtual_path).identifier).sub_ext('')
|
27
|
+
CssModule::Transformer.new(path).class_names(*names, require_prefix: false)
|
28
|
+
.map { |name, _| name }.join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param name [String,Symbol,Array<String,Symbol>]
|
32
|
+
# @param path [Pathname] the path to the CSS file to use for the transformation.
|
33
|
+
# @return [String] the transformed CSS module names concatenated as a string.
|
34
|
+
def class_names(*names, path: nil)
|
35
|
+
names = names.flatten.compact
|
36
|
+
|
37
|
+
return if names.empty?
|
38
|
+
|
39
|
+
path ||= Pathname.new(@lookup_context.find(@virtual_path).identifier).sub_ext('')
|
40
|
+
CssModule::Transformer.new(path).class_names(*names).map { |name, _| name }.join(' ')
|
28
41
|
end
|
29
42
|
|
30
43
|
def include_stylesheets(**options)
|
data/lib/proscenium/importer.rb
CHANGED
@@ -79,14 +79,25 @@ module Proscenium
|
|
79
79
|
def each_stylesheet(delete: false)
|
80
80
|
return if imported.blank?
|
81
81
|
|
82
|
-
blk = proc
|
82
|
+
blk = proc do |key, options|
|
83
|
+
if key.end_with?(*CSS_EXTENSIONS)
|
84
|
+
yield(key, options)
|
85
|
+
true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
83
89
|
delete ? imported.delete_if(&blk) : imported.each(&blk)
|
84
90
|
end
|
85
91
|
|
86
92
|
def each_javascript(delete: false)
|
87
93
|
return if imported.blank?
|
88
94
|
|
89
|
-
blk = proc
|
95
|
+
blk = proc do |key, options|
|
96
|
+
if key.end_with?(*JS_EXTENSIONS)
|
97
|
+
yield(key, options)
|
98
|
+
true
|
99
|
+
end
|
100
|
+
end
|
90
101
|
delete ? imported.delete_if(&blk) : imported.each(&blk)
|
91
102
|
end
|
92
103
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Proscenium::Phlex::AssetInclusions
|
4
|
+
include Phlex::Rails::Helpers::ContentFor
|
5
|
+
include Phlex::Rails::Helpers::StyleSheetPath
|
6
|
+
include Phlex::Rails::Helpers::JavaScriptPath
|
7
|
+
|
8
|
+
def include_stylesheets
|
9
|
+
comment { '[PROSCENIUM_STYLESHEETS]' }
|
10
|
+
end
|
11
|
+
|
12
|
+
def include_javascripts(defer_lazy_scripts: false)
|
13
|
+
comment { '[PROSCENIUM_JAVASCRIPTS]' }
|
14
|
+
!defer_lazy_scripts && include_lazy_javascripts
|
15
|
+
end
|
16
|
+
|
17
|
+
def include_lazy_javascripts
|
18
|
+
comment { '[PROSCENIUM_LAZY_SCRIPTS]' }
|
19
|
+
end
|
20
|
+
|
21
|
+
def include_assets(defer_lazy_scripts: false)
|
22
|
+
include_stylesheets
|
23
|
+
include_javascripts(defer_lazy_scripts: defer_lazy_scripts)
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_template
|
27
|
+
super
|
28
|
+
|
29
|
+
@_buffer.gsub! '<!-- [PROSCENIUM_STYLESHEETS] -->', capture_stylesheets!
|
30
|
+
@_buffer.gsub! '<!-- [PROSCENIUM_JAVASCRIPTS] -->', capture_javascripts!
|
31
|
+
|
32
|
+
if content_for?(:proscenium_lazy_scripts)
|
33
|
+
flush
|
34
|
+
@_buffer.gsub!('<!-- [PROSCENIUM_LAZY_SCRIPTS] -->', capture do
|
35
|
+
content_for(:proscenium_lazy_scripts)
|
36
|
+
end)
|
37
|
+
else
|
38
|
+
@_buffer.gsub! '<!-- [PROSCENIUM_LAZY_SCRIPTS] -->', ''
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def capture_stylesheets!
|
45
|
+
capture do
|
46
|
+
Proscenium::Importer.each_stylesheet(delete: true) do |path, _path_options|
|
47
|
+
link rel: 'stylesheet', href: stylesheet_path(path, extname: false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def capture_javascripts! # rubocop:disable Metrics/*
|
53
|
+
unless Rails.application.config.proscenium.code_splitting &&
|
54
|
+
Proscenium::Importer.multiple_js_imported?
|
55
|
+
return capture do
|
56
|
+
Proscenium::Importer.each_javascript(delete: true) do |path, _|
|
57
|
+
script(src: javascript_path(path, extname: false), type: :module)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
imports = Proscenium::Importer.imported.dup
|
63
|
+
paths_to_build = []
|
64
|
+
Proscenium::Importer.each_javascript(delete: true) do |x, _|
|
65
|
+
paths_to_build << x.delete_prefix('/')
|
66
|
+
end
|
67
|
+
|
68
|
+
result = Proscenium::Builder.build(paths_to_build.join(';'), base_url: helpers.request.base_url)
|
69
|
+
|
70
|
+
# Remove the react components from the results, so they are not side loaded. Instead they
|
71
|
+
# are lazy loaded by the component manager.
|
72
|
+
|
73
|
+
capture do
|
74
|
+
scripts = {}
|
75
|
+
result.split(';').each do |x|
|
76
|
+
inpath, outpath = x.split('::')
|
77
|
+
inpath.prepend '/'
|
78
|
+
outpath.delete_prefix! 'public'
|
79
|
+
|
80
|
+
next unless imports.key?(inpath)
|
81
|
+
|
82
|
+
if (import = imports[inpath]).delete(:lazy)
|
83
|
+
scripts[inpath] = import.merge(outpath: outpath)
|
84
|
+
else
|
85
|
+
script(src: javascript_path(outpath, extname: false), type: :module)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
content_for :proscenium_lazy_scripts do
|
90
|
+
script type: 'application/json', id: 'prosceniumLazyScripts' do
|
91
|
+
unsafe_raw scripts.to_json
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/proscenium/phlex.rb
CHANGED
@@ -8,19 +8,11 @@ module Proscenium
|
|
8
8
|
|
9
9
|
autoload :CssModules
|
10
10
|
autoload :ReactComponent
|
11
|
+
autoload :AssetInclusions
|
11
12
|
|
12
|
-
extend ::Phlex::Rails::HelperMacros
|
13
|
-
include ::Phlex::Rails::Helpers::JavaScriptIncludeTag
|
14
|
-
include ::Phlex::Rails::Helpers::StyleSheetLinkTag
|
15
13
|
include Proscenium::SourcePath
|
16
14
|
include CssModules
|
17
15
|
|
18
|
-
define_output_helper :side_load_stylesheets # deprecated
|
19
|
-
define_output_helper :include_stylesheets
|
20
|
-
define_output_helper :side_load_javascripts # deprecated
|
21
|
-
define_output_helper :include_javascripts
|
22
|
-
define_output_helper :declare_lazy_scripts
|
23
|
-
|
24
16
|
module Sideload
|
25
17
|
def before_template
|
26
18
|
Proscenium::SideLoad.sideload_inheritance_chain self
|
data/lib/proscenium/railtie.rb
CHANGED
@@ -54,8 +54,8 @@ module Proscenium
|
|
54
54
|
|
55
55
|
initializer 'proscenium.middleware' do |app|
|
56
56
|
app.middleware.insert_after ActionDispatch::Static, Middleware
|
57
|
-
|
58
|
-
|
57
|
+
app.middleware.insert_after ActionDispatch::Static, Rack::ETag, 'no-cache'
|
58
|
+
app.middleware.insert_after ActionDispatch::Static, Rack::ConditionalGet
|
59
59
|
end
|
60
60
|
|
61
61
|
initializer 'proscenium.monkey_patches' do
|
data/lib/proscenium/version.rb
CHANGED
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.13.0
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/proscenium/middleware/url.rb
|
112
112
|
- lib/proscenium/monkey.rb
|
113
113
|
- lib/proscenium/phlex.rb
|
114
|
+
- lib/proscenium/phlex/asset_inclusions.rb
|
114
115
|
- lib/proscenium/phlex/css_modules.rb
|
115
116
|
- lib/proscenium/phlex/react_component.rb
|
116
117
|
- lib/proscenium/railtie.rb
|
@@ -144,11 +145,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: 2.7.0
|
145
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
147
|
requirements:
|
147
|
-
- - "
|
148
|
+
- - ">="
|
148
149
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
150
|
+
version: '0'
|
150
151
|
requirements: []
|
151
|
-
rubygems_version: 3.4.
|
152
|
+
rubygems_version: 3.4.22
|
152
153
|
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: The engine powering your Rails frontend
|