ruby_ast_visualizer 0.1.0 → 0.2.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 +4 -4
- data/README.md +15 -7
- data/bin/ruby_ast_visualizer +9 -4
- data/lib/ruby_ast_visualizer.rb +4 -4
- data/lib/ruby_ast_visualizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ec81c0daa6acddeb64dff7b8a6d263a415ece0d
|
4
|
+
data.tar.gz: f4d40be35bc7e2c7f6129d2981b899c14bdaad74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2b1310c613358e90ff7e2e61297461dd930da2717071e1a33d7ae2567e739f402a256c1cda3c699ebc42aaf87c62f784515783b2faaa1c3ee3fa35b395e4246
|
7
|
+
data.tar.gz: 81f726b857fe3a70e871cf6dffe22747844411ffaa17b153499debc8a891ae48b67bbc5418ba8d082528bcc483a4b8ffc81760acb351bfbdbc56994ec97f9893
|
data/README.md
CHANGED
@@ -1,16 +1,24 @@
|
|
1
|
-
# Ruby AST Visualizer
|
1
|
+
# Ruby AST Visualizer [](http://badge.fury.io/rb/ruby_ast_visualizer)
|
2
2
|
|
3
3
|
Ruby AST Visualizer. Based on [Parser](https://github.com/whitequark/parser).
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
6
|
|
7
7
|
An example `ruby_ast_visualizer` command.
|
8
8
|
|
9
9
|
```
|
10
|
-
$
|
10
|
+
$ cat hello.rb
|
11
|
+
puts 'hello, world'
|
12
|
+
$ ruby_ast_visualizer hello.rb
|
11
13
|
```
|
12
14
|
|
13
|
-
|
15
|
+
or
|
16
|
+
|
17
|
+
```
|
18
|
+
$ ruby_ast_visualizer -e 'puts "hello, world"'
|
19
|
+
```
|
20
|
+
|
21
|
+
AST image file is generated.
|
14
22
|
|
15
23
|
<img src="https://raw.githubusercontent.com/koic/ruby_ast_visualizer/master/images/hello_world.png" alt="hello, world"/>
|
16
24
|
|
@@ -19,14 +27,14 @@ Following image file is generated.
|
|
19
27
|
You can specify output path in the `-o` option. That value is default a.png.
|
20
28
|
|
21
29
|
```
|
22
|
-
$ ruby_ast_visualizer -o path/to/file 'puts "hello"'
|
30
|
+
$ ruby_ast_visualizer -o path/to/file -e 'puts "hello, world"'
|
23
31
|
```
|
24
32
|
|
25
|
-
##
|
33
|
+
## Requirements
|
26
34
|
|
27
35
|
* Graphviz
|
28
36
|
|
29
|
-
##
|
37
|
+
## Install
|
30
38
|
|
31
39
|
Add these lines to your application's Gemfile:
|
32
40
|
|
data/bin/ruby_ast_visualizer
CHANGED
@@ -15,20 +15,25 @@ Version = RubyAstVisualizer::VERSION
|
|
15
15
|
|
16
16
|
options = {}
|
17
17
|
|
18
|
-
opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] '
|
18
|
+
opt = OptionParser.new("usage: ruby_ast_visualizer [-o output_path] [-e 'command'] [programfile]")
|
19
19
|
|
20
|
+
opt.on('-e', "--eval 'command'") {|v| options[:eval] = v }
|
20
21
|
opt.on('-o', '--output path/to/file (DEFAULT a.png)') {|v| options[:output] = v }
|
21
22
|
|
22
23
|
begin
|
23
24
|
opt.permute!(ARGV)
|
24
25
|
|
25
|
-
|
26
|
+
source = options[:eval]
|
26
27
|
|
27
|
-
source
|
28
|
+
if source.nil? || source.empty?
|
29
|
+
raise unless ARGV.size == 1
|
30
|
+
|
31
|
+
source = File.read(ARGV.shift)
|
32
|
+
end
|
28
33
|
|
29
34
|
file_name = options[:output] || 'a.png'
|
30
35
|
|
31
|
-
result = RubyAstVisualizer::Core.new(source).
|
36
|
+
result = RubyAstVisualizer::Core.new(source).visualize
|
32
37
|
|
33
38
|
result.output(png: file_name)
|
34
39
|
|
data/lib/ruby_ast_visualizer.rb
CHANGED
@@ -8,19 +8,19 @@ module RubyAstVisualizer
|
|
8
8
|
@source = source
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def visualize
|
12
12
|
g = GraphViz.new(:G, type: :digraph)
|
13
13
|
|
14
14
|
node = Parser::CurrentRuby.parse(@source)
|
15
15
|
|
16
|
-
|
16
|
+
reconfigure(g, node)
|
17
17
|
|
18
18
|
g
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
def
|
23
|
+
def reconfigure(g, node)
|
24
24
|
self_node = g.add_nodes(fetch_node_id(node), label: node.type)
|
25
25
|
|
26
26
|
node.children.each {|node|
|
@@ -35,7 +35,7 @@ module RubyAstVisualizer
|
|
35
35
|
|
36
36
|
self_node << g.add_nodes(fetch_node_id(node), label: label)
|
37
37
|
|
38
|
-
|
38
|
+
reconfigure(g, node) if node.respond_to? :children
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
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.
|
4
|
+
version: 0.2.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: 2016-09-
|
11
|
+
date: 2016-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|