proscenium 0.11.0.pre.6-x86_64-linux → 0.11.0.pre.7-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7c4c3587d91fca2d7f7300e1e9e459e23bd6994bc5a1b5fd26082cb587aaab5
4
- data.tar.gz: cc88859e91b00f94d1971c2a73e8993f00a7979ce3bf2cf535d764d3a2ca4451
3
+ metadata.gz: 88c960e2cb342e9d27c84cfc7f14545e9c900876d64c7ae27db96e9c470d387f
4
+ data.tar.gz: 18c2090d81ccfb1d012d4c8c2a5a72ef66d76555eb3def406dddd17726264238
5
5
  SHA512:
6
- metadata.gz: 5c574ba7c71e93edfcebf6ddde384d710e382be2c03330e56052c90b17c6d0f5ffea47c8c2f5aadda7639a5da694ec653dfb4df948a8f3fa2bde01d52b2b49cc
7
- data.tar.gz: 53d44c13043cfd41b780cb360884188702af5a809acf8b9abc11631e128f425578b32c5febe1eacc719e3e361cf272a56af65020c1b2d3b4ff722c43772eb6ec
6
+ metadata.gz: 63ab8a8d80c739cbafaf8f2f5f3b51eb321a856fc5aed3e4aaf5d92b7574b8d0310ce8b476cf7faa09bc104a3365895c67789b70cb86ac8ea61a4cc542e8a644
7
+ data.tar.gz: e301f752d5a149daf30c11a4c0de268c37a1a5af69761cb92721c8d1850dd25aa43fa895c3fcda566bea2794c6ce9db0a7b353f63567272ab628498ace7df3ee
data/README.md CHANGED
@@ -757,19 +757,18 @@ Rails.application.config.proscenium.cache_max_age = 12.months.to_i
757
757
 
758
758
  Proscenium brings back RJS! Any path ending in .rjs will be served from your Rails app. This allows you to import server rendered javascript.
759
759
 
760
- ## Serving from Ruby Gem
761
-
762
- *docs needed*
763
760
 
764
761
  ## Included Paths
765
762
 
766
- By default, Proscenium will serve files ending with any of these extension: `js,mjs,ts,css,jsx,tsx`, and only from `app/assets`, `config`, `app/views`, `lib` and `node_modules` directories.
763
+ Proscenium will serve files ending with any of these extension: `js,mjs,ts,css,jsx,tsx` from the following directories, and their sub-directories: `/app`, `/lib`, `/config`, `/node_modules`, `/vendor`.
767
764
 
768
- However, you can customise these paths with the `include_path` config option...
765
+ So a file at `/app/views/users/index.js` will be served from `https://yourapp.com/app/views/users/index.js`.
769
766
 
770
- ```ruby
771
- Rails.application.config.proscenium.include_paths << 'app/components'
772
- ```
767
+ You can continue to access any file in the `/public` directory as you normally would, but any file ending with a supported extension (`js,mjs,ts,css,jsx,tsx`) will be processed by Proscenium. For example, `/public/some/file.js` will be served from `https://yourapp.com/some/file.js`.
768
+
769
+ ## Serving from Ruby Gems and Rails Engines
770
+
771
+ Proscenium can serve assets from Ruby Gems and Rails Engines.
773
772
 
774
773
  ## Thanks
775
774
 
Binary file
@@ -35,7 +35,14 @@ module Proscenium
35
35
  alias side_load_stylesheets include_stylesheets
36
36
  deprecate side_load_stylesheets: 'Use `include_stylesheets` instead', deprecator: Deprecator.new
37
37
 
38
- def include_javascripts(**options) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38
+ # Includes all javascripts that have been imported and side loaded.
39
+ #
40
+ # @param extract_lazy_scripts [Boolean] if true, any lazy scripts will be extracted using
41
+ # `content_for` to `:proscenium_lazy_scripts` for later use. Be sure to include this in your
42
+ # page with the `declare_lazy_scripts` helper, or simply
43
+ # `content_for :proscenium_lazy_scripts`.
44
+ # @return [String] the HTML tags for the javascripts.
45
+ def include_javascripts(extract_lazy_scripts: false, **options) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
39
46
  out = []
40
47
 
41
48
  if Rails.application.config.proscenium.code_splitting && Importer.multiple_js_imported?
@@ -66,9 +73,15 @@ module Proscenium
66
73
  end
67
74
  end
68
75
 
