Class: JsDependency::Extractor::ExtractScriptTag
- Inherits:
-
Object
- Object
- JsDependency::Extractor::ExtractScriptTag
- Defined in:
- lib/js_dependency/extractor/extract_script_tag.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Array<String>
-
#initialize(str) ⇒ ExtractScriptTag
constructor
A new instance of ExtractScriptTag.
Constructor Details
#initialize(str) ⇒ ExtractScriptTag
Returns a new instance of ExtractScriptTag.
7 8 9 |
# File 'lib/js_dependency/extractor/extract_script_tag.rb', line 7 def initialize(str) @str = str end |
Class Method Details
.call(str) ⇒ String
35 36 37 |
# File 'lib/js_dependency/extractor/extract_script_tag.rb', line 35 def self.call(str) new(str).call end |
Instance Method Details
#call ⇒ Array<String>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/js_dependency/extractor/extract_script_tag.rb', line 12 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 |