Class: Alchemy::Admin::PreviewUrl

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Translation
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.



38
39
40
# File 'lib/alchemy/admin/preview_url.rb', line 38

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

Instance Method Details

#url_for(page) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/alchemy/admin/preview_url.rb', line 42

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

  if @preview_config && uri
    uri_class.build(
      host: uri.host,
      port: uri.port,
      path: page.url_path,
      userinfo: userinfo,
      query: {alchemy_preview_mode: true}.to_param
    ).to_s
  else
    routes.admin_page_path(page)
  end
end