Module: Jenner::LiquidFilters

Defined in:
lib/jenner/liquid_filters.rb

Instance Method Summary collapse

Instance Method Details

#asset_from_path(path) ⇒ Object



4
5
6
# File 'lib/jenner/liquid_filters.rb', line 4

def asset_from_path(path)
  @context.registers[:site].assets.find { |asset| asset.path == path } || "Asset with path '#{path}' not found"
end

#assign_to(value, name) ⇒ Object



36
37
38
39
# File 'lib/jenner/liquid_filters.rb', line 36

def assign_to(value, name)
  @context[name] = value
  nil
end

#item_from_path(path) ⇒ Object



8
9
10
# File 'lib/jenner/liquid_filters.rb', line 8

def item_from_path(path)
  @context.registers[:site].items.find { |item| item.local_path == path } || "Item with path '#{path}' not found"
end

#items_from_path(path) ⇒ Object



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

def items_from_path(path)
  @context.registers[:site].items.select {|item| item.local_path =~ /^#{path}/ } || []
end

#items_with_data(key, value = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jenner/liquid_filters.rb', line 20

def items_with_data(key, value=nil)
  key_matches = @context.registers[:site].items.select { |item|
    item.data.keys.include?(key)
  }
  return key_matches if value.nil?

  # value was provided
  key_matches.select do |item|
    if item.data[key].is_a?(Array)
      item.data[key].include?(value)
    else
      item.data[key] == value
    end
  end
end

#javascript_tag(path) ⇒ Object



45
46
47
# File 'lib/jenner/liquid_filters.rb', line 45

def javascript_tag(path)
  %(<script type="text/javascript" src="#{path}"></script>)
end


49
50
51
# File 'lib/jenner/liquid_filters.rb', line 49

def link_to(item)
  %(<a href="#{item.url}">#{item.title}</a>)
end

#stylesheet_tag(path) ⇒ Object



41
42
43
# File 'lib/jenner/liquid_filters.rb', line 41

def stylesheet_tag(path)
  %(<link href="#{path}" media="all" rel="stylesheet" type="text/css" />)
end

#tag(name) ⇒ Object



16
17
18
# File 'lib/jenner/liquid_filters.rb', line 16

def tag(name)
  @context.registers[:site].tags.find { |tag| tag.name == name } || "Tag with name '#{name}' not found"
end