tree.rb 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/bin/rjson.rb +1 -2
  2. data/bin/rtree +1 -3
  3. data/bin/tree.rb +1 -3
  4. data/bin/tree_rb +1 -3
  5. data/examples/d3js_layout_partition/run.sh +0 -0
  6. data/examples/d3js_layout_treemap/index.html +0 -0
  7. data/examples/d3js_layout_treemap/run.sh +0 -0
  8. data/examples/d3js_layout_treemap/style.css +0 -0
  9. data/lib/tree_rb.rb +6 -6
  10. data/lib/tree_rb/cli/cli_json.rb +11 -215
  11. data/lib/tree_rb/cli/cli_tree.rb +103 -85
  12. data/lib/tree_rb/core/tree_node.rb +8 -7
  13. data/lib/tree_rb/core/tree_node_visitor.rb +13 -6
  14. data/lib/tree_rb/extension_numeric.rb +4 -4
  15. data/lib/tree_rb/{input_file_system → input_plugins/file_system}/dir_processor.rb +1 -1
  16. data/lib/tree_rb/{input_file_system → input_plugins/file_system}/directory_walker.rb +17 -9
  17. data/lib/tree_rb/{input_html_page → input_plugins/html_page}/dom_walker.rb +0 -0
  18. data/lib/tree_rb/{output_dircat/dircat_helper.rb → output_plugins/dircat/dircat_output.rb} +5 -5
  19. data/lib/tree_rb/{output_dircat → output_plugins/dircat}/dircat_visitor.rb +0 -0
  20. data/lib/tree_rb/{output_dircat → output_plugins/dircat}/entry.rb +1 -1
  21. data/lib/tree_rb/{output_html/d3js_helper.rb → output_plugins/html/d3js_output.rb} +5 -4
  22. data/lib/tree_rb/{output_html → output_plugins/html}/directory_to_hash2_visitor.rb +0 -0
  23. data/lib/tree_rb/{output_html → output_plugins/html}/erb_render.rb +0 -0
  24. data/lib/tree_rb/{output_sqlite → output_plugins/sqlite}/sqlite_dir_tree_visitor.rb +9 -4
  25. data/lib/tree_rb/{output_sqlite/sqlite_helper.rb → output_plugins/sqlite/sqlite_output.rb} +11 -9
  26. data/lib/tree_rb/version.rb +1 -1
  27. data/lib/tree_rb/visitors/print_tree_node_visitor.rb +4 -4
  28. data/spec/fixtures/test_dir_1/.dir_with_dot/dummy.txt +1 -0
  29. data/spec/fixtures/test_dir_2/[Dsube]/sub/.gitkeep +0 -0
  30. data/spec/fixtures/tmp/test.db +0 -0
  31. data/spec/spec_helper.rb +2 -2
  32. data/spec/tree_rb/cli/cli_json_spec.rb +5 -5
  33. data/spec/tree_rb/cli/cli_tree_d3js_spec.rb +3 -3
  34. data/spec/tree_rb/cli/cli_tree_generic_spec.rb +126 -95
  35. data/spec/tree_rb/cli/cli_tree_sqlite_spec.rb +38 -22
  36. data/spec/tree_rb/core/tree_node_spec.rb +135 -135
  37. data/spec/tree_rb/input_file_system/dir_processor_spec.rb +3 -3
  38. data/spec/tree_rb/input_file_system/directory_walker_conf_spec.rb +59 -0
  39. data/spec/tree_rb/input_file_system/directory_walker_run_spec.rb +62 -0
  40. data/tasks/rspec.rake +2 -2
  41. data/tasks/tree_rb.rake +2 -2
  42. data/tasks/yard.rake +1 -1
  43. data/tree.rb.gemspec +1 -1
  44. metadata +121 -108
  45. checksums.yaml +0 -7
  46. data/lib/colors.rb +0 -39
  47. data/spec/fixtures/tmp/dircat +0 -34
  48. data/spec/tree_rb/input_file_system/directory_walker_spec.rb +0 -98
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- #require 'rubygems'
4
- cwd = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ cwd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
5
4
  $:.unshift(cwd) unless $:.include?(cwd)
6
5
  require 'tree_rb_cli'
7
6
 
