mose/shellplay

View on GitHub
bin/shellexport

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'paint'
require 'erb'
require "shell2html"

lib = File.expand_path('../../lib', __FILE__)
tpl = File.expand_path('../../tpl', __FILE__)
basedir = File.join(ENV['HOME'], '.shellplay')

$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'shellplay/session'

@session = Shellplay::Session.new
@session.import(ARGV[0])

dest = File.join(basedir, @session.name)
FileUtils.mkdir_p(dest) unless Dir.exist? dest

erb = ERB.new(File.read(File.join(tpl, 'index.html')))
File.open(File.join(dest, "index.html"), 'w') do |f|
  f.puts erb.result(binding)
end

unless File.exist? File.join(dest, 'jquery-1.11.1.min.js')
  FileUtils.cp(File.join(tpl, 'jquery-1.11.1.min.js'), dest)
end

unless File.exist? File.join(dest, 'shellplay.js')
  FileUtils.cp(File.join(tpl, 'shellplay.js'), dest)
end

unless File.exist? File.join(dest, 'shellplay.css')
  FileUtils.cp(File.join(tpl, 'shellplay.css'), dest)
end

unless File.exist? File.join(dest, 'colors.css')
  File.open(File.join(dest, "colors.css"), 'w') do |f|
    f.puts Shell2html.css
  end
end