Module: Fae::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#body_classObject



57
58
59
# File 'app/helpers/fae/application_helper.rb', line 57

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


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

def change_item_link(change)
  text = "#{change.changeable_type.gsub('Fae::','')}: "
  test_source_method = :data_source_exists?

  if change.changeable_type.exclude?('Fae') && change.changeable_type.exclude?('Page') && !ActiveRecord::Base.connection.send(test_source_method, change.changeable_type.tableize)
    return "#{change.changeable_type}: model destroyed"
  else
    display_text = change.try(:changeable).try(:fae_display_field)
    display_text = (display_text.is_a? Integer) ? display_text.to_s : display_text
    text += display_text || "##{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
end

#col_name_or_image(item, attribute) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/fae/application_helper.rb', line 25

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 value.asset.thumb.url.present?
  # 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) || value.is_a?(ActiveSupport::TimeWithZone)
    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



45
46
47
# File 'app/helpers/fae/application_helper.rb', line 45

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


17
18
19
20
21
22
23
# File 'app/helpers/fae/application_helper.rb', line 17

def nav_active_class(klass, level, idx, parent_idx = nil)
  return klass unless @fae_navigation.coordinates[level] == idx
  return klass unless parent_idx.blank? || @fae_navigation.coordinates[level-1] == parent_idx
  new_klass = parent_idx.blank? ? '-parent-current -open' : '-current'
  new_klass += " #{klass}" if klass.present?
  new_klass
end

#page_titleObject



49
50
51
52
53
54
55
# File 'app/helpers/fae/application_helper.rb', line 49

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

#require_locals(local_array, local_assigns) ⇒ Object



11
12
13
14
15
# File 'app/helpers/fae/application_helper.rb', line 11

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