Module: ContentHelper

Included in:
Admin::BaseController, BaseController
Defined in:
app/helpers/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#content_category_checkbox(content, category) ⇒ Object



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

def (content, category)
  type = content.type.downcase
  checked = content.categories.include?(category)
  name = "#{type}[category_ids][]"
  id = "#{type}_category_#{category.id}"
  check_box_tag(name, category.id, checked, :id => id)
end

#content_path(section, content) ⇒ Object



19
20
21
22
# File 'app/helpers/content_helper.rb', line 19

def content_path(section, content)
  return article_path(section, content) if content.is_a? Article
  link_path(section, content)
end

#content_status(content) ⇒ Object



24
25
26
27
28
29
30
# File 'app/helpers/content_helper.rb', line 24

def content_status(content)
  return "<span>&nbsp;</span>" unless content.respond_to?(:published?)
  klass = content.published? ? 'published' : 'pending'
  text  = content.published? ? t(:'adva.titles.published') : t(:'adva.titles.pending')

  "<span title='#{text}' alt='#{text}' class='status #{klass}'>#{text}</span>"
end


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

def link_to_category(*args)
  text = args.shift if args.first.is_a?(String)
  category = args.pop
  section = args.pop || category.section
  route_name = :"#{section.class.name.downcase}_category_path"
  text ||= category.title
  link_to(text, send(route_name, :section_id => section.id, :category_id => category.id))
end


43
44
45
46
47
# File 'app/helpers/content_helper.rb', line 43

def link_to_content(*args)
  options = args.extract_options!
  object, text = *args.reverse
  link_to_show(text || (object.is_a?(Site) ? object.name : object.title), object, options) if object
end


32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/content_helper.rb', line 32

def link_to_preview(*args)
  options = args.extract_options!
  content, text = *args.reverse

  text ||= :"adva.#{content.class.name.tableize}.links.preview"
  url = show_path(content, :cl => content.class.locale, :namespace => nil)

  options.reverse_merge!(:url => url, :class => "preview #{content.class.name.underscore}")
  link_to_show(text, content, options)
end


64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/content_helper.rb', line 64

def link_to_tag(*args, &block)
  tag = args.pop
  section = args.pop
  route_name = :"#{section.class.name.downcase}_tag_path"

  if block_given?
    link_to(send(route_name, section_permalink: section.permalink, tags: tag), &block)
  else
    text = args.pop || tag.name
    link_to(text, send(route_name, section_permalink: section.permalink, tags: tag))
  end
end


58
59
60
61
62
# File 'app/helpers/content_helper.rb', line 58

def links_to_content_categories(content, key = nil)
  return if content.categories.empty?
  links = content.categories.map { |category| link_to_category content.section, category }
  key ? t(key, :links => links.join(', ')) : links
end


77
78
79
80
81
# File 'app/helpers/content_helper.rb', line 77

def (content, key = nil)
  return if content.tags.empty?
  links = content.tags.map { |tag| link_to_tag content.section, tag }
  key ? t(key, links: links.join(', ')).html_safe : links
end

def article_url(section, article, options = {})

if article.section.is_a?(Blog)
  blog_article_url(section, article.full_permalink.merge(options))
else
  page_article_url(*[section, article.permalink, options].compact)
end

end



15
16
17
# File 'app/helpers/content_helper.rb', line 15

def page_link_path section, link
  link.body_html
end

#published_at_formatted(article) ⇒ Object



2
3
4
5
# File 'app/helpers/content_helper.rb', line 2

def published_at_formatted(article)
  return t(:'adva.contents.not_published') unless article && article.published?
  l(article.published_at, :format => (article.published_at.year == Time.now.year ? :short : :long))
end