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

#compassObject



95
96
97
98
99
# File 'lib/nimbu/command/server.rb', line 95

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

#hamlObject



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

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 –dir DIR # root of your project (default: current directory)



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

def index
  require 'rubygems'
  require "nimbu/server/base"
  require 'term/ansicolor'
  require 'thin'
  require 'filewatcher'
  require 'pathname'
  require 'lolcat'
  require 'socket'

  Nimbu.cli_options[:dir] = options[:dir] if options[:dir]

  # 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 local Nimbu Toolbelt Server (v#{Nimbu::VERSION}, using Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}):"
    title << "\n - with local #{services.join(' and ')} watcher" if @with_compass || @with_haml
    title << "\n - skipping cookies check" if @no_cookies
    title << "\n - proxying webpack resources to #{Nimbu.cli_options[:webpack_url]}" if @webpack_resources
    title << " ..."
    puts white("\n#{title}")
    puts 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