forked from jekyll/jekyll
/
filters.rb
61 lines (49 loc) · 1.16 KB
/
filters.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'uri'
module Jekyll
module Filters
def textilize(input)
#RedCloth.new(input).to_html
TextileConverter.new.convert(input)
end
def date_to_string(date)
date.strftime("%d %b %Y")
end
def date_to_long_string(date)
date.strftime("%d %B %Y")
end
def date_to_xmlschema(date)
date.xmlschema
end
def xml_escape(input)
CGI.escapeHTML(input)
end
def cgi_escape(input)
CGI::escape(input)
end
def uri_escape(input)
URI.escape(input)
end
def number_of_words(input)
input.split.length
end
# Returns all content before the first-encountered WP-style MORE tag.
# Allows authors to mark the fold with an <!--more--> in their drafts.
# e.g. {{ content | before_fold }}
def before_fold(input)
input.split("<!--more-->").first
end
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
end
end