Sha256: 73bf5a46a27515921f2d1c139d3a409fbff34404d176f5bbeddc9ba3545b938d
Contents?: true
Size: 1.08 KB
Versions: 18
Compression:
Stored size: 1.08 KB
Contents
module PageHelper # Creates a hyperlink to a page using the `title` key. Change the default in the args # below if you use a different key for page titles. def link_to_page(page, title_key: "title") link_to page.data.fetch(title_key, page.request_path), page.request_path end # Quick and easy way to change the class of a page if its current. Useful for # navigation menus. def link_to_if_current(text, page, active_class: "active") if page == current_page link_to text, page.request_path, class: active_class else link_to text, page.request_path end end # Conditionally renders the block if an arg is present. If all the args are nil, # the block is not rendered. Handy for laconic templating languages like slim, haml, etc. def with(*args, &block) block.call(*args) unless args.all?(&:nil?) end # Render a block within a layout. This is a useful, and prefered way, to handle # nesting layouts, within Sitepress. def render_layout(layout, **kwargs, &block) render html: capture(&block), layout: "layouts/#{layout}", **kwargs end end
Version data entries
18 entries across 18 versions & 1 rubygems