jekyll-drawio 1.1.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: 62bdc02bcf3506343b120c054bfdf6662a4afc0234a504a22c18b90b75f7eb11
4
- data.tar.gz: 536dd289302a471dac0601b518736a3ab8ca0c105bf5522b0bf46382a4c97386
3
+ metadata.gz: 77b54ec04817d915d1751c45b42c95c0966a42c9d4bc49db0942a34755a49cc5
4
+ data.tar.gz: 82a4263627eb1df5cd9f9c94502dc6dc3fb7d468a0d5b2b75ad408e15bd4ab19
5
5
  SHA512:
6
- metadata.gz: d9a38fae82bcac537cf5a9e2379270e1f18107024acf66ce6db81289e51eb192e35636f09e4acc539ce14c3e5632eb2785a183745592c7456f148b687ed6da6c
7
- data.tar.gz: a845ed537bdf20b61e7e950d80672daf426bfa1e1172580ca0d260e23bacba4838ea22d8ce967fd9d386c4de36650dbd8e0f89c77f012c23447b8e27e894fcf4
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
2
  module DrawIO
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
data/lib/jekyll-drawio.rb CHANGED
@@ -1,21 +1,51 @@
1
1
  require "jekyll"
2
2
  require "jekyll-drawio/version"
3
+ require "diagram_extractor"
3
4
  require "nokogiri"
4
5
  require "erb"
5
6
 
6
7
  MODULE_TAG_NAME = "drawio"
7
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
25
+
8
26
  class DrawIOConverter < Liquid::Tag
9
- attr_accessor :path_to_diagram, :selected_diagram_num, :diagram_height
27
+ attr_accessor :path_to_diagram,
28
+ :selected_diagram_num,
29
+ :diagram_height,
30
+ :markup,
31
+ :diagram_extractor
10
32
 
11
- def initialize(tagName, variables, tokens)
33
+ def initialize(tagName, markup, tokens)
12
34
  super
13
35
  @path_to_diagram = ""
14
- @selected_diagram_num = nil
36
+ @selected_diagram_num = 0
15
37
  @diagram_height = 200
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)
16
46
 
17
- variables.each do |variable|
18
- param_value_pair = variable.split "="
47
+ parameters.each do |param|
48
+ param_value_pair = param.split "="
19
49
  if param_value_pair[0] == "path"
20
50
  # TODO: find appropriate method to trim the string
21
51
  @path_to_diagram = param_value_pair[1].tr('\"', "")
@@ -29,22 +59,13 @@ class DrawIOConverter < Liquid::Tag
29
59
  puts "path=\"#{@path_to_diagram}\" page_num=#{@selected_diagram_num}"
30
60
  end
31
61
 
32
- def extract_diagram(path)
33
- doc = File.open(path) { |f| Nokogiri::XML(f) }
34
- diagrams = doc.xpath("//mxfile//diagram")
35
- puts "Diagrams found at \"#{path}\": #{diagrams.length}. " \
36
- "Selected: #{@selected_diagram_num}. "
37
-
38
- diagram = diagrams[@selected_diagram_num]
39
-
40
- diagram_name = diagram["name"]
41
- diagram_content = diagram.to_html
42
-
43
- return diagram_name, diagram_content
44
- end
45
-
46
62
  def render(context)
47
- diagram_name, diagram_content = self.extract_diagram @path_to_diagram
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
48
69
  encoded_diagram = ERB::Util.url_encode diagram_content
49
70
  encoded_diagram_name = ERB::Util.url_encode diagram_name
50
71
 
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.1.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-17 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
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: erb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.2'
48
+ - - "<"
49
+ - !ruby/object:Gem::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
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '2.2'
58
+ - - "<"
59
+ - !ruby/object:Gem::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
@@ -82,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
89
  - !ruby/object:Gem::Version
83
90
  version: '0'
84
91
  requirements: []
85
- rubygems_version: 3.0.9
92
+ rubygems_version: 3.2.3
86
93
  signing_key:
87
94
  specification_version: 4
88
95
  summary: Jekyll plugin to generate HTML snippets for embedding draw.io diagrams