Module: ApplicationHelper
- Defined in:
- lib/ecrire/app/helpers/application_helper.rb
Overview
ApplicationHelper
provides functions to help build a theme’s layout
Instance Method Summary collapse
-
#favicon_tag(name = 'favicon.ico') ⇒ Object
Render the favicon tag.
-
#main_tag(html_options = {}, &block) ⇒ Object
Render the <main> tag.
-
#popup_tag(partial = nil, html_options = {}, &block) ⇒ Object
Render a popup tag.
-
#rss_tag(relative_path = '/feed') ⇒ Object
Render a RSS auto-discovery tag.
-
#title_tag(title = 'Ecrire') ⇒ Object
Render <title> tag.
Instance Method Details
#favicon_tag(name = 'favicon.ico') ⇒ Object
Render the favicon tag
Will generate the asset url given with the name
of your favicon.
45 46 47 |
# 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: asset_url(name) end |
#main_tag(html_options = {}, &block) ⇒ Object
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>
79 80 81 82 83 84 85 86 |
# File 'lib/ecrire/app/helpers/application_helper.rb', line 79 def main_tag( = {}, &block) [:id] ||= [controller_name, action_name].map(&:capitalize).join [:class] = [[:class]].compact.flatten if content_for?(:class) [:class].concat content_for(:class).split(' ') end content_tag :main, , &block end |
#popup_tag(partial = nil, html_options = {}, &block) ⇒ Object
Render a popup tag
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ecrire/app/helpers/application_helper.rb', line 91 def popup_tag(partial = nil, = {}, &block) .reverse_merge!({ as: 'Popup', id: 'Popup', class: 'popup', overlay: true }) if .delete(:overlay) == true content_tag :div, class: %w(overlay), as: 'Overlay' do content_tag :div, partial, , &block end else content_tag :div, partial, , &block end end |
#rss_tag(relative_path = '/feed') ⇒ Object
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
35 36 37 |
# 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') ⇒ Object
Render <title> tag
The content of the title tag can be one of three things. In priority of order:
-
The value of content_for(:title) if it’s set,
-
The title of the variable @post, if it’s set,
-
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
17 18 19 20 21 22 23 24 25 26 27 |
# 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 |