Module: Collavre::CreativesHelper
- Defined in:
- app/helpers/collavre/creatives_helper.rb
Instance Method Summary collapse
-
#markdown_links_to_html(text, image_refs = {}) ⇒ Object
Delegate to MarkdownConverter for backward compatibility.
- #render_creative_progress(creative, select_mode: false, has_children: nil) ⇒ Object
- #render_creative_tags(creative) ⇒ Object
- #render_creative_tree_markdown(creatives, level = 1, with_progress = false, max_depth: nil) ⇒ Object
- #render_progress_toggle(creative, value) ⇒ Object
- #render_progress_value(value) ⇒ Object
- #render_tags(labels, class_name = nil, name_only = false) ⇒ Object
Instance Method Details
#markdown_links_to_html(text, image_refs = {}) ⇒ Object
Delegate to MarkdownConverter for backward compatibility. These methods are used in views and by MarkdownImporter via ApplicationController.helpers.
180 181 182 |
# File 'app/helpers/collavre/creatives_helper.rb', line 180 def markdown_links_to_html(text, image_refs = {}) MarkdownConverter.markdown_to_html(text, image_refs) end |
#render_creative_progress(creative, select_mode: false, has_children: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/collavre/creatives_helper.rb', line 28 def render_creative_progress(creative, select_mode: false, has_children: nil) progress_value = if params[:tags].present? tag_ids = Array(params[:tags]).map(&:to_s) creative.filtered_progress || creative.(tag_ids) || 0 else creative.progress end content_tag(:div, class: "creative-row-end") do comment_part = if creative.archived? safe_join([]) elsif creative.(Current.user, :feedback) origin = creative.effective_origin comments_count = origin.comments.size pointer = CommentReadPointer.find_by(user: Current.user, creative: origin) last_read_id = pointer&.last_read_comment_id unread_count = last_read_id ? origin.comments.where("id > ? and private = ?", last_read_id, false).count : comments_count if Current.user && CommentPresenceStore.list(origin.id).include?(Current.user.id) unread_count = 0 end classes = [ "comments-btn", "creative-action-btn" ] classes << "no-comments" if comments_count.zero? comment_icon = svg_tag( "comment.svg", class: "comment-icon" ) badge_id = "comment-badge-#{origin.id}" stream = turbo_stream_from [ Current.user, origin, :comment_badge ] badge = render( Inbox::BadgeComponent.new( count: unread_count, badge_id: badge_id, show_zero: comments_count.positive? ) ) stream + ( comment_icon + badge, name: "show-comments-btn", data: { creative_id: creative.id, can_comment: true, creative_snippet: creative.creative_snippet }, class: classes.join(" ") ) else safe_join([]) end is_leaf = has_children.nil? ? !creative.children.exists? : !has_children can_write = creative.(Current.user, :write) progress_part = if is_leaf && can_write && !select_mode render_progress_toggle(creative, progress_value) else render_progress_value(progress_value) end safe_join([ progress_part, comment_part, tag.br, (creative. ? (creative) : safe_join([])) ]) end end |
#render_creative_tags(creative) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/helpers/collavre/creatives_helper.rb', line 20 def (creative) labels = creative.&.includes(:label)&.map(&:label)&.compact return "" if labels&.empty? content_tag(:div, class: "creative-tags", style: "display: none;") do (labels, "unstyled-link", true) end end |
#render_creative_tree_markdown(creatives, level = 1, with_progress = false, max_depth: nil) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/collavre/creatives_helper.rb', line 129 def render_creative_tree_markdown(creatives, level = 1, with_progress = false, max_depth: nil) return "" if creatives.blank? md = "" creatives.each do |creative| desc = creative.effective_description(nil, true) if with_progress && creative.respond_to?(:progress) && !creative.progress.nil? pct = (creative.progress.to_f * 100).round desc = "#{desc} (#{pct}%)" end raw_html = desc.gsub(/<!--.*?-->/m, "").strip markdown_content = MarkdownConverter.html_to_markdown(raw_html) cleaned_markdown = markdown_content.strip rendered_table_block = false table_match = cleaned_markdown.match(/^<div[^>]*>\s*<div[^>]*>\s*(\|.*?\|(?:\n\|.*?\|)*)\s*<\/div>\s*<\/div>$/m) if level <= 4 && table_match table_content = table_match[1].strip if MarkdownConverter.table_block?(table_content) md += "#{table_content}\n\n" rendered_table_block = true end elsif level <= 4 && MarkdownConverter.table_block?(cleaned_markdown) md += "#{cleaned_markdown}\n\n" rendered_table_block = true elsif level <= 4 md += "#{'#' * level} #{ActionView::Base.full_sanitizer.sanitize(markdown_content).strip}\n\n" else inner_html = begin fragment = Nokogiri::HTML.fragment(raw_html) wrapper = fragment.at_css("div.trix-content") if wrapper wrapper.inner_html.strip else ActionView::Base.full_sanitizer.sanitize(markdown_content).strip end end inner = ActionView::Base.full_sanitizer.sanitize(inner_html) indent = " " * (level - 5) md += "#{indent}* #{inner}\n" end children = creative.linked_children if children.present? && (max_depth.nil? || level < max_depth) md += render_creative_tree_markdown(children, level + 1, with_progress, max_depth: max_depth) end md += "\n" if level <= 4 && !rendered_table_block end md end |
#render_progress_toggle(creative, value) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/collavre/creatives_helper.rb', line 89 def render_progress_toggle(creative, value) complete = value == 1 new_value = complete ? 0 : 1 tooltip = complete ? t("collavre.creatives.index.mark_incomplete") : t("collavre.creatives.index.mark_complete") content_tag( :span, class: "progress-toggle-wrap", data: { progress_toggle: true, creative_id: creative.id, current_progress: value, new_progress: new_value }, title: tooltip ) do checkbox = tag.input( type: "checkbox", checked: complete || nil, class: "progress-toggle-checkbox", tabindex: -1, "aria-label": tooltip ) safe_join([ render_progress_value(value), checkbox ]) end end |
#render_progress_value(value) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/helpers/collavre/creatives_helper.rb', line 115 def render_progress_value(value) text = number_to_percentage(value * 100, precision: 0) completion_mark = Collavre::SystemSetting.completion_mark if value == 1 && !completion_mark.nil? text = completion_mark end display_text = text.blank? ? "\u00A0\u00A0" : text content_tag( :span, display_text, class: "creative-progress-#{value == 1 ? 'complete' : 'incomplete'}" ) end |
#render_tags(labels, class_name = nil, name_only = false) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/collavre/creatives_helper.rb', line 3 def (labels, class_name = nil, name_only = false) return "" if labels&.empty? or labels.nil? index = 0 safe_join(labels.map do |label| suffix = name_only ? nil : render_label_suffix(label) index += 1 content_tag(:span, class: "tag") do safe_join([ (index == 1 ? "" : " "), link_to("##{(label.name)}", collavre.creatives_path(tags: [ label.id ]), class: class_name ? class_name: "", title: (label.name)), suffix ].compact) end end) end |