-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathconfig.rb
52 lines (46 loc) · 1.46 KB
/
config.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
# frozen_string_literal: true
require 'ruby-enum'
module CommonMarker
# For Ruby::Enum, these must be classes, not modules
module Config
class Parse
include Ruby::Enum
define :DEFAULT, 0
define :VALIDATE_UTF8, (1 << 9)
define :SMART, (1 << 10)
define :LIBERAL_HTML_TAG, (1 << 12)
define :FOOTNOTES, (1 << 13)
define :STRIKETHROUGH_DOUBLE_TILDE, (1 << 14)
define :UNSAFE, (1 << 17)
end
class Render
include Ruby::Enum
define :DEFAULT, 0
define :SOURCEPOS, (1 << 1)
define :HARDBREAKS, (1 << 2)
define :NOBREAKS, (1 << 4)
define :GITHUB_PRE_LANG, (1 << 11)
define :TABLE_PREFER_STYLE_ATTRIBUTES, (1 << 15)
define :FULL_INFO_STRING, (1 << 16)
define :UNSAFE, (1 << 17)
end
def self.process_options(option, type)
type = Config.const_get(type.capitalize)
if option.is_a?(Symbol)
check_option(option, type)
type.to_h[option]
elsif option.is_a?(Array)
option = [nil] if option.empty?
# neckbearding around. the map will both check the opts and then bitwise-OR it
option.map { |o| check_option(o, type); type.to_h[o] }.inject(0, :|)
else
raise TypeError, 'option type must be a valid symbol or array of symbols'
end
end
def self.check_option(option, type)
unless type.key?(option)
raise TypeError, "option ':#{option}' does not exist for #{type}"
end
end
end
end