minivite_rails 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 346d0e1dda504de6fe45499ad41cbc3d1561aea6be67b7703c4a4beb67df27c5
4
- data.tar.gz: f9f7fa0218f21622446b89a095d6d5ec4631ff4df8cd216172673c209d83c92c
3
+ metadata.gz: 8e417fde65bd798b667b0218f41c60e56d8ddd40a8b98cc14bcdfbb90cee20b3
4
+ data.tar.gz: dce35afe2703eeca8905eab9fa3ebb387952bbc165324b9009af0574c49d4ff4
5
5
  SHA512:
6
- metadata.gz: 33b98d69cca67c961f6af9efadd61499b71f2e97b0585275fa6c1d2d67092bd1c7ae592f4ee356fead6d9acb5a518c94812ef115a2441b2dffd7e2a72e79adca
7
- data.tar.gz: 7d7b59b04ed4f778b9fa079eac169af790802d40c89f01d273f5eb85bc1faa0a6b76396da051eb1ac10024fbfe3553b424ea7d07aefe4fe71c257b8d389dce4d
6
+ metadata.gz: f21100117904f4020589f7e86c3698135e2430b11650d6fd20c9c0cb331b4b66d459175134752ecfec13179ebb355fc18dc12841529ca033460c9476f417fa5a
7
+ data.tar.gz: 73add9b6912dd42500ace7b5b707d359e031345096314194f9c23c97d33bcad5ddb8f9a2ffad2bbfbe87d7d0d1fa3100e0623ed3cddf7b3e1a7a4d8dba89b6dc
data/.editorconfig ADDED
@@ -0,0 +1,8 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ insert_final_newline = true
6
+ trim_trailing_whitespace = true
7
+ indent_style = space
8
+ indent_size = 2
data/.rubocop.yml CHANGED
@@ -1,7 +1,35 @@
1
1
  require: rubocop-rspec
2
2
 
3
+ inherit_mode:
4
+ merge:
5
+ - Exclude
6
+
3
7
  AllCops:
4
- TargetRubyVersion: 2.7
8
+ NewCops: enable
9
+ TargetRubyVersion: 3.1
10
+ Exclude:
11
+ - example/app/assets/**/*
12
+ - example/bin/*
13
+ - example/db/*schema.rb
14
+ - example/log/**/*
15
+ - example/public/**/*
16
+ - example/storage/**/*
17
+
5
18
 
6
19
  Layout/LineLength:
7
20
  Max: 120
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Metrics/ClassLength:
26
+ Max: 200
27
+
28
+ RSpec/NestedGroups:
29
+ Max: 5
30
+
31
+ RSpec/ExampleLength:
32
+ Max: 15
33
+
34
+ RSpec/NamedSubject:
35
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/Gemfile CHANGED
@@ -4,3 +4,11 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in minivite_rails.gemspec
6
6
  gemspec
7
+
8
+ gem 'debug', '>= 1.0.0'
9
+ gem 'rake', '~> 13.1'
10
+ gem 'rspec', '~> 3.13'
11
+ gem 'rubocop', '~> 1.60', require: false
12
+ gem 'rubocop-rspec', '~> 2.26', require: false
13
+ gem 'rubocop-rubycw', require: false
14
+ gem 'solargraph'
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minivite_rails (0.1.0)
5
- actionview (>= 6.0.0)
6
- railties (>= 6.0.0)
4
+ minivite_rails (0.2.0)
5
+ railties (>= 6.0, < 8)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -27,30 +26,42 @@ GEM
27
26
  minitest (>= 5.1)
28
27
  tzinfo (~> 2.0)
29
28
  ast (2.4.2)
29
+ backport (1.2.0)
30
+ benchmark (0.3.0)
30
31
  builder (3.2.4)
31
32
  concurrent-ruby (1.2.0)
32
33
  crass (1.0.6)
33
34
  debug (1.7.1)
