Module: Crm::PostsHelper

Defined in:
app/helpers/crm/posts_helper.rb

Instance Method Summary collapse

Instance Method Details

#crm_post_live_url(post, locale: 'en-US') ⇒ Object

Build the public www URL for a post with the locale embedded in the path.
We construct the path directly because the named post_path helper belongs
to the CRM routes (which lack a :locale segment) and would append locale as
a query-string parameter instead.



6
7
8
# File 'app/helpers/crm/posts_helper.rb', line 6

def crm_post_live_url(post, locale: 'en-US')
  "#{WEB_URL}/#{locale}/posts/#{post.slug}"
end

#crm_post_url_with_referral(post, referral_code, locale: 'en-US') ⇒ Object



10
11
12
# File 'app/helpers/crm/posts_helper.rb', line 10

def crm_post_url_with_referral(post, referral_code, locale: 'en-US')
  "#{crm_post_live_url(post, locale: locale)}?referral_code=#{ERB::Util.url_encode(referral_code)}"
end

#localized_body(post) ⇒ Object



51
52
53
54
55
# File 'app/helpers/crm/posts_helper.rb', line 51

def localized_body(post)
  return unless b = post.solution.presence

  localize_content(b)
end

#post_commands(post) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/crm/posts_helper.rb', line 14

def post_commands(post)
  cmds = []
  cmds << link_to('Edit Post', edit_post_path(post), data: { turbo_action: 'replace' }) if can?(:update, post)
  cmds << link_to('Clone Post', clone_post_path(post), data: { turbo_method: :post }) if can?(:create, Post)

  # Revision system commands
  cmds << link_to('Revision History', post_revisions_path(post)) if post.uses_revisions?

  cmds << link_to('Check Internal Links', check_links_post_path(post), data: { turbo_method: :post }) if can?(:update, post)
  cmds << link_to('Link Analysis', link_checks_path(q: { articles_id_eq: post.id }))
  cmds << link_to('Image Analysis', blog_image_checks_path)
  cmds << link_to('See Post Comments', post_post_comments_path(post_id: post.id))
  cmds << link_to('Flush Cache', flush_cache_post_path(post), data: { turbo_method: :post }) if can?(:update, post)

  # Add confirmation if schema markup already exists
  extract_schema_options = { data: { turbo_method: :post } }
  extract_schema_options[:data][:turbo_confirm] = 'This post already has schema markup. Are you sure you want to extract and potentially overwrite it?' if post.schema_markup.present?
  cmds << link_to('Extract Schema', extract_schema_post_path(post), extract_schema_options) if can?(:update, post)

  cmds << link_to('Delete', post_path(post), data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to destroy the post: #{post.title}" }) if can?(:destroy, post)
  cmds
end

#post_title(post) ⇒ Object



47
48
49
# File 'app/helpers/crm/posts_helper.rb', line 47

def post_title(post)
  link_to post.title[0..65], post_path(post)
end

#revision_state_badge(revision, is_current: nil) ⇒ Object

Returns a Bootstrap badge for the revision status (current or past)



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

def revision_state_badge(revision, is_current: nil)
  is_current = revision.current? if is_current.nil?
  if is_current
    tag.span 'Current', class: 'badge bg-success'
  else
    tag.span 'Past', class: 'badge bg-secondary'
  end
end