Class: Middleman::PreviewServer::ServerUrl

Inherits:
Object
  • Object
show all
Defined in:
middleman-core/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(options_hash = ::Middleman::EMPTY_HASH) ⇒ ServerUrl

Returns a new instance of ServerUrl


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

def initialize(options_hash = ::Middleman::EMPTY_HASH)
  @hosts = options_hash.fetch(:hosts)
  @port  = options_hash.fetch(:port)
  @https = options_hash.fetch(:https, false)
  @format_output = options_hash.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 'middleman-core/lib/middleman-core/preview_server/server_url.rb', line 24

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

#to_config_urlsArray

Return server config urls

Returns:


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'middleman-core/lib/middleman-core/preview_server/server_url.rb', line 62

def to_config_urls
  if format_output
    hosts.map do |l|
      format(
        '"%<protocol>s://%<host>s:%<port>s/__middleman"',
        protocol: https? ? 'https' : 'http',
        host: l.to_browser,
        port: port
      )
    end
  else
    hosts.map do |l|
      format(
        '%<protocol>s://%<host>s:%<port>s/__middleman',
        protocol: https? ? 'https' : 'http',
        host: l.to_browser,
        port: port
      )
    end
  end
end

#to_urlsArray

Return server urls

Returns:


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'middleman-core/lib/middleman-core/preview_server/server_url.rb', line 36

def to_urls
  if format_output
    hosts.map do |l|
      format(
        '"%<protocol>s://%<host>s:%<port>s"',
        protocol: https? ? 'https' : 'http',
        host: l.to_browser,
        port: port
      )
    end
  else
    hosts.map do |l|
      format(
        '%<protocol>s://%<host>s:%<port>s',
        protocol: https? ? 'https' : 'http',
        host: l.to_browser,
        port: port
      )
    end
  end
end