Class: Middleman::PreviewServer::ServerUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/preview_server/server_url.rb

Overview

This builds the server urls for the preview server

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ServerUrl

Returns a new instance of ServerUrl.



13
14
15
16
17
18
# File 'lib/middleman-core/preview_server/server_url.rb', line 13

def initialize(opts={})
  @hosts = opts.fetch(:hosts)
  @port  = opts.fetch(:port)
  @https = opts.fetch(:https, false)
  @format_output = opts.fetch(:format_output, true)
end

Instance Method Details

#to_bind_addressesArray

Return bind addresses

Returns:

  • (Array)

    List of bind addresses of format host:port



24
25
26
27
28
29
30
# File 'lib/middleman-core/preview_server/server_url.rb', line 24

def to_bind_addresses
  if format_output
    hosts.map { |l| format('"%s:%s"', l.to_s, port) }
  else
    hosts.map { |l| format('%s:%s', l.to_s, port) }
  end
end

#to_config_urlsArray

Return server config urls

Returns:



48
49
50
51
52
53
54
# File 'lib/middleman-core/preview_server/server_url.rb', line 48

def to_config_urls
  if format_output
    hosts.map { |l| format('"%s://%s:%s/__middleman"', https? ? 'https' : 'http', l.to_browser, port) }
  else
    hosts.map { |l| format('%s://%s:%s/__middleman', https? ? 'https' : 'http', l.to_browser, port) }
  end
end

#to_urlsArray

Return server urls

Returns:



36
37
38
39
40
41
42
# File 'lib/middleman-core/preview_server/server_url.rb', line 36

def to_urls
  if format_output
    hosts.map { |l| format('"%s://%s:%s"', https? ? 'https' : 'http', l.to_browser, port) }
  else
    hosts.map { |l| format('%s://%s:%s', https? ? 'https' : 'http', l.to_browser, port) }
  end
end