Class: Jekyll::Spaceship::PlantumlProcessor
- Inherits:
-
Processor
- Object
- Processor
- Jekyll::Spaceship::PlantumlProcessor
show all
- Defined in:
- lib/jekyll-spaceship/processors/plantuml-processor.rb
Constant Summary
Constants inherited
from Processor
Jekyll::Spaceship::Processor::DEFAULT_PRIORITY, Jekyll::Spaceship::Processor::PRIORITY_MAP
Instance Attribute Summary
Attributes inherited from Processor
#config, #exclusions, #handled, #logger, #page, #priority, #registers
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Processor
class_name, #converter, #dispatch, escape_html, exclude, #exclusion_regexs, #ext, fetch_img_data, #filename, #get_exclusion, handle_bang_link, #initialize, #initialize_exclusions, #initialize_priority, #initialize_register, make_img_tag, #name, #next?, #on_handle_html, #on_handle_html_block, #on_handled, #output_ext, #post_exclude, #pre_exclude, priority, #process?, register
Class Method Details
.config ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 10
def self.config
{
'mode' => 'default',
'syntax' => {
'code' => 'plantuml!',
'custom' => ['@startuml', '@enduml']
},
'css' => {
'class' => 'plantuml'
},
'src' => 'http://www.plantuml.com/plantuml/svg/'
}
end
|
Instance Method Details
#get_url(code) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 78
def get_url(code)
src = self.config['src']
src += '{hexcode}' if src.match(/\{.*\}/).nil?
if src.include?('{hexcode}')
code = '~h' + code.unpack("H*").first
return src.gsub('{hexcode}', code)
else
raise "No supported src ! #{src}"
end
end
|
#handle_plantuml(code) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 59
def handle_plantuml(code)
code = "@startuml#{code}@enduml".encode('UTF-8')
url = self.get_url(code)
case self.config['mode']
when 'pre-fetch'
data = self.class.fetch_img_data(url)
end
if data.nil?
data = { 'type' => 'url', 'body' => url }
end
data['class'] = self.config['css']['class']
self.class.make_img_tag(data)
end
|
#handle_plantuml_block(pattern, content) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 43
def handle_plantuml_block(pattern, content)
content.scan pattern do |match|
match = match.select { |m| not m.nil? }
block = match[0]
code = match[2]
self.handled = true
content = content.gsub(
block,
handle_plantuml(code)
)
end
content
end
|
#on_handle_markdown(content) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 24
def on_handle_markdown(content)
syntax = self.config['syntax']
code_name = syntax['code']
custom = syntax['custom'][-2, 2]
patterns = [
/((`{3,})\s*#{code_name}((?:.|\n)*?)\2)/,
/((?<!\\)(#{custom[0]})((?:.|\n)*?)(?<!\\)(#{custom[1]}))/
]
patterns.each do |pattern|
content = handle_plantuml_block(pattern, content)
end
content.gsub(/\\(#{custom[0]}|#{custom[1]})/, '\1')
end
|