mini_mindmap 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +27 -1
- data/examples/demo.rb +21 -26
- data/examples/helper.rb +1 -0
- data/examples/mindmap.png +0 -0
- data/lib/mini_mindmap.rb +67 -28
- data/lib/mini_mindmap/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f406880d5f25e79b0f9c3522afbd2ae7ae75e9da002f71b19443211dbd8271fa
|
4
|
+
data.tar.gz: e53d91bc604687a0fa05fb1d124793d67ce8002ec280ef8dfbd822a046c61ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9213b5bec48e3a74f7ba089d12c139b1bb88dd33dc2c3bbd728a2a9bf37c46a1bcb98811008e96fe74cb8b647fd316de04468e2eb1a09ee6b9ea100307bb122
|
7
|
+
data.tar.gz: e290f4c98f793e96495d5262cb99ec03dc6653e927c1703436ae925812d0d0ba7a527de7ae7c19d3b3439e6ce7fbc4cb7b8709cc0a8fffec721eda68b2cc66b7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,8 +22,34 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
DSL Example
|
26
26
|
|
27
|
+
```ruby
|
28
|
+
require "mini_mindmap"
|
29
|
+
|
30
|
+
name = 'mindmap' # filename
|
31
|
+
|
32
|
+
output = {
|
33
|
+
format: 'png',
|
34
|
+
dir: "#{Dir.home}/mindmap" # output dir
|
35
|
+
}
|
36
|
+
|
37
|
+
# online
|
38
|
+
|
39
|
+
dsl = %Q{
|
40
|
+
* MiniMindmap
|
41
|
+
** name
|
42
|
+
** DSL
|
43
|
+
** output
|
44
|
+
*** dir
|
45
|
+
*** format
|
46
|
+
}
|
47
|
+
|
48
|
+
demo = MiniMindmap::Mindmap.new(name,dsl,output)
|
49
|
+
|
50
|
+
demo.export # export files to dir
|
51
|
+
|
52
|
+
```
|
27
53
|
## Development
|
28
54
|
|
29
55
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/examples/demo.rb
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
m.output = {
|
4
|
-
format: 'png',
|
5
|
-
dir: './out'
|
6
|
-
}
|
1
|
+
require_relative "helper.rb"
|
2
|
+
require "mini_mindmap"
|
7
3
|
|
4
|
+
name = 'mindmap' # filename
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
6
|
+
output = {
|
7
|
+
format: 'png',
|
8
|
+
dir: "#{Dir.home}/mindmap" # output dir
|
9
|
+
}
|
28
10
|
|
29
|
-
|
11
|
+
# online
|
12
|
+
|
13
|
+
dsl = %Q{
|
14
|
+
* MiniMindmap
|
15
|
+
** name
|
16
|
+
** DSL
|
17
|
+
** output
|
18
|
+
*** dir
|
19
|
+
*** format
|
20
|
+
}
|
21
|
+
|
22
|
+
demo = MiniMindmap::Mindmap.new(name,dsl,output)
|
23
|
+
|
24
|
+
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,114 @@
|
|
1
1
|
require "mini_mindmap/version"
|
2
|
+
require "fileutils"
|
2
3
|
|
3
4
|
module MiniMindmap
|
4
5
|
class Error < StandardError; end
|
5
6
|
|
6
7
|
class Mindmap
|
7
|
-
|
8
|
+
@@compiles_meta = {
|
9
|
+
basic: {
|
10
|
+
id: "basic",
|
11
|
+
description: "basic expression",
|
12
|
+
syntax: /^(\*+)\s+([^\s]+.*)$/,
|
13
|
+
processor: "basic_processor",
|
14
|
+
}
|
15
|
+
}
|
16
|
+
def self.compiles_meta
|
17
|
+
@@compiles_meta
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(name, dsl, output=nil)
|
21
|
+
|
8
22
|
@name = name
|
9
23
|
@dsl = dsl
|
24
|
+
@output = output || {
|
25
|
+
dir: Dir.home,
|
26
|
+
format: "png"
|
27
|
+
}
|
10
28
|
|
11
29
|
yield(self) if block_given?
|
12
|
-
|
13
|
-
# self.compile
|
14
30
|
end
|
15
31
|
|
16
32
|
attr_accessor(:name, :dsl, :output, :nodes)
|
17
33
|
|
18
|
-
def
|
34
|
+
def compile(code)
|
19
35
|
# TODO 增加拓展语法支持 label等自定义
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
case code.strip
|
37
|
+
when @@compiles_meta[:basic][:syntax]
|
38
|
+
level_prefix = $1
|
39
|
+
content = $2
|
40
|
+
level = level_prefix.length
|
41
|
+
node = [@@compiles_meta[:basic][:id],level, content]
|
42
|
+
else
|
43
|
+
# pass
|
44
|
+
end
|
28
45
|
end
|
29
46
|
|
30
|
-
def
|
47
|
+
def basic_processor
|
31
48
|
nodes = []
|
32
49
|
stack = []
|
33
50
|
dsl = @dsl.split("\n")
|
34
51
|
dsl.each_with_index do |code, current_index|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
stack.
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
|
53
|
+
if not code.strip.empty?
|
54
|
+
current = self.compile(code)
|
55
|
+
|
56
|
+
unless stack.empty?
|
57
|
+
top = stack.pop
|
58
|
+
if current[1] > top[1]
|
59
|
+
nodes << "#{top[2]} -> #{current[2]}"
|
60
|
+
stack.push(top)
|
61
|
+
else
|
62
|
+
while (current[1] <= top[1]) and (not stack.empty?)
|
63
|
+
top = stack.pop
|
64
|
+
end
|
65
|
+
if current[1] > top[1]
|
66
|
+
nodes << "#{top[2]} -> #{current[2]}"
|
67
|
+
stack.push top
|
68
|
+
end
|
69
|
+
|
44
70
|
end
|
45
|
-
(nodes << "#{top[1]} -> #{current[1]}") if (current[0] > top[0])
|
46
71
|
end
|
72
|
+
stack.push(current)
|
47
73
|
end
|
48
|
-
stack.push(current)
|
49
74
|
end
|
50
75
|
@nodes = nodes
|
51
76
|
end
|
52
77
|
|
78
|
+
def processor
|
79
|
+
self.send @@compiles_meta[:basic][:processor]
|
80
|
+
end
|
81
|
+
|
53
82
|
def package_nodes
|
54
83
|
"digraph #{@name} {\n#{@nodes.join("\n")}\n}"
|
55
84
|
end
|
56
85
|
|
57
86
|
def nodes_to_doc
|
58
|
-
File.
|
87
|
+
output_dir = File.absolute_path(@output[:dir])
|
88
|
+
FileUtils::mkdir_p output_dir
|
89
|
+
output_file = File.join(output_dir, "#{@name}.dot")
|
90
|
+
|
91
|
+
File.open("#{output_file}", "w") { |f| f.write(package_nodes) }
|
59
92
|
end
|
60
93
|
|
61
|
-
def
|
62
|
-
self.
|
94
|
+
def run_tasks
|
95
|
+
self.processor
|
63
96
|
self.package_nodes
|
64
97
|
self.nodes_to_doc
|
65
98
|
end
|
66
99
|
|
67
100
|
def export_cmd
|
68
|
-
|
101
|
+
output_dir = @output[:dir]
|
102
|
+
output_file = File.join(output_dir, "#{@name}.#{@output[:format]}")
|
103
|
+
|
104
|
+
output_dotfile = File.join(output_dir, "#{@name}.dot")
|
105
|
+
"dot #{output_dotfile} -T #{@output[:format]} -o #{output_file}"
|
69
106
|
end
|
70
107
|
|
71
108
|
def export
|
109
|
+
self.run_tasks
|
72
110
|
export = self.export_cmd
|
111
|
+
|
73
112
|
puts("[command]: #{export}")
|
74
113
|
`#{export}`
|
75
114
|
end
|
data/lib/mini_mindmap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_mindmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark24
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- bin/console
|
30
30
|
- bin/setup
|
31
31
|
- examples/demo.rb
|
32
|
+
- examples/helper.rb
|
33
|
+
- examples/mindmap.png
|
32
34
|
- lib/mini_mindmap.rb
|
33
35
|
- lib/mini_mindmap/version.rb
|
34
36
|
- mini_mindmap.gemspec
|