34
35
  irb (>= 1.5.0)
35
36
  reline (>= 0.3.1)
36
- diff-lcs (1.5.0)
37
+ diff-lcs (1.5.1)
38
+ e2mmap (0.1.0)
37
39
  erubi (1.12.0)
38
40
  i18n (1.12.0)
39
41
  concurrent-ruby (~> 1.0)
40
42
  io-console (0.6.0)
41
43
  irb (1.6.2)
42
44
  reline (>= 0.3.0)
43
- json (2.6.3)
45
+ jaro_winkler (1.5.6)
46
+ json (2.7.1)
47
+ kramdown (2.4.0)
48
+ rexml
49
+ kramdown-parser-gfm (1.1.0)
50
+ kramdown (~> 2.0)
51
+ language_server-protocol (3.17.0.3)
44
52
  loofah (2.19.1)
45
53
  crass (~> 1.0.2)
46
54
  nokogiri (>= 1.5.9)
47
55
  method_source (1.0.0)
56
+ mini_portile2 (2.8.5)
48
57
  minitest (5.17.0)
49
- nokogiri (1.14.1-x86_64-darwin)
58
+ nokogiri (1.14.1)
59
+ mini_portile2 (~> 2.8.0)
50
60
  racc (~> 1.4)
51
- parallel (1.22.1)
52
- parser (3.2.0.0)
61
+ parallel (1.24.0)
62
+ parser (3.3.0.5)
53
63
  ast (~> 2.4.1)
64
+ racc
54
65
  racc (1.6.2)
55
66
  rack (2.2.6.2)
56
67
  rack-test (2.0.2)
@@ -68,59 +79,90 @@ GEM
68
79
  thor (~> 1.0)
69
80
  zeitwerk (~> 2.5)
70
81
  rainbow (3.1.1)
71
- rake (13.0.6)
72
- regexp_parser (2.6.1)
82
+ rake (13.1.0)
83
+ rbs (2.8.4)
84
+ regexp_parser (2.9.0)
73
85
  reline (0.3.2)
74
86
  io-console (~> 0.5)
75
- rexml (3.2.5)
76
- rspec (3.12.0)
77
- rspec-core (~> 3.12.0)
78
- rspec-expectations (~> 3.12.0)
79
- rspec-mocks (~> 3.12.0)
80
- rspec-core (3.12.0)
81
- rspec-support (~> 3.12.0)
82
- rspec-expectations (3.12.1)
87
+ reverse_markdown (2.1.1)
88
+ nokogiri
89
+ rexml (3.2.6)
90
+ rspec (3.13.0)
91
+ rspec-core (~> 3.13.0)
92
+ rspec-expectations (~> 3.13.0)
93
+ rspec-mocks (~> 3.13.0)
94
+ rspec-core (3.13.0)
95
+ rspec-support (~> 3.13.0)
96
+ rspec-expectations (3.13.0)
83
97
  diff-lcs (>= 1.2.0, < 2.0)
84
- rspec-support (~> 3.12.0)
85
- rspec-mocks (3.12.1)
98
+ rspec-support (~> 3.13.0)
99
+ rspec-mocks (3.13.0)
86
100
  diff-lcs (>= 1.2.0, < 2.0)
87
- rspec-support (~> 3.12.0)
88
- rspec-support (3.12.0)
89
- rubocop (1.42.0)
101
+ rspec-support (~> 3.13.0)
102
+ rspec-support (3.13.0)
103
+ rubocop (1.60.2)
90
104
  json (~> 2.3)
105
+ language_server-protocol (>= 3.17.0)
91
106
  parallel (~> 1.10)
92
- parser (>= 3.1.2.1)
107
+ parser (>= 3.3.0.2)
93
108
  rainbow (>= 2.2.2, < 4.0)
94
109
  regexp_parser (>= 1.8, < 3.0)
95
110
  rexml (>= 3.2.5, < 4.0)
