Class: TreeRb::D3jsOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_rb/output_plugins/html/d3js_output.rb

Instance Method Summary collapse

Instance Method Details

#run(directory_tree_walker, dirname, template, output) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tree_rb/output_plugins/html/d3js_output.rb', line 7

def run(directory_tree_walker, dirname, template, output)
  require 'tree_rb/output_plugins/html/directory_to_hash2_visitor'
  require 'tree_rb/output_plugins/html/erb_render'

  visitor = DirectoryToHash2Visitor.new(dirname)
  root    = directory_tree_walker.run(visitor).root
  begin
    str_json = JSON.pretty_generate(root)
    str_json = 'var data = ' + str_json

    if template
      render = ErbRender.new(template, str_json)
      output.puts render.render
    else
      output.puts str_json
    end

  rescue JSON::NestingError => e
    $stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
  end
end