Sha256: 2ce278b25bb4737e5a70a66a0157107317d323c8fefd825b5abf554ab3455fa6

Contents?: true

Size: 706 Bytes

Versions: 4

Compression:

Stored size: 706 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.uniq.sort.join("\n")
      end

      # @param [String] str
      # @return [String]
      def self.call(str)
        new(str).call
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
js_dependency-0.3.15 lib/js_dependency/extractor/extract_script_tag.rb
js_dependency-0.3.14 lib/js_dependency/extractor/extract_script_tag.rb
js_dependency-0.3.13 lib/js_dependency/extractor/extract_script_tag.rb
js_dependency-0.3.12 lib/js_dependency/extractor/extract_script_tag.rb