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, options = {}) ⇒ 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, options = {}) ⇒ 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
92 93 94 95 96 97 98 |
# File 'app/helpers/content_helper.rb', line 92 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, options = {}) ⇒ Object
26 27 28 29 |
# File 'app/helpers/content_helper.rb', line 26 def content_path(section, content, ={}) return article_path(section, content) if content.is_a? Article link_path(section, content) end |
#content_status(content) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/helpers/content_helper.rb', line 31 def content_status(content) return "<span> </span>" unless content.respond_to?(:published?) klass = content.published? ? 'published' : 'pending' text = content.published? ? "Published" : "Pending" "<span title='#{text}' alt='#{text}' class='status #{klass}'>#{text}</span>" end |
#link_to_category(*args) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/helpers/content_helper.rb', line 56 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
50 51 52 53 54 |
# File 'app/helpers/content_helper.rb', line 50 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
39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/content_helper.rb', line 39 def link_to_preview(*args) = args. content, text = *args.reverse text ||= "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
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/content_helper.rb', line 73 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
65 66 67 68 69 70 71 |
# File 'app/helpers/content_helper.rb', line 65 def links_to_content_categories(content, key = nil) return if content.categories.empty? links = content.categories.map do |category| link_to_category content.section, category end raw "in: #{links.join(', ')}" end |
#links_to_content_tags(content, key = nil) ⇒ Object
86 87 88 89 90 |
# File 'app/helpers/content_helper.rb', line 86 def (content, key = nil) return if content..empty? links = content..map { |tag| link_to_tag content.section, tag } raw "tagged: #{links.join(', ')}" end |
#page_link_path(section, link, options = {}) ⇒ 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
22 23 24 |
# File 'app/helpers/content_helper.rb', line 22 def page_link_path section, link, ={} link.body_html end |
#published_at_formatted(article) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/content_helper.rb', line 2 def published_at_formatted(article) unless article && article.published? if article.published_at&.future? "Will publish on " + l(article.published_at, :format => (article.published_at.year == Time.now.year ? :short : :long)) else "Draft" end else l(article.published_at, :format => (article.published_at.year == Time.now.year ? :short : :long)) end end |