kango 0.0.2.0.9.2 → 0.0.3.0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTA0Yjk3N2E1NWQ4YjFhNjNlOTBkYzc2ZWZhZmNlMmVkMDhiZTk2MA==
4
+ OTgwZWU3NmUwMzk1NDg4OTMwNTEwZTlmYjVlYzMzNmE1NDM0MDAyMg==
5
5
  data.tar.gz: !binary |-
6
- Mjg4YWIxZmFlMjczNTk1YjQ5NDBjY2Q4Mjg1NmJjZWFjOWEwNzJhMQ==
6
+ ZTYwY2E4OTIyNmU4OGM3MGFmMGYxZWE0OWZkMjYxMjI2NmI4MDkyNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDM5MTczMTllMTc1Y2ExYWUxNzY2YmRhNTFhYzZmODk0MDBjOGYxZDUzNmJi
10
- ZjI4OTg2OGZhOTlmMzkyZWYyY2EzODliZjc4ZGRhZDhjOTJiM2E1ZjQwNTRm
11
- MmE2Y2YxYmEwYmYyMzNjNTMwM2VhZWE3YTdkNDExODczNGNjZTE=
9
+ MDk1Mjc0ZjZhNjY2NmI2NDM3ZjZiM2Y2MWFkMGI1ZDJiMDNkZjE4NDY5NTE4
10
+ OGIxNWYzN2VkZGMzZDA2OWI0YTI3ZTgwYzUzYjUwNTdiZjRmOWE3ZWY2ZTk5
11
+ MTA2MTVhNzQ2NTNhZDZhMmRlYzA0Yjg1NGMxMjA4NjdmZjgwYTE=
12
12
  data.tar.gz: !binary |-
13
- ZjNlN2IwNzk2N2QwZDYxZTQ0ZGI1ZDg4ZmZmYWVhM2M5ZjEyZDNmY2I3YmZj
14
- ZTM2NTg2ZmUzYzExNDkxZWFlYzc3NmM0M2I4ZjY2NzY1NWVlYTNhNzY1YzQ2
15
- NmI2NmY3MmI0YWJlNmU5ZDNiYzFhMjg2N2QwMDcwODBmYjVmMGY=
13
+ NTE3MDYzZjZkY2E2ZWViOTM5M2VkNmFlNTcwZmY2YjgyYjkyNTM0ZWM3Y2Rm
14
+ YTUxOGIxY2I5MjBkMmMzYWM5ZDVkMTRjZWJlOTNkNjM5ZTcxZTlhN2Q1ZWU0
15
+ MmJmZDhiN2EzMDNiMzczZTBhNzRiNWU4MGM0ZmRlYzEwMzcyYjQ=
data/README.md CHANGED
@@ -31,6 +31,8 @@ Or install it yourself as:
31
31
 
32
32
  `kango build` will compile your coffeescript and use KangoFramework to build
33
33
 
34
+ `kango watch` will watch your project and autobuild on change
35
+
34
36
  ## Example
35
37
 
36
38
  ```bash
@@ -43,6 +45,10 @@ vim coffee/main.coffee # write coffeescript here!
43
45
  kango build # compile the coffeescript and build with the Kango Framework
44
46
  ```
45
47
 
48
+ ## ExtensionsReloader
49
+
50
+ `kango watch reload.extensions` calls open -a '/Applications/Google\ Chrome\ Canary.app' 'http://reload.extensions', which works if you're on Mac, using Chrome Canary, and have ExtensionsReloader installed.
51
+
46
52
  ## Contributing
47
53
 
48
54
  1. Fork it
data/kango.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency 'thor', '~>0.18.1'
29
29
  spec.add_runtime_dependency 'coffee-script', '~> 2.2.0'
30
30
  spec.add_runtime_dependency 'launchy'
31
+ spec.add_runtime_dependency 'directory_watcher', "~> 1.4.1"
31
32
  end
data/lib/kango.rb CHANGED
@@ -1,95 +1,21 @@
1
1
  require "kango/version"
2
- require 'thor'
3
- require 'pathname'
2
+ require 'kango/tasks'
4
3
 
5
4
  module Kango
