Skip to content

Commit

Permalink
Loading YAML configuration file test
Browse files Browse the repository at this point in the history
  • Loading branch information
orx57 committed May 26, 2015
1 parent 6917a71 commit 64d4503
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion views/_header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title></title>
<title>{{name}} - {{site.title}}</title>

<!-- Bootstrap -->
<!--
Expand Down
21 changes: 15 additions & 6 deletions vikio.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
renderer = CommonMark.HTMLRenderer()


class Struct:
def __init__(self, **entries):
self.__dict__.update(entries)


def config(config_path = 'config.yml'):
"""Get configuration parameters
Get data from YAML configuration file
Expand All @@ -31,15 +36,15 @@ def config(config_path = 'config.yml'):
vikio_config = yaml.load(file(config_path, 'r'))
except yaml.YAMLError, exc:
print('Error in configuration file: %s', exc)

#print(yaml.dump(vikio_config))
return vikio_config
site = Struct(**vikio_config['site'])
return site


@error(404)
@view('error')
def error404(error):
return dict(error=error)
return dict(error=error, name='error404', site=site)


@route('/css/<filename:path>')
Expand All @@ -63,21 +68,25 @@ def download(filename):


@route('/')
def index(name='Stranger'):
def index():
redirect("/page/index")


@route('/page')
@route('/page/')
@route('/page/<name>')
@view('default')
def hello(name='index'):
document = codecs.open("pages/{}.md".format(name), 'r', encoding='utf-8')
ast = parser.parse(document.read())
html = renderer.render(ast)
return dict(content=html, name=name)
return dict(content=html, name=name, site=site)


def main():
""" Run the whole program """
global site
site = config()
run(host='localhost', port=8080, debug=True, reloader=True)


Expand Down

0 comments on commit 64d4503

Please sign in to comment.