Module: Commontator::SharedHelper
- Defined in:
- lib/commontator/shared_helper.rb
Instance Method Summary collapse
- #commontator_gravatar_image_tag(user, border = 1, options = {}) ⇒ Object
- #commontator_set_thread(commontable) ⇒ Object
- #commontator_set_user ⇒ Object
- #commontator_simple_format(text, html_options = {}, options = {}) ⇒ Object
-
#commontator_split_paragraphs(text) ⇒ Object
Unlike the Rails versions of split_paragraphs and simple_format, Commontator’s: - Split paragraphs on any number of newlines optionally adjacent to spaces - Create all <p> tags (no <br/> tags) - Do not add <p> tags between other html tags.
- #commontator_thread(commontable) ⇒ Object
Instance Method Details
#commontator_gravatar_image_tag(user, border = 1, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/commontator/shared_helper.rb', line 24 def commontator_gravatar_image_tag(user, border = 1, = {}) email = Commontator.commontator_email(user) || '' name = Commontator.commontator_name(user) || '' url = "https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?#{.to_query}" image_tag(url, alt: name, title: name, border: border) end |
#commontator_set_thread(commontable) ⇒ Object
6 7 8 |
# File 'lib/commontator/shared_helper.rb', line 6 def commontator_set_thread(commontable) @commontator_thread = commontable.commontator_thread end |
#commontator_set_user ⇒ Object
2 3 4 |
# File 'lib/commontator/shared_helper.rb', line 2 def commontator_set_user @commontator_user = Commontator.current_user_proc.call(self) end |
#commontator_simple_format(text, html_options = {}, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/commontator/shared_helper.rb', line 43 def commontator_simple_format(text, = {}, = {}) wrapper_tag = .fetch(:wrapper_tag, :p) text = sanitize(text) if .fetch(:sanitize, true) paragraphs = commontator_split_paragraphs(text) if paragraphs.empty? content_tag(wrapper_tag, nil, ) else paragraphs.map! do |paragraph| paragraph.starts_with?('<') && paragraph.ends_with?('>') ? raw(paragraph) : content_tag(wrapper_tag, raw(paragraph), ) end.join("\n").html_safe end end |
#commontator_split_paragraphs(text) ⇒ Object
Unlike the Rails versions of split_paragraphs and simple_format, Commontator’s:
-
Split paragraphs on any number of newlines optionally adjacent to spaces
-
Create all <p> tags (no <br/> tags)
-
Do not add <p> tags between other html tags
37 38 39 40 41 |
# File 'lib/commontator/shared_helper.rb', line 37 def commontator_split_paragraphs(text) return [] if text.blank? text.to_str.gsub(/\r\n?/, "\n").gsub(/>\s*</, ">\n<").split(/\s*\n\s*/).reject(&:blank?) end |
#commontator_thread(commontable) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/commontator/shared_helper.rb', line 10 def commontator_thread(commontable) commontator_set_user commontator_set_thread(commontable) render( partial: 'commontator/shared/thread', locals: { user: @commontator_user, thread: @commontator_thread, page: @commontator_page, show_all: @commontator_show_all } ).html_safe end |