class Htmldu::Commands
Public Class Methods
new(dir, script_dir)
click to toggle source
# File lib/htmldu/commands.rb, line 10 def initialize(dir, script_dir) @dir = dir @script_dir = script_dir @dirtree = Htmldu::Dirtree.new(@dir) end
start(args, script_dir)
click to toggle source
# File lib/htmldu/commands.rb, line 5 def self.start(args, script_dir) command = self.new(args[0], script_dir) command.exec end
Public Instance Methods
exec()
click to toggle source
# File lib/htmldu/commands.rb, line 28 def exec() @dirtree.generate_tree json_file = Tempfile.create("htmldu") json_file.write "dirtree=" json_file.write @dirtree.to_json json_file.close json_path = json_file.path + ".js" json_url = "file://#{json_path}" File.rename(json_file.path, json_path) script_url = "file://#{@script_dir}/lib/htmldu/js/show.js" html_file = Tempfile.create("htmldu") html_file.write <<"EOS" <html> <head> <title> DU: #{@dir} </title> <script src="#{json_url}"></script> </head> <body> </body> <script src="#{script_url}"></script> </html> EOS html_file.close html_path = html_file.path + ".html" File.rename(html_file.path, html_path) system "#{open_command} #{html_path}" end
open_command()
click to toggle source
# File lib/htmldu/commands.rb, line 16 def open_command @open_command ||= case RbConfig::CONFIG['host_os'] when /darwin/ 'open' when /linux|bsd/ 'xdg-open' when /mswin|mingw|cygwin/ 'start' end end