data/bin/rtree CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- #require 'rubygems'
4
-
5
- cwd = File.expand_path( File.join( File.dirname(__FILE__), "..", "lib" ) )
3
+ cwd = File.expand_path( File.join( File.dirname(__FILE__), '..', 'lib') )
6
4
  $:.unshift(cwd) unless $:.include?(cwd)
7
5
  require 'tree_rb_cli'
8
6
 
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- #require 'rubygems'
4
-
5
- cwd = File.expand_path( File.join( File.dirname(__FILE__), "..", "lib" ) )
3
+ cwd = File.expand_path( File.join( File.dirname(__FILE__), '..', 'lib') )
6
4
  $:.unshift(cwd) unless $:.include?(cwd)
7
5
  require 'tree_rb_cli'
8
6
 
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- #require 'rubygems'
4
-
5
- cwd = File.expand_path( File.join( File.dirname(__FILE__), "..", "lib" ) )
3
+ cwd = File.expand_path( File.join( File.dirname(__FILE__), '..', 'lib') )
6
4
  $:.unshift(cwd) unless $:.include?(cwd)
7
5
  require 'tree_rb_cli'
8
6
 
File without changes
File without changes
File without changes
File without changes
@@ -35,10 +35,10 @@ require 'tree_rb/core/tree_node'
35
35
  require 'tree_rb/core/basic_tree_node_visitor'
36
36
  require 'tree_rb/core/tree_node_visitor'
37
37
 
38
- require 'tree_rb/input_file_system/directory_walker'
39
- require 'tree_rb/input_file_system/dir_processor'
38
+ require 'tree_rb/input_plugins/file_system/directory_walker'
39
+ require 'tree_rb/input_plugins/file_system/dir_processor'
40
40
 
41
- require 'tree_rb/input_html_page/dom_walker'
41
+ require 'tree_rb/input_plugins/html_page/dom_walker'
42
42
 
43
43
  #
44
44
  # visitors
@@ -48,11 +48,11 @@ visitors_dir = File.join(File.dirname(__FILE__), "tree_rb", "visitors")
48
48
  unless Dir.exist? visitors_dir
49
49
  raise "cannot found directory '#{visitors_dir}'"
50
50
  end
51
- Dir[ File.join(visitors_dir, "*.rb") ].each { |f|require f }
51
+ Dir[ File.join(visitors_dir, '*.rb') ].each { |f|require f }
52
52
 
53
- visitors_dir = File.join(File.dirname(__FILE__), "tree_rb", "visitors_file_system")
53
+ visitors_dir = File.join(File.dirname(__FILE__), 'tree_rb', 'visitors_file_system')
54
54
  unless Dir.exist? visitors_dir
55
55
  raise "cannot found directory '#{visitors_dir}'"
56
56
  end
57
- Dir[ File.join(visitors_dir, "*.rb") ].each { |f|require f }
57
+ Dir[ File.join(visitors_dir, '*.rb') ].each { |f|require f }
58
58
 
@@ -16,23 +16,12 @@ module TreeRb
16
16
  def options_parser(options)
17
17
  parser = OptionParser.new
18
18
  parser.banner = "Usage: rjson.rb [options] [directory]"
19
- parser.separator "pretty format json file"
20
- parser.separator "Code https://github.com/tokiro/treevisitor. Feedback to tokiro.oyama@gmail.com"
19
+ parser.separator 'pretty format json file'
20
+ parser.separator 'Code https://github.com/tokiro/treevisitor. Feedback to tokiro.oyama@gmail.com'
21
21
 
22
- #parser.separator ""
23
- #parser.separator "Generic options: "
24
- #
25
- #parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
26
- # options[:verbose] = v
27
- #end
28
- #
29
- #parser.on("-q", "--quiet", "quiet mode as --no-verbose") do
30
- # options[:verbose] = false
31
- #end
32
- #
33
- parser.on("-o [FILE]", "--output [FILE]", String) do |v|
22
+ parser.on('-o [FILE]', "--output [FILE]", String) do |v|
34
23
  if options[:output]
35
- puts "only one file of output can be used"
24
+ puts 'only one file of output can be used'
36
25
  options[:exit] = true
37
26
  end
38
27
  options[:output] = v
@@ -42,121 +31,7 @@ module TreeRb
42
31
  parser.on("--force", "overwrite output") do
43
32
  options[:force_overwrite_output] = true
44
33
  end