96
- rubocop-ast (>= 1.24.1, < 2.0)
111
+ rubocop-ast (>= 1.30.0, < 2.0)
97
112
  ruby-progressbar (~> 1.7)
98
- unicode-display_width (>= 1.4.0, < 3.0)
99
- rubocop-ast (1.24.1)
100
- parser (>= 3.1.1.0)
101
- rubocop-capybara (2.17.1)
113
+ unicode-display_width (>= 2.4.0, < 3.0)
114
+ rubocop-ast (1.30.0)
115
+ parser (>= 3.2.1.0)
116
+ rubocop-capybara (2.20.0)
102
117
  rubocop (~> 1.41)
103
- rubocop-rspec (2.18.1)
104
- rubocop (~> 1.33)
118
+ rubocop-factory_bot (2.25.1)
119
+ rubocop (~> 1.41)
120
+ rubocop-rspec (2.26.1)
121
+ rubocop (~> 1.40)
105
122
  rubocop-capybara (~> 2.17)
106
- ruby-progressbar (1.11.0)
123
+ rubocop-factory_bot (~> 2.22)
124
+ rubocop-rubycw (0.1.6)
125
+ rubocop (~> 1.0)
126
+ ruby-progressbar (1.13.0)
127
+ solargraph (0.50.0)
128
+ backport (~> 1.2)
129
+ benchmark
130
+ bundler (~> 2.0)
131
+ diff-lcs (~> 1.4)
132
+ e2mmap
133
+ jaro_winkler (~> 1.5)
134
+ kramdown (~> 2.3)
135
+ kramdown-parser-gfm (~> 1.1)
136
+ parser (~> 3.0)
137
+ rbs (~> 2.0)
138
+ reverse_markdown (~> 2.0)
139
+ rubocop (~> 1.38)
140
+ thor (~> 1.0)
141
+ tilt (~> 2.0)
142
+ yard (~> 0.9, >= 0.9.24)
107
143
  thor (1.2.1)
144
+ tilt (2.3.0)
108
145
  tzinfo (2.0.6)
109
146
  concurrent-ruby (~> 1.0)
110
- unicode-display_width (2.4.2)
147
+ unicode-display_width (2.5.0)
148
+ yard (0.9.34)
111
149
  zeitwerk (2.6.6)
112
150
 
113
151
  PLATFORMS
152
+ arm64-darwin-23
114
153
  x86_64-darwin-21
115
154
  x86_64-darwin-22
155
+ x86_64-linux
116
156
 
117
157
  DEPENDENCIES
118
- debug (~> 1.0)
158
+ debug (>= 1.0.0)
119
159
  minivite_rails!
120
- rake (~> 13.0)
121
- rspec (~> 3.0)
122
- rubocop (~> 1.21)
123
- rubocop-rspec (~> 2.18)
160
+ rake (~> 13.1)
161
+ rspec (~> 3.13)
162
+ rubocop (~> 1.60)
163
+ rubocop-rspec (~> 2.26)
164
+ rubocop-rubycw
165
+ solargraph
124
166
 
125
167
  BUNDLED WITH
126
168
  2.4.6
data/README.md CHANGED
@@ -51,8 +51,8 @@ MiniviteRails.configuration do |c|
51
51
  # Vite public directory, default will be `public`
52
52
  # c.public_dir, default: 'public'
53
53
 
54
- # Vite manifest file path, default will be `#{c.public_dir}#{c.public_base_path}/manifest.json`
55
- # c.manifest_path = "#{c.public_dir}#{c.public_base_path}/manifest.json"
54
+ # Vite manifest file path, default will be `#{c.public_dir}#{c.public_base_path}/.vite/manifest.json`
55
+ # c.manifest_path = "#{c.public_dir}#{c.public_base_path}/.vite/manifest.json"
56
56
  end
