-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_hooks.rb
More file actions
67 lines (50 loc) · 1.19 KB
/
Copy pathruby_hooks.rb
File metadata and controls
67 lines (50 loc) · 1.19 KB
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
62
63
64
65
66
67
module Formatter
class AbstractMethodError < StandardError; end
class Base
attr_accessor :content
def initialize(content)
@content = content
end
def to_html
raise Formatter::AbstractMethodError
end
end
end
module Formatter
class UnknownFormatterError < StandardError; end
FORMATTERS = {
textile: "Formatter::Textile",
markdown: "Formatter::Markdown"
}
def self.format(type, content)
formatter_name = FORMATTERS[type.to_sym]
raise UnknownFormatterError unless formatter_name
formatter = eval(formatter_name)
formatter.new(content).to_html
end
end
require 'RedCloth'
require 'rdiscount'
module Formatter
class Textile < Base
def to_html
RedCloth.new(@content).to_html
end
end
class Markdown < Base
def to_html
RDiscount.new(@content).to_html
end
end
end
puts Formatter.format(:textile, 'h1. Isso é muito black mirror')
puts Formatter.format(:markdown, '# Isso é muito black mirror')
module Formatter
class Xunda < Base
def to_html
"<h1>XUNDA!</h1>"
end
end
end
Formatter::FORMATTERS[:xunda] = 'Formatter::Xunda'
puts Formatter.format(:xunda, '# Isso é muito black mirror')