45
- #
46
- #parser.separator ""
47
- #parser.separator "Filter options: "
48
- #
49
- #parser.on("-a", "All file are listed i.e. include dot files") do
50
- # options[:all_files] = true
51
- #end
52
- #
53
- #parser.on("-d", "List directories only") do
54
- # options[:only_directories] = true
55
- #end
56
- #
57
- #options[:only_files] = false
58
- #parser.on("--only-files", "show only file implies -i") do
59
- # options[:only_files] = true
60
- # options[:show_indentation] = false
61
- #end
62
- #
63
- #algos = %w[build-dir print-dir json json2 yaml sqlite]
64
- #algo_aliases = { "b" => "build-dir", "v" => "print-dir", "j" => "json", "y" => "yaml", "s" => "sqlite" }
65
- #
66
- #algo_list = (algo_aliases.keys + algos).join(',')
67
- #parser.on("--format ALGO", algos, algo_aliases, "select an algo", " (#{algo_list})") do |algo|
68
- # options[:algo] = algo
69
- #end
70
- #
71
- #parser.separator ""
72
- #parser.separator "print options:"
73
- #
74
- ##
75
- ## begin colorize
76
- ##
77
- ## copied from tree man page
78
- #parser.on("-n", "Turn colorization off always, over-ridden by the -C option.") do
79
- # options[:colorize_force] = false
80
- #end
81
- #
82
- ## copied from tree man page
83
- #parser.on("-C",
84
- # "Turn colorization on always, using built-in color",
85
- # " defaults if the LS_COLORS environment variable is not set.",
86
- # " Useful to colorize output to a pipe.") do
87
- # options[:colorize_force] = true
88
- #end
89
- #
90
- ##
91
- ## end colorize
92
- ##
93
- #
94
- #options[:max_level] = nil
95
- #parser.on("-L [LEVEL]", Integer, "Max display depth of the directory tree.") do |l|
96
- # options[:max_level] = l
97
- #end
98
- #
99
- #options[:show_full_path] = false
100
- #parser.on("-f", "Prints the full path prefix for each file.") do
101
- # options[:show_full_path] = true
102
- #end
103
- #
104
- #parser.on("-s", "Print the size of each file in bytes along with the name.") do
105
- # options[:show_size] = true
106
- #end
107
- #
108
- #parser.on("-h",
109
- # "Print the size of each file but in a more human readable way,",
110
- # " e.g. appending a size letter for kilobytes (K), megabytes (M),",
111
- # " gigabytes (G), terrabytes (T), petabytes (P) and exabytes (E).") do
112
- # options[:show_size_human] = true
113
- #end
114
- #
115
- #options[:show_indentation] = true
116
- #parser.on("-i",
117
- # "Makes tree not print the indentation lines, ",
118
- # " useful when used in conjunction with the -f option.") do
119
- # options[:show_indentation] = false
120
- #end
121
- #
122
- #options[:show_md5] = false
123
- #parser.on("--md5", "show md5 of file") do
124
- # options[:show_md5] = true
125
- #end
126
- #
127
- #options[:show_sha1] = false
128
- #parser.on("--sha1", "show sha1 of a file") do
129
- # options[:show_sha1] = true
130
- #end
131
- #
132
- #options[:show_report] = true
133
- #parser.on("--noreport", "Omits printing of the file and directory report at the end of the tree listing.") do
134
- # options[:show_report] = false
135
- #end
136
- #
137
- #parser.separator ""
138
- #parser.separator "shortcut options:"
139
- #
140
- #options[:show_md5sum] = false
141
- #parser.on("--md5sum", "show ake md5sum implies -i and --only-files") do
142
- # options[:only_files] = true
143
- # options[:show_md5sum] = true
144
- # options[:show_indentation] = false
145
- # options[:show_report] = false
146
- #end
147
- #
148
- #options[:show_sha1sum] = false
149
- #parser.on("--sha1sum", "show ake sha1sum output implies -i and --only-files") do
150
- # options[:only_files] = true
151
- # options[:show_sha1sum] = true
152
- # options[:show_indentation] = false
153
- # options[:show_report] = false
154
- #end
155
- #
156
- #parser.separator ""
157
- #parser.separator "Other options:"
158
- #
159
- parser.on_tail("--help", "Show this message") do
34
+ parser.on_tail('--help', 'Show this message') do
160
35
  puts parser
