Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
;; CSV -> LISTS
|
||||
(define (csv->row line) (string-split line ","))
|
||||
(define (csv->table csv) (map csv->row (string-split csv "\n")))
|
||||
|
||||
;; LISTS->HTML
|
||||
(define html 'html)
|
||||
(define (emit-tag tag html-proc content )
|
||||
(if (style tag)
|
||||
(push html (format "<%s style='%a'>" tag (style tag)))
|
||||
(push html (format "<%s>" tag )))
|
||||
(html-proc content)
|
||||
(push html (format "</%s> " tag )))
|
||||
|
||||
;; html procs : 1 tag, 1 proc
|
||||
(define (h-raw content)
|
||||
(push html (format "%s" content)))
|
||||
(define (h-header headers)
|
||||
(for ((h headers)) (emit-tag 'th h-raw h)))
|
||||
(define (h-row row)
|
||||
(for ((item row)) (emit-tag 'td h-raw item)))
|
||||
(define (h-table table )
|
||||
(emit-tag 'tr h-header (first table))
|
||||
(for ((row (rest table))) (emit-tag 'tr h-row row)))
|
||||
|
||||
(define (html-dump) (string-join (stack->list html) " "))
|
||||
|
||||
;; STYLES
|
||||
(style 'td "text-align:left")
|
||||
(style 'table "border-spacing: 10px;border:28px ridge orange") ;; special biblical border
|
||||
(style 'th "color:blue;")
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
;; changed <angry> to <b> to show that html tags inside text are correctly transmitted.
|
||||
(define MontyPython #<<
|
||||
Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<b>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</b>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!
|
||||
>>#)
|
||||
|
||||
(define (task speech)
|
||||
(define table (csv->table speech))
|
||||
(stack html)
|
||||
(emit-tag 'table h-table table)
|
||||
(html-dump))
|
||||
|
||||
(task MontyPython)
|
||||
23
Task/CSV-to-HTML-translation/Nim/csv-to-html-translation.nim
Normal file
23
Task/CSV-to-HTML-translation/Nim/csv-to-html-translation.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import cgi, strutils
|
||||
|
||||
const csvtext = """Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!"""
|
||||
|
||||
proc row2tr(row): string =
|
||||
result = "<tr>"
|
||||
let cols = xmlEncode(row).split(",")
|
||||
for col in cols:
|
||||
result.add "<td>"&col&"</td>"
|
||||
result.add "</tr>"
|
||||
|
||||
proc csv2html(txt): string =
|
||||
result = "<table summary=\"csv2html program output\">\n"
|
||||
for row in txt.splitLines():
|
||||
result.add " <tbody>"&row2tr(row)&"</tbody>\n"
|
||||
result.add "</table>"
|
||||
|
||||
echo csv2html(csvtext)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
constant input = "Character,Speech\n" &
|
||||
"The multitude,The messiah! Show us the messiah!\n" &
|
||||
"Brians mother,<angry>Now you listen here! He's not the messiah; " &
|
||||
"he's a very naughty boy! Now go away!</angry>\n" &
|
||||
"The multitude,Who are you?\n" &
|
||||
"Brians mother,I'm his mother; that's who!\n" &
|
||||
"The multitude,Behold his mother! Behold his mother!"
|
||||
|
||||
puts(1,"<table>\n<tr><td>")
|
||||
for i = 1 to length(input) do
|
||||
switch input[i] do
|
||||
case '\n' then puts(1,"</td></tr>\n<tr><td>")
|
||||
case ',' then puts(1,"</td><td>")
|
||||
case '<' then puts(1,"<")
|
||||
case '>' then puts(1,">")
|
||||
case '&' then puts(1,"&")
|
||||
case else puts(1,input[i])
|
||||
end switch
|
||||
end for
|
||||
puts(1,"</td></tr>\n</table>")
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<table>
|
||||
<tr><td>Character</td><td>Speech</td></tr>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</table>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
func escape(str) { str.trans(« & < > », « & < > ») }
|
||||
func tag(t, d) { "<#{t}>#{d}</#{t}>" }
|
||||
|
||||
func csv2html(str) {
|
||||
|
||||
var template = <<'-EOT'
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Some Text</title></head>
|
||||
<body><table>
|
||||
%s
|
||||
</table></body></html>
|
||||
EOT
|
||||
|
||||
template.sprintf(escape(str).lines.map{ |line|
|
||||
tag('tr', line.split(',').map{|cell| tag('td', cell) }.join)
|
||||
}.join("\n")
|
||||
)
|
||||
}
|
||||
|
||||
var str = <<'EOT';
|
||||
Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!
|
||||
EOT
|
||||
|
||||
print csv2html(str)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Some Text</title></head>
|
||||
<body><table>
|
||||
<tr><td>Character</td><td>Speech</td></tr>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</table></body></html>
|
||||
|
|
@ -0,0 +1 @@
|
|||
jq -R . csv2html.csv | jq -r -s -f csv2html.jq
|
||||
22
Task/CSV-to-HTML-translation/jq/csv-to-html-translation-2.jq
Normal file
22
Task/CSV-to-HTML-translation/jq/csv-to-html-translation-2.jq
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
def headerrow2html:
|
||||
[" <thead> <tr>"]
|
||||
+ (split(",") | map(" <th>\(@html)</th>"))
|
||||
+ [ " </tr> </thead>" ]
|
||||
;
|
||||
|
||||
def row2html:
|
||||
[" <tr>"]
|
||||
+ (split(",") | map(" <td>\(@html)</td>"))
|
||||
+ [ " </tr>" ]
|
||||
;
|
||||
|
||||
def csv2html:
|
||||
def rows: reduce .[] as $row
|
||||
([]; . + ($row | row2html));
|
||||
["<table>"]
|
||||
+ (.[0] | headerrow2html)
|
||||
+ (.[1:] | rows)
|
||||
+ [ "</table>"]
|
||||
;
|
||||
|
||||
csv2html | .[]
|
||||
26
Task/CSV-to-HTML-translation/jq/csv-to-html-translation-3.jq
Normal file
26
Task/CSV-to-HTML-translation/jq/csv-to-html-translation-3.jq
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<table>
|
||||
<thead> <tr>
|
||||
<th>Character</th>
|
||||
<th>Speech </th>
|
||||
</tr> </thead>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>The messiah! Show us the messiah! </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Brians mother</td>
|
||||
<td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>Who are you? </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Brians mother</td>
|
||||
<td>I'm his mother; that's who! </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>Behold his mother! Behold his mother! </td>
|
||||
</tr>
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue