mini_mindmap 0.3.1 → 0.6.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: cf3019409b24f81143cb4efc1c1cbfbf344063c866f900d90e08f24a246eef41
4
- data.tar.gz: 326c75b84b04b27e01d5e42bc03f1fc8437f6b2befa09707b09219b8b624cfa5
3
+ metadata.gz: 2b143ee9e9001990d4274b842a7cd910259f997072d14e2cb62e7bb04d7c5486
4
+ data.tar.gz: 7f19f9a4bc3c4e74903ef01a78307be609bf1bf93db6b6026c7d9e1e00651ff1
5
5
  SHA512:
6
- metadata.gz: a865dc6855c61c3b05bb3684696d7a364d4872d0f0466cafe26b7167edc148117347416c08eabe69f6623ed52017e5102e7d61dff5fcb1f225f74746c30f0b9e
7
- data.tar.gz: e8f2b6fc5f239955850a1483a6061317c53589df578ed8d836b2b74e57cdc557374279f72fe3045f4f52c4296aa3aa1975fbd1179d8135c6cf5ad0d6a0dcba18
6
+ metadata.gz: e869b5f69da282dabe8add02ad4dc2f67b8a2d57fea6ea38e78295e5ff20421371d5d48e3764c86e4770253eea32df3d4f39c2ba9fed34cff6031c4f6a9c5902
7
+ data.tar.gz: 98d59b6b3a98a878aca95497cffbdc3b285591be03d727d34758fd7a101d4c57ca46c769058d134994e1096ec2233384665b0cf85c664f19ba71517d7b080180
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
File without changes
@@ -1,3 +1,22 @@
1
+ ## 0.6.0
2
+
3
+ * Remove Markdown title support syntax
4
+
5
+ ## 0.5.0
6
+
7
+ * Add annotion syntax
8
+ * Add markdown title support syntax
9
+
10
+ ## 0.4.1
11
+
12
+ * Fix name bug.
13
+
14
+ ## 0.4.0
15
+
16
+ * Add Config Field with `node` ,`edge`. You can config fonts sharp etc.
17
+ * Also support add attrs http://www.graphviz.org/doc/info/attrs.html
18
+ now we can write config like `** name [color=red]`
19
+
1
20
  ## 0.3.0
2
21
 
3
22
  * Change to node style to export dotfile.
File without changes
data/Gemfile CHANGED
File without changes
File without changes
File without changes
data/README.md CHANGED
@@ -22,6 +22,28 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install mini_mindmap
24
24
 
25
+ ## Syntax
26
+
27
+ PlantUML Mindmap Syntax
28
+
29
+ ```
30
+
31
+ * Subject
32
+ ** Foo
33
+ ** Bar
34
+
35
+ ```
36
+
37
+ Suppo Annotation with //
38
+
39
+ ```
40
+
41
+ // one line annotation
42
+
43
+ ** Foo // you can add annotation here too
44
+
45
+ ```
46
+
25
47
  ## Usage
26
48
 
27
49
  DSL Example
@@ -31,6 +53,17 @@ require "mini_mindmap"
31
53
 
32
54
  name = 'mindmap' # filename
33
55
 
