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

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')
   :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(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
   :main, html_options, &block
end

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, html_options = {}, &block)
  html_options.reverse_merge!({
    as: 'Popup',
    id: 'Popup',
    class: 'popup',
    overlay: true
  })

  if html_options.delete(:overlay) == true
     :div, class: %w(overlay), as: 'Overlay' do
       :div, partial, html_options, &block
    end
  else
     :div, partial, html_options, &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')
   :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:

  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



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')
   :title do
    if content_for?(:title)
      content_for(:title)
    elsif defined? @post
      @post.title.name
    else
      title
    end
  end
end