jekyll-drawio 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/diagram_extractor.rb +18 -0
- data/lib/jekyll-drawio/version.rb +3 -3
- data/lib/jekyll-drawio.rb +53 -30
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b54ec04817d915d1751c45b42c95c0966a42c9d4bc49db0942a34755a49cc5
|
4
|
+
data.tar.gz: 82a4263627eb1df5cd9f9c94502dc6dc3fb7d468a0d5b2b75ad408e15bd4ab19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb92b079556c1bde06902b2e550c47151ae2cdbdaa8cd239bbf601a62aac3312776d81939ecd0c81d653000d5a2015cfefaa7d70bb711fbbd01fa484138370c3
|
7
|
+
data.tar.gz: 3acea9b0f8d1adf3a94ef49c02710a97213441bc9a0f66f66458959e0276c259b1c0ae9cfddde77bd13270a9b80bbf94d4886629167020e2249ae5ac91fd000d
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class DiagramExtractor
|
2
|
+
def initialize
|
3
|
+
end
|
4
|
+
|
5
|
+
def extract_diagram(path, diagram_num)
|
6
|
+
doc = File.open(path) { |f| Nokogiri::XML(f) }
|
7
|
+
diagrams = doc.xpath("//mxfile//diagram")
|
8
|
+
puts "Diagrams found at \"#{path}\": #{diagrams.length}. " \
|
9
|
+
"Selected: #{diagram_num}. "
|
10
|
+
|
11
|
+
diagram = diagrams[diagram_num]
|
12
|
+
|
13
|
+
diagram_name = diagram["name"]
|
14
|
+
diagram_content = diagram.to_html
|
15
|
+
|
16
|
+
return diagram_name, diagram_content
|
17
|
+
end
|
18
|
+
end
|
data/lib/jekyll-drawio.rb
CHANGED
@@ -1,22 +1,54 @@
|
|
1
1
|
require "jekyll"
|
2
2
|
require "jekyll-drawio/version"
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "diagram_extractor"
|
4
|
+
require "nokogiri"
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
MODULE_TAG_NAME = "drawio"
|
8
|
+
|
9
|
+
def split_parameters_line(parameters_line)
|
10
|
+
params = []
|
11
|
+
tmp = ""
|
12
|
+
|
13
|
+
parameters_line.each_char do |symbol|
|
14
|
+
if symbol == " "
|
15
|
+
params.push tmp
|
16
|
+
tmp = ""
|
17
|
+
else
|
18
|
+
tmp += symbol
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
params.push tmp
|
23
|
+
params
|
24
|
+
end
|
5
25
|
|
6
26
|
class DrawIOConverter < Liquid::Tag
|
27
|
+
attr_accessor :path_to_diagram,
|
28
|
+
:selected_diagram_num,
|
29
|
+
:diagram_height,
|
30
|
+
:markup,
|
31
|
+
:diagram_extractor
|
7
32
|
|
8
|
-
def initialize(tagName,
|
33
|
+
def initialize(tagName, markup, tokens)
|
9
34
|
super
|
10
|
-
@variables = variables.split " "
|
11
35
|
@path_to_diagram = ""
|
12
|
-
@selected_diagram_num =
|
36
|
+
@selected_diagram_num = 0
|
13
37
|
@diagram_height = 200
|
14
|
-
|
15
|
-
@
|
16
|
-
|
38
|
+
@markup = markup
|
39
|
+
@diagram_extractor = DiagramExtractor.new()
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_content(context)
|
43
|
+
parameters_line = Liquid::Template.parse(@markup).render context
|
44
|
+
parameters_line.strip!
|
45
|
+
parameters = split_parameters_line(parameters_line)
|
46
|
+
|
47
|
+
parameters.each do |param|
|
48
|
+
param_value_pair = param.split "="
|
17
49
|
if param_value_pair[0] == "path"
|
18
50
|
# TODO: find appropriate method to trim the string
|
19
|
-
@path_to_diagram = param_value_pair[1].tr('\"',
|
51
|
+
@path_to_diagram = param_value_pair[1].tr('\"', "")
|
20
52
|
elsif param_value_pair[0] == "page_number"
|
21
53
|
@selected_diagram_num = param_value_pair[1].to_i
|
22
54
|
elsif param_value_pair[0] == "height"
|
@@ -24,36 +56,27 @@ class DrawIOConverter < Liquid::Tag
|
|
24
56
|
end
|
25
57
|
end
|
26
58
|
|
27
|
-
puts "path=\"#{
|
28
|
-
end
|
29
|
-
|
30
|
-
def extract_diagram(path, selected_diagram_num)
|
31
|
-
doc = File.open(path) { |f| Nokogiri::XML(f) }
|
32
|
-
diagrams = doc.xpath("//mxfile//diagram")
|
33
|
-
puts "Diagrams found at \"#{ path }\": #{ diagrams.length }. " \
|
34
|
-
"Selected: #{ @selected_diagram_num }. "
|
35
|
-
|
36
|
-
diagram = diagrams[selected_diagram_num]
|
37
|
-
|
38
|
-
diagram_name = diagram["name"]
|
39
|
-
diagram_content = diagram.content.to_s
|
40
|
-
|
41
|
-
return diagram_name, diagram_content
|
59
|
+
puts "path=\"#{@path_to_diagram}\" page_num=#{@selected_diagram_num}"
|
42
60
|
end
|
43
61
|
|
44
62
|
def render(context)
|
45
|
-
|
63
|
+
if @markup.empty?
|
64
|
+
return "Error processing input, incorrect syntax"
|
65
|
+
end
|
66
|
+
parse_content context
|
67
|
+
|
68
|
+
diagram_name, diagram_content = self.diagram_extractor.extract_diagram @path_to_diagram, @selected_diagram_num
|
46
69
|
encoded_diagram = ERB::Util.url_encode diagram_content
|
47
70
|
encoded_diagram_name = ERB::Util.url_encode diagram_name
|
48
71
|
|
49
|
-
puts "Parsed diagram: name=#{
|
72
|
+
puts "Parsed diagram: name=#{diagram_name} length=#{diagram_content.length} height=#{@diagram_height}"
|
50
73
|
|
51
74
|
viewer_url_base = "https://viewer.diagrams.net/?highlight=0000ff&edit=_blank&layers=1&nav=1"
|
52
|
-
|
53
|
-
viewer_style = "style=\"width:100%;height:#{
|
75
|
+
viewer_url = "#{viewer_url_base}&title=#{encoded_diagram_name}\#R#{encoded_diagram}"
|
76
|
+
viewer_style = "style=\"width:100%;height:#{@diagram_height}px\""
|
54
77
|
|
55
|
-
%Q{<iframe frameborder="0" #{
|
78
|
+
%Q{<iframe frameborder="0" #{viewer_style} src="#{viewer_url}"></iframe>}
|
56
79
|
end
|
57
80
|
|
58
|
-
Liquid::Template.register_tag
|
81
|
+
Liquid::Template.register_tag MODULE_TAG_NAME, self
|
59
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-drawio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Illia Gorbatiuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -30,28 +30,34 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.12'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: erb
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
- - "<"
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
50
|
+
version: '5.0'
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.2'
|
58
|
+
- - "<"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '5.0'
|
55
61
|
description:
|
56
62
|
email:
|
57
63
|
- ilya.gorbatiuk@gmail.com
|
@@ -59,6 +65,7 @@ executables: []
|
|
59
65
|
extensions: []
|
60
66
|
extra_rdoc_files: []
|
61
67
|
files:
|
68
|
+
- lib/diagram_extractor.rb
|
62
69
|
- lib/jekyll-drawio.rb
|
63
70
|
- lib/jekyll-drawio/version.rb
|
64
71
|
homepage: https://github.com/mutcher/jekyll-drawio
|