Module: Fae::ApplicationHelper

Defined in:
app/helpers/fae/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#body_classObject



91
92
93
# File 'app/helpers/fae/application_helper.rb', line 91

def body_class
  @body_class.present? ? @body_class : "#{controller_name} #{action_name}"
end


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/fae/application_helper.rb', line 95

def change_item_link(change)
  text = "#{change.changeable_type}: "
  text += change.try(:changeable).try(:fae_display_field) || "##{change.changeable_id}"

  begin
    return link_to text, fae.edit_content_block_path(change.changeable.slug) if change.changeable_type == 'Fae::StaticPage'
    parent = change.changeable.respond_to?(:fae_parent) ? change.changeable.fae_parent : nil
    edit_path = edit_polymorphic_path([main_app, fae_scope, parent, change.changeable])
    return link_to text, edit_path
  rescue
    return text
  end
end

#col_name_or_image(item, attribute) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/fae/application_helper.rb', line 59

def col_name_or_image(item, attribute)
  value = item.send(attribute)
  return if value.blank?
  # if item is an image
  if value.class.name == 'Fae::Image'
    image_tag(value.asset.thumb.url)
  # if item's attribute is an association
  elsif item.class.reflections.include?(attribute)
    value.try(:fae_display_field)
  # if item is a date or a time adjust to timezone
  elsif value.is_a?(Date)
    fae_date_format(value)
  elsif value.is_a?(Time)
    fae_datetime_format(value)
  else
    # otherwise it's an attribute so display it's value
    value
  end
end

#fae_scopeObject



79
80
81
# File 'app/helpers/fae/application_helper.rb', line 79

def fae_scope
  fae.root_path.gsub('/', '')
end

#form_header(name) ⇒ Object



4
5
6
7
8
9
# File 'app/helpers/fae/application_helper.rb', line 4

def form_header(name)
  name = name.class.name.split('::').last unless name.is_a? String
  form_title = "#{params[:action]} #{name}".titleize
  form_title = form_title.singularize if params[:action] == 'edit'
   :h1, form_title
end

#markdown_helper(links: true, formatting: true, emphasis: true, headers: true, list: true, paragraph: true) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/fae/application_helper.rb', line 11

def markdown_helper(links: true, formatting: true, emphasis: true, headers: true, list: true, paragraph: true)
  helper = "<h3>Markdown Options</h3>"
  helper += "<h4>Links</h4>
        <p>
          To link text, place a [bracket] around the link title and use a (/url) to house the url.<br>
          <br>
          Internal Link: [link to about](/about)<br>
          External link: [link to about](http://www.google.com/about)
        </p>" if links
  helper += "<h4>Formatting</h4>
        <p>
          Emphasize text in a variety of ways by placing **asterisks** to bold, _underscores_ to italicize.<br>
          <br>
          Bold  **bold**<br>
          Italicize _italic_
        </p>" if formatting || emphasis
  helper += "<h4>Headers</h4>
        <p>
          Use up to six hashtags to identify the importance of the section header.<br>
          <br>
          Page Header: # Page Header<br>
          Sub Header: ## Sub Header
        </p>" if headers
  helper += "<h4>List</h4>
        <p>
          Format lists by swapping out the characters that lead the list item.</br>
          <br>
          <span>Bulleted List:</span><br>
          * bullet<br>
          * bullet 2<br>
          <br>
          <span>Numbered List:</span><br>
          1. line item<br>
          2. line item
        </p>" if list
  helper += "<h4>Paragraph Break</h4>
        <p>
          Adding a blank line in between your paragraphs makes a paragraph break.
        </p>" if paragraph
  helper.html_safe
end

#page_titleObject



83
84
85
86
87
88
89
# File 'app/helpers/fae/application_helper.rb', line 83

def page_title
  if @page_title.present?
    @page_title
  else
    default_page_title
  end
end

#require_locals(local_array, local_assigns) ⇒ Object



53
54
55
56
57
# File 'app/helpers/fae/application_helper.rb', line 53

def require_locals(local_array, local_assigns)
  local_array.each do |loc|
    raise "#{loc} is a required local, please define it when you render this partial" unless local_assigns[loc.to_sym].present?
  end
end