mini_mindmap 0.3.0 → 0.5.1

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: 1f24a2e0b808b8387d32b02a04baa1eb6fa570955125ac4c88fdc076bb68d065
4
- data.tar.gz: 24e0d5afa135f91a32acfa90d1a2553892c275ba48428c78f950763ffcf17b19
3
+ metadata.gz: a0865bd40d96ada82490d52027f0041c32038c54089965dec88767840c3393e8
4
+ data.tar.gz: a9a646bf6572830c45737be6babd3b66e5df597096a15a6b5e0803bc354775f2
5
5
  SHA512:
6
- metadata.gz: bde88c6ffc6e8e375c393d71222c20bdf6d46cd397b503e946d7ca4b711f11e09c4bbb27f9024403bf5ca7982f6fdccb6d95e5e74670a2666b03ecab71b7968b
7
- data.tar.gz: ebc14a4a642135b11980befe86dbb25ecea1a2c8b485b6875ed38a7675b540168d456f11c22149a37df8ff6f805fdc70107c2bdde0dc77f6f0b79880bae91396
6
+ metadata.gz: 53cbdf6683c3ed91489e9888700d2fae223dcbb652d1134a4b520a29efbae066d767d21a4180b523ebbd18ca3be4763ed0ff76a04f814348192535ff05d42b6d
7
+ data.tar.gz: 460035c48eaa9c57801949abf28da266dc6a7dd04c6c4318be5643b801740334e69c968d97ee2bdbd33c9c73b679894e384acf3b7db1935a07b2c74565c2455a
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,13 @@
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
+
1
11
  ## 0.3.0
2
12
 
3
13
  * 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,37 @@ 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
+ Support Markdown Title Syntax
38
+
39
+ ```
40
+ # Subject
41
+ ## Foo
42
+ ## Bar
43
+
44
+ ```
45
+
46
+ Suppo Annotation with //
47
+
48
+ ```
49
+
50
+ // one line annotation
51
+
52
+ ** Foo // you can add annotation here too
53
+
54
+ ```
55
+
25
56
  ## Usage
26
57
 
27
58
  DSL Example
@@ -31,6 +62,17 @@ require "mini_mindmap"
31
62
 
32
63
  name = 'mindmap' # filename
33
64
 
65
+ # support add attrs http://www.graphviz.org/doc/info/attrs.html
66
+ config = {
67
+ rankdir: "LR",# "TB", "LR", "BT", "RL", 分别对应于从上到下,从左到右,从下到上和从右到左绘制的有向图
68
+ node: {
69
+ fontname: "wqy-microhei",
70
+ fontcolor: "black"
71
+ },
72
+ edge: {
73
+ fontname: "wqy-microhei"
74
+ }
75
+ }
34
76
  output = {
35
77
  format: 'png',
36
78
  dir: "#{Dir.home}/mindmap" # output dir
@@ -45,28 +87,42 @@ dsl = %Q{
45
87
  ** output
46
88
  *** dir
47
89
  *** format
90
+ ** 汉字测试
48
91
  }
49
92
 
50
- demo = MiniMindmap::Mindmap.new(name,dsl,output)
93
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
51
94
 
52
95
  demo.export # export files to dir
53
96
 
54
97
  ```
55
- ## Development
98
+ output img
56
99
 
57
- 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.
100
+ ![demo.png](https://wx2.sbimg.cn/2020/07/16/CiWr6.png)
58
101
 
59
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+ ## Q&A
60
103
 
61
- ## Contributing
104
+ ### Chinese charset code problem
62
105
 
63
- Bug reports and pull requests are welcome on GitHub at https://github.com/mark24code/mini_mindmap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mark24code/mini_mindmap/blob/master/CODE_OF_CONDUCT.md).
106
+ 1. To check fonts. Run `fc-list` or go to `/etc/fonts` to check if you have correct fonts.
64
107
 
108
+ 2. You may need to install fonts, for example : Chinese font —— 文泉驿。 Run `sudo apt list fonts-wqy-zenhei`
109
+ 3. Make config with correct font name
65
110
 
66
- ## License
111
+ >
112
+ ```ruby
113
+ config = {
114
+ rankdir: "LR",# "TB", "LR", "BT", "RL" direction
115
+ node: {
116
+ fontname: "wqy-microhei"
117
+ },
118
+ edge: {
119
+ fontname: "wqy-microhei"
120
+ }
121
+ }
67
122
 
68
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
123
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
69
124
 
70
- ## Code of Conduct
125
+ ```
126
+ ## License
71
127
 
72
- Everyone interacting in the MiniMindmap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mark24code/mini_mindmap/blob/master/CODE_OF_CONDUCT.md).
128
+ 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
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -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.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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.com/Mark24Code/mini_mindmap"
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.3.0
4
+ version: 0.5.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-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:
@@ -26,19 +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
32
33
  - examples/helper.rb
33
34
  - examples/mindmap.png
34
35
  - lib/mini_mindmap.rb
36
+ - lib/mini_mindmap/utils/deep_merge.rb
35
37
  - lib/mini_mindmap/version.rb
36
38
  - mini_mindmap.gemspec
37
- homepage: https://github.com/Mark24Code/mini_mindmap
39
+ homepage: https://mark24code.github.io/mini_mindmap/
38
40
  licenses:
39
41
  - MIT
40
42
  metadata:
41
- homepage_uri: https://github.com/Mark24Code/mini_mindmap
43
+ homepage_uri: https://mark24code.github.io/mini_mindmap/
42
44
  source_code_uri: https://github.com/Mark24Code/mini_mindmap
43
45
  changelog_uri: https://github.com/Mark24Code/mini_mindmap/blob/master/CHANGELOG.md
44
46
  post_install_message: