Module: Yass::LiquidFilters

Defined in:
lib/yass/liquid_filters.rb

Instance Method Summary collapse

Instance Method Details

#match(str, regex) ⇒ Object



16
# File 'lib/yass/liquid_filters.rb', line 16

def match(str, regex) = Regexp.new(regex).match? str

#relative(url) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/yass/liquid_filters.rb', line 3

def relative(url)
  url = Pathname.new(url)
  to = context.registers[:source].dest_path
  in_root = to.dirname.to_s == "."
  updirs = in_root ? [] : to.dirname.to_s.split("/").map { ".." }
  Pathname.new([*updirs, url].join("/")).to_s
end

#strip_index(url) ⇒ Object



11
12
13
14
# File 'lib/yass/liquid_filters.rb', line 11

def strip_index(url)
  path = strip_index? ? url.sub(%r'/?index\.html([\?#][^/]*)?$', '/\1') : url
  path == "/" ? "." : path
end

#where_match(objects, field, regex) ⇒ Object



18
19
20
21
# File 'lib/yass/liquid_filters.rb', line 18

def where_match(objects, field, regex)
  regex = Regexp.new(regex)
  objects.select { |obj| regex =~ obj[field].to_s }
end

#where_not(objects, field, value) ⇒ Object



23
# File 'lib/yass/liquid_filters.rb', line 23

def where_not(objects, field, value) = objects.reject { |obj| obj.send(field) == value }