Module: Publinator::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#asset_file_tag(object, asset_type, size = 'original', img_class = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'app/helpers/publinator/application_helper.rb', line 90

def asset_file_tag(object, asset_type, size = 'original', img_class = nil)
  imgs = object.asset_files(asset_type)
  return unless imgs && imgs.first
  if img_class
    image_tag(imgs.first.asset.url(size.to_sym), :class => img_class)
  else
    image_tag(imgs.first.asset.url(size.to_sym))
  end
end

#clean_result_text(txt) ⇒ Object



100
101
102
103
# File 'app/helpers/publinator/application_helper.rb', line 100

def clean_result_text(txt)
  stp_txt = truncate(strip_tags(m(txt)), :length => 200)
  stp_txt.gsub("'", "'").gsub("&", "&").gsub("®", "").gsub("™", "") unless stp_txt.nil?
end

#collection_li_tag(object, li_collection_title = nil, li_collection_path = nil) ⇒ Object



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
52
53
# File 'app/helpers/publinator/application_helper.rb', line 22

def collection_li_tag(object, li_collection_title = nil, li_collection_path = nil)
  return if object.respond_to?(:hide_in_submenu) && object.hide_in_submenu
  collection_title = li_collection_title.present? ? li_collection_title : object.first.collection_name
  collection_slug  = object.first.class.to_s.tableize.humanize
  collection_path  = li_collection_path.present? ? li_collection_path : "/#{object.first.class.to_s.tableize}"

  # object is an array
  #   1. add a link to the collection name
  #   2. add a ul for the collection
  #   3. add li tags for each object in the collection


  (:li, :id => object.first.class.to_s.tableize) do
    li_content = ""
    li_content += link_to collection_title, collection_path


    li_content += (:div, :class => 'submenu', :id => object.first.class.to_s.tableize) do
      div_contents = ""
      div_contents += (:ul) do
        next_contents = ""
        object.each do |o|
          next_contents += li_tag(o) unless o.respond_to?(:hide_in_submenu) && o.hide_in_submenu
        end
        next_contents.html_safe
      end
      div_contents.html_safe
    end

    li_content.html_safe
  end
end

#li_tag(object) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/publinator/application_helper.rb', line 55

def li_tag(object)
  (:li, :id => object.my_slug) do
    li_content = ""
    li_content += link_to object.title, object.path
    if object.menu_collection && object.menu_collection.length > 0
      li_content += ("<br>" + submenu(object).html_safe)
    end
    li_content.html_safe
  end
end


5
6
7
# File 'app/helpers/publinator/application_helper.rb', line 5

def link_to_page(link_text, section, slug)
  link_to link_text, "/#{section}/#{slug}"
end

#m(markdown_text) ⇒ Object



9
10
11
12
# File 'app/helpers/publinator/application_helper.rb', line 9

def m(markdown_text)
  return if !markdown_text || markdown_text.blank?
  RDiscount.new(markdown_text).to_html.html_safe
end


14
15
16
17
18
19
20
# File 'app/helpers/publinator/application_helper.rb', line 14

def menu_item(object)
  if object.respond_to?(:is_publishable?)
    li_tag(object)
  else
    collection_li_tag(object)
  end
end

#publishable_asset(pub, asset_type) ⇒ Object



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

def publishable_asset(pub, asset_type)
  return if !pub
  asset = pub.asset_file(asset_type)
  image_tag asset.url if asset
end


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/publinator/application_helper.rb', line 66

def submenu(object)
  (:div, :class => 'submenu', :id => object.slug) do
    div_content = ""
    ul_content = ""
    div_content += (:ul) do
      object.menu_collection.each do |mco|
        unless mco.respond_to?(:hide_in_submenu) && mco.hide_in_submenu
          ul_content += li_tag(mco)
        end
      end
      ul_content.html_safe
    end
    div_content.html_safe
  end
rescue => e
  logger.info e
end

#toggle_details(lnk_text, obj_link) ⇒ Object



105
106
107
# File 'app/helpers/publinator/application_helper.rb', line 105

def toggle_details(lnk_text, obj_link)
  link_to lnk_text, obj_link, :class => 'toggle_details'
end