Module: Jekyll::Filters
- Defined in:
- lib/jekyll/filters.rb
Instance Method Summary collapse
-
#array_to_sentence_string(array) ⇒ Object
Join an array of things into a string by separating with commes and the word “and” for the last one.
-
#cgi_escape(input) ⇒ Object
CGI escape a string for use in a URL.
-
#date_to_long_string(date) ⇒ Object
Format a date in long format e.g.
-
#date_to_rfc822(date) ⇒ Object
Format a date according to RFC-822.
-
#date_to_string(date) ⇒ Object
Format a date in short format e.g.
-
#date_to_xmlschema(date) ⇒ Object
Format a date for use in XML.
-
#json(input) ⇒ Object
Convert the input into json string.
-
#markdownify(input) ⇒ Object
Convert a Markdown string into HTML output.
-
#number_of_words(input) ⇒ Object
Count the number of words in the input string.
-
#textilize(input) ⇒ Object
Convert a Textile string into HTML output.
-
#uri_escape(input) ⇒ Object
URI escape a string.
-
#xml_escape(input) ⇒ Object
XML escape a string for use.
Instance Method Details
#array_to_sentence_string(array) ⇒ Object
Join an array of things into a string by separating with commes and the word “and” for the last one.
array - The Array of Strings to join.
Examples
array_to_sentence_string(["apples", "oranges", "grapes"])
# => "apples, oranges, and grapes"
Returns the formatted String.
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/jekyll/filters.rb', line 137 def array_to_sentence_string(array) connector = "and" case array.length when 0 "" when 1 array[0].to_s when 2 "#{array[0]} #{connector} #{array[1]}" else "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}" end end |
#cgi_escape(input) ⇒ Object
CGI escape a string for use in a URL. Replaces any special characters with appropriate %XX replacements.
input - The String to escape.
Examples
cgi_escape('foo,bar;baz?')
# => "foo%2Cbar%3Bbaz%3F"
Returns the escaped String.
99 100 101 |
# File 'lib/jekyll/filters.rb', line 99 def cgi_escape(input) CGI::escape(input) end |
#date_to_long_string(date) ⇒ Object
Format a date in long format e.g. “27 January 2011”.
date - The Time to format.
Returns the formatted String.
41 42 43 |
# File 'lib/jekyll/filters.rb', line 41 def date_to_long_string(date) time(date).strftime("%d %B %Y") end |
#date_to_rfc822(date) ⇒ Object
Format a date according to RFC-822
date - The Time to format.
Examples
date_to_rfc822(Time.now)
# => "Sun, 24 Apr 2011 12:34:46 +0000"
Returns the formatted String.
69 70 71 |
# File 'lib/jekyll/filters.rb', line 69 def date_to_rfc822(date) time(date).rfc822 end |
#date_to_string(date) ⇒ Object
Format a date in short format e.g. “27 Jan 2011”.
date - the Time to format.
Returns the formatting String.
32 33 34 |
# File 'lib/jekyll/filters.rb', line 32 def date_to_string(date) time(date).strftime("%d %b %Y") end |
#date_to_xmlschema(date) ⇒ Object
Format a date for use in XML.
date - The Time to format.
Examples
date_to_xmlschema(Time.now)
# => "2011-04-24T20:34:46+08:00"
Returns the formatted String.
55 56 57 |
# File 'lib/jekyll/filters.rb', line 55 def date_to_xmlschema(date) time(date).xmlschema end |
#json(input) ⇒ Object
Convert the input into json string
input - The Array or Hash to be converted
Returns the converted json string
156 157 158 |
# File 'lib/jekyll/filters.rb', line 156 def json(input) input.to_json end |
#markdownify(input) ⇒ Object
Convert a Markdown string into HTML output.
input - The Markdown String to convert.
Returns the HTML formatted String.
21 22 23 24 25 |
# File 'lib/jekyll/filters.rb', line 21 def markdownify(input) site = @context.registers[:site] converter = site.getConverterImpl(Jekyll::Converters::Markdown) converter.convert(input) end |
#number_of_words(input) ⇒ Object
Count the number of words in the input string.
input - The String on which to operate.
Returns the Integer word count.
122 123 124 |
# File 'lib/jekyll/filters.rb', line 122 def number_of_words(input) input.split.length end |
#textilize(input) ⇒ Object
Convert a Textile string into HTML output.
input - The Textile String to convert.
Returns the HTML formatted String.
10 11 12 13 14 |
# File 'lib/jekyll/filters.rb', line 10 def textilize(input) site = @context.registers[:site] converter = site.getConverterImpl(Jekyll::Converters::Textile) converter.convert(input) end |
#uri_escape(input) ⇒ Object
URI escape a string.
input - The String to escape.
Examples
uri_escape('foo, bar \\baz?')
# => "foo,%20bar%20%5Cbaz?"
Returns the escaped String.
113 114 115 |
# File 'lib/jekyll/filters.rb', line 113 def uri_escape(input) URI.escape(input) end |
#xml_escape(input) ⇒ Object
XML escape a string for use. Replaces any special characters with appropriate HTML entity replacements.
input - The String to escape.
Examples
xml_escape('foo "bar" <baz>')
# => "foo "bar" <baz>"
Returns the escaped String.
84 85 86 |
# File 'lib/jekyll/filters.rb', line 84 def xml_escape(input) CGI.escapeHTML(input) end |