tree.rb 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tree_rb/cli/cli_tree.rb +16 -20
- data/lib/tree_rb/d3js_helper.rb +20 -0
- data/lib/tree_rb/version.rb +1 -1
- data/lib/tree_rb_cli.rb +1 -0
- data/spec/tree_rb/cli/cli_tree_d3js_spec.rb +32 -0
- metadata +5 -2
data/lib/tree_rb/cli/cli_tree.rb
CHANGED
@@ -74,7 +74,7 @@ module TreeRb
|
|
74
74
|
options[:show_indentation] = false
|
75
75
|
end
|
76
76
|
|
77
|
-
algos = %w[build-dir print-dir json d3js html_partition yaml sqlite]
|
77
|
+
algos = %w[build-dir print-dir json d3js html_partition html_tree html_treemap yaml sqlite]
|
78
78
|
# algo_aliases = { "b" => "build-dir", "v" => "print-dir", "j" => "json", "y" => "yaml", "s" => "sqlite" }
|
79
79
|
# algo_list = (algo_aliases.keys + algos).join(',')
|
80
80
|
parser.on("--format ALGO", algos, "select an algo", " (#{algos})") do |algo|
|
@@ -231,18 +231,18 @@ module TreeRb
|
|
231
231
|
# 1. build dir tree walker
|
232
232
|
#
|
233
233
|
dirname = File.expand_path(dirname)
|
234
|
-
|
234
|
+
directory_tree_walker = DirTreeWalker.new(dirname, options)
|
235
235
|
unless options[:all_files]
|
236
|
-
|
236
|
+
directory_tree_walker.ignore(/^\.[^.]+/) # ignore all file starting with "."
|
237
237
|
end
|
238
|
-
|
238
|
+
directory_tree_walker.visit_file = !options[:only_directories]
|
239
239
|
|
240
240
|
case options[:algo]
|
241
241
|
|
242
242
|
when 'build-dir'
|
243
243
|
|
244
244
|
visitor = BuildDirTreeVisitor.new(options)
|
245
|
-
|
245
|
+
directory_tree_walker.run(visitor)
|
246
246
|
|
247
247
|
output.puts visitor.root.to_str('', options)
|
248
248
|
|
@@ -253,11 +253,11 @@ module TreeRb
|
|
253
253
|
|
254
254
|
when 'print-dir'
|
255
255
|
visitor = PrintDirTreeVisitor.new
|
256
|
-
|
256
|
+
directory_tree_walker.run(visitor)
|
257
257
|
|
258
258
|
when 'json'
|
259
259
|
visitor = DirectoryToHashVisitor.new(dirname)
|
260
|
-
root =
|
260
|
+
root = directory_tree_walker.run(visitor).root
|
261
261
|
begin
|
262
262
|
output.puts JSON.pretty_generate(root)
|
263
263
|
rescue JSON::NestingError => e
|
@@ -266,7 +266,7 @@ module TreeRb
|
|
266
266
|
|
267
267
|
when 'd3js'
|
268
268
|
visitor = DirectoryToHash2Visitor.new(dirname)
|
269
|
-
root =
|
269
|
+
root = directory_tree_walker.run(visitor).root
|
270
270
|
begin
|
271
271
|
str_json = JSON.pretty_generate(root)
|
272
272
|
str_json = "var data = " + str_json
|
@@ -276,21 +276,17 @@ module TreeRb
|
|
276
276
|
end
|
277
277
|
|
278
278
|
when 'html_partition'
|
279
|
-
|
280
|
-
root = dtw.run(visitor).root
|
281
|
-
begin
|
282
|
-
str_json = JSON.pretty_generate(root)
|
283
|
-
str_json = "var data = " + str_json
|
279
|
+
D3jsHelper.new.run(directory_tree_walker, dirname,"d3js_layout_partition.erb", output)
|
284
280
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
281
|
+
when 'html_tree'
|
282
|
+
D3jsHelper.new.run(directory_tree_walker, dirname,"d3js_layout_tree.erb", output)
|
283
|
+
|
284
|
+
when 'html_treemap'
|
285
|
+
D3jsHelper.new.run(directory_tree_walker, dirname,"d3js_layout_treemap.erb", output)
|
290
286
|
|
291
287
|
when 'yaml'
|
292
288
|
visitor = DirectoryToHashVisitor.new(dirname)
|
293
|
-
root =
|
289
|
+
root = directory_tree_walker.run(visitor).root
|
294
290
|
output.puts root.to_yaml
|
295
291
|
|
296
292
|
when 'sqlite'
|
@@ -305,7 +301,7 @@ module TreeRb
|
|
305
301
|
#start = Time.now
|
306
302
|
#me = self
|
307
303
|
#bytes = 0
|
308
|
-
|
304
|
+
directory_tree_walker.run(visitor)
|
309
305
|
end
|
310
306
|
|
311
307
|
rescue LoadError
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module TreeRb
|
3
|
+
|
4
|
+
class D3jsHelper
|
5
|
+
|
6
|
+
def run(directory_tree_walker, dirname, template, output)
|
7
|
+
visitor = DirectoryToHash2Visitor.new(dirname)
|
8
|
+
root = directory_tree_walker.run(visitor).root
|
9
|
+
begin
|
10
|
+
str_json = JSON.pretty_generate(root)
|
11
|
+
str_json = "var data = " + str_json
|
12
|
+
|
13
|
+
render = ErbRender.new(template, str_json)
|
14
|
+
output.puts render.render
|
15
|
+
rescue JSON::NestingError => e
|
16
|
+
$stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end # module
|
data/lib/tree_rb/version.rb
CHANGED
data/lib/tree_rb_cli.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
3
|
+
|
4
|
+
describe CliTree do
|
5
|
+
|
6
|
+
it "should accepts --format html_partition" do
|
7
|
+
captured = capture_output do
|
8
|
+
args = %w{--format html_partition}
|
9
|
+
args << File.join(FIXTURES, "test_dir_1")
|
10
|
+
CliTree.new.parse_args(args)
|
11
|
+
end
|
12
|
+
captured.out.should match /d3.layout.partition/
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accepts --format html_tree" do
|
16
|
+
captured = capture_output do
|
17
|
+
args = %w{--format html_tree}
|
18
|
+
args << File.join(FIXTURES, "test_dir_1")
|
19
|
+
CliTree.new.parse_args(args)
|
20
|
+
end
|
21
|
+
captured.out.should match /d3.layout.tree/
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accepts --format html_treemap" do
|
25
|
+
captured = capture_output do
|
26
|
+
args = %w{--format html_treemap}
|
27
|
+
args << File.join(FIXTURES, "test_dir_1")
|
28
|
+
CliTree.new.parse_args(args)
|
29
|
+
end
|
30
|
+
captured.out.should match /d3.layout.treemap/
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tree.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/tree_rb/extension_digest.rb
|
169
169
|
- lib/tree_rb/tree_node_visitor.rb
|
170
170
|
- lib/tree_rb/tree_node.rb
|
171
|
+
- lib/tree_rb/d3js_helper.rb
|
171
172
|
- lib/tree_rb/basic_tree_node_visitor.rb
|
172
173
|
- lib/tree_rb/erb_render.rb
|
173
174
|
- lib/tree_rb/version.rb
|
@@ -197,6 +198,7 @@ files:
|
|
197
198
|
- spec/tree_rb/cli/cli_tree_sqlite_spec.rb
|
198
199
|
- spec/tree_rb/cli/cli_tree_digest_spec.rb
|
199
200
|
- spec/tree_rb/cli/cli_tree_generic_spec.rb
|
201
|
+
- spec/tree_rb/cli/cli_tree_d3js_spec.rb
|
200
202
|
- spec/tree_rb/cli/cli_json_spec.rb
|
201
203
|
- spec/tree_rb/util/dir_processor_spec.rb
|
202
204
|
- spec/tree_rb/visitors/depth_tree_node_visitor_spec.rb
|
@@ -253,6 +255,7 @@ test_files:
|
|
253
255
|
- spec/tree_rb/cli/cli_tree_sqlite_spec.rb
|
254
256
|
- spec/tree_rb/cli/cli_tree_digest_spec.rb
|
255
257
|
- spec/tree_rb/cli/cli_tree_generic_spec.rb
|
258
|
+
- spec/tree_rb/cli/cli_tree_d3js_spec.rb
|
256
259
|
- spec/tree_rb/cli/cli_json_spec.rb
|
257
260
|
- spec/tree_rb/util/dir_processor_spec.rb
|
258
261
|
- spec/tree_rb/visitors/depth_tree_node_visitor_spec.rb
|