forked from JetBrains/kotlin-web-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |