Module: ThemeCheck::RegexHelpers
- Included in:
- AssetSizeCSS, AssetSizeCSSStylesheetTag, AssetSizeJavaScript, LanguageServer::CompletionProvider, LanguageServer::DocumentLinkEngine
- Defined in:
- lib/theme_check/regex_helpers.rb
Constant Summary collapse
- VARIABLE =
/#{Liquid::VariableStart}.*?#{Liquid::VariableEnd}/om
- START_OR_END_QUOTE =
/(^['"])|(['"]$)/
Instance Method Summary collapse
Instance Method Details
#href_to_file_size(href) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/theme_check/regex_helpers.rb', line 17 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 |
#matches(s, re) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/theme_check/regex_helpers.rb', line 7 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 |