mini_mindmap 0.2.0 → 0.5.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: f406880d5f25e79b0f9c3522afbd2ae7ae75e9da002f71b19443211dbd8271fa
4
- data.tar.gz: e53d91bc604687a0fa05fb1d124793d67ce8002ec280ef8dfbd822a046c61ce0
3
+ metadata.gz: ded43843536db25fc831210fc5634ea8471b2cb1dc49c16139be472a31deecad
4
+ data.tar.gz: 61ef0ad9aaea38ec11c51f9354364fbc29b0c70888eaf19a277e37ac2c1949ca
5
5
  SHA512:
6
- metadata.gz: e9213b5bec48e3a74f7ba089d12c139b1bb88dd33dc2c3bbd728a2a9bf37c46a1bcb98811008e96fe74cb8b647fd316de04468e2eb1a09ee6b9ea100307bb122
7
- data.tar.gz: e290f4c98f793e96495d5262cb99ec03dc6653e927c1703436ae925812d0d0ba7a527de7ae7c19d3b3439e6ce7fbc4cb7b8709cc0a8fffec721eda68b2cc66b7
6
+ metadata.gz: 2d3456dd56cee10bfdc9f1f98ba84809deeb20aaedcd097435618d7a58d0abef43f72492b87929f9bf7b13ac0645c5d9e326f59f87b7199df50242a99c48e3da
7
+ data.tar.gz: 4d84fb8f18fcd52acdf9ef931b1fd3149e2fc05b445ecb83e1bbcbf6818aa9a26ee7ec5c78d1a385dbaf6288d4e34a00f7961cd2e2d575175f36d8ebfe403a5f
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
File without changes
@@ -1,6 +1,20 @@
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
+
11
+ ## 0.3.0
12
+
13
+ * Change to node style to export dotfile.
14
+
1
15
  ## 0.2.0
2
16
 
3
- * Export mindmap
17
+ * Export mindmap.
4
18
 
5
19
  ## 0.1.0
6
20
 
File without changes
data/Gemfile CHANGED
File without changes
File without changes
File without changes
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # MiniMindmap
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mini_mindmap`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## Prepare
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ You need install graphviz first.
6
+
7
+ [graphviz download](http://www.graphviz.org/download/)
6
8
 
7
9
  ## Installation
8
10
 
@@ -20,6 +22,37 @@ Or install it yourself as:
20
22
 
21
23
  $ gem install mini_mindmap
22
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
+
23
56
  ## Usage
24
57
 
25
58
  DSL Example
@@ -29,6 +62,17 @@ require "mini_mindmap"
29
62
 
30
63
  name = 'mindmap' # filename
31
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
+ }
32
76
  output = {
33
77
  format: 'png',
34
78
  dir: "#{Dir.home}/mindmap" # output dir
@@ -43,28 +87,42 @@ dsl = %Q{
43
87
  ** output
44
88
  *** dir
45
89
  *** format
90
+ ** 汉字测试
46
91
  }
47
92
 
48
- demo = MiniMindmap::Mindmap.new(name,dsl,output)
93
+ demo = MiniMindmap::Mindmap.new(name,dsl,output=output,config=config)
49
94
 
50
95
  demo.export # export files to dir
51
96
 
52
97
  ```
53
- ## Development
98
+ output img
54
99
 
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.
100
+ ![demo.png](https://wx2.sbimg.cn/2020/07/16/CiWr6.png)
56
101
 
57
- 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
58
103
 
59
- ## Contributing
104
+ ### Chinese charset code problem
60
105
 
61
- 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.
62
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
63
110
 
64
- ## 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
+ }
65
122
 
66
- 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)
67
124
 
68
- ## Code of Conduct
125
+ ```
126
+ ## License
69
127
 
70
- 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)
44
+ attr_accessor(:name, :dsl, :config, :output, :nodes, :declares)
33
45
 
34
46
  def compile(code)
35
47
  # TODO 增加拓展语法支持 label等自定义
@@ -37,33 +49,58 @@ 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
 
47
68
  def basic_processor
69
+ declares = [];
48
70
  nodes = []
49
71
  stack = []
50
72
  dsl = @dsl.split("\n")
51
73
  dsl.each_with_index do |code, current_index|
52
74
 
53
75
  if not code.strip.empty?
76
+ current_id = current_index
54
77
  current = self.compile(code)
78
+ current.unshift(current_id)
79
+ # [id, type_id, level, content, config]
80
+
81
+
82
+ current_declare = "node#{current_id}[label=\"#{current[3]}\"]";
83
+ declares.push(current_declare)
55
84
 
56
85
  unless stack.empty?
57
86
  top = stack.pop
58
- if current[1] > top[1]
59
- nodes << "#{top[2]} -> #{current[2]}"
87
+ if current[2] > top[2]
88
+ node_line = "node#{top[0]} -> node#{current[0]}"
89
+ if current.length >=5
90
+ node_line += " #{current[4]}"
91
+ end
92
+ nodes << node_line
60
93
  stack.push(top)
61
94
  else
62
- while (current[1] <= top[1]) and (not stack.empty?)
95
+ while (current[2] <= top[2]) and (not stack.empty?)
63
96
  top = stack.pop
64
97
  end
65
- if current[1] > top[1]
66
- nodes << "#{top[2]} -> #{current[2]}"
98
+ if current[2] > top[2]
99
+ node_line = "node#{top[0]} -> node#{current[0]}"
100
+ if current.length >=5
101
+ node_line += " #{current[4]}"
102
+ end
103
+ nodes << node_line
67
104
  stack.push top
68
105
  end
69
106
 
@@ -72,6 +109,7 @@ module MiniMindmap
72
109
  stack.push(current)
73
110
  end
74
111
  end
112
+ @declares = declares
75
113
  @nodes = nodes
76
114
  end
77
115
 
@@ -80,7 +118,9 @@ module MiniMindmap
80
118
  end
81
119
 
82
120
  def package_nodes
83
- "digraph #{@name} {\n#{@nodes.join("\n")}\n}"
121
+ node_config = @config[:node].map {|k,v| "#{k}=\"#{v}\""}.join(",")
122
+ edge_config = @config[:edge].map {|k,v| "#{k}=\"#{v}\""}.join(",")
123
+ "digraph \"#{@name}\" {\nrankdir = #{@config[:rankdir]};\nnode [#{node_config}];\nedge [#{edge_config}];\n#{@declares.join("\n")}\n#{@nodes.join("\n")}\n}"
84
124
  end
85
125
 
86
126
  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.2.0"
2
+ VERSION = "0.5.0"
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.2.0
4
+ version: 0.5.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:
@@ -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: