mini_mindmap 0.1.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -0
- data/CHANGELOG.md +18 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +65 -12
- data/Rakefile +0 -0
- data/_config.yml +1 -0
- data/examples/demo.rb +32 -25
- data/examples/helper.rb +1 -0
- data/examples/mindmap.png +0 -0
- data/lib/mini_mindmap.rb +101 -30
- data/lib/mini_mindmap/utils/deep_merge.rb +34 -0
- data/lib/mini_mindmap/version.rb +1 -1
- data/mini_mindmap.gemspec +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0941fbef61833009099b52dc0561ef6c2672bffd0e5e12ae16a54db7a1aa479d'
|
4
|
+
data.tar.gz: ee55990fa4bced3ce05ff9e69099d806bfc4cb3bf0af5695f5f72501ffa26353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95894edeafb90a53e04bae3429e5b2e0fbcc7bc487d98b8a9d23524396210c9a594055bf5c316f1b6f731d7d8149f3d2b533c506a1facf69ba3216d69665c6d5
|
7
|
+
data.tar.gz: 0cf17b703155452c3252be70afbe622b4440736ed92f5c9f28e74d4f74928ea8856e02ee7a2ed948cbee8e437400182ccd61a2e746371c4ac725276706e483e6
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.4.1
|
2
|
+
|
3
|
+
* Fix name bug.
|
4
|
+
|
5
|
+
## 0.4.0
|
6
|
+
|
7
|
+
* Add Config Field with `node` ,`edge`. You can config fonts sharp etc.
|
8
|
+
* Also support add attrs http://www.graphviz.org/doc/info/attrs.html
|
9
|
+
now we can write config like `** name [color=red]`
|
10
|
+
|
11
|
+
## 0.3.0
|
12
|
+
|
13
|
+
* Change to node style to export dotfile.
|
14
|
+
|
15
|
+
## 0.2.0
|
16
|
+
|
17
|
+
* Export mindmap.
|
18
|
+
|
1
19
|
## 0.1.0
|
2
20
|
|
3
21
|
* Initial gem release of 0.1 codebase.
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# MiniMindmap
|
2
2
|
|
3
|
-
|
3
|
+
## Prepare
|
4
4
|
|
5
|
-
|
5
|
+
You need install graphviz first.
|
6
|
+
|
7
|
+
[graphviz download](http://www.graphviz.org/download/)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,23 +24,74 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
DSL Example
|
26
28
|
|
27
|
-
|
29
|
+
```ruby
|
30
|
+
require "mini_mindmap"
|
31
|
+
|
32
|
+
name = 'mindmap' # filename
|
33
|
+
|
34
|
+
# support add attrs http://www.graphviz.org/doc/info/attrs.html
|
35
|
+
config = {
|
36
|
+
rankdir: "LR",# "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
|
37
|
+
node: {
|
38
|
+
fontname: "wqy-microhei",
|
39
|
+
fontcolor: "black"
|
40
|
+
},
|
41
|
+
edge: {
|
42
|
+
fontname: "wqy-microhei"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
output = {
|
46
|
+
format: 'png',
|
47
|
+
dir: "#{Dir.home}/mindmap" # output dir
|
48
|
+
}
|
49
|
+
|
50
|
+
# online
|
51
|
+
|
52
|
+
dsl = %Q{
|
53
|
+
* MiniMindmap
|
54
|
+
** name
|
55
|
+
** DSL
|
56
|
+
** output
|
57
|
+
*** dir
|
58
|
+
*** format
|
59
|
+
** 汉字测试
|
60
|
+
}
|
61
|
+
|
62
|
+
demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
|
63
|
+
|
64
|
+
demo.export # export files to dir
|
28
65
|
|
29
|
-
|
66
|
+
```
|
67
|
+
output img
|
30
68
|
|
31
|
-
|
69
|
+
![demo.png](https://wx2.sbimg.cn/2020/07/16/CiWr6.png)
|
32
70
|
|
33
|
-
##
|
71
|
+
## Q&A
|
34
72
|
|
35
|
-
|
73
|
+
### Chinese charset code problem
|
36
74
|
|
75
|
+
1. To check fonts. Run `fc-list` or go to `/etc/fonts` to check if you have correct fonts.
|
37
76
|
|
38
|
-
|
77
|
+
2. You may need to install fonts, for example : Chinese font —— 文泉驿。 Run `sudo apt list fonts-wqy-zenhei`
|
78
|
+
3. Make config with correct font name
|
39
79
|
|
40
|
-
|
80
|
+
>
|
81
|
+
```ruby
|
82
|
+
config = {
|
83
|
+
rankdir: "LR",# "TB", "LR", "BT", "RL" direction
|
84
|
+
node: {
|
85
|
+
fontname: "wqy-microhei"
|
86
|
+
},
|
87
|
+
edge: {
|
88
|
+
fontname: "wqy-microhei"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
|
41
93
|
|
42
|
-
|
94
|
+
```
|
95
|
+
## License
|
43
96
|
|
44
|
-
|
97
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
File without changes
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/examples/demo.rb
CHANGED
@@ -1,29 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative "helper.rb"
|
2
|
+
require "mini_mindmap"
|
3
|
+
|
4
|
+
name = 'mindmap' # filename
|
5
|
+
|
6
|
+
# support add attrs http://www.graphviz.org/doc/info/attrs.html
|
7
|
+
config = {
|
8
|
+
rankdir: "LR",# "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
|
9
|
+
node: {
|
10
|
+
fontname: "wqy-microhei",
|
11
|
+
fontcolor: "black"
|
12
|
+
},
|
13
|
+
edge: {
|
14
|
+
fontname: "wqy-microhei"
|
6
15
|
}
|
16
|
+
}
|
17
|
+
output = {
|
18
|
+
format: 'png',
|
19
|
+
dir: "#{Dir.home}/mindmap" # output dir
|
20
|
+
}
|
21
|
+
|
22
|
+
# online
|
7
23
|
|
24
|
+
dsl = %Q{
|
25
|
+
* MiniMindmap
|
26
|
+
** name
|
27
|
+
** DSL
|
28
|
+
** output
|
29
|
+
*** dir
|
30
|
+
*** format
|
31
|
+
** 汉字测试
|
32
|
+
}
|
8
33
|
|
9
|
-
|
10
|
-
* React
|
11
|
-
** 生命周期
|
12
|
-
*** ComponentDidMount
|
13
|
-
**** ComponentWillMount
|
14
|
-
***** AAAComponentWillMount
|
15
|
-
** BBBB
|
16
|
-
*** CCCCC
|
17
|
-
**** DDDD
|
18
|
-
***** FFFF
|
19
|
-
******* KK
|
20
|
-
** OPLL
|
21
|
-
* GO
|
22
|
-
** Woker
|
23
|
-
*** KKKKKLLL
|
24
|
-
* CASIO
|
25
|
-
* KO
|
26
|
-
Mindmap
|
27
|
-
end
|
34
|
+
demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
|
28
35
|
|
29
|
-
|
36
|
+
demo.export # export files to dir
|
data/examples/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
Binary file
|
data/lib/mini_mindmap.rb
CHANGED
@@ -1,75 +1,146 @@
|
|
1
1
|
require "mini_mindmap/version"
|
2
|
+
require "mini_mindmap/utils/deep_merge"
|
3
|
+
require "fileutils"
|
2
4
|
|
3
5
|
module MiniMindmap
|
4
6
|
class Error < StandardError; end
|
5
7
|
|
6
8
|
class Mindmap
|
7
|
-
|
9
|
+
@@compiles_meta = {
|
10
|
+
basic: {
|
11
|
+
id: "basic",
|
12
|
+
description: "basic expression",
|
13
|
+
syntax: /^(\*+)\s+([^\s]*[^\[\]]*)\s*(\[.*\])*\s*$/,
|
14
|
+
processor: "basic_processor",
|
15
|
+
}
|
16
|
+
}
|
17
|
+
def self.compiles_meta
|
18
|
+
@@compiles_meta
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(name, dsl,output={},config={})
|
22
|
+
|
8
23
|
@name = name
|
9
24
|
@dsl = dsl
|
25
|
+
@config = {
|
26
|
+
rankdir: 'LR', # "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
|
27
|
+
node: {},
|
28
|
+
edge: {}
|
29
|
+
}.deep_merge(config)
|
30
|
+
@output = {
|
31
|
+
dir: Dir.home,
|
32
|
+
format: "png"
|
33
|
+
}.deep_merge(output)
|
10
34
|
|
11
35
|
yield(self) if block_given?
|
12
|
-
|
13
|
-
# self.compile
|
14
36
|
end
|
15
37
|
|
16
|
-
attr_accessor(:name, :dsl, :output, :nodes)
|
38
|
+
attr_accessor(:name, :dsl, :config, :output, :nodes, :declares)
|
17
39
|
|
18
|
-
def
|
40
|
+
def compile(code)
|
19
41
|
# TODO 增加拓展语法支持 label等自定义
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
case code.strip
|
43
|
+
when @@compiles_meta[:basic][:syntax]
|
44
|
+
level_prefix = $1
|
45
|
+
content = $2
|
46
|
+
config = $3
|
47
|
+
level = level_prefix.length
|
48
|
+
node = [@@compiles_meta[:basic][:id],level, content]
|
49
|
+
|
50
|
+
if config
|
51
|
+
node.push(config)
|
52
|
+
end
|
53
|
+
|
54
|
+
return node
|
55
|
+
else
|
56
|
+
# pass
|
57
|
+
end
|
28
58
|
end
|
29
59
|
|
30
|
-
def
|
60
|
+
def basic_processor
|
61
|
+
declares = [];
|
31
62
|
nodes = []
|
32
63
|
stack = []
|
33
64
|
dsl = @dsl.split("\n")
|
34
65
|
dsl.each_with_index do |code, current_index|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
66
|
+
|
67
|
+
if not code.strip.empty?
|
68
|
+
current_id = current_index
|
69
|
+
current = self.compile(code)
|
70
|
+
current.unshift(current_id)
|
71
|
+
# [id, type_id, level, content, config]
|
72
|
+
|
73
|
+
|
74
|
+
current_declare = "node#{current_id}[label=\"#{current[3]}\"]";
|
75
|
+
declares.push(current_declare)
|
76
|
+
|
77
|
+
unless stack.empty?
|
78
|
+
top = stack.pop
|
79
|
+
if current[2] > top[2]
|
80
|
+
node_line = "node#{top[0]} -> node#{current[0]}"
|
81
|
+
if current.length >=5
|
82
|
+
node_line += " #{current[4]}"
|
83
|
+
end
|
84
|
+
nodes << node_line
|
85
|
+
stack.push(top)
|
86
|
+
else
|
87
|
+
while (current[2] <= top[2]) and (not stack.empty?)
|
88
|
+
top = stack.pop
|
89
|
+
end
|
90
|
+
if current[2] > top[2]
|
91
|
+
node_line = "node#{top[0]} -> node#{current[0]}"
|
92
|
+
if current.length >=5
|
93
|
+
node_line += " #{current[4]}"
|
94
|
+
end
|
95
|
+
nodes << node_line
|
96
|
+
stack.push top
|
97
|
+
end
|
98
|
+
|
44
99
|
end
|
45
|
-
(nodes << "#{top[1]} -> #{current[1]}") if (current[0] > top[0])
|
46
100
|
end
|
101
|
+
stack.push(current)
|
47
102
|
end
|
48
|
-
stack.push(current)
|
49
103
|
end
|
104
|
+
@declares = declares
|
50
105
|
@nodes = nodes
|
51
106
|
end
|
52
107
|
|
108
|
+
def processor
|
109
|
+
self.send @@compiles_meta[:basic][:processor]
|
110
|
+
end
|
111
|
+
|
53
112
|
def package_nodes
|
54
|
-
"
|
113
|
+
node_config = @config[:node].map {|k,v| "#{k}=\"#{v}\""}.join(",")
|
114
|
+
edge_config = @config[:edge].map {|k,v| "#{k}=\"#{v}\""}.join(",")
|
115
|
+
"digraph \"#{@name}\" {\nrankdir = #{@config[:rankdir]};\nnode [#{node_config}];\nedge [#{edge_config}];\n#{@declares.join("\n")}\n#{@nodes.join("\n")}\n}"
|
55
116
|
end
|
56
117
|
|
57
118
|
def nodes_to_doc
|
58
|
-
File.
|
119
|
+
output_dir = File.absolute_path(@output[:dir])
|
120
|
+
FileUtils::mkdir_p output_dir
|
121
|
+
output_file = File.join(output_dir, "#{@name}.dot")
|
122
|
+
|
123
|
+
File.open("#{output_file}", "w") { |f| f.write(package_nodes) }
|
59
124
|
end
|
60
125
|
|
61
|
-
def
|
62
|
-
self.
|
126
|
+
def run_tasks
|
127
|
+
self.processor
|
63
128
|
self.package_nodes
|
64
129
|
self.nodes_to_doc
|
65
130
|
end
|
66
131
|
|
67
132
|
def export_cmd
|
68
|
-
|
133
|
+
output_dir = @output[:dir]
|
134
|
+
output_file = File.join(output_dir, "#{@name}.#{@output[:format]}")
|
135
|
+
|
136
|
+
output_dotfile = File.join(output_dir, "#{@name}.dot")
|
137
|
+
"dot #{output_dotfile} -T #{@output[:format]} -o #{output_file}"
|
69
138
|
end
|
70
139
|
|
71
140
|
def export
|
141
|
+
self.run_tasks
|
72
142
|
export = self.export_cmd
|
143
|
+
|
73
144
|
puts("[command]: #{export}")
|
74
145
|
`#{export}`
|
75
146
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
5
|
+
#
|
6
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
7
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
8
|
+
#
|
9
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
10
|
+
#
|
11
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
12
|
+
# to merge values:
|
13
|
+
#
|
14
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
15
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
16
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
17
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
18
|
+
def deep_merge(other_hash, &block)
|
19
|
+
dup.deep_merge!(other_hash, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Same as +deep_merge+, but modifies +self+.
|
23
|
+
def deep_merge!(other_hash, &block)
|
24
|
+
merge!(other_hash) do |key, this_val, other_val|
|
25
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
26
|
+
this_val.deep_merge(other_val, &block)
|
27
|
+
elsif block_given?
|
28
|
+
block.call(key, this_val, other_val)
|
29
|
+
else
|
30
|
+
other_val
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/mini_mindmap/version.rb
CHANGED
data/mini_mindmap.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
|
9
9
|
spec.summary = %q{A kind of DSL to generate mindmap.}
|
10
10
|
spec.description = %q{[Experimenting!] A kind of DSL to generate mindmap. Depend on Graphviz.}
|
11
|
-
spec.homepage = "https://github.
|
11
|
+
spec.homepage = "https://mark24code.github.io/mini_mindmap/"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_mindmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark24
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "[Experimenting!] A kind of DSL to generate mindmap. Depend on Graphviz."
|
14
14
|
email:
|
@@ -26,17 +26,21 @@ files:
|
|
26
26
|
- LICENSE.txt
|
27
27
|
- README.md
|
28
28
|
- Rakefile
|
29
|
+
- _config.yml
|
29
30
|
- bin/console
|
30
31
|
- bin/setup
|
31
32
|
- examples/demo.rb
|
33
|
+
- examples/helper.rb
|
34
|
+
- examples/mindmap.png
|
32
35
|
- lib/mini_mindmap.rb
|
36
|
+
- lib/mini_mindmap/utils/deep_merge.rb
|
33
37
|
- lib/mini_mindmap/version.rb
|
34
38
|
- mini_mindmap.gemspec
|
35
|
-
homepage: https://github.
|
39
|
+
homepage: https://mark24code.github.io/mini_mindmap/
|
36
40
|
licenses:
|
37
41
|
- MIT
|
38
42
|
metadata:
|
39
|
-
homepage_uri: https://github.
|
43
|
+
homepage_uri: https://mark24code.github.io/mini_mindmap/
|
40
44
|
source_code_uri: https://github.com/Mark24Code/mini_mindmap
|
41
45
|
changelog_uri: https://github.com/Mark24Code/mini_mindmap/blob/master/CHANGELOG.md
|
42
46
|
post_install_message:
|