56
+ # support add attrs http://www.graphviz.org/doc/info/attrs.html
57
+ config = {
58
+ rankdir: "LR",# "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
59
+ node: {
60
+ fontname: "wqy-microhei",
61
+ fontcolor: "black"
62
+ },
63
+ edge: {
64
+ fontname: "wqy-microhei"
65
+ }
66
+ }
34
67
  output = {
35
68
  format: 'png',
36
69
  dir: "#{Dir.home}/mindmap" # output dir
@@ -45,9 +78,10 @@ dsl = %Q{
45
78
  ** output
46
79
  *** dir
47
80
  *** format
81
+ ** 汉字测试
48
82
  }
49
83
 
50
- demo = MiniMindmap::Mindmap.new(name,dsl,output)
84
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
51
85
 
52
86
  demo.export # export files to dir
53
87
 
@@ -56,6 +90,30 @@ output img
56
90
 
57
91
  ![demo.png](https://wx2.sbimg.cn/2020/07/16/CiWr6.png)
58
92
 
93
+ ## Q&A
94
+
95
+ ### Chinese charset code problem
96
+
97
+ 1. To check fonts. Run `fc-list` or go to `/etc/fonts` to check if you have correct fonts.
98
+
99
+ 2. You may need to install fonts, for example : Chinese font —— 文泉驿。 Run `sudo apt list fonts-wqy-zenhei`
100
+ 3. Make config with correct font name
101
+
102
+ >
103
+ ```ruby
104
+ config = {
105
+ rankdir: "LR",# "TB", "LR", "BT", "RL" direction
106
+ node: {
107
+ fontname: "wqy-microhei"
108
+ },
109
+ edge: {
110
+ fontname: "wqy-microhei"
111
+ }
112
+ }
113
+
114
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
115
+
116
+ ```
59
117
  ## License
60
118
 
61
119
  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
File without changes
@@ -3,6 +3,17 @@ require "mini_mindmap"
3
3
 
4
4
  name = 'mindmap' # filename
5
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"
15
+ }
16
+ }
6
17
  output = {
7
18
  format: 'png',
8
19
  dir: "#{Dir.home}/mindmap" # output dir
@@ -11,14 +22,15 @@ output = {
11
22
  # online
12
23
 
13
24
  dsl = %Q{
14
- * MiniMindmap
15
- ** name
16
- ** DSL
25
+ # MiniMindmap
26
+ ## name [color=red]
27
+ ** DSL // this is annotion
17
28
  ** output
18
29
  *** dir
19
30
  *** format
31
+ ** 汉字测试
20
32
  }
21
33
 
22
- demo = MiniMindmap::Mindmap.new(name,dsl,output)
34
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
23
35
 
24
- demo.export # export files to dir
36
+ demo.export # export files to dir
File without changes
File without changes
@@ -1,4 +1,5 @@
1
1
  require "mini_mindmap/version"
2
+ require "mini_mindmap/utils/deep_merge"
2
3
  require "fileutils"
3
4
 
4
5
  module MiniMindmap
@@ -9,27 +10,38 @@ module MiniMindmap
9
10
  basic: {
10
11
  id: "basic",
11
12
  description: "basic expression",
12
- syntax: /^(\*+)\s+([^\s]+.*)$/,
13
+ syntax: /^(\*+)\s+([^\s]*[^\[\]]*)\s*(\[.*\])*\s*(\/\/.*)*\s*$/,
13
14
  processor: "basic_processor",
15
+ },
16
+ annotation: {
17
+ id: "annotation",
18
+ description: "annotation expression",
19
+ syntax: /^\s*\/\/.*\s*/,
20
+ processor: "annotation_processor",
14
21
  }
15
22
  }
16
23
  def self.compiles_meta
17
24
  @@compiles_meta
18
25
  end
19
26
 
20
- def initialize(name, dsl, output=nil)
27
+ def initialize(name, dsl,output={},config={})
21
28
 
22
29
  @name = name
23
30
  @dsl = dsl
24
- @output = output || {
31
+ @config = {
32
+ rankdir: 'LR', # "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
33
+ node: {},
34
+ edge: {}
35
+ }.deep_merge(config)
36
+ @output = {
25
37
  dir: Dir.home,
26
38
  format: "png"
27
- }
39
+ }.deep_merge(output)
28
40
 
29
41
  yield(self) if block_given?
30
42
  end
31
43
 
32
- attr_accessor(:name, :dsl, :output, :nodes, :declares)
44
+ attr_accessor(:name, :dsl, :config, :output, :nodes, :declares)
33
45
 
34
46
  def compile(code)
35
47
  # TODO 增加拓展语法支持 label等自定义
@@ -37,10 +49,19 @@ module MiniMindmap
37
49
  when @@compiles_meta[:basic][:syntax]
38
50
  level_prefix = $1
39
51
  content = $2
52
+ config = $3
40
53
  level = level_prefix.length
41
54
  node = [@@compiles_meta[:basic][:id],level, content]
55
+
56
+ if config
57
+ node.push(config)
58
+ end
59
+
60
+ return node
61
+ when @@compiles_meta[:annotation][:syntax]
62
+ # pass annotation
42
63
  else
43
- # pass
64
+ # rest pass
44
65
  end
45
66
  end
46
67
 
@@ -54,23 +75,35 @@ module MiniMindmap
54
75
  if not code.strip.empty?
55
76
  current_id = current_index
56
77
  current = self.compile(code)
57
- current << current_id
78
+ if not current
79
+ next
80
+ end
81
+ current.unshift(current_id)
82
+ # [id, type_id, level, content, config]
58
83
 
59
84
 
60
- current_declare = "node#{current_id}[label=\"#{current[2]}\"]";
85
+ current_declare = "node#{current_id}[label=\"#{current[3]}\"]";
61
86
  declares.push(current_declare)
62
87
 
63
88
  unless stack.empty?
64
89
  top = stack.pop
65
- if current[1] > top[1]
66
- nodes << "node#{top[3]} -> node#{current[3]}"
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
67
96
  stack.push(top)
68
97
  else
69
- while (current[1] <= top[1]) and (not stack.empty?)
98
+ while (current[2] <= top[2]) and (not stack.empty?)
70
99
  top = stack.pop
71
100
  end
72
- if current[1] > top[1]
73
- nodes << "node#{top[3]} -> node#{current[3]}"
101
+ if current[2] > top[2]
102
+ node_line = "node#{top[0]} -> node#{current[0]}"
103
+ if current.length >=5
104
+ node_line += " #{current[4]}"
105
+ end
106
+ nodes << node_line
74
107
  stack.push top
75
108
  end
76
109
 
@@ -88,7 +121,9 @@ module MiniMindmap
88
121
  end
89
122
 
90
123
  def package_nodes
91
- "digraph #{@name} {\n#{@declares.join("\n")}\n#{@nodes.join("\n")}\n}"
124
+ node_config = @config[:node].map {|k,v| "#{k}=\"#{v}\""}.join(",")
125
+ edge_config = @config[:edge].map {|k,v| "#{k}=\"#{v}\""}.join(",")
126
+ "digraph \"#{@name}\" {\nrankdir = #{@config[:rankdir]};\nnode [#{node_config}];\nedge [#{edge_config}];\n#{@declares.join("\n")}\n#{@nodes.join("\n")}\n}"
92
127
  end
93
128
 
94
129
  def nodes_to_doc
@@ -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
@@ -1,3 +1,3 @@
1
1
  module MiniMindmap
2
- VERSION = "0.3.1"
2
+ VERSION = "0.6.0"
3
3
  end
File without changes
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.3.1
4
+ version: 0.6.0
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-16 00:00:00.000000000 Z
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:
@@ -33,6 +33,7 @@ files:
33
33
  - examples/helper.rb
34
34
  - examples/mindmap.png
35
35
  - lib/mini_mindmap.rb
36
+ - lib/mini_mindmap/utils/deep_merge.rb
36
37
  - lib/mini_mindmap/version.rb
37
38
  - mini_mindmap.gemspec
38
39
  homepage: https://mark24code.github.io/mini_mindmap/