Sha256: f86353fa82cbc13dcc078cea975d68acd688a1ff76fee743e11bf1c34db5eb59

Contents?: true

Size: 908 Bytes

Versions: 3

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

module ThemeCheck
  module RegexHelpers
    VARIABLE = /#{Liquid::VariableStart}.*?#{Liquid::VariableEnd}/om
    START_OR_END_QUOTE = /(^['"])|(['"]$)/
    def matches(s, re)
      start_at = 0
      matches = []
      while (m = s.match(re, start_at))
        matches.push(m)
        start_at = m.end(0)
      end
      matches
    end

    def href_to_file_size(href)
      # asset_url (+ optional stylesheet_tag) variables
      if href =~ /^#{VARIABLE}$/o && href =~ /asset_url/ && href =~ Liquid::QuotedString
        asset_id = Regexp.last_match(0).gsub(START_OR_END_QUOTE, "")
        asset = @theme.assets.find { |a| a.name.end_with?("/" + asset_id) }
        return if asset.nil?
        asset.gzipped_size

      # remote URLs
      elsif href =~ %r{^(https?:)?//}
        asset = RemoteAssetFile.from_src(href)
        asset.gzipped_size
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-1.2.0 lib/theme_check/regex_helpers.rb
theme-check-1.1.0 lib/theme_check/regex_helpers.rb
theme-check-1.0.0 lib/theme_check/regex_helpers.rb