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.


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

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


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

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:


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

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:


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

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