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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97d28b88662422e5a90c85b6b01faf9195cdd9041ae302dafb55fff94ddfe101
4
- data.tar.gz: a822c03eef5073e26e7d494e3b60c9c6b0ee1bea8d0fcbe922d4a02fb30e9539
3
+ metadata.gz: 77b54ec04817d915d1751c45b42c95c0966a42c9d4bc49db0942a34755a49cc5
4
+ data.tar.gz: 82a4263627eb1df5cd9f9c94502dc6dc3fb7d468a0d5b2b75ad408e15bd4ab19
5
5
  SHA512:
6
- metadata.gz: af7f6f4063834fee805f7c2b541a98eee83cc95cf2347028d20120280a69277004b003159d32c1be29d74cb3ae5317c7dff374d941785f21b7de7a6cad29345e
7
- data.tar.gz: 5c9e365bfef257cd8164f258b1cb97d87e0d16db5f56f96b1661ed1907ffd33fc79ebfdabe5d27c0ebc02b18c00a77c5a83550a751e440f2e5cd2f4cca03d365
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
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
- module DrawIO
3
- VERSION = "1.0.0"
4
- end
2
+ module DrawIO
3
+ VERSION = "1.1.1"
5
4
  end
5
+ end
data/lib/jekyll-drawio.rb CHANGED
@@ -1,22 +1,54 @@
1
1
  require "jekyll"
2
2
  require "jekyll-drawio/version"
3
- require 'nokogiri'
4
- require 'erb'
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, variables, tokens)
33
+ def initialize(tagName, markup, tokens)
9
34
  super
10
- @variables = variables.split " "
11
35
  @path_to_diagram = ""
12
- @selected_diagram_num = nil
36
+ @selected_diagram_num = 0
13
37
  @diagram_height = 200
14
-
15
- @variables.each do |variable|
16
- param_value_pair = variable.split "="
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=\"#{ @path_to_diagram}\" page_num=#{ @selected_diagram_num }"
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
- diagram_name, diagram_content = self.extract_diagram @path_to_diagram, @selected_diagram_num
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=#{ diagram_name } length=#{ diagram_content.length } height=#{ @diagram_height }"
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
- viewer_url = "#{ viewer_url_base }&title=#{ encoded_diagram_name }\#R#{ encoded_diagram }"
53
- viewer_style = "style=\"width:100%;height:#{ @diagram_height }px\""
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" #{ viewer_style } src="#{ viewer_url }"></iframe>}
78
+ %Q{<iframe frameborder="0" #{viewer_style} src="#{viewer_url}"></iframe>}
56
79
  end
57
80
 
58
- Liquid::Template.register_tag "drawio", self
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.0.0
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-04-16 00:00:00.000000000 Z
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.14'
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.14'
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: '4.0'
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: '4.0'
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