forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_test_helper.rb
More file actions
44 lines (35 loc) · 782 Bytes
/
filter_test_helper.rb
File metadata and controls
44 lines (35 loc) · 782 Bytes
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
module FilterTestHelper
extend ActiveSupport::Concern
included do
class_attribute :filter_class
end
def filter
@filter ||= filter_class.new @body || '', context, result
end
def filter_output
@filter_output ||= begin
filter.instance_variable_set :@html, @body if @body
filter.call
end
end
def filter_output_string
@filter_output_string ||= filter_output.to_s
end
def filter_result
@filter_result ||= filter_output && result
end
class Context < Hash
def []=(key, value)
super key, key.to_s.end_with?('url') ? Docs::URL.parse(value) : value
end
end
def context
@context ||= Context.new
end
def result
@result ||= {}
end
def link_to(href)
%(<a href="#{href}">Link</a>)
end
end