class Alchemy::Admin::PreviewUrl
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"] %>
Attributes
routes[R]
Public Class Methods
new(routes:)
click to toggle source
# File lib/alchemy/admin/preview_url.rb, line 38 def initialize(routes:) @routes = routes.url_helpers end
Public Instance Methods
url_for(page)
click to toggle source
# 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
Private Instance Methods
preview_config_for(page)
click to toggle source
# File lib/alchemy/admin/preview_url.rb, line 62 def preview_config_for(page) preview_config = Alchemy::Config.get(:preview) return unless preview_config preview_config[page.site.name] || preview_config end
uri()
click to toggle source
# File lib/alchemy/admin/preview_url.rb, line 69 def uri return unless @preview_config["host"] URI(@preview_config["host"]) end
uri_class()
click to toggle source
# File lib/alchemy/admin/preview_url.rb, line 75 def uri_class if uri.instance_of?(URI::Generic) raise MissingProtocolError, "Please provide the protocol with preview['host']" else uri.class end end
userinfo()
click to toggle source
# File lib/alchemy/admin/preview_url.rb, line 83 def userinfo auth = @preview_config["auth"] auth ? "#{auth["username"]}:#{auth["password"]}" : nil end