Class: Inkcite::Cli::Server
- Inherits:
-
Object
- Object
- Inkcite::Cli::Server
- Defined in:
- lib/inkcite/cli/server.rb
Defined Under Namespace
Classes: InkciteApp
Class Method Summary collapse
Class Method Details
.start(email, opts) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/inkcite/cli/server.rb', line 12 def self.start email, opts puts puts "Inkcite #{Inkcite::VERSION} is starting up ..." puts 'Documentation available at http://inkcite.readme.io' puts # Read the hostname and port from the opts provided on the command # line - or inherit the default of localhost:4567 port = opts[:port].to_i host = opts[:host] # Attempt to resolve the machine's public IP so we can display the # address for mobile devices. ip = begin IPSocket.getaddress(Socket.gethostname) rescue nil end fork do # Programmatically construct a Guard configuration file that # instructs it to monitor all of the HTML, TSV, YML and images # that can be used in the email project. guardfile = " guard :livereload do\n watch(%r{^*.+\\.(html|tsv|yml)})\n watch(%r{images/.+\\.(gif|jpg|png)})\n end\n\n logger level: :error\n EOF\n\n # You can omit the call to Guard.setup, Guard.start will call Guard.setup\n # under the hood if Guard has not been setuped yet\n Guard.start :guardfile_contents => guardfile, :no_interactions => true\n\n end\n\n # Assemble the Rack app with the static content middleware and the\n # InkciteApp to server the email as the root index page.\n app = Rack::Builder.new do\n use Rack::LiveReload\n use Rack::Static, :urls => %w( /images /images-optim ), :root => '.'\n run InkciteApp.new(email, opts)\n end\n\n puts \"Your email is being served at http://\#{host}:\#{port}\"\n puts \"Point your mobile device to http://\#{ip}:\#{port}\" if ip\n puts 'Press CTRL-C to exit server mode'\n puts ''\n\n begin\n\n # Start the server and disable WEBrick's verbose logging.\n Rack::Server.start({\n :Host => host,\n :Port => port,\n :AccessLog => [],\n :Logger => WEBrick::Log.new(nil, 0),\n :app => app\n })\n rescue Errno::EADDRINUSE\n abort <<-USAGE.strip_heredoc\n\n Oops! Inkcite can't start its preview server. Port \#{port} is\n unavailable. Either close the instance of Inkcite already running\n on that port or start this Inkcite instance on a new port with:\n\n inkcite server --port=\#{port+1}\n\n USAGE\n end\n\nend\n" |