From 780fe49f715c2fced88e958b02541bf8e7dca934 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Wed, 8 Aug 2012 18:02:56 -0400 Subject: Rename project to 'Dashing', and do some other cleanups --- bin/dashing | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 bin/dashing (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing new file mode 100755 index 0000000..32c89c8 --- /dev/null +++ b/bin/dashing @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby + +require 'thor' +require 'net/http' +require 'json' + +class MockScheduler + def method_missing(*args) + yield + end +end + +def send_event(id, data) + req = Net::HTTP::Post.new("/widgets/#{id}") + req["content-type"] = "application/json" + req.body = JSON.unparse(data.merge(:auth_token => Dashing::CLI.auth_token)) + res = Net::HTTP.new('localhost', 3000).start { |http| http.request(req) } + puts "Data Sent to #{id}: #{data}" +end + +SCHEDULER = MockScheduler.new + +module Dashing + + class CLI < Thor + include Thor::Actions + + class << self + attr_accessor :auth_token + end + + attr_accessor :name + + no_tasks do + ['widget', 'dashboard', 'job'].each do |type| + define_method "generate_#{type}" do |name| + @name = Thor::Util.snake_case(name) + directory type.to_sym, File.join("#{type}s") + end + end + end + + def self.source_root + File.expand_path('../../templates', __FILE__) + end + + desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project structure." + def new(name) + @name = Thor::Util.snake_case(name) + directory :project, @name + end + + desc "generate GENERATOR NAME", "Creates a new widget with all the fixins'" + def generate(type, name) + send("generate_#{type}".to_sym, name) + rescue NoMethodError => e + puts "Invalid generator. Either use widget, dashboard, or job" + end + map "g" => :generate + + desc "start", "Starts the server in style!" + method_option :job_path, :desc => "Specify the directory where jobs are stored" + def start(*args) + args = args.join(" ") + command = "bundle exec thin -R config.ru start #{args}" + command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] + system(command) + end + map "s" => :start + + desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job." + def job(name, auth_token = "") + Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } + self.class.auth_token = auth_token + f = File.join(Dir.pwd, "jobs", "#{name}.rb") + require f + end + + end +end + +Dashing::CLI.start \ No newline at end of file -- cgit v1.2.3 From 16f51fd9dc454b26d9866b080caa17ffe2f8ce27 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Mon, 13 Aug 2012 23:36:38 -0400 Subject: Updated to use sprockets! Ah, much cleaner. --- bin/dashing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 32c89c8..a9e6022 100755 --- a/bin/dashing +++ b/bin/dashing @@ -50,7 +50,7 @@ module Dashing directory :project, @name end - desc "generate GENERATOR NAME", "Creates a new widget with all the fixins'" + desc "generate GENERATOR NAME", "Creates a new wigdget, dashboard, or job." def generate(type, name) send("generate_#{type}".to_sym, name) rescue NoMethodError => e -- cgit v1.2.3 From 8e3ca1d64444408677c93721c198908de43fa417 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Mon, 13 Aug 2012 23:40:43 -0400 Subject: Added more descriptive thor task descriptions. --- bin/dashing | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index a9e6022..e363ee2 100755 --- a/bin/dashing +++ b/bin/dashing @@ -44,13 +44,13 @@ module Dashing File.expand_path('../../templates', __FILE__) end - desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project structure." + desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project." def new(name) @name = Thor::Util.snake_case(name) directory :project, @name end - desc "generate GENERATOR NAME", "Creates a new wigdget, dashboard, or job." + desc "generate (widget/dashboard/job) NAME", "Creates a new widget, dashboard, or job." def generate(type, name) send("generate_#{type}".to_sym, name) rescue NoMethodError => e @@ -68,7 +68,7 @@ module Dashing end map "s" => :start - desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job." + desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job. Make sure to supply your auth token if you have one set." def job(name, auth_token = "") Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } self.class.auth_token = auth_token -- cgit v1.2.3 From 76cf77a89a17dd12299a6f4b63c967163ceae39a Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Tue, 30 Oct 2012 11:45:12 -0400 Subject: Make the default port 3030 --- bin/dashing | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index e363ee2..fb1332f 100755 --- a/bin/dashing +++ b/bin/dashing @@ -14,7 +14,7 @@ def send_event(id, data) req = Net::HTTP::Post.new("/widgets/#{id}") req["content-type"] = "application/json" req.body = JSON.unparse(data.merge(:auth_token => Dashing::CLI.auth_token)) - res = Net::HTTP.new('localhost', 3000).start { |http| http.request(req) } + res = Net::HTTP.new('localhost', 3030).start { |http| http.request(req) } puts "Data Sent to #{id}: #{data}" end @@ -61,8 +61,9 @@ module Dashing desc "start", "Starts the server in style!" method_option :job_path, :desc => "Specify the directory where jobs are stored" def start(*args) + port_option = args.include?('-p')? '' : ' -p 3030' args = args.join(" ") - command = "bundle exec thin -R config.ru start #{args}" + command = "bundle exec thin -R config.ru start #{port_option} #{args}" command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] system(command) end -- cgit v1.2.3 From 4247f127bd88cd5d09f3778e07daf2a5d9c5de88 Mon Sep 17 00:00:00 2001 From: Emmanuel Hadoux Date: Wed, 20 Mar 2013 14:43:09 +0100 Subject: Add a Thor command to install a widget by its Gist Id. --- bin/dashing | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'bin/dashing') 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 -- cgit v1.2.3 From 31bdc6da2706eec95c54ca46cb8e544661296bf6 Mon Sep 17 00:00:00 2001 From: Federico Bana Date: Mon, 25 Mar 2013 16:58:19 -0300 Subject: Properly hyphenate css class names for widgets. --- bin/dashing | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 4fb4b50..8c7e348 100755 --- a/bin/dashing +++ b/bin/dashing @@ -28,6 +28,11 @@ module Dashing class << self attr_accessor :auth_token + + def hyphenate(str) + return str.downcase if str =~ /^[A-Z-]+$/ + str.gsub('_', '-').gsub(/\B[A-Z]/, '-\&').squeeze('-').downcase + end end attr_accessor :name @@ -106,4 +111,4 @@ module Dashing end end -Dashing::CLI.start \ No newline at end of file +Dashing::CLI.start -- cgit v1.2.3 From 1a974c754789b0b675d39442cead91213f706851 Mon Sep 17 00:00:00 2001 From: Aaron Peckham Date: Tue, 7 May 2013 15:09:54 -0700 Subject: Test that the Sinatra app redirects to the default dashboard; saves data posted to /widgets/X, and requires auth; returns data on /events; returns the sample dashboards; and returns sample widgets. --- bin/dashing | 8 -------- 1 file changed, 8 deletions(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 8c7e348..30824ce 100755 --- a/bin/dashing +++ b/bin/dashing @@ -11,14 +11,6 @@ class MockScheduler end end -def send_event(id, data) - req = Net::HTTP::Post.new("/widgets/#{id}") - req["content-type"] = "application/json" - req.body = JSON.unparse(data.merge(:auth_token => Dashing::CLI.auth_token)) - res = Net::HTTP.new('localhost', 3030).start { |http| http.request(req) } - puts "Data Sent to #{id}: #{data}" -end - SCHEDULER = MockScheduler.new module Dashing -- cgit v1.2.3 From bf0315fde57d27602a90ee6f2ecc92b2b73d42f5 Mon Sep 17 00:00:00 2001 From: Matt Critchlow Date: Tue, 23 Jul 2013 17:54:19 -0700 Subject: add stop command to dashing fix dashing stop text description remove local comment from stop method --- bin/dashing | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 30824ce..9d97700 100755 --- a/bin/dashing +++ b/bin/dashing @@ -92,6 +92,12 @@ module Dashing end map "s" => :start + desc "stop", "Stops the thin server" + def stop + command = "bundle exec thin stop" + system(command) + end + desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job. Make sure to supply your auth token if you have one set." def job(name, auth_token = "") Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } -- cgit v1.2.3 From d0eef2dbe9d1178111cd768116a66b32a3a4b2b5 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Wed, 18 Dec 2013 19:12:43 -0500 Subject: moving cli to lib and updating bin file --- bin/dashing | 115 +++--------------------------------------------------------- 1 file changed, 5 insertions(+), 110 deletions(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 9d97700..051acba 100755 --- a/bin/dashing +++ b/bin/dashing @@ -1,112 +1,7 @@ #!/usr/bin/env ruby +require "pathname" +bin_file = Pathname.new(__FILE__).realpath +$:.unshift File.expand_path("../../lib", bin_file) -require 'thor' -require 'net/http' -require 'json' -require 'open-uri' - -class MockScheduler - def method_missing(*args) - yield - end -end - -SCHEDULER = MockScheduler.new - -module Dashing - - class CLI < Thor - include Thor::Actions - - class << self - attr_accessor :auth_token - - def hyphenate(str) - return str.downcase if str =~ /^[A-Z-]+$/ - str.gsub('_', '-').gsub(/\B[A-Z]/, '-\&').squeeze('-').downcase - end - end - - attr_accessor :name - - no_tasks do - ['widget', 'dashboard', 'job'].each do |type| - define_method "generate_#{type}" do |name| - @name = Thor::Util.snake_case(name) - directory type.to_sym, File.join("#{type}s") - end - end - end - - def self.source_root - File.expand_path('../../templates', __FILE__) - end - - desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project." - def new(name) - @name = Thor::Util.snake_case(name) - directory :project, @name - end - - desc "generate (widget/dashboard/job) NAME", "Creates a new widget, dashboard, or job." - def generate(type, name) - send("generate_#{type}".to_sym, name) - rescue NoMethodError => e - puts "Invalid generator. Either use widget, dashboard, or job" - 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) - port_option = args.include?('-p')? '' : ' -p 3030' - args = args.join(" ") - command = "bundle exec thin -R config.ru start #{port_option} #{args}" - command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] - system(command) - end - map "s" => :start - - desc "stop", "Stops the thin server" - def stop - command = "bundle exec thin stop" - system(command) - end - - desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job. Make sure to supply your auth token if you have one set." - def job(name, auth_token = "") - Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } - self.class.auth_token = auth_token - f = File.join(Dir.pwd, "jobs", "#{name}.rb") - require f - end - - end -end - -Dashing::CLI.start +require 'dashing' +Dashing::CLI.start(ARGV) -- cgit v1.2.3 From e975ce77408f5995213cc1b85f61e806152ba3a2 Mon Sep 17 00:00:00 2001 From: pseudomuto Date: Thu, 19 Dec 2013 12:08:07 -0500 Subject: light refactoring for better test coverage --- bin/dashing | 1 + 1 file changed, 1 insertion(+) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 051acba..97a7af5 100755 --- a/bin/dashing +++ b/bin/dashing @@ -4,4 +4,5 @@ bin_file = Pathname.new(__FILE__).realpath $:.unshift File.expand_path("../../lib", bin_file) require 'dashing' +Dashing::CLI.source_root(File.expand_path('../../templates', bin_file)) Dashing::CLI.start(ARGV) -- cgit v1.2.3 From d3ccecb096821b2df3b492dd349e5c650929a591 Mon Sep 17 00:00:00 2001 From: pushmatrix Date: Fri, 30 May 2014 14:28:51 -0400 Subject: Don't start the dashing app when you run the bin file. --- bin/dashing | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bin/dashing') diff --git a/bin/dashing b/bin/dashing index 97a7af5..cce9340 100755 --- a/bin/dashing +++ b/bin/dashing @@ -3,6 +3,7 @@ require "pathname" bin_file = Pathname.new(__FILE__).realpath $:.unshift File.expand_path("../../lib", bin_file) -require 'dashing' +require 'dashing/cli' +require 'dashing/downloader' Dashing::CLI.source_root(File.expand_path('../../templates', bin_file)) Dashing::CLI.start(ARGV) -- cgit v1.2.3