161
36
  options[:exit] = SUCCESS
162
37
  end
@@ -170,7 +45,7 @@ module TreeRb
170
45
  end
171
46
 
172
47
  def parse_args(argv)
173
- options = { :verbose => true, :force => false, :algo => 'build-dir' }
48
+ options = { :verbose => true, :force => false, :output_plugins => 'build-dir' }
174
49
  parser = options_parser(options)
175
50
 
176
51
  begin
@@ -202,93 +77,14 @@ module TreeRb
202
77
  output = File.open(filename, "w")
203
78
  $stderr.puts "Writing file '#{filename}'"
204
79
  end
205
- #
206
- #if options[:colorize_force]
207
- # options[:colorize] = options[:colorize_force]
208
- #else
209
- # options[:colorize] = output.isatty
210
- #end
211
- #
212
- ## TODO: capture CTRL^C to avoid show the stack trace
213
- ## http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-trap
214
- #Signal.trap('INT') { puts "intercepted ctr+c"; exit }
215
- #
216
80
 
217
81
  if rest.length < 1
218
- $stderr.puts "missing arg"
82
+ $stderr.puts 'missing arg'
219
83
  return FAILURE
220
84
  else
221
85
  filename = rest[0]
222
86
  end
223
87
 
224
- #
225
- ##
226
- ## 1. build dir tree walker
227
- ##
228
- #dirname = File.expand_path(dirname)
229
- #dtw = DirTreeWalker.new(dirname, options)
230
- #unless options[:all_files]
231
- # dtw.ignore(/^\.[^.]+/) # ignore all file starting with "."
232
- #end
233
- #dtw.visit_file = !options[:only_directories]
234
- #
235
- #case options[:algo]
236
- #
237
- # when 'build-dir'
238
- #
239
- # visitor = BuildDirTreeVisitor.new(options)
240
- # dtw.run(visitor)
241
- #
242
- # output.puts visitor.root.to_str('', options)
243
- #
244
- # if options[:show_report]
245
- # output.puts
246
- # output.puts "#{visitor.nr_directories} directories, #{visitor.nr_files} files"
247
- # end
248
- #
249
- # when 'print-dir'
250
- # visitor = PrintDirTreeVisitor.new
251
- # dtw.run(visitor)
252
- #
253
- # when 'json'
254
- # visitor = DirectoryToHashVisitor.new(dirname)
255
- # root = dtw.run(visitor).root
256
- # output.puts JSON.pretty_generate(root)
257
- #
258
- # when 'json2'
259
- # visitor = DirectoryToHash2Visitor.new(dirname)
260
- # root = dtw.run(visitor).root
261
- # output.puts JSON.pretty_generate(root)
262
- #
263
- # when 'yaml'
264
- # visitor = DirectoryToHashVisitor.new(dirname)
265
- # root = dtw.run(visitor).root
266
- # output.puts root.to_yaml
267
- #
268
- # when 'sqlite'
269
- # begin
270
- # require 'sqlite3'
271
- # unless options[:output]
272
- # $stderr.puts "need to specify the -o options"
273
- # else
274
- # output.close
275
- # filename = options[:output]
276
- # visitor = SqliteDirTreeVisitor.new(filename)
277
- # #start = Time.now
278
- # #me = self
279
- # #bytes = 0
280
- # dtw.run(visitor)
281
- # end
282
- #
283
- # rescue LoadError
284
- # puts 'You must gem install sqlite3 to use this output format'
285
- # end
286
- #
287
- # else
288
- # puts "unknown algo #{options[:algo]} specified"
289
- #end
290
-
291
-
292
88
  show_input = false
293
89
 
294
90
  unless File.exists?(filename)
@@ -299,21 +95,21 @@ module TreeRb
299
95
  my_json_str = File.read(filename)
300
96
 
301
97
  if show_input
302
- $stderr.puts "*************************"
98
+ $stderr.puts '*************************'
303
99
  $stderr.puts my_json_str
304
- $stderr.puts "*************************"
100
+ $stderr.puts '*************************'
305
101
  end
306
102
 
307
103
  begin
308
104
  my_json = JSON(my_json_str)
309
105
  rescue JSON::ParserError
310
- $stderr.puts "json is malformed"
106
+ $stderr.puts 'json is malformed'
311
107
  return FAILURE
