Module: Jekyll::UJPowertools
- Defined in:
- lib/jekyll-uj-powertools.rb,
lib/jekyll-uj-powertools/version.rb
Constant Summary collapse
- VERSION =
"1.0.14"
Instance Method Summary collapse
-
#uj_increment_return(input) ⇒ Object
Increment a global counter that can be accessed from any page then return the new value def uj_increment_return(input) @context.registers ||= 0 @context.registers @context.registers += input end.
-
#uj_json_escape(value) ⇒ Object
Escape a string for use in JSON def uj_json_escape(value) value .gsub(‘\’, ‘\\’) # Escape backslashes .gsub(‘“’, ‘"’) # Escape double quotes .gsub(”b“, ‘\b’) # Escape backspace .gsub(”f“, ‘\f’) # Escape formfeed .gsub(”n“, ‘\n’) # Escape newline .gsub(”r“, ‘\r’) # Escape carriage return .gsub(”t“, ‘\t’) # Escape tab end.
-
#uj_random(input) ⇒ Object
Return a random number between 0 and the input.
-
#uj_strip_ads(input) ⇒ Object
Strip ads from the input.
-
#uj_title_case(input) ⇒ Object
Title case.
Instance Method Details
#uj_increment_return(input) ⇒ Object
Increment a global counter that can be accessed from any page then return the new value def uj_increment_return(input)
@context.registers[:uj_incremental_return] ||= 0
@context.registers[:uj_incremental_return]
@context.registers[:uj_incremental_return] += input
end
35 36 37 38 39 |
# File 'lib/jekyll-uj-powertools.rb', line 35 def uj_increment_return(input) @context ||= { registers: {} } @context[:registers][:uj_incremental_return] ||= 0 @context[:registers][:uj_incremental_return] += input end |
#uj_json_escape(value) ⇒ Object
Escape a string for use in JSON def uj_json_escape(value)
value
.gsub('\\', '\\\\') # Escape backslashes
.gsub('"', '\"') # Escape double quotes
.gsub("\b", '\\b') # Escape backspace
.gsub("\f", '\\f') # Escape formfeed
.gsub("\n", '\\n') # Escape newline
.gsub("\r", '\\r') # Escape carriage return
.gsub("\t", '\\t') # Escape tab
end
25 26 27 |
# File 'lib/jekyll-uj-powertools.rb', line 25 def uj_json_escape(value) value.to_json[1..-2] # Convert to JSON and remove the surrounding quotes end |
#uj_random(input) ⇒ Object
Return a random number between 0 and the input
42 43 44 |
# File 'lib/jekyll-uj-powertools.rb', line 42 def uj_random(input) rand(input) end |
#uj_strip_ads(input) ⇒ Object
Strip ads from the input
6 7 8 9 10 11 12 |
# File 'lib/jekyll-uj-powertools.rb', line 6 def uj_strip_ads(input) input # Remove HTML <ad-units> .gsub(/\s*<ad-unit>[\s\S]*?<\/ad-unit>\s*/m, '') # Remove includes starting with "/master/modules/adunits/" .gsub(/\s*\{% include \/master\/modules\/adunits\/.*? %\}\s*/m, '') end |
#uj_title_case(input) ⇒ Object
Title case
47 48 49 |
# File 'lib/jekyll-uj-powertools.rb', line 47 def uj_title_case(input) input.split(' ').map(&:capitalize).join(' ') end |