Module: Trejo::ViewHelpers

Defined in:
lib/trejo/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#body_classObject



36
37
38
# File 'lib/trejo/view_helpers.rb', line 36

def body_class
  content_for?(:page_class) ? content_for(:page_class) : nil
end

#body_idObject



28
29
30
31
32
33
34
# File 'lib/trejo/view_helpers.rb', line 28

def body_id
  if content_for?(:page_id)
    content_for(:page_id)
  else
    "#{controller.controller_name}-#{controller.action_name}-page".dasherize
  end
end


48
49
50
# File 'lib/trejo/view_helpers.rb', line 48

def copyright_notice company_name = nil
  "\u00A9 #{Date.current.year} #{company_name.presence || Trejo.configuration.company_name}, All Rights Reserved"
end

#merge_classes(*classes) ⇒ Object



16
17
18
19
20
# File 'lib/trejo/view_helpers.rb', line 16

def merge_classes(*classes)
  classes.flatten
    .reject(&:blank?).map(&:split)
    .flatten.uniq.join ' '
end


3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/trejo/view_helpers.rb', line 3

def nav_item name, url, options={}
  current_path = request.fullpath

  selected = if options[:selected]
    current_path =~ options[:selected]
  else
    current_path =~ /^#{Regexp.escape(url)}.*(?:\?.*)?/
  end

  link_class = options[:class] || 'active' if selected
  link_to name, url, class: link_class
end

#page_class(value) ⇒ Object



44
45
46
# File 'lib/trejo/view_helpers.rb', line 44

def page_class value
  content_for(:page_class) { value }
end

#page_id(value) ⇒ Object



40
41
42
# File 'lib/trejo/view_helpers.rb', line 40

def page_id value
  content_for(:page_id) { value }
end

#site_titleObject



52
53
54
# File 'lib/trejo/view_helpers.rb', line 52

def site_title
  Trejo.configuration.site_title
end

#title(page_title = nil) ⇒ Object



22
23
24
25
26
# File 'lib/trejo/view_helpers.rb', line 22

def title page_title = nil
  content_for(:title) do
    [page_title, Trejo.configuration.site_title].compact.join(' | ')
  end
end