tree_html 0.1.9 → 0.1.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20504c724cbd2859c9bfc6c6235f17cabd109932adc86ed84ee60f2549e540e5
4
- data.tar.gz: 4b2f5d2ca583f0f79d6ba403f1e566966ba3a582ae1d8a507d72c66a74d51aa6
3
+ metadata.gz: 1c5567586e5ba48d99e6bfea031f5c43795b6c78166af1a386405f89fde58ac2
4
+ data.tar.gz: 0653e2bf6e13d584a92781a3285c882f5a610fa598a21139c88aa2cff8c8d4b7
5
5
  SHA512:
6
- metadata.gz: 21139d38408d2be9a12e9f1e0b7396a6371568d7467d780827935248c959ada040613e0c801e8e74e5cb1f4982ad87edc6b00c98027d86b461d51ecc488c95ef
7
- data.tar.gz: a6d3e49ee00f675c8acd0a5ee89c7555c1fb4ef8805aa82a4c89fd8d7d85814fc5bf12414173e3237b091059b0ac08a434b0cb2cf4692d8120b0563d154a5bdf
6
+ metadata.gz: d405b3211570e877137fe534bec36f059784ba11e7522ab09d7018f3abf4495912fc9a55f069d4fd48bb3cbf2361349ea5ab8c38e17b891afb16a35534e86f20
7
+ data.tar.gz: 4db190bfc3b7621d805c558fc10d497da71f957c322e1ec6ac4288584a1345f88cc1d2a258049c883eba8f9b9b32a4fc09efd9b8d8c8f06ae60d2918e5abb1c7
data/README.md CHANGED
@@ -30,7 +30,13 @@ By Default, any object can be leaf, and renders as `to_s`.
30
30
 
31
31
  You may overwrite `data_for_tree_html`, `head_js_for_tree_html`, `body_js_for_tree_html`, `css_for_tree_html` to specify your own style.
32
32
 
33
- In generated html, hover a branch and press `f`/`u` to fold/unfold it's children, press `p`/`n` to jump to it's previous/next sibling branch. You may change these function keys in `body_js_for_tree_html`.
33
+ In generated html, hover a branch and
34
+
35
+ - press `f`/`u` to fold/unfold it's children
36
+ - press `p`/`n` to jump to it's previous/next sibling branch
37
+ - press `a` to print ascii tree in console
38
+
39
+ You may change these function keys in `body_js_for_tree_html`.
34
40
 
35
41
  Or checkout [test/tree_html_test.rb](https://github.com/turnon/tree_html/blob/master/test/tree_html_test.rb) to see how to use.
36
42
 
@@ -76,7 +76,50 @@ var TreeHtml = (function(){
76
76
  twinkle(li.querySelector('a'), 6);
77
77
  }
78
78
 
79
+
80
+ function ascii(li) {
81
+ let lines = []
82
+ function add_line(prefix, text) {
83
+ if (lines.length) lines.push('\n')
84
+ prefix = replace_branchs(prefix)
85
+ lines = lines.concat(prefix)
86
+ lines.push(' ')
87
+ lines.push(text)
88
+ }
89
+
90
+ function replace_branchs(array){
91
+ if (array.length === 0) return [];
92
+ let arr = array.map(ele => { return (ele === ' ├─' || ele === ' │ ') && ' │ ' || ' ' })
93
+ arr[array.length - 1] = array[array.length - 1]
94
+ return arr
95
+ }
96
+
97
+ function walk(li, prefix) {
98
+ let a = li.querySelector('a')
99
+ let checkbox = a.previousSibling.previousSibling
100
+ let fold = checkbox && (checkbox.checked && '+' || '-') || ' '
101
+ let text = a.innerText
102
+ add_line(prefix, fold + ' ' + text)
103
+
104
+ if (!checkbox || checkbox.checked) return
105
+ let ul = li.querySelector('ul')
106
+ if (ul === null) return
107
+ let i = 1
108
+ ul.childNodes.forEach(child => {
109
+ let branch = ul.childNodes.length === i ? ' └─' : ' ├─'
110
+ prefix.push(branch)
111
+ walk(child, prefix)
112
+ prefix.pop()
113
+ i = i + 1
114
+ })
115
+ }
116
+
117
+ walk(li, [])
118
+ console.log(lines.join(''))
119
+ }
120
+
79
121
  var actions = {
122
+ ascii: ascii,
80
123
  fold: function(node) {
81
124
  check_children(node, true);
82
125
  },
@@ -93,7 +136,7 @@ var TreeHtml = (function(){
93
136
  }
94
137
  };
95
138
 
96
- var key_cmds = {f: 'fold', u: 'unfold', p: 'prev', n: 'next'};
139
+ var key_cmds = {f: 'fold', u: 'unfold', p: 'prev', n: 'next', a: 'ascii'};
97
140
 
98
141
  var resp_keypress = [function(e) {
99
142
  e = e || window.event;
@@ -1,3 +1,3 @@
1
1
  module TreeHtml
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-27 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.0.3
95
+ rubygems_version: 3.1.6
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: generate plain css tree structure