Class: BlueDoc::SML::Rules::File

Inherits:
Base
  • Object
show all
Extended by:
ActiveSupport::NumberHelper
Defined in:
lib/bluedoc/sml/rules/file.rb

Constant Summary

Constants inherited from Base

Base::INDENT_PX

Class Method Summary collapse

Methods inherited from Base

to_text

Class Method Details

.match?(node) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/bluedoc/sml/rules/file.rb', line 9

def self.match?(node)
  tag_name(node) == "file"
end

.to_html(node, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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 = "  <a class=\"attachment-file\" title=\"\#{attrs[:name]}\" target=\"_blank\" href=\"\#{attrs[:src]}\"\#{nid_attr}>\n    <span class=\"icon-box\"><i class=\"fas fa-file fa-\#{file_type}-file\"></i></span>\n    <span class=\"filename\">\#{escape_html(attrs[:name])}</span>\n    <span class=\"filesize\">\#{escape_html(humanize_size)}</span>\n  </a>\n  HTML\n\n  out\nend\n"