312
108
  end
313
109
 
314
110
  output.puts JSON.pretty_generate(my_json)
315
111
 
316
- return SUCCESS
112
+ SUCCESS
317
113
  end
318
114
 
319
115
  end # end class
@@ -2,7 +2,7 @@
2
2
  module TreeRb
3
3
 
4
4
  #
5
- #
5
+ # Command Line Interface to Tree
6
6
  #
7
7
  class CliTree
8
8
 
@@ -11,11 +11,11 @@ module TreeRb
11
11
  end
12
12
 
13
13
  def options_parser(options)
14
- parser = OptionParser.new
15
- parser.banner = "Usage: tree.rb [options] [directory]"
16
- parser.separator "list contents of directories in a tree-like format"
17
- parser.separator "this is a almost :-) a clone of tree unix command written in ruby"
18
- parser.separator "Code https://github.com/tokiro/treevisitor. Feedback to tokiro.oyama@gmail.com"
14
+ parser = OptionParser.new
15
+ parser.banner = 'Usage: tree.rb [options] [directory]'
16
+ parser.separator 'list contents of directories in a tree-like format'
17
+ parser.separator 'this is a almost :-) a clone of tree unix command written in ruby'
18
+ parser.separator 'Code https://github.com/tokiro/treevisitor. Feedback to tokiro.oyama@gmail.com'
19
19
 
20
20
  #
21
21
  # Generic
@@ -70,19 +70,19 @@ module TreeRb
70
70
 
71
71
  options[:only_files] = false
72
72
  parser.on("--only-files", "show only file implies -i") do
73
- options[:only_files] = true
73
+ options[:only_files] = true
74
74
  options[:show_indentation] = false
75
75
  end
76
76
 
77
- algos = %w[build-dir print-dir json d3js html_partition html_tree html_treemap yaml sqlite dircat]
77
+ formats = %w[build-dir print-dir json d3js html_partition html_tree html_treemap yaml sqlite dircat]
78
78
  # algo_aliases = { "b" => "build-dir", "v" => "print-dir", "j" => "json", "y" => "yaml", "s" => "sqlite" }
79
- # algo_list = (algo_aliases.keys + algos).join(',')
80
- parser.on("--format ALGO", algos, "select an algo", " (#{algos})") do |algo|
81
- options[:algo] = algo
79
+ # algo_list = (algo_aliases.keys + formats).join(',')
80
+ parser.on('--format FORMAT', formats, 'select a output format', " (#{formats})") do |format|
81
+ options[:output_plugins] = format
82
82
  end
83
83
 
84
84
  options[:max_level] = nil
85
- parser.on("-L [LEVEL]", Integer, "Max display depth of the directory tree.") do |l|
85
+ parser.on("-L [LEVEL]", Integer, 'Max display depth of the directory tree.') do |l|
86
86
  options[:max_level] = l
87
87
  end
88
88
 
@@ -96,13 +96,13 @@ module TreeRb
96
96
  # begin colorize
97
97
  #
98
98
  # copied from tree man page
99
- parser.on("-n", "Turn colorization off always, over-ridden by the -C option.") do
99
+ parser.on("-n", 'Turn colorization off always, over-ridden by the -C option.') do
100
100
  options[:colorize_force] = false
101
101
  end
102
102
 
103
103
  # copied from tree man page
104
104
  parser.on("-C",
105
- "Turn colorization on always, using built-in color",
105
+ 'Turn colorization on always, using built-in color',
106
106
  " defaults if the LS_COLORS environment variable is not set.",
107
107
  " Useful to colorize output to a pipe.") do
108
108
  options[:colorize_force] = true
@@ -134,8 +134,8 @@ module TreeRb
134
134
 
135
135
  options[:show_indentation] = true
136
136
  parser.on("-i",
137
- "Makes tree not print the indentation lines, ",
138
- " useful when used in conjunction with the -f option.") do
137
+ 'Makes tree not print the indentation lines, ',
138
+ ' useful when used in conjunction with the -f option.') do
139
139
  options[:show_indentation] = false
140
140
  end
141
141
 
@@ -159,18 +159,18 @@ module TreeRb
159
159
 
160
160
  options[:show_md5sum] = false
161
161
  parser.on("--md5sum", "show ake md5sum implies -i and --only-files") do
