module ApplicationHelper

ApplicationHelper provides functions to help build a theme's layout

Public Instance Methods

favicon_tag(name = 'favicon.ico') click to toggle source

Render the favicon tag

Will generate the asset url given with the name of your favicon.

# File lib/ecrire/app/helpers/application_helper.rb, line 45
def favicon_tag(name = 'favicon.ico')
  content_tag :link, nil, rel: %w(shortcut icon), href: image_path(name)
end
main_tag(html_options = {}, &block) click to toggle source

Render the <main> tag

The html_options is a hash that will map to key/value for the tag. Unless you know what you are doing, you should not specify an id in html_options. Ecrire will generate one using the controller and action for the given request.

You can also provide any key/value that you wish to see rendered in the main tag.

Example with posts#index (/posts):

<%= main_tag contentEditable: true do %>
  Hello world!
<% end %>

<main contentEditable=true id='PostsIndex'>
  Hello world!
</main>

Another example with posts#index (/posts):

<%= main_tag class: 'content' do %>
  Hello World!
<% end %>

<main class='content' id='PostsIndex'>
  Hello World!
</main>
# File lib/ecrire/app/helpers/application_helper.rb, line 79
def main_tag(html_options = {}, &block)
  html_options[:id] ||= [controller_name, action_name].map(&:capitalize).join
  html_options[:class] = [html_options[:class]].compact.flatten
  if content_for?(:class)
    html_options[:class].concat content_for(:class).split(' ')
  end
  content_tag :main, html_options, &block
end
popup_tag(partial = nil, html_options = {}, &block) click to toggle source

Render a popup tag

rss_tag(relative_path = '/feed') click to toggle source

Render a RSS auto-discovery tag

You can pass another relative path if you want. Ecrire will render an absolute path using the relative_path

# File lib/ecrire/app/helpers/application_helper.rb, line 35
def rss_tag(relative_path = '/feed')
  content_tag :link, nil, rel: 'alternate', type: 'application/rss+xml', title: 'RSS', href: url(relative_path, absolute_path: true)
end
title_tag(title = 'Ecrire') click to toggle source

Render <title> tag

The content of the title tag can be one of three things. In priority of order:

  1. The value of content_for(:title) if it's set,

  2. The title of the variable @post, if it's set,

  3. The title passed

If you need more information about content_for and how to use it, please read: ecrire.io/posts/configure-layout-element-with-content_for

# File lib/ecrire/app/helpers/application_helper.rb, line 17
def title_tag(title = 'Ecrire')
  content_tag :title do
    if content_for?(:title)
      content_for(:title)
    elsif defined? @post
      @post.title.name
    else
      title
    end
  end
end