Class: Nimbu::Command::Server

Inherits:
Base
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/nimbu/command/server.rb

Overview

running a local server to speed up designing Nimbu themes

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, namespace, #nimbu

Methods included from Helpers

#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, disable_error_capture, #display, #display_header, #display_object, #display_row, #display_table, enable_error_capture, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output, #output_with_arrow, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Methods included from Helpers::System

#browser_launcher, #command?, #osx?, #tmp_dir, #which, #windows?

Constructor Details

This class inherits a constructor from Nimbu::Command::Base

Instance Method Details

#bareObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/nimbu/command/server.rb', line 79

def bare
  puts "Starting server..."
  server_options = {
    :Port               => options[:port] || 4567,
    :DocumentRoot       => Dir.pwd
  }
  Rack::Handler::Thin.run Nimbu::Server::Base, server_options  do |server|
    [:INT, :TERM].each { |sig| trap(sig) { server.respond_to?(:stop!) ? server.stop! : server.stop } }
  end
end

#compassObject



97
98
99
100
101
# File 'lib/nimbu/command/server.rb', line 97

def compass
  require 'compass'
  require 'compass/exec'
  Compass::Exec::SubCommandUI.new(["watch","."]).run!
end

#hamlObject



90
91
92
93
94
95
# File 'lib/nimbu/command/server.rb', line 90

def haml
  require 'haml'
  puts "Starting..."
  haml_listener = HamlWatcher.watch
  sleep
end

#indexObject

server

starts a local development server, using the data from the Nimbu cloud in real time.

-p PORT, –port PORT # set the port on which to start the http server –host HOST # set the host on which to start the http server -h, –haml # start local HAML watcher -c, –compass # start local Compass watcher -d, –debug # enable debugging output –webpack RES # comma separated list of webpack resources (relative to /javascripts) –webpackurl URL # proxy requests for webpack resources to the given URL prefix (default: localhost:8080) –nocookies # disable session refresh cookie check



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
# File 'lib/nimbu/command/server.rb', line 24

def index
  # Check if config file is present?
  if !Nimbu::Auth.read_configuration
    print red(bold("ERROR")), ": this directory does not seem to contain any Nimbu theme configuration. \n ==> Run \"", bold { "nimbu init"}, "\" to initialize this directory."
  elsif Nimbu::Auth.token.nil?
    print red(bold("ERROR")), ": it seems you are not authenticated. \n ==> Run \"", bold { "nimbu login"}, "\" to initialize a session."
  else
    @with_haml    = options[:haml]
    @with_compass = options[:compass] || options[:c]
    @no_cookies   = options[:nocookies]
    @webpack_resources = options[:webpack]
    @webpack_url  = options[:webpackurl]

    if @no_cookies
      Nimbu.cli_options[:nocookies] = true
    end

    if @webpack_resources
      Nimbu.cli_options[:webpack_resources] = @webpack_resources.split(",").map(&:strip)
      if @webpack_url
        Nimbu.cli_options[:webpack_url] = @webpack_url
      else
        Nimbu.cli_options[:webpack_url] = "http://localhost:8080"
      end
    end

    if @with_compass
      require 'compass'
      require 'compass/exec'
    end

    if @with_haml
      require 'haml'
    end

    services = []
    services << "HAML" if @with_haml
    services << "Compass" if @with_compass
    title = "Starting up Nimbu Server"
    title << " (with local #{services.join(' and ')} watcher)" if @with_compass || @with_haml
    title << " (skipping cookies check)" if @no_cookies
    title << " (proxying webpack resources to #{Nimbu.cli_options[:webpack_url]})" if @webpack_resources
    title << " ..."
    puts white("\n#{title}")
    puts green(nimbu_header)
    puts green("\nConnnected to '#{Nimbu::Auth.site}.#{Nimbu::Auth.admin_host}', using '#{Nimbu::Auth.theme}' theme#{Nimbu.debug ? ' (in debug mode)'.red : nil}.\n")

    if Nimbu::Helpers.running_on_windows?
      run_on_windows!
    else
      run_on_unix!
    end
  end
end