class Jasmine::CommandLineTool

Public Instance Methods

copy_unless_exists(relative_path, dest_path = nil) click to toggle source
# File lib/jasmine/command_line_tool.rb, line 19
def copy_unless_exists(relative_path, dest_path = nil)
  unless File.exist?(dest_path(relative_path))
    FileUtils.copy(template_path(relative_path), dest_path(dest_path || relative_path))
  end
end
cwd() click to toggle source
# File lib/jasmine/command_line_tool.rb, line 3
def cwd
  File.expand_path(File.join(File.dirname(__FILE__), '../..'))
end
dest_path(filepath) click to toggle source
# File lib/jasmine/command_line_tool.rb, line 15
def dest_path(filepath)
  expand(Dir.pwd, filepath)
end
expand(*paths) click to toggle source
# File lib/jasmine/command_line_tool.rb, line 7
def expand(*paths)
  File.expand_path(File.join(*paths))
end
process(argv) click to toggle source
# File lib/jasmine/command_line_tool.rb, line 25
def process(argv)
  if argv[0] == 'init'
    require 'fileutils'

    FileUtils.makedirs('public/javascripts')
    FileUtils.makedirs('spec/javascripts')
    FileUtils.makedirs('spec/javascripts/support')
    FileUtils.makedirs('spec/javascripts/helpers')

    copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
    copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
    copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
    copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')

    copy_unless_exists('spec/javascripts/support/jasmine.yml')
    copy_unless_exists('spec/javascripts/support/jasmine_helper.rb')
    require 'rake'
    write_mode = 'w'
    if File.exist?(dest_path('Rakefile'))
      load dest_path('Rakefile')
      write_mode = 'a'
    end

    unless Rake::Task.task_defined?('jasmine')
      File.open(dest_path('Rakefile'), write_mode) do |f|
        f.write("\n" + File.read(template_path('lib/tasks/jasmine.rake')))
      end
    end
    File.open(template_path('INSTALL'), 'r').each_line do |line|
      puts line
    end
  elsif argv[0] == "license"
    puts File.new(expand(cwd, "MIT.LICENSE")).read
  else
    puts "unknown command #{argv}"
    puts "Usage: jasmine init"
    puts "               license"
  end
end
template_path(filepath) click to toggle source
# File lib/jasmine/command_line_tool.rb, line 11
def template_path(filepath)
  expand(cwd, File.join("generators", "jasmine" ,"templates", filepath))
end