57
57
  ```
58
58
 
@@ -90,7 +90,7 @@ Use the following helpers in your Rails views to resolve paths to assets which a
90
90
 
91
91
  ### `vite_javascript_tag`
92
92
 
93
- Renders a `<script>` tag for the specified Vite js entrypoints. This is the most commonly used helper and will also load needed css entrypoints.
93
+ Renders a `<script>` tag for the specified Vite js entrypoints. This is the most commonly used helper and will also load needed css entrypoints. The entry path must be relative to the root path of Vite project.
94
94
 
95
95
  ```erb
96
96
  <%= vite_javascript_tag 'src/main.js' %>
@@ -136,6 +136,14 @@ Render a path to a specified asset built by Vite
136
136
 
137
137
  Same as `vite_asset_path` but returns a full URL
138
138
 
139
+ ### `vite_public_asset_path`
140
+
141
+ Render a path to a public asset copied by Vite
142
+
143
+ ```erb
144
+ <%= vite_public_asset_path 'logo.svg' %>
145
+ ```
146
+
139
147
  ### `vite_image_tag`
140
148
 
141
149
  Renders an `<img>` tag for the specified Vite image asset
@@ -162,7 +170,7 @@ MiniviteRails.configuration do |c|
162
170
  end
163
171
  ```
164
172
 
165
- And the corresponding Vite configuration for admin panel:
173
+ The corresponding Vite configuration for above admin panel:
166
174
 
167
175
  ```js
168
176
  import { fileURLToPath, URL } from 'node:url'
@@ -171,7 +179,7 @@ import react from '@vitejs/plugin-react'
171
179
 
172
180
  // https://vitejs.dev/config/
