Module: ContentHelper
- Included in:
- Admin::BaseController, BaseController
- Defined in:
- app/helpers/content_helper.rb
Instance Method Summary collapse
- #content_category_checkbox(content, category) ⇒ Object
- #content_path(section, content) ⇒ Object
- #content_status(content) ⇒ Object
- #link_to_category(*args) ⇒ Object
- #link_to_content(*args) ⇒ Object
- #link_to_preview(*args) ⇒ Object
- #link_to_tag(*args, &block) ⇒ Object
- #links_to_content_categories(content, key = nil) ⇒ Object
- #links_to_content_tags(content, key = nil) ⇒ Object
-
#page_link_path(section, link) ⇒ Object
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.
- #published_at_formatted(article) ⇒ Object
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_checkbox(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> </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 |
#link_to_category(*args) ⇒ Object
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 |
#link_to_content(*args) ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/content_helper.rb', line 43 def link_to_content(*args) = args. object, text = *args.reverse link_to_show(text || (object.is_a?(Site) ? object.name : object.title), object, ) if object end |
#link_to_preview(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/content_helper.rb', line 32 def link_to_preview(*args) = args. content, text = *args.reverse text ||= :"adva.#{content.class.name.tableize}.links.preview" url = show_path(content, :cl => content.class.locale, :namespace => nil) .reverse_merge!(:url => url, :class => "preview #{content.class.name.underscore}") link_to_show(text, content, ) end |
#link_to_tag(*args, &block) ⇒ Object
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 |
#links_to_content_categories(content, key = nil) ⇒ Object
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 |
#links_to_content_tags(content, key = nil) ⇒ Object
77 78 79 80 81 |
# File 'app/helpers/content_helper.rb', line 77 def (content, key = nil) return if content..empty? links = content..map { |tag| link_to_tag content.section, tag } key ? t(key, links: links.join(', ')).html_safe : links end |
#page_link_path(section, link) ⇒ Object
def article_url(section, article, options = {})
if article.section.is_a?(Blog)
blog_article_url(section, article.full_permalink.merge())
else
page_article_url(*[section, article.permalink, ].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 |