Module: PostsHelper

Defined in:
app/helpers/posts_helper.rb

Defined Under Namespace

Classes: PostScrubber

Instance Method Summary collapse

Instance Method Details

#cancel_redirect_path(post) ⇒ String

Get the redirect path to use when the user cancels an edit.

Returns:

  • (String)


16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/posts_helper.rb', line 16

def cancel_redirect_path(post)
  if post.id.present?
    post_url(post)
  elsif post.parent_id.present?
    post_url(post.parent_id)
  elsif post.category_id.present?
    category_url(post.category_id)
  else
    root_url
  end
end

#max_body_length(_category) ⇒ Integer

Get the maximum body length for the specified category. Returns a constant 30,000 at present but intended to return a configurable value in the future.

Parameters:

Returns:

  • (Integer)


41
42
43
# File 'app/helpers/posts_helper.rb', line 41

def max_body_length(_category)
  30_000
end

#max_title_length(_category) ⇒ Integer

Get the maximum title length for the specified category. Has a hard limit of 255 characters.

Parameters:

Returns:

  • (Integer)


62
63
64
# File 'app/helpers/posts_helper.rb', line 62

def max_title_length(_category)
  [SiteSetting['MaxTitleLength'] || 255, 255].min
end

#min_body_length(category) ⇒ Integer

Get the minimum body length for the specified category.

Parameters:

Returns:

  • (Integer)


32
33
34
# File 'app/helpers/posts_helper.rb', line 32

def min_body_length(category)
  category&.min_body_length || 30
end

#min_title_length(category, post_type) ⇒ Integer

Get the minimum title length for the specified category.

Parameters:

  • category (Category, nil)
  • post_type (PostType)

    Type of the post (system limits are relaxed)

Returns:

  • (Integer)


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

def min_title_length(category, post_type)
  if post_type.system?
    1
  else
    category&.min_title_length || 15
  end
end

#post_markdown(scope, field_name) ⇒ String

Get markdown submitted for a post - should only be used in Markdown create/edit requests. Prioritises using the client-side rendered HTML over rendering server-side.

Parameters:

  • scope (Symbol)

    The parameter scope for the markdown - i.e. if the form submits it as posts[body_markdown], this should be :posts.

  • field_name (Symbol)

    The parameter name for the markdown - i.e. :body_markdown in the same example.

Returns:

  • (String)


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

def post_markdown(scope, field_name)
  params['__html'].presence || render_markdown(params[scope][field_name])
end

#scrubberPostScrubber

Get a post scrubber instance.

Returns:



83
84
85
# File 'app/helpers/posts_helper.rb', line 83

def scrubber
  PostsHelper::PostScrubber.new
end