173
181
  export default defineConfig({
174
- base: '/vite_ops/',
182
+ base: '/vite_admin/',
175
183
  plugins: [react()],
176
184
  build: {
177
185
  manifest: true, // This is required
@@ -189,6 +197,8 @@ export default defineConfig({
189
197
 
190
198
  ```
191
199
 
200
+ __Note:__ The sub configuration must have a unique name and it will inherit all the configurations' value from the main configuration.
201
+
192
202
  ## Special Thanks
193
203
 
194
204
  This project uses ideas and codes from the following projects:
data/Rakefile CHANGED
@@ -9,4 +9,4 @@ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- task default: %i[spec rubocop]
12
+ task default: %i[rubocop spec]
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniviteRails
4
+ # Class to manage configuration related logics.
4
5
  class Configuration
5
6
  class Error < StandardError; end
6
7
 
@@ -15,13 +16,12 @@ module MiniviteRails
15
16
  end
16
17
  end
17
18
 
18
- define_method("#{prop}=".to_sym) do |v|
19
+ define_method(:"#{prop}=") do |v|
19
20
  @config[prop] = v
20
21
  end
21
22
  end
22
23
  end
23
24
 
24
- # Private
25
25
  config_attr :id, default: ROOT_DEFAULT_ID
26
26
  config_attr :cache, default: false
27
27
  # The base directory of the frontend.
@@ -50,24 +50,24 @@ module MiniviteRails
50
50
  @children.each_value(&:reload_manifest)
51
51
  end
52
52
 
53
- def add(id)
53
+ def add(child_id)
54
54
  raise Error, 'Can only define sub configuration from root config' unless root?
55
- raise Error, 'Id already used by root configuration' if id == @config[:id]
55
+ raise Error, 'Id already used by root configuration' if child_id == id
56
56
 
57
- @children[id] ||= self.class.new.tap do |c|
57
+ @children[child_id] ||= self.class.new.tap do |c|
58
58
  c.instance_variable_set(:@parent, self)
59
59
  c.instance_variable_set(:@children, nil)
60
- c.id = id
60
+ c.id = child_id
61
61
  yield c if block_given?
62
62
  end
63
63
  end
64
64
 
65
- def child_by_id(id)
65
+ def child_by_id(child_id)
66
66
  raise Error, 'Can only get sub configuration from root config' unless root?
67
67
 
68
- return self if id == @config[:id] # return itself if id is root id
68
+ return self if child_id == id # return itself if id is root id
69
69
 
70
- @children.fetch(id)
70
+ @children.fetch(child_id)
71
71
  rescue KeyError
72
72
  raise Error, "No sub configuration with id #{id}"
73
73
  end
@@ -8,6 +8,7 @@ require 'active_support/core_ext/object/blank'
8
8
  require 'rails'
9
9
 
10
10
  module MiniviteRails
11
+ # Class to load and parse the manifest.json file generated by Vite.
11
12
  class Manifest
12
13
  class FileNotFoundError < StandardError; end
13
14
  class MissingEntryError < StandardError; end
@@ -20,7 +21,7 @@ module MiniviteRails
20
21
 
21
22
  def update_config(config)
22
23
  @config = config
23
- @manifest_path = config.manifest_path || File.join(config.public_asset_dir, 'manifest.json')
24
+ @manifest_path = config.manifest_path || File.join(config.public_asset_dir, '.vite', 'manifest.json')
24
25
  @data = nil
25
26
  end
26
27
 
@@ -34,11 +35,17 @@ module MiniviteRails
34
35
  lookup!(name, **options).fetch('file')
35
36
  end
36
37
 
38
+ def public_path_for(name)
39
+ return prefix_vite_asset(name) if dev_server_available?
40
+
41
+ File.join(config.public_base_path, name)
42
+ end
43
+
37
44
  def vite_client_src
38
45
  prefix_vite_asset('@vite/client') if dev_server_available?
39
46
  end
40
47
 
41
- def resolve_entries(*names, **options)
48
+ def resolve_entries(*names, **options) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
42
49
  entries = names.map { |name| lookup!(name, **options) }
43
50
  script_paths = entries.map { |entry| entry.fetch('file') }
44
51
 
@@ -50,20 +57,30 @@ module MiniviteRails
50
57
  }
51
58
  end
52
59
 
60
+ # Public: The content of the preamble needed by the React Refresh plugin.
53
61
  def react_refresh_preamble
54
- return unless dev_server_available?
62
+ return unless dev_server_running?
55
63
 
56
64
  <<~REACT_REFRESH
57
65
  <script type="module">
58
- import RefreshRuntime from '#{prefix_vite_asset('@react-refresh')}'
59
- RefreshRuntime.injectIntoGlobalHook(window)
60
- window.$RefreshReg$ = () => {}
61
- window.$RefreshSig$ = () => (type) => type
62
- window.__vite_plugin_react_preamble_installed__ = true
66
+ #{react_preamble_code}
63
67
  </script>
64
68
  REACT_REFRESH
65
69
  end
66
70
 
71
+ # Public: Source script for the React Refresh plugin.
72
+ def react_preamble_code
73
+ return unless dev_server_available?
74
+
75
+ <<~REACT_PREAMBLE_CODE
76
+ import RefreshRuntime from '#{prefix_vite_asset('@react-refresh')}'
77
+ RefreshRuntime.injectIntoGlobalHook(window)
78
+ window.$RefreshReg$ = () => {}
79
+ window.$RefreshSig$ = () => (type) => type
80
+ window.__vite_plugin_react_preamble_installed__ = true
81
+ REACT_PREAMBLE_CODE
82
+ end
83
+
67
84
  protected
68
85
 
69
86
  def dev_server_available?
@@ -112,40 +129,28 @@ module MiniviteRails
112
129
  # manifest.lookup('calendar.js')
113
130
  # => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
114
131
  def lookup(name, **options)
115
- find_manifest_entry resolve_entry_name(name, **options)
132
+ find_manifest_entry(resolve_entry_name(name, **options))
116
133
  end
117
134
 
118
135
  def find_manifest_entry(name)
119
- if dev_server_available?
120
- { 'file' => prefix_vite_asset(name) }
121
- else
122
- data[name]
123
- end
136
+ # If dev server is available, we don't need to get manifest entry from the manifest
137
+ dev_server_available? ? { 'file' => prefix_vite_asset(name) } : data[name]
124
138
  end
125
139
 
126
140
  def resolve_entry_name(name, type: nil)
127
- return resolve_virtual_entry(name) if type == :virtual
128
-
129
141
  name = with_file_extension(name.to_s, type)
130
- raise ArgumentError, "Asset names can not be relative. Found: #{name}" if name.start_with?('.')
142
+ if name =~ %r{\A(\.|~|/).+}
143
+ raise ArgumentError, "Asset names must be direct path from the project root. Found: #{name}"
144
+ end
131
145
 
132
- # Explicit path, relative to the source_code_dir.
133
- name.sub(%r{^~/(.+)$}) { return Regexp.last_match(1) }
134
146
  name
135
147
  end
136
148
 
137
- # Internal: Resolves a virtual entry by walking all the manifest keys.
138
- def resolve_virtual_entry(name)
139
- data.keys.find { |file| file.include?(name) } || name
140
- end
141
-
142
149
  # Internal: Adds a file extension to the file name, unless it already has one.
143
150
  def with_file_extension(name, entry_type)
144
- if File.extname(name).empty? && (ext = extension_for_type(entry_type))
145
- "#{name}.#{ext}"
146
- else
147
- name
148
- end
151
+ return name unless File.extname(name).empty?
152
+
153
+ "#{name}.#{extension_for_type(entry_type)}"
149
154
  end
150
155
 
151
156
  # Internal: Allows to receive :javascript and :stylesheet as :type in helpers.
@@ -5,20 +5,25 @@ require 'action_view'
5
5
  # Use tag helpers from Vite Ruby
6
6
  # https://github.com/ElMassimo/vite_ruby/blob/main/vite_rails/lib/vite_rails/tag_helpers.rb
7
7
 
8
- # Public: Allows to render HTML tags for scripts and styles processed by Vite.
9
8
  module MiniviteRails
9
+ # Public: Allows to render HTML tags for scripts and styles processed by Vite.
10
10
  module TagHelpers
11
11
  # Public: Renders a script tag for vite/client to enable HMR in development.
12
- def vite_client_tag(id: nil, **options)
13
- src = vite_manifest(id: id).vite_client_src
12
+ def vite_client_tag(id: nil, crossorigin: 'anonymous', **options)
13
+ src = vite_manifest(id:).vite_client_src
14
14
  return unless src
15
15
 
16
- javascript_include_tag(src, type: 'module', extname: false, **options)
16
+ javascript_include_tag(src, type: 'module', extname: false, crossorigin:, **options)
17
17
  end
18
18
 
19
19
  # Public: Renders a script tag to enable HMR with React Refresh.
20
- def vite_react_refresh_tag(id: nil)
21
- vite_manifest(id: id).react_refresh_preamble&.html_safe
20
+ def vite_react_refresh_tag(id: nil, **options)
21
+ react_preamble_code = vite_manifest(id:).react_preamble_code
22
+ return unless react_preamble_code
23
+
24
+ options[:nonce] = true if Rails::VERSION::MAJOR >= 6 && !options.key?(:nonce)
25
+
26
+ javascript_tag(react_preamble_code.html_safe, type: :module, **options)
22
27
  end
23
28
 
24
29
  # Public: Resolves the path for the specified Vite asset.
@@ -26,7 +31,7 @@ module MiniviteRails
26
31
  # Example:
27
32
  # <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
28
33
  def vite_asset_path(name, id: nil, **options)
29
- path_to_asset vite_manifest(id: id).path_for(name, **options)
34
+ path_to_asset vite_manifest(id:).path_for(name, **options)
30
35
  end
31
36
 
32
37
  # Public: Resolves the url for the specified Vite asset.
@@ -34,11 +39,19 @@ module MiniviteRails
34
39
  # Example:
35
40
  # <%= vite_asset_url 'calendar.css' %> # => "https://example.com/vite/assets/calendar-1016838bab065ae1e122.css"
36
41
  def vite_asset_url(name, id: nil, **options)
37
- url_to_asset vite_manifest(id: id).path_for(name, **options)
42
+ url_to_asset vite_manifest(id:).path_for(name, **options)
43
+ end
44
+
45
+ # Public: Resolves the path for Vite's public assets
46
+ #
47
+ # Example:
48
+ # <%= vite_public_asset_path 'logo.svg' %> # => "/vite/logo.svg"
49
+ def vite_public_asset_path(name, id: nil)
50
+ path_to_asset vite_manifest(id:).public_path_for(name)
38
51
  end
39
52
 
40
53
  # Public: Renders a <script> tag for the specified Vite entrypoints.
41
- def vite_javascript_tag(*names,
54
+ def vite_javascript_tag(*names, # rubocop:disable Metrics/ParameterLists
42
55
  id: nil,
43
56
  type: 'module',
44
57
  asset_type: :javascript,
@@ -47,26 +60,26 @@ module MiniviteRails
47
60
  crossorigin: 'anonymous',
48
61
  media: 'screen',
49
62
  **options)
50
- entries = vite_manifest(id: id).resolve_entries(*names, type: asset_type)
51
- tags = javascript_include_tag(*entries.fetch(:scripts), crossorigin: crossorigin, type: type, extname: false,
63
+ entries = vite_manifest(id:).resolve_entries(*names, type: asset_type)
64
+ tags = javascript_include_tag(*entries.fetch(:scripts), crossorigin:, type:, extname: false,
52
65
  **options)
53
- tags << vite_preload_tag(*entries.fetch(:imports), crossorigin: crossorigin, **options) unless skip_preload_tags
66
+ tags << vite_preload_tag(*entries.fetch(:imports), crossorigin:, **options) unless skip_preload_tags
54
67
 
55
68
  options[:extname] = false if Rails::VERSION::MAJOR >= 7
56
69
 
57
- tags << stylesheet_link_tag(*entries.fetch(:stylesheets), media: media, **options) unless skip_style_tags
70
+ tags << stylesheet_link_tag(*entries.fetch(:stylesheets), media:, **options) unless skip_style_tags
58
71
 
59
72
  tags
60
73
  end
61
74
 
62
75
  # Public: Renders a <script> tag for the specified Vite entrypoints.
63
76
  def vite_typescript_tag(*names, id: nil, **options)
64
- vite_javascript_tag(*names, id: id, asset_type: :typescript, **options)
77
+ vite_javascript_tag(*names, id:, asset_type: :typescript, **options)
65
78
  end
66
79
 
67
80
  # Public: Renders a <link> tag for the specified Vite entrypoints.
68
81
  def vite_stylesheet_tag(*names, id: nil, **options)
69
- style_paths = names.map { |name| vite_asset_path(name, id: id, type: :stylesheet) }
82
+ style_paths = names.map { |name| vite_asset_path(name, id:, type: :stylesheet) }
70
83
 
71
84
  options[:extname] = false if Rails::VERSION::MAJOR >= 7
72
85
 
@@ -77,27 +90,31 @@ module MiniviteRails
77
90
  def vite_image_tag(name, id: nil, **options)
78
91
  if options[:srcset] && !options[:srcset].is_a?(String)
79
92
  options[:srcset] = options[:srcset].map do |src_name, size|
80
- "#{vite_asset_path(src_name, id: id)} #{size}"
93
+ "#{vite_asset_path(src_name, id:)} #{size}"
81
94
  end.join(', ')
82
95
  end
83
96
 
84
- image_tag(vite_asset_path(name, id: id), options)
97
+ image_tag(vite_asset_path(name, id:), options)
85
98
  end
86
99
 
87
100
  private
88
101
 
89
102
  # Internal: Returns the current manifest loaded by Vite Ruby.
90
103
  def vite_manifest(id: nil)
91
- MiniviteRails.manifest(id: id)
104
+ MiniviteRails.manifest(id:)
92
105
  end
93
106
 
94
107
  # Internal: Renders a modulepreload link tag.
95
108
  def vite_preload_tag(*sources, crossorigin:, **options)
96
- sources.map do |source|
97
- href = path_to_asset(source)
98
- try(:request).try(:send_early_hints,
99
- 'Link' => %(<#{href}>; rel=modulepreload; as=script; crossorigin=#{crossorigin}))
100
- tag.link(rel: 'modulepreload', href: href, as: 'script', crossorigin: crossorigin, **options)
109
+ asset_paths = sources.map { |source| path_to_asset(source) }
110
+ try(:request).try(
111
+ :send_early_hints,
112
+ 'Link' => asset_paths.map do |href|
113
+ %(<#{href}>; rel=modulepreload; as=script; crossorigin=#{crossorigin})
114
+ end.join("\n")
115
+ )
116
+ asset_paths.map do |href|
117
+ tag.link(rel: 'modulepreload', href:, as: 'script', crossorigin:, **options)
101
118
  end.join("\n").html_safe
102
119
  end
103
120
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniviteRails
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Main entrypoint
3
4
  module MiniviteRails
4
5
  require 'minivite_rails/configuration'
5
6
  require 'minivite_rails/manifest'
@@ -25,5 +26,5 @@ end
25
26
 
26
27
  require 'active_support/lazy_load_hooks'
27
28
  ActiveSupport.on_load :action_view do
28
- ::ActionView::Base.include MiniviteRails::TagHelpers
29
+ ActionView::Base.include MiniviteRails::TagHelpers
29
30
  end
metadata CHANGED
@@ -1,122 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minivite_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linh Tran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-03 00:00:00.000000000 Z
11
+ date: 2024-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: actionview
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 6.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 6.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: railties
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 6.0.0
19
+ version: '6.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8'
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - ">="
39
28
  - !ruby/object:Gem::Version
40
- version: 6.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: debug
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.21'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.21'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2.18'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
29
+ version: '6.0'
30
+ - - "<"
109
31
  - !ruby/object:Gem::Version
110
- version: '2.18'
111
- description: Minivite Ruby Gem
32
+ version: '8'
33
+ description: Provides a minimalistic way to use Vite.js with Rails.
112
34
  email:
113
35
  - linh.mtran168@live.com
114
36
  executables: []
115
37
  extensions: []
116
38
  extra_rdoc_files: []
117
39
  files:
40
+ - ".editorconfig"
118
41
  - ".rspec"
119
42
  - ".rubocop.yml"
43
+ - ".ruby-version"
120
44
  - ".vscode/settings.json"
121
45
  - Gemfile
122
46
  - Gemfile.lock
@@ -133,6 +57,7 @@ licenses:
133
57
  - MIT
134
58
  metadata:
135
59
  homepage_uri: https://github.com/linhmtran168/minivite_rails
60
+ rubygems_mfa_required: 'true'
136
61
  post_install_message:
137
62
  rdoc_options: []
138
63
  require_paths:
@@ -141,14 +66,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
66
  requirements:
142
67
  - - ">="
143
68
  - !ruby/object:Gem::Version
144
- version: 2.7.0
69
+ version: '3.1'
145
70
  required_rubygems_version: !ruby/object:Gem::Requirement
146
71
  requirements:
147
72
  - - ">="
148
73
  - !ruby/object:Gem::Version
149
74
  version: '0'
150
75
  requirements: []
151
- rubygems_version: 3.4.6
76
+ rubygems_version: 3.5.3
152
77
  signing_key:
153
78
  specification_version: 4
154
79
  summary: Minivite Ruby Gem