Module: PostsHelper
- Defined in:
- app/helpers/posts_helper.rb
Defined Under Namespace
Classes: PostScrubber
Instance Method Summary collapse
-
#cancel_redirect_path(post) ⇒ String
Get the redirect path to use when the user cancels an edit.
-
#max_body_length(_category) ⇒ Integer
Get the maximum body length for the specified category.
-
#max_title_length(_category) ⇒ Integer
Get the maximum title length for the specified category.
-
#min_body_length(category) ⇒ Integer
Get the minimum body length for the specified category.
-
#min_title_length(category, post_type) ⇒ Integer
Get the minimum title length for the specified category.
-
#post_markdown(scope, field_name) ⇒ String
Get markdown submitted for a post - should only be used in Markdown create/edit requests.
-
#scrubber ⇒ PostScrubber
Get a post scrubber instance.
Instance Method Details
#cancel_redirect_path(post) ⇒ String
Get the redirect path to use when the user cancels an edit.
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.
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.
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.
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.
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.
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 |
#scrubber ⇒ PostScrubber
Get a post scrubber instance.
83 84 85 |
# File 'app/helpers/posts_helper.rb', line 83 def scrubber PostsHelper::PostScrubber.new end |