Module: Jekyll::Filters

Defined in:
lib/jekyll/filters.rb

Instance Method Summary collapse

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.



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jekyll/filters.rb', line 103

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.



75
76
77
# File 'lib/jekyll/filters.rb', line 75

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.



42
43
44
# File 'lib/jekyll/filters.rb', line 42

def date_to_long_string(date)
  date.strftime("%d %B %Y")
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.



33
34
35
# File 'lib/jekyll/filters.rb', line 33

def date_to_string(date)
  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.



56
57
58
# File 'lib/jekyll/filters.rb', line 56

def date_to_xmlschema(date)
  date.xmlschema
end

#markdownify(input) ⇒ Object

Convert a Markdown string into HTML output.

input - The Markdown String to convert.

Returns the HTML formatted String.



22
23
24
25
26
# File 'lib/jekyll/filters.rb', line 22

def markdownify(input)
  site = @context.registers[:site]
  converter = site.getConverterImpl(Jekyll::MarkdownConverter)
  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.



88
89
90
# File 'lib/jekyll/filters.rb', line 88

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.



11
12
13
14
15
# File 'lib/jekyll/filters.rb', line 11

def textilize(input)
  site = @context.registers[:site]
  converter = site.getConverterImpl(Jekyll::TextileConverter)
  converter.convert(input)
end

#uri_escape(input) ⇒ Object



79
80
81
# File 'lib/jekyll/filters.rb', line 79

def uri_escape(input)
  URI.escape(input)
end

#xml_escape(input) ⇒ Object



60
61
62
# File 'lib/jekyll/filters.rb', line 60

def xml_escape(input)
  CGI.escapeHTML(input)
end