tree_html 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/tree_html/shortkey.js +44 -1
- data/lib/tree_html/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5567586e5ba48d99e6bfea031f5c43795b6c78166af1a386405f89fde58ac2
|
4
|
+
data.tar.gz: 0653e2bf6e13d584a92781a3285c882f5a610fa598a21139c88aa2cff8c8d4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
data/lib/tree_html/shortkey.js
CHANGED
@@ -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;
|
data/lib/tree_html/version.rb
CHANGED
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.
|
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-
|
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.
|
95
|
+
rubygems_version: 3.1.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: generate plain css tree structure
|