Module: ViteHanami::TagHelpers
- Defined in:
- lib/vite_hanami/tag_helpers.rb
Overview
Public: Allows to render HTML tags for scripts and styles processed by Vite.
Instance Method Summary collapse
-
#vite_asset_path(name, **options) ⇒ Object
Public: Resolves the path for the specified Vite asset.
-
#vite_client ⇒ Object
Public: Renders a script tag for vite/client to enable HMR in development.
-
#vite_javascript(*names, type: 'module', asset_type: :javascript, skip_preload_tags: false, skip_style_tags: false, crossorigin: 'anonymous', **options) ⇒ Object
Public: Renders a <script> tag for the specified Vite entrypoints.
-
#vite_react_refresh ⇒ Object
Public: Renders a script tag to enable HMR with React Refresh.
-
#vite_stylesheet(*names, **options) ⇒ Object
Public: Renders a <link> tag for the specified Vite entrypoints.
-
#vite_typescript(*names, **options) ⇒ Object
Public: Renders a <script> tag for the specified Vite entrypoints.
Instance Method Details
#vite_asset_path(name, **options) ⇒ Object
Public: Resolves the path for the specified Vite asset.
Example:
<%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
22 23 24 |
# File 'lib/vite_hanami/tag_helpers.rb', line 22 def vite_asset_path(name, **) asset_path vite_manifest.path_for(name, **) end |
#vite_client ⇒ Object
Public: Renders a script tag for vite/client to enable HMR in development.
6 7 8 9 10 |
# File 'lib/vite_hanami/tag_helpers.rb', line 6 def vite_client return unless src = vite_manifest.vite_client_src html.script(src: src, type: 'module') end |
#vite_javascript(*names, type: 'module', asset_type: :javascript, skip_preload_tags: false, skip_style_tags: false, crossorigin: 'anonymous', **options) ⇒ Object
Public: Renders a <script> tag for the specified Vite entrypoints.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vite_hanami/tag_helpers.rb', line 27 def vite_javascript(*names, type: 'module', asset_type: :javascript, skip_preload_tags: false, skip_style_tags: false, crossorigin: 'anonymous', **) entries = vite_manifest.resolve_entries(*names, type: asset_type) = javascript(*entries.fetch(:scripts), crossorigin: crossorigin, type: type, **) << vite_modulepreload(*entries.fetch(:imports), crossorigin: crossorigin) unless << stylesheet(*entries.fetch(:stylesheets)) unless ::Hanami::Utils::Escape::SafeString.new() end |
#vite_react_refresh ⇒ Object
Public: Renders a script tag to enable HMR with React Refresh.
13 14 15 16 |
# File 'lib/vite_hanami/tag_helpers.rb', line 13 def vite_react_refresh tag = vite_manifest.react_refresh_preamble raw(tag) if tag end |
#vite_stylesheet(*names, **options) ⇒ Object
Public: Renders a <link> tag for the specified Vite entrypoints.
47 48 49 50 |
# File 'lib/vite_hanami/tag_helpers.rb', line 47 def vite_stylesheet(*names, **) style_paths = names.map { |name| vite_asset_path(name, type: :stylesheet) } stylesheet(*style_paths, **) end |
#vite_typescript(*names, **options) ⇒ Object
Public: Renders a <script> tag for the specified Vite entrypoints.
42 43 44 |
# File 'lib/vite_hanami/tag_helpers.rb', line 42 def vite_typescript(*names, **) vite_javascript(*names, asset_type: :typescript, **) end |