lib/kango.rb in kango-0.0.2.0.9.2 vs lib/kango.rb in kango-0.0.3.0.9.2
- old
+ new
@@ -1,95 +1,21 @@
require "kango/version"
-require 'thor'
-require 'pathname'
+require 'kango/tasks'
module Kango
- KANGO_FRAMEWORK_URL = "http://kangoextensions.com/kango/kango-framework-latest.zip"
- KANGO_FRAMEWORK = File.expand_path(File.join('~', 'kango-framework'))
+ module Framework
+ URL = "http://kangoextensions.com/kango/kango-framework-latest.zip"
+ PATH = File.expand_path(File.join('~', 'kango-framework'))
- def self.framework_exists?
- File.directory? KANGO_FRAMEWORK
- end
-
- class Tasks < Thor
- desc "install", "Install the kango framework"
- def install
- require 'kango/install'
- if Kango.framework_exists?
- puts "Framework exists! Will not re-install."
- else
- Kango.install!
- end
+ def self.exists?
+ File.directory? Kango::Framework::PATH
end
- desc 'compile', 'Compile coffeescript userscripts into common as javascript'
- def compile
- require 'coffee-script'
- Dir.glob('coffee/**/*.coffee') do |file|
- script = file.gsub(/(^coffee|coffee$)/, 'js').split('/').last
- path = Pathname.new('src/common').join(script)
- puts "[ INFO] Compiling #{file} to #{path.to_s}"
- FileUtils.mkdir_p path.dirname
- File.open(path.to_s, 'w') do |f|
- f.puts userscript_commentblock(file)
- f.puts CoffeeScript.compile File.read(file), :bare => true
- end
- end
+ def self.build!
+ `python #{Kango::Framework::PATH}/kango.py build .`
end
- desc 'build', 'Build the extensions with Kango'
- def build
- self.compile
- ensure_framework do
- `python #{KANGO_FRAMEWORK}/kango.py build .`
- end
- end
-
- desc 'create', 'Create a new kango project'
- def create name
- require 'kango/templates'
- ensure_framework do
- path = File.expand_path(File.join(Dir.pwd, name))
- puts "Creating Kango project at #{path}"
- `echo #{name} | python #{KANGO_FRAMEWORK}/kango.py create #{path}`
- File.open(File.join(path, 'Gemfile'), 'w') do |gemfile|
- gemfile.puts Kango::Templates.gemfile
- end
- FileUtils.mkdir File.join(path, 'coffee')
- File.open(File.join(path, 'coffee', 'main.coffee'), 'w') do |main|
- main.puts Kango::Templates.main_coffee
- end
- end
- end
-
- desc 'docs', 'Open Kango Framework documentation'
- def docs
- require 'launchy'
- Launchy.open("http://kangoextensions.com/docs/index.html")
- end
-
- private
-
- ##
- # Extract userscript comment block from CoffeeScript file.
- def userscript_commentblock(coffee_file)
- comment = ""
- File.open(coffee_file) do |f|
- while line = f.gets
- break unless line =~ /^#/
- comment += line.gsub(/^#/, '//')
- end
- end
- comment
- end
-
- ##
- # Calls the block only if the framework exists
- def ensure_framework &block
- if Kango.framework_exists?
- block.call
- else
- puts "Kango Framework is missing. Install it with 'kango install'"
- end
+ def self.create_project! name, path
+ `echo #{name} | python #{Kango::Framework::PATH}/kango.py create #{path}`
end
end
end