69
- out << javascript_tag("window.prosceniumLazyScripts = #{scripts.to_json}")
76
+ if extract_lazy_scripts
77
+ content_for :proscenium_lazy_scripts do
78
+ javascript_tag "window.prosceniumLazyScripts = #{scripts.to_json}"
79
+ end
80
+ else
81
+ out << javascript_tag("window.prosceniumLazyScripts = #{scripts.to_json}")
82
+ end
70
83
  else
71
- Importer.each_javascript(delete: true) do |path, _path_options|
84
+ Importer.each_javascript(delete: true) do |path, _|
72
85
  out << javascript_include_tag(path, extname: false, **options)
73
86
  end
74
87
  end
@@ -77,5 +90,9 @@ module Proscenium
77
90
  end
78
91
  alias side_load_javascripts include_javascripts
79
92
  deprecate side_load_javascripts: 'Use `include_javascripts` instead', deprecator: Deprecator.new
93
+
94
+ def declare_lazy_scripts
95
+ content_for :proscenium_lazy_scripts
96
+ end
80
97
  end
81
98
  end
@@ -43,12 +43,11 @@ module Proscenium
43
43
  return Url if request.path.match?(%r{^/https?%3A%2F%2F})
44
44
  return Runtime if request.path.match?(%r{^/@proscenium/})
45
45
 
46
- Esbuild if Pathname.new(request.path).fnmatch?(path_glob, File::FNM_EXTGLOB)
46
+ Esbuild if Pathname.new(request.path).fnmatch?(app_path_glob, File::FNM_EXTGLOB)
47
47
  end
48
48
 
49
- def path_glob
50
- paths = Rails.application.config.proscenium.include_paths.join(',')
51
- "/{#{paths}}/**.{#{FILE_EXTENSIONS.join(',')}}"
49
+ def app_path_glob
50
+ "/{#{Proscenium::ALLOWED_DIRECTORIES.join(',')}}/**.{#{FILE_EXTENSIONS.join(',')}}"
52
51
  end
53
52
 
54
53
  # TODO: handle precompiled assets
@@ -20,6 +20,7 @@ module Proscenium
20
20
  define_output_helper :include_stylesheets
21
21
  define_output_helper :side_load_javascripts # deprecated
22
22
  define_output_helper :include_javascripts
23
+ define_output_helper :declare_lazy_scripts
23
24
 
24
25
  module Sideload
25
26
  def before_template
@@ -19,7 +19,6 @@ module Proscenium
19
19
  config.proscenium.debug = false
20
20
  config.proscenium.side_load = true
21
21
  config.proscenium.code_splitting = true
22
- config.proscenium.include_paths = Set.new(APPLICATION_INCLUDE_PATHS)
23
22
 
24
23
  # TODO: implement!
25
24
  config.proscenium.cache_query_string = Rails.env.production? && ENV.fetch('REVISION', nil)
@@ -48,11 +47,6 @@ module Proscenium
48
47
  # }
49
48
  config.proscenium.side_load_gems = {}
50
49
 
51
- initializer 'proscenium.configuration' do |app|
52
- options = app.config.proscenium
53
- options.include_paths = Set.new(APPLICATION_INCLUDE_PATHS) if options.include_paths.blank?
54
- end
55
-
56
50
  initializer 'proscenium.middleware' do |app|
57
51
  app.middleware.insert_after ActionDispatch::Static, Middleware
58
52
  app.middleware.insert_after ActionDispatch::Static, Rack::ETag, 'no-cache'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.11.0.pre.6'
4
+ VERSION = '0.11.0.pre.7'
5
5
  end
data/lib/proscenium.rb CHANGED
@@ -8,8 +8,7 @@ module Proscenium
8
8
  FILE_EXTENSIONS = ['js', 'mjs', 'ts', 'jsx', 'tsx', 'css', 'js.map', 'mjs.map', 'jsx.map',
9
9
  'ts.map', 'tsx.map', 'css.map'].freeze
10
10
 
11
- APPLICATION_INCLUDE_PATHS = ['config', 'app/assets', 'app/views', 'app/components', 'lib',
12
- 'node_modules'].freeze
11
+ ALLOWED_DIRECTORIES = %w[app lib config vendor node_modules].freeze
13
12
 
14
13
  # Environment variables that should always be passed to the builder.
15
14
  DEFAULT_ENV_VARS = Set['RAILS_ENV', 'NODE_ENV'].freeze
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.11.0.pre.6
4
+ version: 0.11.0.pre.7
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: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport