Module: Avmtrf1::InventarioSistemas::SiteBuild::HtmlPageBase::Elements

Defined in:
lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb

Instance Method Summary collapse

Instance Method Details


10
11
12
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 10

def html_link(link_text, link_href)
  "<a href=#{link_href}>#{link_text}</a>"
end

#html_linkfy(input) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 14

def html_linkfy(input)
  output = url_or_text(input)
  if output.is_a?(::Addressable::URI)
    html_link(output, output)
  else
    output
  end
end

#html_table(columns, rows) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 23

def html_table(columns, rows)
  b = '<table><theader>'
  b += html_table_row(columns, 'th', '')
  b += '</theader><tbody>'
  rows.each_with_index do |row, index|
    b += html_table_row(row, 'td', (index % 2).zero? ? 'even' : 'odd')
  end
  b + '</tbody></theader>'
end

#html_table_row(values, tag, css_class) ⇒ Object


33
34
35
36
37
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 33

def html_table_row(values, tag, css_class)
  begin_tag = "<#{tag} class='#{css_class}'>"
  end_tag = "</#{tag}>"
  '<tr>' + values.map { |v| begin_tag + v + end_tag }.join + "</tr>\n"
end

39
40
41
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 39

def self_html_link
  html_link(title, href)
end

#url_or_text(input) ⇒ Object


43
44
45
46
47
48
49
# File 'lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb', line 43

def url_or_text(input)
  converted_input = input.gsub('\\', '/').gsub(%r{\A//}, 'smb://')
  uri = ::Addressable::URI.parse(converted_input)
  uri.scheme.present? && uri.host.present? ? uri : input
rescue Addressable::URI::InvalidURIError
  input
end