visual_call_html 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/html.rb +64 -0
  3. data/lib/tracer.rb +44 -0
  4. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef3222b170ff9c8d84ef68316682389631dadaa7024b76c8f844f5f09ceb002f
4
- data.tar.gz: 9a6b9c8f25f93eb4030b32d48cb547c4034a89ed0147e7e3d46a453097402cc4
3
+ metadata.gz: e96daf1a114a7e4494c69aeebc4c552a7f560d350038b8aaab38a2bc553a278a
4
+ data.tar.gz: f4c998648e348ab0b482cce29b22528a7b7a7ced809006caf762d6284de037ea
5
5
  SHA512:
6
- metadata.gz: fbc947f31caf6ac24b237f84054ec48005939fd306233e0dbe670c6f615f512a34a7b6c71e61eb4bcf83a64a56ce2c26fc919e8de4527d46ab26ed57a2beb701
7
- data.tar.gz: 03ca4e92d7210b37484e70f7e1af5907af5a80688ed777525115762321394b6c751efdd7bb8980c2dcd29ea5c4876360fc3ccd2529d106364fc0d4ec2a1a3d02
6
+ metadata.gz: ed609ffe7b768f7444a0b0ae41badb45e0124af8e57ac83e9c6b6ba4a6235ff4e0cf183c87dc975dde201242377c1626f32bf9c60a8382c67bb2fddaae536672
7
+ data.tar.gz: 95b11f7e4bf22346369b30242fe1dead75bf1858017d50f8531b3690407533d8a160bd4f63f6ab4f4b062a09252a4c3ed72bc812f52fb8da140532d82d423540
@@ -0,0 +1,64 @@
1
+ require 'json'
2
+
3
+ class Html
4
+ def initialize data
5
+ @data = data.to_json
6
+ end
7
+
8
+ def print
9
+ File.write("#{Dir.pwd}/docx.html", doc)
10
+ end
11
+
12
+ private
13
+
14
+ def doc
15
+ <<-HTML
16
+ <!DOCTYPE html>
17
+ <html>
18
+ <head>
19
+ <script src="https://cdn.jsdelivr.net/npm/gojs/release/go.js">
20
+ </script>
21
+ <style>
22
+ * {
23
+ margin: 0;
24
+ padding: 0;
25
+ }
26
+ html, body, #myDiagramDiv {
27
+ width: 100%;
28
+ height: 100%;
29
+ }
30
+ body {
31
+ overflow: hidden;
32
+ }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <div id="myDiagramDiv"></div>
37
+ <script>
38
+ var $ = go.GraphObject.make;
39
+ var myDiagram =
40
+ $(go.Diagram, "myDiagramDiv",
41
+ {
42
+ "undoManager.isEnabled": true,
43
+ layout: $(go.TreeLayout, // specify a Diagram.layout that arranges trees
44
+ { angle: 90, layerSpacing: 35 })
45
+ });
46
+
47
+ // the template we defined earlier
48
+ myDiagram.nodeTemplate =
49
+ $(go.Node, "Horizontal",
50
+ { background: "#44CCFF" },
51
+ $(go.TextBlock, "Default Text",
52
+ { margin: 12, stroke: "white", font: "bold 16px sans-serif" },
53
+ new go.Binding("text", "text"))
54
+ );
55
+
56
+ var model = $(go.TreeModel);
57
+ model.nodeDataArray = JSON.parse('#{@data}')
58
+ myDiagram.model = model;
59
+ </script>
60
+ </body>
61
+ </html>
62
+ HTML
63
+ end
64
+ end
@@ -0,0 +1,44 @@
1
+ class Tracer
2
+ attr_reader :path, :data
3
+
4
+ def initialize
5
+ @trace = build_tracer
6
+ @path = []
7
+ @data = []
8
+ end
9
+
10
+ def enable
11
+ @trace.enable
12
+ end
13
+
14
+ def disable
15
+ @trace.disable
16
+ end
17
+
18
+ private
19
+
20
+ def uniq_key
21
+ rand(1..1_000).to_s + Time.now.to_f.to_s
22
+ end
23
+
24
+ def build_tracer
25
+ TracePoint.new(:call, :return) do |event|
26
+ next if event.defined_class == self.class
27
+
28
+ case event.event
29
+ when :return
30
+ event.return_value && @data.push(
31
+ key: uniq_key,
32
+ parent: @path.last,
33
+ text: "Return: #{event.return_value}"
34
+ )
35
+ @path.pop
36
+ when :call
37
+ key = uniq_key
38
+ data = { key: key, parent: @path.last, text: event.method_id }.compact
39
+ @data.push(data)
40
+ @path.push(key)
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visual_call_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hungkieu
@@ -17,6 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - lib/html.rb
21
+ - lib/tracer.rb
20
22
  - lib/visual_call_html.rb
21
23
  homepage:
22
24
  licenses: []