ruby_ast_visualizer 0.3.0 → 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
  SHA1:
3
- metadata.gz: 1696695ee0506076fd3cc5ef7135c80194b19162
4
- data.tar.gz: ac777855cc5d0ff1571c7c48839462bb382aeec5
3
+ metadata.gz: d69af471a20f595af80957cdb5527f8cc5d191b7
4
+ data.tar.gz: 63284a298caae3c0337bd2aef57b4aefda3a02e0
5
5
  SHA512:
6
- metadata.gz: 31ddc501e00200655cbe90c9a7db85bc3982f3b33a4504d655a39bf5370c46900d03866445bb7b379575fd3fd543d2f51e7b56ae83f5f9c25083a2d6200aa3cc
7
- data.tar.gz: d53e2d540287c2c30b15230eede0b3758d9ca943578b3ca569975ce4b620f37ceeceb72c62cb7f4123e7de6cd2f2bb9c6c28b9259920534157a089f438022034
6
+ metadata.gz: 7c00e893fa21a2bd739761bb1bc3021fb02e917884561cdf0b9a9bbba39fa049fe1ad808c0a56fcaf2b9f600c4f4b5bbdfb28612a85ce8c294e585d70d6cca58
7
+ data.tar.gz: 1406f749c11f7230b4fae09baffa626d8ebbaef563187da06266e5dd594eb6585145ce30f6dbf261a6bbbf4e278d716b1184f99d485a396bac78f0743872165a
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Ruby AST Visualizer. Based on [Parser](https://github.com/whitequark/parser).
4
4
 
5
+ ## Install
6
+
7
+ ```sh
8
+ $ gem install ruby_ast_visualizer
9
+ ```
10
+
5
11
  ## Usage
6
12
 
7
13
  An example `ruby_ast_visualizer` command.
@@ -10,12 +16,22 @@ An example `ruby_ast_visualizer` command.
10
16
  $ cat hello.rb
11
17
  puts 'hello, world'
12
18
  $ ruby_ast_visualizer hello.rb
19
+
20
+ (send nil :puts
21
+ (str "hello, world"))
22
+
23
+ Wrote a.png
13
24
  ```
14
25
 
15
26
  or
16
27
 
17
28
  ```sh
18
29
  $ ruby_ast_visualizer -e 'puts "hello, world"'
30
+
31
+ (send nil :puts
32
+ (str "hello, world"))
33
+
34
+ Wrote a.png
19
35
  ```
20
36
 
21
37
  AST image file is generated.
@@ -28,31 +44,26 @@ You can specify output path in the `-o` option. That value is default a.png.
28
44
 
29
45
  ```sh
30
46
  $ ruby_ast_visualizer -o path/to/file -e 'puts "hello, world"'
31
- ```
32
-
33
- ## Requirements
34
-
35
- * Graphviz
36
47
 
37
- ## Install
38
-
39
- Add these lines to your application's Gemfile:
48
+ (send nil :puts
49
+ (str "hello, world"))
40
50
 
41
- ```sh
42
- gem 'ruby_ast_visualizer'
51
+ Wrote path/to/file
43
52
  ```
44
53
 
45
- And then execute:
54
+ And you can also specify the `-n` (`--no-image`) option if you don't need an image.
55
+ You can only get the result of S-expression by Parser gem.
46
56
 
47
57
  ```sh
48
- $ bundle
58
+ $ ruby_ast_visualizer -n -e 'puts "hello, world"'
59
+
60
+ (send nil :puts
61
+ (str "hello, world"))
49
62
  ```
50
63
 
51
- Or install it yourself as:
64
+ ## Requirements
52
65
 
53
- ```sh
54
- $ gem install ruby_ast_visualizer
55
- ```
66
+ * Graphviz
56
67
 
57
68
  ## Contributing
58
69
 
@@ -16,9 +16,10 @@ Version = RubyAstVisualizer::VERSION
16
16
 
17
17
  options = {}
18
18
 
19
- opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-e 'command'] [programfile]")
19
+ opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-n] [-e 'command'] [programfile]")
20
20
 
21
21
  opt.on('-e', "--eval 'command'") {|v| options[:eval] = v }
22
+ opt.on('-n', "--no-image") {|v| options[:no_image] = v }
22
23
  opt.on('-o', '--output path/to/file (DEFAULT a.png)') {|v| options[:output] = v }
23
24
 
24
25
  begin
@@ -36,13 +37,15 @@ begin
36
37
 
37
38
  ast = Parser::CurrentRuby.parse(source)
38
39
 
39
- puts "\n#{ast}\n\n"
40
+ puts "\n#{ast}\n"
41
+
42
+ exit unless options[:no_image].nil?
40
43
 
41
44
  result = RubyAstVisualizer::Core.new(ast).visualize
42
45
 
43
46
  result.output(png: file_name)
44
47
 
45
- puts "Wrote #{file_name}"
48
+ puts "\nWrote #{file_name}"
46
49
  rescue
47
50
  puts opt.help
48
51
 
@@ -18,19 +18,19 @@ module RubyAstVisualizer
18
18
  def reconfigure(g, node)
19
19
  self_node = g.add_nodes(fetch_node_id(node), label: node.type)
20
20
 
21
- node.children.each {|node|
22
- label = case node
23
- when Integer; node
21
+ node.children.each {|child|
22
+ label = case child
23
+ when Integer; child
24
24
  when NilClass; 'nil'
25
- when String; "\"#{node}\""
26
- when Symbol; ":#{node}"
25
+ when String; "\"#{child}\""
26
+ when Symbol; ":#{child}"
27
27
  else
28
- node.type.to_s
28
+ child.type.to_s
29
29
  end
30
30
 
31
- self_node << g.add_nodes(fetch_node_id(node), label: label)
31
+ self_node << g.add_nodes(fetch_node_id(child), label: label)
32
32
 
33
- reconfigure(g, node) if node.respond_to? :children
33
+ reconfigure(g, child) if child.respond_to? :children
34
34
  }
35
35
  end
36
36
 
@@ -1,3 +1,3 @@
1
1
  module RubyAstVisualizer
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ast_visualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-12 00:00:00.000000000 Z
11
+ date: 2017-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.5.2
74
+ rubygems_version: 2.6.13
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Ruby AST Visualizer.