class Tolaria::HelpLink
Class representing a configured Tolaria
help link.
Attributes
The path to link to when not rendering a Markdown file
The file path to the Markdown file
Part part of the link at `/admin/help/:slug` when rendering a Markdown file
The title of the link
Public Class Methods
Create a new HelpLink
with the passed settings. You must provide `title`, the title of the link. To configure automatic rendering of a Markdown file, provide a string `slug` and the path to a `markdown_file`. A route to view the file will be constructed for you at `/admin/help/:slug`. To link to an arbitrary path or URI, provide it as `link_to`.
# File lib/tolaria/help_links.rb, line 38 def initialize(title:, slug:nil, markdown_file:nil, link_to:nil) @title = title.to_s.freeze @slug = slug.to_s.freeze @markdown_file = markdown_file.to_s.freeze @link_to = link_to.to_s.freeze validate! end
Public Instance Methods
True if this HelpLink
is a link to an arbitrary path.
# File lib/tolaria/help_links.rb, line 47 def link_type? link_to.present? end
True if this HelpLink
is a Markdown file.
# File lib/tolaria/help_links.rb, line 52 def markdown_type? markdown_file.present? end
Quack like an ActiveRecord::Base
model, returns slug.
# File lib/tolaria/help_links.rb, line 57 def to_param slug end
Raises RuntimeError if this HelpLink
is incorrectly configured.
# File lib/tolaria/help_links.rb, line 62 def validate! if title.blank? raise RuntimeError, "HelpLinks must provide a string title" end file_configured = (slug.present? && markdown_file.present?) link_configured = link_to.present? unless file_configured || link_configured raise RuntimeError, "Incomplete HelpLink config. You must provide link_to, or both slug and markdown_file." end if file_configured && link_configured raise RuntimeError, "Ambiguous HelpLink config. You must provide link_to, or both slug and markdown_file, but not all three." end end