comparison htmlhlp.R @ 2:20d69a062da3 draft

planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author prog
date Thu, 02 Mar 2017 08:55:00 -0500
parents e66bb061af06
children
comparison
equal deleted inserted replaced
1:253d531a0193 2:20d69a062da3
39 39
40 ############# 40 #############
41 # WRITE TAG # 41 # WRITE TAG #
42 ############# 42 #############
43 43
44 HtmlWriter$methods( writeTag = function(tag, text = NA_character_, indent = NA_integer_, newline = TRUE) { 44 HtmlWriter$methods( writeTag = function(tag, attr = NA_character_, text = NA_character_, indent = NA_integer_, newline = TRUE) {
45 45
46 if (is.na(text)) 46 if (is.na(text)) {
47 .self$write(paste0("<", tag, "/>"), indent = indent, newline = newline, escape = FALSE) 47 attributes <- if (is.na(attr)) '' else paste0(' ', paste(vapply(names(attr), function(a) paste0(a, '="', attr[[a]], '"'), FUN.VALUE=''), collapse = ' '))
48 .self$write(paste0("<", tag, attributes, "/>"), indent = indent, newline = newline, escape = FALSE)
49 }
48 else { 50 else {
49 .self$writeBegTag(tag, indent = indent, newline = FALSE) 51 .self$writeBegTag(tag, attr = attr, indent = indent, newline = FALSE)
50 .self$write(text, escape = TRUE , indent = 0, newline = FALSE) 52 .self$write(text, escape = TRUE , indent = 0, newline = FALSE)
51 .self$writeEndTag(tag, indent = 0, newline = newline) 53 .self$writeEndTag(tag, indent = 0, newline = newline)
52 } 54 }
53 }) 55 })
54 56
55 ################### 57 ###################
56 # WRITE BEGIN TAG # 58 # WRITE BEGIN TAG #
57 ################### 59 ###################
58 60
59 HtmlWriter$methods( writeBegTag = function(tag, indent = NA_integer_, newline = TRUE) { 61 HtmlWriter$methods( writeBegTag = function(tag, attr = NA_character_, indent = NA_integer_, newline = TRUE) {
60 62
61 # Write opening tag 63 # Write opening tag
62 .self$write(paste0("<", tag, ">"), indent = indent, newline = newline, escape = FALSE) 64 attributes <- if (is.na(attr)) '' else paste0(' ', paste(vapply(names(attr), function(a) paste0(a, '="', attr[[a]], '"'), FUN.VALUE=''), collapse = ' '))
65 .self$write(paste0("<", tag, attributes, ">"), indent = indent, newline = newline, escape = FALSE)
63 66
64 # Increment auto-indent 67 # Increment auto-indent
65 if ( ! is.na(.self$.auto.indent)) 68 if ( ! is.na(.self$.auto.indent))
66 .auto.indent <<- .self$.auto.indent + 1 69 .auto.indent <<- .self$.auto.indent + 1
67 }) 70 })
90 93
91 # Write table header 94 # Write table header
92 if ( ! is.null(colnames(x))) { 95 if ( ! is.null(colnames(x))) {
93 .self$writeBegTag('tr', indent = indent + 1, newline = newline) 96 .self$writeBegTag('tr', indent = indent + 1, newline = newline)
94 for (field in colnames(x)) 97 for (field in colnames(x))
95 .self$writeTag('th', field, indent = indent + 2, newline = newline) 98 .self$writeTag('th', text = field, indent = indent + 2, newline = newline)
96 .self$writeEndTag('tr', indent = indent + 1, newline = newline) 99 .self$writeEndTag('tr', indent = indent + 1, newline = newline)
97 } 100 }
98 101
99 # Write values 102 # Write values
100 if (nrow(x) > 0 && ncol(x) > 0) 103 if (nrow(x) > 0 && ncol(x) > 0)
101 for (i in 1:nrow(x)) { 104 for (i in 1:nrow(x)) {
102 .self$writeBegTag('tr', indent = indent + 1, newline = newline) 105 .self$writeBegTag('tr', indent = indent + 1, newline = newline)
103 for (j in 1:ncol(x)) 106 for (j in 1:ncol(x))
104 .self$writeTag('td', x[i, j], indent = indent + 2, newline = newline) 107 .self$writeTag('td', text = x[i, j], indent = indent + 2, newline = newline)
105 .self$writeEndTag('tr', indent = indent + 1, newline = newline) 108 .self$writeEndTag('tr', indent = indent + 1, newline = newline)
106 } 109 }
107 .self$writeEndTag('table', indent = indent, newline = newline) 110 .self$writeEndTag('table', indent = indent, newline = newline)
108 }) 111 })
109 112