Module: Lookbook::PageHelper
- Defined in:
- lib/lookbook/helpers/page_helper.rb
Overview
Helpers for documentation page templates
Instance Method Summary collapse
-
#embed(preview, scenario = nil, **opts) ⇒ Object
Render a ‘live’ embed of a component preview.
-
#page_path(id) ⇒ Object
private
Returns the URL path to a page.
Instance Method Details
#embed(preview, scenario = nil, **opts) ⇒ Object
Render a ‘live’ embed of a component preview.
If no scenario name is provided then the default (first) preview scenario will be rendered in the embed.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lookbook/helpers/page_helper.rb', line 27 def (preview, scenario = nil, **opts) preview_entity = if preview.is_a?(Symbol) Engine.previews.find_by_path(preview) else Engine.previews.find_by_preview_class(preview) end scenario_entity = scenario ? preview_entity&.scenario(scenario) : preview_entity&.default_scenario opts[:actions] ||= ["inspect", "open"] lookbook_render Embed::Component.new( scenario: scenario_entity, params: opts.fetch(:params, {}), options: opts.except(:params) ) end |
#page_path(id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the URL path to a page.
10 11 12 13 14 15 16 17 |
# File 'lib/lookbook/helpers/page_helper.rb', line 10 def page_path(id) page = id.is_a?(PageEntity) ? id : Engine.pages.find_by_id(id) if page.present? page.docs_path else Lookbook.logger.warn "Could not find page with id ':#{id}'" end end |