Sha256: 0eb5e7fb750fcf056081cec98da13f6261359b79642632eb3e7468d45159e7f5
Contents?: true
Size: 1013 Bytes
Versions: 2
Compression:
Stored size: 1013 Bytes
Contents
# frozen_string_literal: true module JsDependency module Extractor class ExtractScriptTag # @param [String] str def initialize(str) @str = str end # @return [Array<String>] def call str = @str scripts = str.gsub(%r{<script>(.+)</script>}m).with_object([]) do |_, list| list << Regexp.last_match(1) end scripts += str.gsub(%r{<script.+src=["'].+["']>(.+)</script>}m).with_object([]) do |_, list| list << Regexp.last_match(1) end scripts += str.gsub(%r{<script.+setup>(.+)</script>}m).with_object([]) do |_, list| list << Regexp.last_match(1) end scripts += str.gsub(%r{<script.+lang=["'][tj]s["']>(.+)</script>}m).with_object([]) do |_, list| list << Regexp.last_match(1) end scripts.uniq.sort.join("\n") end # @param [String] str # @return [String] def self.call(str) new(str).call end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
js_dependency-0.4.1 | lib/js_dependency/extractor/extract_script_tag.rb |
js_dependency-0.4.0 | lib/js_dependency/extractor/extract_script_tag.rb |