162
- options[:only_files] = true
163
- options[:show_md5sum] = true
162
+ options[:only_files] = true
163
+ options[:show_md5sum] = true
164
164
  options[:show_indentation] = false
165
- options[:show_report] = false
165
+ options[:show_report] = false
166
166
  end
167
167
 
168
168
  options[:show_sha1sum] = false
169
- parser.on("--sha1sum", "show ake sha1sum output implies -i and --only-files") do
170
- options[:only_files] = true
171
- options[:show_sha1sum] = true
169
+ parser.on('--sha1sum', 'show ake sha1sum output implies -i and --only-files') do
170
+ options[:only_files] = true
171
+ options[:show_sha1sum] = true
172
172
  options[:show_indentation] = false
173
- options[:show_report] = false
173
+ options[:show_report] = false
174
174
  end
175
175
 
176
176
 
@@ -178,22 +178,22 @@ module TreeRb
178
178
  end
179
179
 
180
180
  def parse_args(argv)
181
- options = { :verbose => true, :force => false, :algo => 'build-dir' }
182
- parser = options_parser(options)
181
+ options = {:verbose => true, :force => false, :output_plugins => 'build-dir'}
182
+ parser = options_parser(options)
183
183
 
184
184
  begin
185
185
  rest = parser.parse(argv)
186
186
  rescue OptionParser::InvalidOption => e
187
187
  $stderr.puts e.to_s
188
- $stderr.puts "try --help for help"
188
+ $stderr.puts 'try --help for help'
189
189
  return false
190
190
  rescue OptionParser::MissingArgument => e
191
191
  $stderr.puts e.to_s
192
- $stderr.puts "try --help for help"
192
+ $stderr.puts 'try --help for help'
193
193
  return false
194
194
  rescue OptionParser::InvalidArgument => e
195
195
  $stderr.puts e.to_s
196
- $stderr.puts "try --help for help"
196
+ $stderr.puts 'try --help for help'
197
197
  return false
198
198
  end
199
199
 
@@ -211,7 +211,7 @@ module TreeRb
211
211
  $stderr.puts "catalog '#{filename}' exists use --force to overwrite"
212
212
  return 0
213
213
  end
214
- output = File.open(filename, "w")
214
+ output = File.open(filename, 'w')
215
215
  $stderr.puts "Writing file '#{filename}'"
216
216
  end
217
217
 
@@ -223,7 +223,10 @@ module TreeRb
223
223
 
224
224
  # TODO: capture CTRL^C to avoid show the stack trace
225
225
  # http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-trap
226
- Signal.trap('INT') { puts "intercepted ctr+c"; exit }
226
+ Signal.trap('INT') do
227
+ puts 'intercepted ctr+c'
228
+ exit
229
+ end
227
230
 
228
231
  if rest.length < 1
229
232
  dirname = Dir.pwd
@@ -247,64 +250,79 @@ module TreeRb
247
250
  end
248
251
  directory_tree_walker.visit_file = !options[:only_directories]
249
252
 
