class BlueDoc::SML::Rules::File

Public Class Methods

match?(node) click to toggle source
# File lib/bluedoc/sml/rules/file.rb, line 9
def self.match?(node)
  tag_name(node) == "file"
end
to_html(node, opts = {}) click to toggle source
# File lib/bluedoc/sml/rules/file.rb, line 13
    def self.to_html(node, opts = {})
      attrs = attributes(node)
      attrs[:name] ||= ""

      return attrs[:name] if attrs[:src].blank?

      humanize_size = number_to_human_size(attrs[:size] || 0)

      file_type = (::File.extname(attrs[:name]) || "none").sub(".", "")

      nid_attr = name_by_attrs(attrs)
      out = <<~HTML
      <a class="attachment-file" title="#{attrs[:name]}" target="_blank" href="#{attrs[:src]}"#{nid_attr}>
        <span class="icon-box"><i class="fas fa-file fa-#{file_type}-file"></i></span>
        <span class="filename">#{escape_html(attrs[:name])}</span>
        <span class="filesize">#{escape_html(humanize_size)}</span>
      </a>
      HTML

      out
    end