Module: Jekyll::UJPowertools
- Defined in:
- lib/jekyll-uj-powertools.rb,
lib/jekyll-uj-powertools/version.rb
Constant Summary collapse
- VERSION =
"1.0.9"
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.
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
31 32 33 34 35 |
# File 'lib/jekyll-uj-powertools.rb', line 31 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
21 22 23 |
# File 'lib/jekyll-uj-powertools.rb', line 21 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
38 39 40 |
# File 'lib/jekyll-uj-powertools.rb', line 38 def uj_random(input) rand(input) end |
#uj_strip_ads(input) ⇒ Object
Strip ads from the input
6 7 8 |
# File 'lib/jekyll-uj-powertools.rb', line 6 def uj_strip_ads(input) input.gsub(/\s*<ad-unit>[\s\S]*?<\/ad-unit>\s*/m, '') end |