Class: Alchemy::Admin::PreviewUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy/admin/preview_url.rb

Overview

Preview window URL configuration

By default Alchemy uses its internal page preview renderer, but you can configure it to be any URL instead.

Basic Auth is supported.

Example config/alchemy/config.yml

preview:
  host: https://www.my-static-site.com
  auth:
    username: <%= ENV["BASIC_AUTH_USERNAME"] %>
    password: <%= ENV["BASIC_AUTH_PASSWORD"] %>

Preview config per site is supported as well.

Example config/alchemy/config.yml

preview:
  My site name:
    host: https://www.my-static-site.com
    auth:
      username: <%= ENV["BASIC_AUTH_USERNAME"] %>
      password: <%= ENV["BASIC_AUTH_PASSWORD"] %>

Defined Under Namespace

Classes: MissingProtocolError

Instance Method Summary collapse

Constructor Details

#initialize(routes:) ⇒ PreviewUrl

Returns a new instance of PreviewUrl.


36
37
38
# File 'lib/alchemy/admin/preview_url.rb', line 36

def initialize(routes:)
  @routes = routes.url_helpers
end

Instance Method Details

#url_for(page) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/alchemy/admin/preview_url.rb', line 40

def url_for(page)
  @preview_config = preview_config_for(page)

  if @preview_config && uri
    uri_class.build(
      host: uri.host,
      path: page.url_path,
      userinfo: userinfo,
    ).to_s
  else
    routes.admin_page_path(page)
  end
end