Class: Eggplant::CLI
- Inherits:
-
Thor
- Object
- Thor
- Eggplant::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/eggplant/cli.rb
Instance Method Summary collapse
- #build(html_file = './index.html') ⇒ Object
- #heroku ⇒ Object
- #new(path = '.') ⇒ Object
- #show ⇒ Object
Instance Method Details
#build(html_file = './index.html') ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/eggplant/cli.rb', line 36 def build html_file='./index.html' path = File. '.' html_file = File. html_file puts "Build presentation in #{path}" Eggplant::Server.configure path, [:ui] File.unlink html_file if File.exists?(html_file) Eggplant::Server.build_html html_file end |
#heroku ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/eggplant/cli.rb', line 101 def heroku path = File. '.' config_path = File.join path, 'config.ru' gemfile_path = File.join path, 'Gemfile' File.unlink(config_path) if File.exists?(config_path) File.open(config_path, 'w') do |f| f << "require 'eggplant/server'\n" f << "Eggplant::Server.configure File.expand_path('.'), #{[:ui].inspect}\n" f << "run Eggplant::Server\n" end end |
#new(path = '.') ⇒ Object
29 30 31 32 |
# File 'lib/eggplant/cli.rb', line 29 def new path='.' path = File. path puts "Created new presentation in #{path}" end |
#show ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/eggplant/cli.rb', line 50 def show path = File.('.') puts "Serving presentation from #{path}" EventMachine.run do # Server options = { :port => [:port], :presentation_root => path, :ui => [:ui] } if [:mode] == 'show' [:environment] = :production end # Eggplant::Server Eggplant::Server.run! # Eggplant::WebSocket @channel = Eggplant::Channel.new @count = 0 @current_slide = 0 EventMachine::WebSocket.start(:host => '0.0.0.0', :port => [:remote_port]) do |ws| ws.onopen do sid = @channel.subscribe do |msg| ws.send msg end @count += 1 @channel.push({:type => 'join', :total_clients => @count, :current_slide => @current_slide}.to_json) ws. do |msg| = JSON.parse msg if ['type'] == 'goto' @current_slide = ['idx'] end @channel.push_except sid, "#{msg}" end ws.onclose do @channel.unsubscribe sid @count -= 1 @channel.push({:type => 'leave', :total_clients => @count}.to_json) end end end end end |