Module: ArticlesHelper

Defined in:
app/helpers/articles_helper.rb

Overview

View helper: articles.

Instance Method Summary collapse

Instance Method Details

#article_command_options(article) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/articles_helper.rb', line 8

def article_command_options(article)
  links = []
  links << link_to("Edit", send("edit_#{params[:controller].singularize}_path", article)) if can?(:update, article)
  links << link_to("Convert to PDF", send("#{params[:controller].singularize}_path", format: :pdf))
  links << link_to("Send by Email", send("send_by_email_#{params[:controller].singularize}_path"))
  if can?(:destroy, article)
    links << link_to("Delete", send("#{params[:controller].singularize}_path"),
                data: { turbo_confirm: "Are you sure?", turbo_method: :delete })
  end
  links
end

#article_conversion_options(article) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/articles_helper.rb', line 20

def article_conversion_options(article)
  conversions = { 'ArticleFaq' => 'Faq', 'ArticleTechnical' => 'Technical', 'ArticleTraining' => 'Training', 'ArticleProcedure' => 'Procedure' }
  links = []
  conversions.each do |sti_type, label|
    next if article.type == sti_type

    links << link_to("Convert to #{label}", send("convert_type_#{params[:controller].singularize}_path", id: article, article_type_id: sti_type), data: { turbo_confirm: 'Are you sure you want to convert this article?' })
  end
  links
end

#article_state_label(article) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'app/helpers/articles_helper.rb', line 47

def article_state_label(article)
  css_state = {
    draft: 'secondary',
    scheduled: 'info',
    published: 'success',
    archived: 'warn'
  }[article.state.to_sym] || 'default'
  (:span, article.human_state_name, class: "badge bg-#{css_state}")
end

#polymorphic_article_path(article) ⇒ Object



39
40
41
42
43
44
45
# File 'app/helpers/articles_helper.rb', line 39

def polymorphic_article_path(article)
  return nil unless article.present? && article.respond_to?(:to_model)

  polymorphic_path(article)
rescue ActionController::UrlGenerationError, NoMethodError
  nil
end

#safe_edit_path(record) ⇒ Object



31
32
33
34
35
36
37
# File 'app/helpers/articles_helper.rb', line 31

def safe_edit_path(record)
  return nil unless record.present? && record.respond_to?(:to_model)

  polymorphic_path([:edit, record])
rescue ActionController::UrlGenerationError, NoMethodError
  nil
end

#setup_training_article(article) ⇒ Object



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

def setup_training_article(article)
  # Create one page of content
  article.tap do |article|
    article.article_pages.build(position: 1) if article.article_pages.blank?
  end
end

#time_choices_for_articleObject



4
5
6
# File 'app/helpers/articles_helper.rb', line 4

def time_choices_for_article
  [['', nil]] + (15..240).step(15).to_a.map { |t| ["#{t} min", t] }
end