Skip to content

Commit

Permalink
Close #8 - Implement tool for generating smssync web pages
Browse files Browse the repository at this point in the history
Reads in markdown files and generates a fine html pages
  • Loading branch information
eyedol committed Jan 30, 2012
1 parent a372282 commit c3ffbea
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 11 deletions.
25 changes: 25 additions & 0 deletions genwebsite/site_footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="container">
<footer class="footer">
<div class="container">
<div class="pull-right">
powered by <a href="http://www.ushahidi.com">Ushahidi</a>
</div>
<p>#Date Copyright &copy; 2010 - 2012 <a href="http://www.ushahidi.com">Ushahidi.com</a></p>
</div>
</footer>
</div>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12063676-22']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
</body>
</html>
36 changes: 36 additions & 0 deletions genwebsite/site_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SMSSync by Ushahidi</title>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="libs/js/google-code-prettify/prettify.css" rel="stylesheet">
<script src="libs/js/google-code-prettify/prettify.js"></script>
</head>
<body>
<div class="topbar" data-scrollspy="scrollspy" >
<div class="fill">
<div class="container">
<div id="logo">
<h3>
<a href="#">SMSSync</a>
</h3>
</div>
<ul class="nav">
<li class="active"><a href="http://smssync.ushahidi.com/">Home</a></li>
<li><a href="http://dev.ushahidi.com/projects/SMSSync/news">News</a></li>
<li><a href="http://smssync.ushahidi.com/download/">Download</a></li>
<li><a href="http://smssync.ushahidi.com/doc/">Documentation</a></li>
<li><a href="http://forums.ushahidi.com/forum/ushahidi-apps">Support</a></li>
<li><a href="http://smssync.ushahidi.com/contact/">Contact</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="hero-unit">
<h2>The free and open source SMS gateway for Android</h2>
</div>
</div>
57 changes: 46 additions & 11 deletions tools/build_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,84 @@
import os
import sys
import markdown
import time

from optparse import OptionParser

#from markdown import markdown.extensions.nl2br
from datetime import date

#TODO:// figure out how to use markdown
class BuildSite:

def __init__(self,source,destination):
self.source = source
self.destination = destination
self.parts_of_webpages = '../genwebsite/'

def transform_markdown_from_string(self,mkdown):
print markdown.markdown(mkdown)
return markdown.markdown(mkdown)

def transform_markdown_from_file(self,mkdown):
input_file = codecs.open(mkdown, mode="r", encoding="utf-8")
mkdown_text = input_file.read()

return markdown.markdown(mkdown_text)

def write_html_to_file(self,html_file,html_string):
output_file = codecs.open(html_file,"w", encoding="utf-8",
errors="xmlcharrefreplace"
)
print "Writing file "+html_file
output_file = open(html_file,'w')
output_file.write(html_string)

def read_html_files(self):
f = open(self.source,'r')
content = f.readLines()
print "Succesffully Done!"

def read_html_files(self,source):
f = open(source,'r')
content = f.read()
f.close()

return content

def build_pages(self):
""" build web pages for smssync.ushahidi.com """

#read header html stuff
header = self.read_html_files(self.parts_of_webpages+'site_header.html')

#read html stuff for the main content
body = self.read_html_files(self.source)

#Get today's date
d = date.today()

#read footer html stuff
footer = self.apply_filter('#Date','Generated: '+d.strftime("%d-%m-%Y"),
self.read_html_files(self.parts_of_webpages+'site_footer.html'))

#combine the different parts of the web page into a single one
#TODO:// figure a better way of doing this.

page = header + body + footer

mkdown = self.transform_markdown_from_string(page)

#write content to a file
self.write_html_to_file(self.destination,mkdown)

def apply_filter(self,keyword, word, content):
""" find and replace for stuff in the html tags """
return content.replace(keyword,word)


def main(args,options,parser):
if len(args) < 2:
parser.print_usage()
print "%s: " %(str(len(args)))
else :
build_site = BuildSite(args[0],args[0])
build_site = BuildSite(args[0],args[1])
if options.mkfile == True:
build_site.transform_markdown_from_file(args)
else:
build_site.transform_markdown_from_string(args[0])
build_site.build_pages()
usage = "usage: %prog <markdown string> <destination file>"

parser = OptionParser(usage=usage)
Expand Down

0 comments on commit c3ffbea

Please sign in to comment.