mini_mindmap 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf3019409b24f81143cb4efc1c1cbfbf344063c866f900d90e08f24a246eef41
4
- data.tar.gz: 326c75b84b04b27e01d5e42bc03f1fc8437f6b2befa09707b09219b8b624cfa5
3
+ metadata.gz: 505731f94e3e881738b651e252af499f1294d4e506368bc6437cd4ef2a738428
4
+ data.tar.gz: 9f6686c9da9993c3e45a9db0ddfc32e09291259939a2c08c27e6ded6934e2ca2
5
5
  SHA512:
6
- metadata.gz: a865dc6855c61c3b05bb3684696d7a364d4872d0f0466cafe26b7167edc148117347416c08eabe69f6623ed52017e5102e7d61dff5fcb1f225f74746c30f0b9e
7
- data.tar.gz: e8f2b6fc5f239955850a1483a6061317c53589df578ed8d836b2b74e57cdc557374279f72fe3045f4f52c4296aa3aa1975fbd1179d8135c6cf5ad0d6a0dcba18
6
+ metadata.gz: d8214b9ab884d7e596d280088efc6ba2dc7da7dc98b0c0a0bea5a367bc4c9746e416edaa3a8293b7c44ccc8d11ec9cf9d772f9b4846be9497fec49a78bcdfe10
7
+ data.tar.gz: 9e648756a7ae10e6903c25cca1bafbaa9feb3ad1e2721b7aa93effbe73148857b98ea95ebb359cea9bbe53ab9b081275348cf54cddd8ee2cf38e24fccb04e039
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,7 @@
1
+ ## 0.4.0
2
+
3
+ * Add Config Field with `node` ,`edge`. You can config fonts sharp etc.
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  * 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
@@ -31,6 +31,17 @@ require "mini_mindmap"
31
31
 
32
32
  name = 'mindmap' # filename
33
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
+ }
34
45
  output = {
35
46
  format: 'png',
36
47
  dir: "#{Dir.home}/mindmap" # output dir
@@ -45,9 +56,10 @@ dsl = %Q{
45
56
  ** output
46
57
  *** dir
47
58
  *** format
59
+ ** 汉字测试
48
60
  }
49
61
 
50
- demo = MiniMindmap::Mindmap.new(name,dsl,output)
62
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
51
63
 
52
64
  demo.export # export files to dir
53
65
 
@@ -56,6 +68,30 @@ output img
56
68
 
57
69
  ![demo.png](https://wx2.sbimg.cn/2020/07/16/CiWr6.png)
58
70
 
71
+ ## Q&A
72
+
73
+ ### Chinese charset code problem
74
+
75
+ 1. To check fonts. Run `fc-list` or go to `/etc/fonts` to check if you have correct fonts.
76
+
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
79
+
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)
93
+
94
+ ```
59
95
  ## License
60
96
 
61
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
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
@@ -17,8 +28,9 @@ dsl = %Q{
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,7 +10,7 @@ module MiniMindmap
9
10
  basic: {
10
11
  id: "basic",
11
12
  description: "basic expression",
12
- syntax: /^(\*+)\s+([^\s]+.*)$/,
13
+ syntax: /^(\*+)\s+([^\s]*[^\[\]]*)\s*(\[.*\])*\s*$/,
13
14
  processor: "basic_processor",
14
15
  }
15
16
  }
@@ -17,19 +18,24 @@ module MiniMindmap
17
18
  @@compiles_meta
18
19
  end
19
20
 
20
- def initialize(name, dsl, output=nil)
21
+ def initialize(name, dsl,output={},config={})
21
22
 
22
23
  @name = name
23
24
  @dsl = dsl
24
- @output = output || {
25
+ @config = {
26
+ rankdir: 'LR', # "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
27
+ node: {},
28
+ edge: {}
29
+ }.deep_merge(config)
30
+ @output = {
25
31
  dir: Dir.home,
26
32
  format: "png"
27
- }
33
+ }.deep_merge(output)
28
34
 
29
35
  yield(self) if block_given?
30
36
  end
31
37
 
32
- attr_accessor(:name, :dsl, :output, :nodes, :declares)
38
+ attr_accessor(:name, :dsl, :config, :output, :nodes, :declares)
33
39
 
34
40
  def compile(code)
35
41
  # TODO 增加拓展语法支持 label等自定义
@@ -37,8 +43,15 @@ module MiniMindmap
37
43
  when @@compiles_meta[:basic][:syntax]
38
44
  level_prefix = $1
39
45
  content = $2
46
+ config = $3
40
47
  level = level_prefix.length
41
48
  node = [@@compiles_meta[:basic][:id],level, content]
49
+
50
+ if config
51
+ node.push(config)
52
+ end
53
+
54
+ return node
42
55
  else
43
56
  # pass
44
57
  end
@@ -54,23 +67,32 @@ module MiniMindmap
54
67
  if not code.strip.empty?
55
68
  current_id = current_index
56
69
  current = self.compile(code)
57
- current << current_id
70
+ current.unshift(current_id)
71
+ # [id, type_id, level, content, config]
58
72
 
59
73
 
60
- current_declare = "node#{current_id}[label=\"#{current[2]}\"]";
74
+ current_declare = "node#{current_id}[label=\"#{current[3]}\"]";
61
75
  declares.push(current_declare)
62
76
 
63
77
  unless stack.empty?
64
78
  top = stack.pop
65
- if current[1] > top[1]
66
- nodes << "node#{top[3]} -> node#{current[3]}"
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
67
85
  stack.push(top)
68
86
  else
69
- while (current[1] <= top[1]) and (not stack.empty?)
87
+ while (current[2] <= top[2]) and (not stack.empty?)
70
88
  top = stack.pop
71
89
  end
72
- if current[1] > top[1]
73
- 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
74
96
  stack.push top
75
97
  end
76
98
 
@@ -88,7 +110,9 @@ module MiniMindmap
88
110
  end
89
111
 
90
112
  def package_nodes
91
- "digraph #{@name} {\n#{@declares.join("\n")}\n#{@nodes.join("\n")}\n}"
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}"
92
116
  end
93
117
 
94
118
  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.4.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.4.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/