Class: LcpRuby::Display::Renderers::LinkList
- Inherits:
-
BaseRenderer
- Object
- BaseRenderer
- LcpRuby::Display::Renderers::LinkList
- Defined in:
- lib/lcp_ruby/display/renderers/link_list.rb
Overview
Renders an array of strings as a list of clickable links.
Options:
href_prefix: String prepended to each value to form the URL (default: "/")
strip_extension: Extension to remove from href (default: nil, e.g. ".md")
label_strip_prefix: Prefix to remove from the display label (default: nil, e.g. "docs/")
target: Link target attribute (default: nil; use "_blank" for new tab)
list_style: Rendering mode (default: "br")
"br" — links separated by <br> (default)
"ul" — unordered bullet list <ul><li>...</li></ul>
"ol" — ordered numbered list <ol><li>...</li></ol>
"inline" — inline with custom separator
"comma" — shorthand for inline with ", "
separator: Custom separator for "inline" list_style (default: ", ")
Examples:
# Vertical line-break list (default)
field :docs_refs, renderer: :link_list, options: { href_prefix: "/docs/" }
# Bullet list
field :links, renderer: :link_list, options: { list_style: "ul", target: "_blank" }
# Numbered list
field :steps, renderer: :link_list, options: { list_style: "ol" }
# Inline comma-separated
field :tags, renderer: :link_list, options: { list_style: "comma" }
# Inline with custom separator
field :refs, renderer: :link_list, options: { list_style: "inline", separator: " | " }
Instance Method Summary collapse
Instance Method Details
#link_producing? ⇒ Boolean
84 85 86 |
# File 'lib/lcp_ruby/display/renderers/link_list.rb', line 84 def link_producing? true end |
#render(value, options = {}, record: nil, view_context: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lcp_ruby/display/renderers/link_list.rb', line 35 def render(value, = {}, record: nil, view_context: nil) items = Array(value).reject(&:blank?) return nil if items.empty? links = items.map { |item| build_link(item, , view_context) } case (["list_style"] || "br").to_s when "ul" list_items = links.map { |link| view_context.content_tag(:li, link) } view_context.content_tag(:ul, view_context.safe_join(list_items), class: "lcp-link-list") when "ol" list_items = links.map { |link| view_context.content_tag(:li, link) } view_context.content_tag(:ol, view_context.safe_join(list_items), class: "lcp-link-list") when "comma" view_context.safe_join(links, ", ") when "inline" separator = ["separator"] || ", " view_context.safe_join(links, separator) else # "br" view_context.safe_join(links, "<br>".html_safe) end end |