class DocTemplate::Tags::LinkTag
Constants
- FORTHCOMING_PATH
Public Instance Methods
parse(node, opts = {})
click to toggle source
# File lib/doc_template/tags/link_tag.rb, line 8 def parse(node, opts = {}) # preserve the node content and replace only the tag by the link content = node.to_s.sub(self.class.tag_with_html_regexp, link(opts)) opts[:iteration] ||= 1 opts[:parent_node] = content @content = parse_nested content, opts replace_tag node self end
Private Instance Methods
build_href(title, metadata)
click to toggle source
# File lib/doc_template/tags/link_tag.rb, line 30 def build_href(title, metadata) # if the first param is a url, then use it directly return title if title =~ URI::DEFAULT_PARSER.make_regexp || title.strip == FORTHCOMING_PATH # if we don't have proper metadata info, just use a placeholder return '#' unless metadata # build the path for unbounded-supplemental-materials on s3 path = %i(subject grade module unit topic).map do |key| if metadata[key].present? # if its a number return `key-number` else return the parameterized value /^(\d+)$/.match(metadata[key]) { |num| "#{key}-#{num}" } || metadata[key].try(:parameterize) end end.compact.join('/') filename = title.ends_with?('.pdf') ? title : "#{title}.pdf" "https://unbounded-supplemental-materials.s3.amazonaws.com/#{path}/#{filename}" end
link(opts)
click to toggle source
# File lib/doc_template/tags/link_tag.rb, line 21 def link(opts) title, text = opts[:value].split(';').map(&:strip) # If we don't have a text, use the fa-book icon label = text.present? ? "<b>#{text}</b>" : '' href = build_href(title, opts[:metadata]) "<a href=\"#{href}\" target=\"_blank\" title=\"#{title}\"><i class=\"fas fa-book\"></i> #{label}</a>" end