Hugonweb | BoBo Templates

Enables the use of reStructuredText files to make pages:

import bobo
from docutils.core import publish_string
import glob
import os.path

DIRNAME=os.path.dirname(__file__)+"/"

def restToHtml(inString):
  settings_overrides={
        "output_encoding":"unicode",
        #"stylesheet":"voidspace.css",
        #"stylesheet_path":"",
        "stylesheet_path": DIRNAME+"voidspace.css",
        "embed_stylesheet":True
  }
  return publish_string(source=inString,
        writer_name="html", settings_overrides=settings_overrides
    )
def restFileToHtml(inFileName):
  inFile = open(inFileName)
  inString = inFile.read()
  inFile.close()
  return restToHtml(inString)

@bobo.query("/")
def index(bobo_request):
  result = restFileToHtml(DIRNAME+"pages/index.rst")
  return result

@bobo.query("/:name")
#@bobo.query("/",content_type="application/json")
def hello(bobo_request,name="World!",data=""):
  result ="""
This is the Title
==================

#. This is an item
#. This is another

- path you entered: {name}
- option data: {data}

.. This should be a link: `google<http://google.com>`_

This should be a link: google_

.. _google: http://google.com

This should also be: `google2 <http://www.google.com>`_

.. raw:: html

    <div style="margin-top:10px;">
      <iframe width="560" height="315" src="http://www.youtube.com/embed/_EjisXtMy_Y" frameborder="0" allowfullscreen></iframe>
    </div>

The Current Directory: {currDir}

  """
  result = result.format(currDir=DIRNAME,name=name,data=data)
  result = restToHtml(result)
  return result

application = bobo.Application(bobo_resources=__name__)