exe/dirtree in dirtree-0.2.0 vs exe/dirtree in dirtree-0.3.0

- old
+ new

@@ -1,10 +1,11 @@ #!/usr/bin/env ruby require 'dirtree' require 'optparse' require 'json' require 'erb' +require 'open-uri' templates_dir = File.join(File.dirname(__FILE__), '..', 'templates') templates = Dir.open(templates_dir).map do |file| file[0...file.index('.')] end.reject(&:empty?) @@ -33,13 +34,22 @@ puts opts exit end opts.on( + '-l', + '--local-dependencies', + 'Use saved JavaScript libraries instead of downloading them' + ) do + options[:local_dependencies] = true + end + + opts.on( '-oFile.html', '--output=File.html', - 'Specify a path to write output, by default will be printed to STDOUT' + 'Specify a path to write output, if + not specified output will be printed to STDOUT' ) do |value| options[:output] = value end opts.on( @@ -59,9 +69,19 @@ template_file = File.join(templates_dir, options[:template] + '.html.erb') template = File.read(File.expand_path(template_file)) tree = root.as_json result = ERB.new(template).result binding + +if options[:local_dependencies] + result.gsub! %r{(<script src="(.+)"><\/script>)} do + injection = '<script>' + injection << open($2).read + injection << '</script>' + + injection + end +end if options.key?(:output) File.write(options[:output], result) else puts result