Module: JekyllFilterTemplate

Included in:
JekyllPluginTemplate
Defined in:
lib/jekyll_filter_template.rb

Overview

Template for Jekyll filters.

Author:

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/jekyll_filter_template.rb', line 7

def logger
  @logger
end

Instance Method Details

#my_filter_template(input_string) ⇒ String

This Jekyll filter returns the URL to search Google for the contents of the input string.

Examples:

Use.

{{ 'joy' | my_filter_template }} => <a href='https://www.google.com/search?q=joy' target='_blank' rel='nofollow'>joy</a>

Parameters:

  • input_string (String)

    .

Returns:

  • (String)

    empty string if input_string has no contents except whitespace.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll_filter_template.rb', line 16

def my_filter_template(input_string)
  # @context[Liquid::Context] is available here to look up variables defined in front matter, templates, page, etc.

  JekyllFilterTemplate.logger.debug do
    'Defined filters are: ' + self.class # rubocop:disable Style/StringConcatenation
                                  .class_variable_get('@@global_strainer')
                                  .filter_methods.instance_variable_get('@hash')
                                  .map { |k, _v| k }
                                  .sort
  end

  input_string.strip!
  JekyllFilterTemplate.logger.debug "input_string=#{input_string}"
  if input_string.empty?
    ''
  else
    "<a href='https://www.google.com/search?q=#{input_string}' target='_blank' rel='nofollow'>#{input_string}</a>"
  end
end