6
- KANGO_FRAMEWORK_URL = "http://kangoextensions.com/kango/kango-framework-latest.zip"
7
- KANGO_FRAMEWORK = File.expand_path(File.join('~', 'kango-framework'))
5
+ module Framework
6
+ URL = "http://kangoextensions.com/kango/kango-framework-latest.zip"
7
+ PATH = File.expand_path(File.join('~', 'kango-framework'))
8
8
 
9
- def self.framework_exists?
10
- File.directory? KANGO_FRAMEWORK
11
- end
12
-
13
- class Tasks < Thor
14
- desc "install", "Install the kango framework"
15
- def install
16
- require 'kango/install'
17
- if Kango.framework_exists?
18
- puts "Framework exists! Will not re-install."
19
- else
20
- Kango.install!
21
- end
22
- end
23
-
24
- desc 'compile', 'Compile coffeescript userscripts into common as javascript'
25
- def compile
26
- require 'coffee-script'
27
- Dir.glob('coffee/**/*.coffee') do |file|
28
- script = file.gsub(/(^coffee|coffee$)/, 'js').split('/').last
29
- path = Pathname.new('src/common').join(script)
30
- puts "[ INFO] Compiling #{file} to #{path.to_s}"
31
- FileUtils.mkdir_p path.dirname
32
- File.open(path.to_s, 'w') do |f|
33
- f.puts userscript_commentblock(file)
34
- f.puts CoffeeScript.compile File.read(file), :bare => true
35
- end
36
- end
37
- end
38
-
39
- desc 'build', 'Build the extensions with Kango'
40
- def build
41
- self.compile
42
- ensure_framework do
43
- `python #{KANGO_FRAMEWORK}/kango.py build .`
44
- end
9
+ def self.exists?
10
+ File.directory? Kango::Framework::PATH
45
11
  end
46
12
 
