module Jekyll::J1_Filters

Constants

ADOC_HEAD_LINE
ADOC_INLINE_COMMENT
ADOC_TAG_LINE
ALL_SPACES
COMMENT_LINE
EMPTY
EMPTY_LINE
HTML_COMMENT_LINE

HTML_COMMENT_LINE = /^s*<!–.*–>|s*<!–.*–>/

JBX_INDEX_TAG
JS_COMMENT_LINE
LIQUID_TAG
MULTIPLE_SPACES
NOTHING
SPACE

Public Instance Methods

contain_substr(input, substr) click to toggle source

contain_substr: check if a string contains a substring

Example:

# File lib/starter_web/_plugins/filters.rb, line 108
def contain_substr(input, substr)
   input.include?(substr) ? true : false
end
contains(input, substr) click to toggle source

contains: check if a string contains a substring

Example:

# File lib/starter_web/_plugins/filters.rb, line 98
def contains(input, substr)
   input.include?(substr) ? true : false
end
is_array(input) click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 285
def is_array(input)
  input.kind_of?(Array)
  return type
end
is_fixnum(input) click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 276
def is_fixnum(input)
  input.kind_of?(Fixnum)
end
is_hash(input) click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 290
def is_hash(input)
  input.kind_of?(Hash)
end
is_numeric(input) click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 280
def is_numeric(input)
  return true if input =~ /\A\d+\Z/
  true if Float(input) rescue false
end
is_string(input) click to toggle source

is_XXXX:

"Duck typing" methods to determine the object (base) class
 returns true|false

Example:

# File lib/starter_web/_plugins/filters.rb, line 272
def is_string(input)
   input.kind_of?(String)
end
is_type(input) click to toggle source

is_type:

Example:

# File lib/starter_web/_plugins/filters.rb, line 259
def is_type(input)
  "#{input.class}".to_s.strip.downcase
end
json(input) click to toggle source

json:

Example:

# File lib/starter_web/_plugins/filters.rb, line 249
def json(input)
  input.to_json
end
merge(input, hash) click to toggle source

merge: merge two hashes (input <- hash)

Example:
 {% assign settings = options|merge:defaults %}

# File lib/starter_web/_plugins/filters.rb, line 71
def merge(input, hash)
  unless input.respond_to?(:to_hash)
    # value = input == EMPTY ? 'empty' : input
    is_caller = caller[0][/`([^']*)'/, 1]
    raise ArgumentError.new('merge filter requires at least a hash for 1st arg, found caller|args: ' + "#{is_caller}|#{input}:#{hash}")
  end
  # if hash to merge is NOT a hash or empty return first hash (input)
  unless hash.respond_to?(:to_hash)
    input
  end
  if hash.nil? || hash.empty?
    input
  else
    merged = input.dup
    hash.each do |k, v|
      merged[k] = v
    end
    merged
  end
end
newline_to_nothing(input) click to toggle source

newline_to_space:
Replace all newlines by space

Example:

# File lib/starter_web/_plugins/filters.rb, line 312
def newline_to_nothing(input)
  input.to_s.gsub(/\n/, NOTHING)
end
newline_to_space(input) click to toggle source

newline_to_space:
Replace all newlines by space

Example:

# File lib/starter_web/_plugins/filters.rb, line 301
def newline_to_space(input)
  input.to_s.gsub(/\n/, SPACE)
end
rand(input) click to toggle source

rand:

Example:

# File lib/starter_web/_plugins/filters.rb, line 238
def rand(input)
  max = input.to_i
  Random.new.rand(1..max)
end
read_index(input) click to toggle source

read_index:

Example:

# File lib/starter_web/_plugins/filters.rb, line 229
def read_index(input)
end
regex_replace(input, regex, replacement = NOTHING) click to toggle source

regex_replace:

Example:

# File lib/starter_web/_plugins/filters.rb, line 128
def regex_replace(input, regex, replacement = NOTHING)
   input.to_s.gsub(Regexp.new(regex), replacement.to_s)
end
regex_replace_first(input, regex, replacement = NOTHING) click to toggle source

regex_replace_first: replace the FIRST occurence

Example:

# File lib/starter_web/_plugins/filters.rb, line 118
def regex_replace_first(input, regex, replacement = NOTHING)
   input.to_s.sub(Regexp.new(regex), replacement.to_s)
end
strip_adoc(input) click to toggle source

strip_adoc:

Example:

# File lib/starter_web/_plugins/filters.rb, line 198
def strip_adoc(input)
  input.to_s.gsub(ADOC_TAG_LINE, SPACE).gsub(ADOC_INLINE_COMMENT, SPACE).gsub(ADOC_HEAD_LINE, SPACE)
end
strip_all_spaces(input) click to toggle source

strip_all_spaces:

Example:

# File lib/starter_web/_plugins/filters.rb, line 188
def strip_all_spaces(input)
   input.to_s.gsub(Regexp.new(ALL_SPACES), SPACE)
end
strip_comments(input) click to toggle source

strip_comments:

Example:

# File lib/starter_web/_plugins/filters.rb, line 148
def strip_comments(input)
   input.to_s.gsub(Regexp.new(COMMENT_LINE), NOTHING)
end
strip_empty_lines(input) click to toggle source

strip_empty_lines:

Example:

# File lib/starter_web/_plugins/filters.rb, line 138
def strip_empty_lines(input)
   input.to_s.gsub(Regexp.new(EMPTY_LINE), NOTHING)
end
strip_html_comments(input) click to toggle source

strip_html_comments:

Example:

# File lib/starter_web/_plugins/filters.rb, line 158
def strip_html_comments(input)
   input.to_s.gsub(Regexp.new(HTML_COMMENT_LINE), NOTHING)
end
strip_js_comments(input) click to toggle source

strip_js_comments:

Example:

# File lib/starter_web/_plugins/filters.rb, line 168
def strip_js_comments(input)
   input.to_s.gsub(Regexp.new(JS_COMMENT_LINE), NOTHING)
end
strip_liquid_tag(input) click to toggle source

strip_liquid_tag:

Example:

# File lib/starter_web/_plugins/filters.rb, line 208
def strip_liquid_tag(input)
  input.to_s.gsub(LIQUID_TAG, SPACE)
end
strip_multiple_spaces(input) click to toggle source

strip_multiple_spaces:

Example:

# File lib/starter_web/_plugins/filters.rb, line 178
def strip_multiple_spaces(input)
   input.to_s.gsub(Regexp.new(MULTIPLE_SPACES), SPACE)
end
strip_my_html(input) click to toggle source

strip_my_html:

Example:

# File lib/starter_web/_plugins/filters.rb, line 218
def strip_my_html(input)
  space = ' '.freeze
  input.to_s.gsub(/<script.*?<\/script>/m, space).gsub(/<!--.*?-->/m, space).gsub(/<style.*?<\/style>/m, space).gsub(/<.*?>/m, space)
end