summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEmmanuel Hadoux <emmanuel.hadoux@gmail.com>2013-03-20 14:43:09 +0100
committerpushmatrix <daniel.beauchamp@gmail.com>2013-03-24 23:08:49 +0100
commit4247f127bd88cd5d09f3778e07daf2a5d9c5de88 (patch)
tree2c08de3fad5d72a077810fcc537efde58abf3829 /bin
parent339f2e24ffeae847684a643d95eee4b923d27452 (diff)
Add a Thor command to install a widget by its Gist Id.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dashing30
1 files changed, 28 insertions, 2 deletions
diff --git a/bin/dashing b/bin/dashing
index fb1332f..4fb4b50 100755
--- a/bin/dashing
+++ b/bin/dashing
@@ -3,6 +3,7 @@
require 'thor'
require 'net/http'
require 'json'
+require 'open-uri'
class MockScheduler
def method_missing(*args)
@@ -55,9 +56,34 @@ module Dashing
send("generate_#{type}".to_sym, name)
rescue NoMethodError => e
puts "Invalid generator. Either use widget, dashboard, or job"
- end
+ end
map "g" => :generate
+ desc "install GIST_ID", "Installs a new widget from a gist."
+ def install(gist_id)
+ public_url = "https://gist.github.com/#{gist_id}"
+ gist = JSON.parse(open("https://api.github.com/gists/#{gist_id}").read)
+
+ gist['files'].each do |filename, contents|
+ if filename.end_with?(".rb")
+ create_file File.join(Dir.pwd, 'jobs', filename), contents['content']
+ elsif filename.end_with?(".coffee", ".html", ".scss")
+ widget_name = File.basename(filename, '.*')
+ create_file File.join(Dir.pwd, 'widgets', widget_name, filename), contents['content']
+ end
+ end
+
+ print set_color("Don't forget to edit the ", :yellow)
+ print set_color("Gemfile ", :yellow, :bold)
+ print set_color("and run ", :yellow)
+ print set_color("bundle install ", :yellow, :bold)
+ say set_color("if needed. More information for this widget can be found at #{public_url}", :yellow)
+
+ rescue OpenURI::HTTPError => e
+ say set_color("Could not find gist at #{public_url}"), :red
+ end
+ map "i" => :install
+
desc "start", "Starts the server in style!"
method_option :job_path, :desc => "Specify the directory where jobs are stored"
def start(*args)
@@ -76,7 +102,7 @@ module Dashing
f = File.join(Dir.pwd, "jobs", "#{name}.rb")
require f
end
-
+
end
end