Class: DoctorIpsum::Markdown
- Defined in:
- lib/doctor_ipsum/markdown.rb
Class Method Summary collapse
-
.blockquote(input = nil, level = 5) ⇒ Object
Simple Blockquote (no Markdown inside…yet).
-
.emphasis(input = nil, level = 1) ⇒ Object
Uses underscore.
-
.entry(*args) ⇒ Object
Random markdown blog entry.
-
.header(input = nil, level = 1) ⇒ Object
Uses Atx-style i.e.
-
.horizontal ⇒ Object
10 dashes.
-
.image(width = rand(300..500), height = rand(300..500)) ⇒ Object
Images from placehold.it.
-
.link ⇒ Object
Opinionated link format.
-
.list(input = nil, level = 2, ordered = false) ⇒ Object
Uses *.
Methods inherited from Lorem
paragraph, paragraphs, sentence, sentences, word, words
Methods inherited from Base
Class Method Details
.blockquote(input = nil, level = 5) ⇒ Object
Simple Blockquote (no Markdown inside…yet)
18 19 20 21 |
# File 'lib/doctor_ipsum/markdown.rb', line 18 def blockquote(input = nil, level = 5) input ||= sentences [].tap { |x| resolve_md(input).split(' ').each_slice(level) { |s| x << s.join(' ').prepend('> ') } }.join("\n") end |
.emphasis(input = nil, level = 1) ⇒ Object
Uses underscore
11 12 13 14 15 |
# File 'lib/doctor_ipsum/markdown.rb', line 11 def emphasis(input = nil, level = 1) input ||= words underscore = '_'*[0,level,2].sort[1] resolve_md(input).prepend(underscore).concat(underscore) end |
.entry(*args) ⇒ Object
Random markdown blog entry
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/doctor_ipsum/markdown.rb', line 51 def entry(*args) out = [] allowed = ["header","emphasis","paragraphs","blockquote", "list","link","image"] elements = ( args ? allowed : filter(args.flatten,allowed) ) out << header if elements.include? 'header' rand(3..10).times do cmd = elements.sample out << (cmd == 'image' ? image(500,500) : send(cmd) ) << paragraphs end out.join("\n\n") end |
.header(input = nil, level = 1) ⇒ Object
Uses Atx-style i.e. ## Header
5 6 7 8 |
# File 'lib/doctor_ipsum/markdown.rb', line 5 def header(input = nil, level = 1) input ||= words resolve_md(input, true).prepend('#'*[0,level,6].sort[1]+' ') end |
.horizontal ⇒ Object
10 dashes
34 35 36 |
# File 'lib/doctor_ipsum/markdown.rb', line 34 def horizontal '-'*10 end |
.image(width = rand(300..500), height = rand(300..500)) ⇒ Object
Images from placehold.it
45 46 47 48 |
# File 'lib/doctor_ipsum/markdown.rb', line 45 def image(width = rand(300..500), height = rand(300..500)) url = 'placehold.it/'+width.to_s+'x'+height.to_s basic_format( nil, url, nil).prepend('!') end |
.link ⇒ Object
Opinionated link format
39 40 41 42 |
# File 'lib/doctor_ipsum/markdown.rb', line 39 def link url = (rand(0..1)>0 ? 'google.com' : 'github.com/geekjuice/doctor_ipsum') basic_format( nil, url , nil) end |
.list(input = nil, level = 2, ordered = false) ⇒ Object
Uses *
24 25 26 27 28 29 30 31 |
# File 'lib/doctor_ipsum/markdown.rb', line 24 def list(input = nil, level = 2, ordered = false) input ||= words(10) [].tap { |x| resolve_md(input).split(' ').each_slice(level).with_index { |s,i| x << s.join(' ').prepend((ordered ? (i+1).to_s+'.' : '*')+' ') } }.join("\n") end |