250
- case options[:algo]
251
-
252
- when 'build-dir'
253
-
254
- visitor = BuildDirTreeVisitor.new(options)
255
- directory_tree_walker.run(visitor)
256
-
257
- output.puts visitor.root.to_str('', options)
258
-
259
- if options[:show_report]
260
- output.puts
261
- output.puts "#{visitor.nr_directories} directories, #{visitor.nr_files} files"
253
+ formats = {
254
+ 'build-dir' => Proc.new do |directory_tree_walker,output,options|
255
+
256
+ visitor = BuildDirTreeVisitor.new(options)
257
+ directory_tree_walker.run(visitor)
258
+
259
+ output.puts visitor.root.to_str('', options)
260
+
261
+ if options[:show_report]
262
+ output.puts
263
+ output.puts "#{visitor.nr_directories} directories, #{visitor.nr_files} files"
264
+ end
265
+ end,
266
+
267
+ 'print-dir' => Proc.new do |directory_tree_walker,output,options|
268
+ visitor = PrintDirTreeVisitor.new
269
+ directory_tree_walker.run(visitor)
270
+ end,
271
+
272
+ 'yaml' => Proc.new do |directory_tree_walker,output,options|
273
+ visitor = DirectoryToHashVisitor.new(dirname)
274
+ root = directory_tree_walker.run(visitor).root
275
+ output.puts root.to_yaml
276
+ end,
277
+
278
+ 'json' => Proc.new do |directory_tree_walker,output,options|
279
+ visitor = DirectoryToHashVisitor.new(dirname)
280
+ root = directory_tree_walker.run(visitor).root
281
+ begin
282
+ output.puts JSON.pretty_generate(root)
283
+ rescue JSON::NestingError => e
284
+ $stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
285
+ end
286
+ end,
287
+
288
+ 'd3js' => Proc.new do |directory_tree_walker,output,options|
289
+ require 'tree_rb/output_plugins/html/d3js_output'
290
+ D3jsOutput.new.run(directory_tree_walker, dirname, nil, output)
291
+ end,
292
+
293
+ 'html_partition' => Proc.new do |directory_tree_walker,output,options|
294
+ require 'tree_rb/output_plugins/html/d3js_output'
295
+ D3jsOutput.new.run(directory_tree_walker, dirname, 'd3js_layout_partition.erb', output)
296
+ end,
297
+
298
+ 'html_tree' => Proc.new do |directory_tree_walker,output,options|
299
+ require 'tree_rb/output_plugins/html/d3js_output'
300
+ D3jsOutput.new.run(directory_tree_walker, dirname, 'd3js_layout_tree.erb', output)
301
+ end,
302
+
303
+ 'html_treemap' => Proc.new do |directory_tree_walker,output,options|
304
+ require 'tree_rb/output_plugins/html/d3js_output'
305
+ D3jsOutput.new.run(directory_tree_walker, dirname, 'd3js_layout_treemap.erb', output)
306
+ end,
307
+
308
+ 'dircat' => Proc.new do |directory_tree_walker,output,options|
309
+ require 'tree_rb/output_plugins/dircat/dircat_output'
310
+ DirCatOutput.new.run(directory_tree_walker, options)
311
+ end,
312
+
313
+ 'sqlite' => Proc.new do |directory_tree_walker,output,options|
314
+ require 'tree_rb/output_plugins/sqlite/sqlite_output'
315
+ SqliteOutput.new.run(directory_tree_walker, output, options)
262
316
  end
317
+ }
263
318
 
264
- when 'print-dir'
265
- visitor = PrintDirTreeVisitor.new
266
- directory_tree_walker.run(visitor)
267
-
268
- when 'yaml'
269
- visitor = DirectoryToHashVisitor.new(dirname)
270
- root = directory_tree_walker.run(visitor).root
271
- output.puts root.to_yaml
272
-
273
- when 'json'
274
- visitor = DirectoryToHashVisitor.new(dirname)
275
- root = directory_tree_walker.run(visitor).root
276
- begin
277
- output.puts JSON.pretty_generate(root)
278
- rescue JSON::NestingError => e
279
- $stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
280
- end
281
-
282
- when 'd3js'
283
- require 'tree_rb/output_html/d3js_helper'
284
- D3jsHelper.new.run(directory_tree_walker, dirname, nil, output)
285
-
286
- when 'html_partition'
287
- require 'tree_rb/output_html/d3js_helper'
288
- D3jsHelper.new.run(directory_tree_walker, dirname, "d3js_layout_partition.erb", output)
289
-
290
- when 'html_tree'
291
- require 'tree_rb/output_html/d3js_helper'
292
- D3jsHelper.new.run(directory_tree_walker, dirname, "d3js_layout_tree.erb", output)
319
+ format = options[:output_plugins]
293
320
 
294
- when 'html_treemap'
295
- require 'tree_rb/output_html/d3js_helper'
296
- D3jsHelper.new.run(directory_tree_walker, dirname, "d3js_layout_treemap.erb", output)
297
-
298
- when 'sqlite'
299
- require 'tree_rb/output_sqlite/sqlite_helper'
300
- SqliteHelper.new.run(directory_tree_walker, output, options)
301
-
302
- when 'dircat'
303
- require 'tree_rb/output_dircat/dircat_helper'
304
- DirCatHelper.new.run(directory_tree_walker, options)
305
-
306
- else
307
- puts "unknown format #{options[:algo]} specified"
321
+ p = formats[format]
322
+ if p
323
+ p.call(directory_tree_walker, output, options)
324
+ else
325
+ puts "unknown format #{options[:output_plugins]} specified"
308
326
  end
309
327
 
310
328
  0