47
- desc 'create', 'Create a new kango project'
48
- def create name
49
- require 'kango/templates'
50
- ensure_framework do
51
- path = File.expand_path(File.join(Dir.pwd, name))
52
- puts "Creating Kango project at #{path}"
53
- `echo #{name} | python #{KANGO_FRAMEWORK}/kango.py create #{path}`
54
- File.open(File.join(path, 'Gemfile'), 'w') do |gemfile|
55
- gemfile.puts Kango::Templates.gemfile
56
- end
57
- FileUtils.mkdir File.join(path, 'coffee')
58
- File.open(File.join(path, 'coffee', 'main.coffee'), 'w') do |main|
59
- main.puts Kango::Templates.main_coffee
60
- end
61
- end
62
- end
63
-
64
- desc 'docs', 'Open Kango Framework documentation'
65
- def docs
66
- require 'launchy'
67
- Launchy.open("http://kangoextensions.com/docs/index.html")
68
- end
69
-
70
- private
71
-
72
- ##
73
- # Extract userscript comment block from CoffeeScript file.
74
- def userscript_commentblock(coffee_file)
75
- comment = ""
76
- File.open(coffee_file) do |f|
77
- while line = f.gets
78
- break unless line =~ /^#/
79
- comment += line.gsub(/^#/, '//')
80
- end
81
- end
82
- comment
13
+ def self.build!
14
+ `python #{Kango::Framework::PATH}/kango.py build .`
83
15
  end
84
16
 
85
- ##
86
- # Calls the block only if the framework exists
87
- def ensure_framework &block
88
- if Kango.framework_exists?
89
- block.call
90
- else
91
- puts "Kango Framework is missing. Install it with 'kango install'"
92
- end
17
+ def self.create_project! name, path
18
+ `echo #{name} | python #{Kango::Framework::PATH}/kango.py create #{path}`
93
19
  end
94
20
  end
95
21
  end
@@ -0,0 +1,26 @@
1
+ module Kango
2
+ module Installer
3
+ def self.run!
4
+ if Kango::Framework.exists?
5
+ puts "Framework exists! Will not re-install."
6
+ else
7
+ zipfile = File.expand_path(File.join("~", 'kango-framework.zip'))
8
+ puts "Downloading Kango Framework to #{zipfile}..."
9
+ require 'open-uri'
10
+ File.open(zipfile, 'wb') do |file|
11
+ open(Kango::Framework::URL, 'rb') do |download|
12
+ file.write download.read
13
+ end
14
+ end
15
+ puts "Download complete! Extracting..."
16
+ `unzip #{zipfile} -d #{Kango::Framework::PATH}`
17
+ if Kango::Framework.exists?
18
+ FileUtils.rm zipfile
19
+ puts "Kango Framework is ready. You can now 'kango build'"
20
+ else
21
+ puts "Something went wrong... probably could not download Kango Framework"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ module Kango
2
+ module Reloader
3
+ module Chrome
4
+ class ExtensionsReloader
5
+ attr_accessor :watch_folder, :watcher, :on
6
+
7
+ def initialize
8
+ self.watch_folder = File.join(Dir.pwd, 'output', 'chrome')
9
+ STDOUT.puts "#{self.class} watching #{self.watch_folder}"
10
+ STDOUT.puts "WARNING: This experimental feature requires the chrome extension called ExtensionsReloader and calls the following command: #{command}"
11
+ end
12
+
13
+ def trigger &block
14
+ return if @on
15
+ self.watcher = DirectoryWatcher.new(self.watch_folder, :pre_load => true)
16
+ self.watcher.interval = 1
17
+ self.watcher.add_observer do |*args|
18
+ block.call
19
+ end
20
+ self.watcher.start
21
+ self.on = true
22
+ end
23
+
24
+ def command
25
+ %{open -a '/Applications/Google\ Chrome\ Canary.app' 'http://reload.extensions'}
26
+ end
27
+
28
+ def reload_browser
29
+ system(command)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ require 'coffee-script'
2
+
3
+ module Kango
4
+ class ScriptCompiler
5
+ def initialize dir_glob, extension, compiler
6
+ @compiler = compiler
7
+ @extension = extension
8
+ @files = Dir.glob("#{dir_glob}.#{extension}")
9
+ end
10
+
11
+ def script_regex
12
+ /(^#{@extension}|#{@extension}$)/
13
+ end
14
+
15
+ def compile
16
+ @files.each do |file|
17
+ script = file.gsub(script_regex, 'js').split('/').last
18
+ path = File.join('src', 'common', script)
19
+ puts "[ INFO] Compiling #{file} to #{path.to_s}"
20
+ FileUtils.mkdir_p File.dirname(path)
21
+ File.open(path.to_s, 'w') do |f|
22
+ if @compiler.to_s == 'CoffeeScript'
23
+ f.puts Kango::ScriptCompiler.coffee_userscript_commentblock file
24
+ end
25
+ f.puts Kango::ScriptCompiler.compile file, with: @compiler
26
+ end
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Compile the script to javascript
32
+ def self.compile file, options
33
+ compiler = options[:with]
34
+ compiler.compile File.read(file), :bare => true
35
+ end
36
+
37
+ ##
38
+ # Extract userscript comment block from CoffeeScript file.
39
+ def self.coffee_userscript_commentblock(coffee_file)
40
+ comment = ""
41
+ File.open(coffee_file) do |f|
42
+ while line = f.gets
43
+ break unless line =~ /^#/
44
+ comment += line.gsub(/^#/, '//')
45
+ end
46
+ end
47
+ comment
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,101 @@
1
+ require 'thor'
2
+
3
+ module Kango
4
+ class Tasks < Thor
5
+ desc "install", "Install the kango framework"
6
+ def install
7
+ require 'kango/installer'
8
+ Kango::Installer.run!
9
+ end
10
+
11
+ desc 'compile', 'Compile coffeescript userscripts into common as javascript'
12
+ def compile
13
+ require 'kango/script_compiler'
14
+ Kango::ScriptCompiler.new('coffee/**/*', 'coffee', CoffeeScript).compile
15
+ end
16
+
17
+ desc 'build', 'Build the extensions with Kango'
18
+ def build
19
+ ensure_framework do
20
+ self.compile if File.directory?(File.join(Dir.pwd, 'coffee'))
21
+ Kango::Framework.build!
22
+ end
23
+ end
24
+
25
+ desc 'create', 'Create a new kango project'
26
+ def create name
27
+ require 'kango/templates'
28
+ ensure_framework do
29
+ path = File.expand_path(File.join(Dir.pwd, name))
30
+ puts "Creating Kango project at #{path}"
31
+ Kango::Framework.create_project! name, path
32
+ File.open(File.join(path, 'Gemfile'), 'w') do |gemfile|
33
+ gemfile.puts Kango::Templates.gemfile
34
+ end
35
+ FileUtils.mkdir File.join(path, 'coffee')
36
+ File.open(File.join(path, 'coffee', 'main.coffee'), 'w') do |main|
37
+ main.puts Kango::Templates.main_coffee
38
+ end
39
+ end
40
+ end
41
+
42
+ desc 'docs', 'Open Kango Framework documentation'
43
+ def docs
44
+ require 'launchy'
45
+ Launchy.open("http://kangoextensions.com/docs/index.html")
46
+ end
47
+
48
+ desc 'watch', 'Watch for changes and build automatically'
49
+ def watch *opts
50
+ ensure_framework do
51
+ require 'directory_watcher'
52
+
53
+ if opts.include? 'reload.extensions'
54
+ require 'kango/reloader/chrome/extensions_reloader'
55
+ @reloader = Kango::Reloader::Chrome::ExtensionsReloader.new
56
+ end
57
+
58
+ coffee = DirectoryWatcher.new(File.join(Dir.pwd,'coffee'), globs:'**/*.coffee', :pre_load => true)
59
+ coffee.interval = 1
60
+ coffee.add_observer do |*args|
61
+ self.compile
62
+ end
63
+ coffee.start
64
+
65
+ common = DirectoryWatcher.new(File.join(Dir.pwd,'src','common'), :pre_load => true)
66
+ common.interval = 1
67
+ common.add_observer do |*args|
68
+ Kango::Framework.build!
69
+ end
70
+ common.start
71
+
72
+ if @reloader
73
+ @reloader.trigger do
74
+ @reloader.reload_browser
75
+ end
76
+ end
77
+
78
+ unless options['serving']
79
+ trap("INT") do
80
+ puts " Halting auto-regeneration."
81
+ exit 0
82
+ end
83
+
84
+ loop { sleep 1000 }
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ ##
92
+ # Calls the block only if the framework exists
93
+ def ensure_framework &block
94
+ if Kango::Framework.exists?
95
+ block.call
96
+ else
97
+ puts "Kango Framework is missing. Install it with 'kango install'"
98
+ end
99
+ end
100
+ end
101
+ end
data/lib/kango/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kango
2
- VERSION = "0.0.2.0.9.2"
2
+ VERSION = "0.0.3.0.9.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kango
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.0.9.2
4
+ version: 0.0.3.0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keyvan Fatehi
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: directory_watcher
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.4.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 1.4.1
139
153
  description: Wraps the brilliant Kango Framework with ruby niceties
140
154
  email:
141
155
  - keyvanfatehi@gmail.com
@@ -154,7 +168,10 @@ files:
154
168
  - bin/kango
155
169
  - kango.gemspec
156
170
  - lib/kango.rb
157
- - lib/kango/install.rb
171
+ - lib/kango/installer.rb
172
+ - lib/kango/reloader/chrome/extensions_reloader.rb
173
+ - lib/kango/script_compiler.rb
174
+ - lib/kango/tasks.rb
158
175
  - lib/kango/templates.rb
159
176
  - lib/kango/version.rb
160
177
  - spec/spec_helper.rb
data/lib/kango/install.rb DELETED
@@ -1,20 +0,0 @@
1
- module Kango
2
- def self.install!
3
- zipfile = File.expand_path(File.join("~", 'kango-framework.zip'))
4
- puts "Downloading Kango Framework to #{zipfile}..."
5
- require 'open-uri'
6
- File.open(zipfile, 'wb') do |file|
7
- open(KANGO_FRAMEWORK_URL, 'rb') do |download|
8
- file.write download.read
9
- end
10
- end
11
- puts "Download complete! Extracting..."
12
- `unzip #{zipfile} -d #{KANGO_FRAMEWORK}`
13
- if Kango.framework_exists?
14
- FileUtils.rm zipfile
15
- puts "Kango Framework is ready. You can now 'kango build'"
16
- else
17
- puts "Something went wrong... probably could not download Kango Framework"
18
- end
19
- end
20
- end