Module: Hicube::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/hicube/application_helper.rb', line 17

def breadcrumbs
  return [] if controller_name.eql?('dashboards')
  case
  when current_page?(action: :index)
    { controller_name.camelize => {path: nil, active: true} }
  when current_page?(action: :new)
    {
      controller_name.camelize => {path: url_for(controller: controller_name, action: :index), active: false},
      'New' => {path: nil, active: true}
    }
  else # show & edit
    {
      controller_name.camelize => {path: url_for(controller: controller_name, action: :index), active: false},
      instance_variable_get("@#{controller_name.singularize}") => {path: nil, active: true}
    }
  end
end

#headingObject



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

def heading
  if current_page?(action: :new)
    'New'
  else
    instance_variable_get("@#{controller_name.singularize}") || controller_name.camelize
  end
end

#root_pathObject



56
57
58
# File 'app/helpers/hicube/application_helper.rb', line 56

def root_path
  '/'
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/hicube/application_helper.rb', line 35

def sidebar_class(action, model, options = {})
  case action
  when :edit, :new
    if options.nil?
      current_page?(eval("#{action}_#{model}_path")) ? :active : nil rescue nil # for edit
    else
      current_page?(eval("#{action}_#{model}_path(options)")) ? :active : nil rescue nil # for edit
    end
  when :index
    current_page?(eval("#{model.to_s.pluralize}_path")) ? :active : nil
  when :show
    if options.nil?
      current_page?(eval("#{model}_path")) ? :active : nil rescue nil
    else
      current_page?(eval("#{model}_path(options)")) ? :active : nil rescue nil
    end        
  else
    nil
  end
end

#snippet_render(name) ⇒ Object

def header_links

Hicube::Page.parents

end



64
65
66
67
68
69
70
71
# File 'app/helpers/hicube/application_helper.rb', line 64

def snippet_render(name)
  snippet = Hicube::Snippet.find_by(name: name)
  raw "#{Hicube::Markdown.render(::Liquid::Template.parse(snippet.body).render).html_safe}"
rescue Mongoid::Errors::DocumentNotFound => dnf
  raw "Snippet Not found with name #{name}"
rescue Exception => e
  raw "#{e}"
end

#subheadingObject



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

def subheading
  return if controller_name.eql?('dashboards')
  controller_name.singularize.camelize unless current_page?(action: :index)
end