summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2016-06-04 17:16:20 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2016-06-04 17:16:20 +0100
commitcf70fe629a909b1eeba086b5bbc436250898ae97 (patch)
tree7694f186f17cef8588a5eb281069066369c9ce44 /tools
parent1d44fee399868ebc6c5e412ee23c7fd1e4c37351 (diff)
downloadNim-cf70fe629a909b1eeba086b5bbc436250898ae97.tar.gz
Implemented generation of sponsors page + missing assets.
Diffstat (limited to 'tools')
-rw-r--r--tools/nimweb.nim37
-rw-r--r--tools/website.tmpl34
2 files changed, 70 insertions, 1 deletions
diff --git a/tools/nimweb.nim b/tools/nimweb.nim
index 8b7cb381f..f0479a258 100644
--- a/tools/nimweb.nim
+++ b/tools/nimweb.nim
@@ -9,7 +9,7 @@
 
 import
   os, strutils, times, parseopt, parsecfg, streams, strtabs, tables,
-  re, htmlgen, macros, md5, osproc
+  re, htmlgen, macros, md5, osproc, parsecsv
 
 type
   TKeyValPair = tuple[key, id, val: string]
@@ -29,6 +29,15 @@ type
   TAction = enum
     actAll, actOnlyWebsite, actPdf
 
+  Sponsor = object
+    logo: string
+    name: string
+    url: string
+    thisMonth: int
+    allTime: int
+    since: string
+    level: int
+
 var action: TAction
 
 proc initConfigData(c: var TConfigData) =
@@ -83,6 +92,7 @@ Compile_options:
   rYearMonthDayTitle = r"(\d{4})-(\d{2})-(\d{2})\s+(.*)"
   rssUrl = "http://nim-lang.org/news.xml"
   rssNewsUrl = "http://nim-lang.org/news.html"
+  sponsors = "web/sponsors.csv"
   validAnchorCharacters = Letters + Digits
 
 
@@ -407,6 +417,30 @@ proc buildJS(destPath: string) =
   exec("nim js -d:release --out:$1 web/nimblepkglist.nim" %
       [destPath / "nimblepkglist.js"])
 
+proc readSponsors(sponsorsFile: string): seq[Sponsor] =
+  result = @[]
+  var fileStream = newFileStream(sponsorsFile, fmRead)
+  if fileStream == nil: quit("Cannot open sponsors.csv file: " & sponsorsFile)
+  var parser: CsvParser
+  open(parser, fileStream, sponsorsFile)
+  discard readRow(parser) # Skip the header row.
+  while readRow(parser):
+    result.add(Sponsor(logo: parser.row[0], name: parser.row[1],
+        url: parser.row[2], thisMonth: parser.row[3].parseInt,
+        allTime: parser.row[4].parseInt,
+        since: parser.row[5], level: parser.row[6].parseInt))
+  parser.close()
+
+proc buildSponsors(c: var TConfigData, sponsorsFile: string, outputDir: string) =
+  let sponsors = generateSponsors(readSponsors(sponsorsFile))
+  let outFile = outputDir / "sponsors.html"
+  var f: File
+  if open(f, outFile, fmWrite):
+    writeLine(f, generateHtmlPage(c, "Our Sponsors", sponsors, ""))
+    close(f)
+  else:
+    quit("[Error] Cannot write file: " & outFile)
+
 proc buildWebsite(c: var TConfigData) =
   const
     cmd = "nim rst2html --compileonly $1 -o:web/$2.temp web/$2.txt"
@@ -438,6 +472,7 @@ proc buildWebsite(c: var TConfigData) =
     removeFile(temp)
   copyDir("web/assets", "web/upload/assets")
   buildNewsRss(c, "web/upload")
+  buildSponsors(c, sponsors, "web/upload")
 
 proc main(c: var TConfigData) =
   buildWebsite(c)
diff --git a/tools/website.tmpl b/tools/website.tmpl
index 6ae975839..69547ca9e 100644
--- a/tools/website.tmpl
+++ b/tools/website.tmpl
@@ -209,3 +209,37 @@ runForever()
 #  end if
 </body>
 </html>
+#end proc
+#
+#proc generateSponsors(sponsors: seq[Sponsor]): string =
+#result = ""
+<h1 id="our-current-sponsors">Our Current Sponsors</h1>
+<p>This page lists the companies and individuals that are, very kindly, contributing a
+monthly amount to help sustain Nim's development. For more details take a
+look at the <a href="https://salt.bountysource.com/teams/nim">Bountysource campaign</a>.</p>
+<dl>
+#for sponsor in sponsors:
+  <dt class="level-${sponsor.level}">
+    #if sponsor.url.len > 0:
+      <a href="${sponsor.url}" target="_blank">${sponsor.name}</a>
+    #else:
+      ${sponsor.name}
+    #end if
+  </dt>
+  <dd class="logo">
+    #if sponsor.logo.len > 0:
+    <a href="${sponsor.url}" target="_blank">
+      <img alt="${sponsor.name}'s logo" src="${sponsor.logo}"/>
+    </a>
+    #end if
+  </dd>
+  <dd class="this_month">
+    Donated <b>$$${sponsor.thisMonth}</b> this month
+  </dd>
+  <dd class="legend">
+    Donated $$${sponsor.allTime} in total since ${sponsor.since}
+  </dd>
+#end for
+</dl>
+#
+#end proc