jekyll-drawio 0.0.4 → 0.0.5

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: dfa4acca7cd42d3e7c9929040a115da7b2481848114e79e5a842f33fcb83e9b5
4
- data.tar.gz: ec8267649cad2f33f1b7f5bee9df67bf8f65a81efa2963f7cda7ca99c373eadc
3
+ metadata.gz: 6fbe444671f6cfd66efe7239cede4745a9b444ef7b03425ff24283d198dbb34a
4
+ data.tar.gz: b8c9ce1eab7b0f9ed73253b45fe36680c0661f0a6a2406540ba76bb1a8985bad
5
5
  SHA512:
6
- metadata.gz: 658107cdb6378da8db15120dc93ff183e22cd155c466edb4a0d23165a1b1a6851de713006c18bc77ba4ff645ba182c87f12e007887bb35d9a277ad7bc4559120
7
- data.tar.gz: 704b985b3eeed272b7c734e6f9a9b682932046fbacca7cc283f33a69b102c59dc24486db3ce487f10914c88ae9bfcce8cb993ca2df934594cc7eb7d4af2c43be
6
+ metadata.gz: 54b62ade3690caecbe6825c8615822c9fe9d509ccb546167561ef89aa905550341d92d994433a52c0d618761ce4353051618e15a98e2128381fa577f36b055f1
7
+ data.tar.gz: 6e5939e5b0b38ecd2b29ba4e34ab76889ba7010ad393189b04581444cfd60cf1c924e12a3024e5df7ca04d3633d2ce5a3a2775a232f5b167caa45d076cf303e4
@@ -0,0 +1,57 @@
1
+ require "jekyll"
2
+ require "jekyll-drawio/version"
3
+ require 'nokogiri'
4
+ require 'erb'
5
+
6
+ class DrawIOConverter < Liquid::Tag
7
+
8
+ def initialize(tagName, variables, tokens)
9
+ super
10
+ @variables = variables.split " "
11
+ @path_to_diagram = ""
12
+ @selected_diagram_num = nil
13
+ @diagram_height = 200
14
+
15
+ @variables.each do |variable|
16
+ param_value_pair = variable.split "="
17
+ if param_value_pair[0] == "path"
18
+ # TODO: find appropriate method to trim the string
19
+ @path_to_diagram = param_value_pair[1].tr('\"', '')
20
+ elsif param_value_pair[0] == "page_number"
21
+ @selected_diagram_num = param_value_pair[1].to_i
22
+ elsif param_value_pair[0] == "height"
23
+ @diagram_height = param_value_pair[1].to_i
24
+ end
25
+ end
26
+
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
+ "Height: #{ @diagram_height }"
36
+ diagram = diagrams[selected_diagram_num]
37
+
38
+ diagram_name = diagram["name"]
39
+ diagram_content = diagram.content
40
+
41
+ return diagram_name, diagram_content
42
+ end
43
+
44
+ def render(context)
45
+ diagram_name, diagram_content = self.extract_diagram @path_to_diagram, @selected_diagram_num
46
+ encoded_diagram = ERB::Util.url_encode diagram_content
47
+ encoded_diagram_name = ERB::Util.url_encode diagram_name
48
+
49
+ viewer_url_base = "https://viewer.diagrams.net/?highlight=0000ff&edit=_blank&layers=1&nav=1"
50
+ viewer_url = "#{ viewer_url_base }&title=#{ encoded_diagram_name }\#R#{ encoded_diagram }"
51
+ viewer_style = "style=\"width:100%;height:#{ @diagram_height }px\""
52
+
53
+ %Q{<iframe frameborder="0" #{ viewer_style } src="#{ viewer_url }"></iframe>}
54
+ end
55
+
56
+ Liquid::Template.register_tag "drawio", self
57
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module DrawIO
3
+ VERSION = "0.0.5"
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-drawio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Illia Gorbatiuk
@@ -58,7 +58,9 @@ email:
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files: []
61
+ files:
62
+ - lib/jekyll-drawio.rb
63
+ - lib/jekyll-drawio/version.rb
62
64
  homepage: https://github.com/mutcher/jekyll-drawio
63
65
  licenses:
64
66
  - MIT