Class: Jekyll::Vite::JavascriptTag

Inherits:
Tag
  • Object
show all
Defined in:
lib/jekyll/vite/tags.rb

Overview

Public: Renders a <script> tag for the specified file.

Instance Method Summary collapse

Methods inherited from Tag

#render_variable

Instance Method Details

#render(context) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/jekyll/vite/tags.rb', line 132

def render(context)
  super {
    media = @params.delete(:media) || 'screen'
    crossorigin = @params.delete(:crossorigin) || 'anonymous'
    type = @params.delete(:type) || 'module'
    asset_type = @tag_name == 'vite_typescript_tag' ? :typescript : :javascript

    entries = vite_manifest.resolve_entries(@file, type: asset_type)

    [
      script_tags(entries.fetch(:scripts), crossorigin: crossorigin, type: type, **@params),
      link_tags(entries.fetch(:imports), rel: 'modulepreload', as: 'script', crossorigin: crossorigin, **@params),
      link_tags(entries.fetch(:stylesheets), rel: 'stylesheet', media: media, crossorigin: crossorigin, **@params),
    ].join("\n")
  }
end

#syntax_exampleObject



149
150
151
# File 'lib/jekyll/vite/tags.rb', line 149

def syntax_example
  "{% #{ @tag_name } application %}"
end