Module: HtmlUtils
- Defined in:
- lib/htmlutils/macro.rb,
lib/htmlutils/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
-
.importHTML(urls) ⇒ Object
Generates HTML-loading code.
-
.keywords(words) ⇒ Object
Allows easily adding keywords.
-
.loadScripts(urls, type = "text/javascript") ⇒ Object
Generates script-loading code.
-
.loadStyles(urls, type = "text/css") ⇒ Object
Generates style-loading code.
-
.makeVTable(data, mainAttr = "", trhAttr = "", thAttr = "", trAttr = "", tdAttr = "") ⇒ Object
Generates vertical table.
-
.utf8 ⇒ Object
Shortcut for string below.
Class Method Details
.importHTML(urls) ⇒ Object
Generates HTML-loading code. Good for polymer-using apps.
21 22 23 24 25 26 27 |
# File 'lib/htmlutils/macro.rb', line 21 def self.importHTML(urls) str = "" urls.each do |url| str << %{<link rel="import" href="#{url}">\n} end str end |
.keywords(words) ⇒ Object
Allows easily adding keywords
52 53 54 55 56 57 58 |
# File 'lib/htmlutils/macro.rb', line 52 def self.keywords(words) str = "" words.each do |word| str << "#{word}," end %{<meta name="keywords" contents="#{str[0..-2]}">} end |
.loadScripts(urls, type = "text/javascript") ⇒ Object
Generates script-loading code
3 4 5 6 7 8 9 |
# File 'lib/htmlutils/macro.rb', line 3 def self.loadScripts(urls, type="text/javascript") str = "" urls.each do |url| str << %{<script type="#{type}" src="#{url}"></script>\n} end str end |
.loadStyles(urls, type = "text/css") ⇒ Object
Generates style-loading code
12 13 14 15 16 17 18 |
# File 'lib/htmlutils/macro.rb', line 12 def self.loadStyles(urls, type="text/css") str = "" urls.each do |url| str << %{<link type="#{type}" rel="stylesheet" href="#{url}">\n} end str end |
.makeVTable(data, mainAttr = "", trhAttr = "", thAttr = "", trAttr = "", tdAttr = "") ⇒ Object
Generates vertical table
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/htmlutils/macro.rb', line 30 def self.makeVTable(data, mainAttr="", trhAttr="", thAttr="", trAttr="", tdAttr="") str = "" str << "<table #{mainAttr}>\n" str << " <tr #{trhAttr}>\n" data.each do |d| str << %{ <th #{thAttr}>#{d[0]}</th>\n} end str << " </tr>\n" data.each do |d| str << " <tr #{trAttr}>\n" d[1..-1].each do |d1| str << " <td #{tdAttr}>#{d1}</td>\n" end str << " </tr>\n" end str << "</table>\n" end |
.utf8 ⇒ Object
Shortcut for string below
61 62 63 |
# File 'lib/htmlutils/macro.rb', line 61 def self.utf8 %{<meta charset="UTF-8">} end |