#!/usr/bin/env ruby $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'shining' require 'stringex' include Shining::FileMethods ACTIONS = { :new_on! => ['build'], :new_slide! => ['slide'], :help_and_exit! => ['help', '-h', '--help'], :play => ['play', 'go'], :deploy => ['deploy'], :remove => ['remove', 'delete', 'rm'], :version => ['version', '-v'], :start => ['go', 'start'] } def bail! reason Shining.error reason exit -2 end def figure_what_to_do! help_and_exit! if ARGV.empty? if ACTIONS.values.flatten.include? ARGV.first action = ACTIONS.select { |action, args| args.include? ARGV.first }.flatten.first send action, *ARGV[1..(ARGV.length - 1)] else new_on! ARGV.first end end def help_and_exit! STDERR.puts <<-HELP Shine - Generates a new Shining presentation. Usage: shine Example: shine mycoolpreso Other commands you can run: help shows this menu version shows the current version of Shining you have installed Commands you can run from inside a presentation directory: slide takes 1 argument with the slide name and optionally the format, as in: $ shine slide pretty The above will create a HTML slide called "pretty". deploy deploys the presentation to Heroku remove takes a slide name as argument. Removes the slide. Example: $ shine remove pretty HELP exit -1 end def new_on! dir Shining::Preso.new dir end def new_slide! name, format = 'html' preso = Shining::Preso.open Dir.pwd name, extension = name_and_extension(name) extension = format if extension.blank? preso.new_slide "#{name}.#{extension}", :with => ['styles', 'script'] end def play preso = Shining::Preso.open Dir.pwd player = Shining::Player.new preso player.go! end def deploy name = nil preso = Shining::Preso.open(Dir.pwd) heroku = Shining::Heroku.new preso name ||= preso.name.to_url heroku.deploy name end def remove slide preso = Shining::Preso.open Dir.pwd preso.remove_slide slide end def version Shining.say Shining::VERSION end def start port = 4567 preso = Shining::Preso.open Dir.pwd raise "Cannot find the rackup command in your path. Make sure Rack is installed!" if `which rackup`.empty? puts "Shining started on port #{port}." `rackup -p #{port}` end figure_what_to_do!