3
3
require 'thor'
4
4
require 'net/http'
5
5
require 'json'
6
+ require 'open-uri'
6
7
7
8
class MockScheduler
8
9
def method_missing ( *args )
@@ -55,9 +56,34 @@ module Dashing
55
56
send ( "generate_#{ type } " . to_sym , name )
56
57
rescue NoMethodError => e
57
58
puts "Invalid generator. Either use widget, dashboard, or job"
58
- end
59
+ end
59
60
map "g" => :generate
60
61
62
+ desc "install GIST_ID" , "Installs a new widget from a gist."
63
+ def install ( gist_id )
64
+ public_url = "https://gist.github.com/#{ gist_id } "
65
+ gist = JSON . parse ( open ( "https://api.github.com/gists/#{ gist_id } " ) . read )
66
+
67
+ gist [ 'files' ] . each do |filename , contents |
68
+ if filename . end_with? ( ".rb" )
69
+ create_file File . join ( Dir . pwd , 'jobs' , filename ) , contents [ 'content' ]
70
+ elsif filename . end_with? ( ".coffee" , ".html" , ".scss" )
71
+ widget_name = File . basename ( filename , '.*' )
72
+ create_file File . join ( Dir . pwd , 'widgets' , widget_name , filename ) , contents [ 'content' ]
73
+ end
74
+ end
75
+
76
+ print set_color ( "Don't forget to edit the " , :yellow )
77
+ print set_color ( "Gemfile " , :yellow , :bold )
78
+ print set_color ( "and run " , :yellow )
79
+ print set_color ( "bundle install " , :yellow , :bold )
80
+ say set_color ( "if needed. More information for this widget can be found at #{ public_url } " , :yellow )
81
+
82
+ rescue OpenURI ::HTTPError => e
83
+ say set_color ( "Could not find gist at #{ public_url } " ) , :red
84
+ end
85
+ map "i" => :install
86
+
61
87
desc "start" , "Starts the server in style!"
62
88
method_option :job_path , :desc => "Specify the directory where jobs are stored"
63
89
def start ( *args )
@@ -76,7 +102,7 @@ module Dashing
76
102
f = File . join ( Dir . pwd , "jobs" , "#{ name } .rb" )
77
103
require f
78
104
end
79
-
105
+
80
106
end
81
107
end
82
108
0 commit comments