module Jekyll::J1_Filters
Constants
- ADOC_HEAD_LINE
- ADOC_INLINE_COMMENT
- ADOC_TAG_LINE
- ALL_SPACES
- COMMENT_LINE
- 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 96 def contain_substr(input, substr) input.include?(substr) ? true : false end
is_array(input)
click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 273 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 264 def is_fixnum(input) input.kind_of?(Fixnum) end
is_hash(input)
click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 278 def is_hash(input) input.kind_of?(Hash) end
is_numeric(input)
click to toggle source
# File lib/starter_web/_plugins/filters.rb, line 268 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 260 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 247 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 237 def json(input) input.to_json end
merge(input, hash)
click to toggle source
merge: merge two hashes (input <- hash) Example: {% assign nav_bar_options = nav_bar_default | merge: nav_bar_config %}
# File lib/starter_web/_plugins/filters.rb, line 71 def merge(input, hash) unless input.respond_to?(:to_hash) raise ArgumentError.new("merge filter requires hash arguments: arg_input") 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 300 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 289 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 226 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 217 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 116 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 106 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 186 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 176 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 136 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 126 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 146 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 156 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 196 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 166 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 206 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