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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03611e87e07f7d586a6f0338a57d671e476d67e7dbc727d9977bdb0f5876ed48
4
- data.tar.gz: cb861ebcadcf43ea70e463063425b7ef4fb14e247880edc8a1e98490bd4cb985
3
+ metadata.gz: f406880d5f25e79b0f9c3522afbd2ae7ae75e9da002f71b19443211dbd8271fa
4
+ data.tar.gz: e53d91bc604687a0fa05fb1d124793d67ce8002ec280ef8dfbd822a046c61ce0
5
5
  SHA512:
6
- metadata.gz: 1bf82626bfe580a51e38d55a1b3cbd61d5f160d5b55e1d8e81f885ad331b37b831d2f688f5e9d061389b80ab6361a3da747b30fdf569f111de133d64f0be728e
7
- data.tar.gz: 9d980a34bc29f60afcee9b87f671b2d3bafc9938dfa3a728b71a605d88f520f95a1e458f41317e05a0db043816116a258a5decb4cdc4806d599bce62b6d9b399
6
+ metadata.gz: e9213b5bec48e3a74f7ba089d12c139b1bb88dd33dc2c3bbd728a2a9bf37c46a1bcb98811008e96fe74cb8b647fd316de04468e2eb1a09ee6b9ea100307bb122
7
+ data.tar.gz: e290f4c98f793e96495d5262cb99ec03dc6653e927c1703436ae925812d0d0ba7a527de7ae7c19d3b3439e6ce7fbc4cb7b8709cc0a8fffec721eda68b2cc66b7
@@ -1,3 +1,7 @@
1
+ ## 0.2.0
2
+
3
+ * Export mindmap
4
+
1
5
  ## 0.1.0
2
6
 
3
7
  * Initial gem release of 0.1 codebase.
data/README.md CHANGED
@@ -22,8 +22,34 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
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.
@@ -1,29 +1,24 @@
1
- react_mind = RubyMindmap::Mindmap.new do |m|
2
- m.name = 'React'
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
- m.dsl = <<-Mindmap
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
6
+ output = {
7
+ format: 'png',
8
+ dir: "#{Dir.home}/mindmap" # output dir
9
+ }
28
10
 
29
- react_mind.export
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
@@ -0,0 +1 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
Binary file
@@ -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
- def initialize(name, dsl)
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 node(code)
34
+ def compile(code)
19
35
  # TODO 增加拓展语法支持 label等自定义
20
- # 同步Test也要更新
21
- node_express = /^(\*+)\s+([^\s]+.*)$/
22
- node_express =~ code.strip
23
-
24
- level_prefix = $1
25
- content = $2
26
- level = level_prefix.length
27
- node = [level, content]
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 dsl_to_nodes
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
- current = self.node(code)
36
- unless stack.empty?
37
- top = stack.pop
38
- if (current[0] > top[0])
39
- (nodes << "#{top[1]} -> #{current[1]}")
40
- stack.push(top)
41
- else
42
- while (current[0] <= top[0]) and (not stack.empty?)
43
- top = stack.pop
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.open("#{@name}.dot", "w") { |f| f.write(package_nodes) }
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 compile
62
- self.dsl_to_nodes
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
- "dot #{@name}.dot -T #{@output[:format]} -o #{@name}.#{@output[:format]}"
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
@@ -1,3 +1,3 @@
1
1
  module MiniMindmap
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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