Skip to content

Commit

Permalink
Rename data folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
satamas committed Apr 5, 2016
1 parent a53cc78 commit 0a8a0e8
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Navigaton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class NavItem:
def __init__(self, config, page):
if 'url' in config:
self.url = config['url']
else:
self.url = None
self.title = config['title']
self.items = []
if 'items' in config:
self.items = [NavItem(item_config, page) for item_config in config['items']]
self._config = config
self._current_url = page.path

def is_active(self):
for item in self.items:
if item.is_active():
return True
if self.url is not None:
url = self.url
if url.startswith("/"):
url = url[1:]
if url.endswith(".html"):
url = url[:-5]
return self._current_url.startswith(url)
else:
return False

def is_external(self):
if hasattr(self, 'url'):
return self.url.startswith("http://") or self.url.startswith("https://")
else:
return False

def __getitem__(self, item):
return self._config[item]


class Nav:
def __init__(self, config, page):
self._nav = {}
for nav_id in config:
self._nav[nav_id] = [NavItem(nav_item_config, page) for nav_item_config in config[nav_id]]

def __getitem__(self, item):
return self._nav[item]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions kotlin-website-flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

import yaml
from flask import Flask, render_template
from flask.ext.flatpages import FlatPages
from os import path

from Navigaton import Nav

app = Flask(__name__)
app.config.from_pyfile('mysettings.py')
pages = FlatPages(app)
data_folder = path.join(os.path.dirname(__file__), "data")


def get_data():
data = {}
for data_file in os.listdir(data_folder):
data_file_path = path.join(data_folder, data_file)
with open(data_file_path) as stream:
try:
file_name_without_extension = data_file[:-4] if data_file.endswith(".yml") else data_file
data[file_name_without_extension] = yaml.load(stream)
except yaml.YAMLError as exc:
print 'Cant parse data file ' + data_file
print exc.message
except IOError as exc:
print 'Cant open data file ' + data_file
print exc.message
return data


site_data = get_data()


@app.route('/')
def hello_world():
return 'Hello World!'


@app.route('/<path:path>/')
def page(path):
page = pages.get_or_404(path)
nav = Nav(site_data['_nav'], page)
template = page.meta["layout"] if 'layout' in page.meta else 'default.html'
if not template.endswith(".html"):
template += ".html"
return render_template(template, page=page, data=site_data, nav=nav, baseurl="")


if __name__ == '__main__':
app.run()
11 changes: 11 additions & 0 deletions mysettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import markdown.extensions.fenced_code
import markdown.extensions.codehilite
import markdown.extensions.attr_list

DEBUG = True
FLATPAGES_EXTENSION = '.md'
FLATPAGES_MARKDOWN_EXTENSIONS = [
markdown.extensions.attr_list.AttrListExtension(),
markdown.extensions.codehilite.CodeHiliteExtension(guess_lang=False, css_class="code"),
markdown.extensions.fenced_code.FencedCodeExtension()
]
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask = 0.10.1
flask-flatpages = 0.6
Pygments = 2.1.1

0 comments on commit 0a8a0e8

Please sign in to comment.