Module: Jekyll::Filters
- Defined in:
- lib/jekyll/filters.rb
Instance Method Summary collapse
- #array_to_sentence_string(array) ⇒ Object
-
#before_fold(input) ⇒ Object
Returns all content before the first-encountered <hr /> tag.
- #date_to_long_string(date) ⇒ Object
- #date_to_rfc2822(date) ⇒ Object
- #date_to_string(date) ⇒ Object
- #date_to_xmlschema(date) ⇒ Object
- #educate(input) ⇒ Object
- #gist(id) ⇒ Object
- #html_truncatewords(input, words = 15, truncate_string = "...") ⇒ Object
- #markdown(input) ⇒ Object
- #number_of_words(input) ⇒ Object
- #strip_html_suffix(input) ⇒ Object
- #textilize(input) ⇒ Object
- #xml_escape(input) ⇒ Object
Instance Method Details
#array_to_sentence_string(array) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jekyll/filters.rb', line 39 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 |
#before_fold(input) ⇒ Object
Returns all content before the first-encountered <hr /> tag. Allows authors to mark the fold with an hr in their drafts. e.g. content | before_fold }
35 36 37 |
# File 'lib/jekyll/filters.rb', line 35 def before_fold(input) input.split("<hr").first end |
#date_to_long_string(date) ⇒ Object
16 17 18 |
# File 'lib/jekyll/filters.rb', line 16 def date_to_long_string(date) date.strftime("%d %B %Y") end |
#date_to_rfc2822(date) ⇒ Object
8 9 10 |
# File 'lib/jekyll/filters.rb', line 8 def date_to_rfc2822(date) date.rfc2822 end |
#date_to_string(date) ⇒ Object
12 13 14 |
# File 'lib/jekyll/filters.rb', line 12 def date_to_string(date) date.strftime("%d %b %Y") end |
#date_to_xmlschema(date) ⇒ Object
20 21 22 |
# File 'lib/jekyll/filters.rb', line 20 def date_to_xmlschema(date) date.xmlschema end |
#educate(input) ⇒ Object
68 69 70 |
# File 'lib/jekyll/filters.rb', line 68 def educate(input) Smartypants.educate_string(input) end |
#gist(id) ⇒ Object
63 64 65 66 |
# File 'lib/jekyll/filters.rb', line 63 def gist(id) js = open("http://gist.github.com/#{id}.js").read js.match(/document.write\('(<div.+)'\)/)[1].gsub(/\\"/, '"').gsub(/\\\//, '/').gsub(/\\n/, '') end |
#html_truncatewords(input, words = 15, truncate_string = "...") ⇒ Object
53 54 55 56 |
# File 'lib/jekyll/filters.rb', line 53 def html_truncatewords(input, words = 15, truncate_string = "...") doc = Hpricot.parse(input) (doc/:"text()").to_s.split[0..words].join(' ') + truncate_string end |
#markdown(input) ⇒ Object
72 73 74 |
# File 'lib/jekyll/filters.rb', line 72 def markdown(input) Maruku.new(input).to_html end |
#number_of_words(input) ⇒ Object
28 29 30 |
# File 'lib/jekyll/filters.rb', line 28 def number_of_words(input) input.split.length end |
#strip_html_suffix(input) ⇒ Object
59 60 61 |
# File 'lib/jekyll/filters.rb', line 59 def strip_html_suffix(input) input.gsub(/\.html$/, '') end |
#textilize(input) ⇒ Object
4 5 6 |
# File 'lib/jekyll/filters.rb', line 4 def textilize(input) RedCloth.new(input).to_html end |
#xml_escape(input) ⇒ Object
24 25 26 |
# File 'lib/jekyll/filters.rb', line 24 def xml_escape(input) input.gsub("&", "&").gsub("<", "<").gsub(">", ">") end |