Skip to content
Permalink
Browse files

core: add project templates

Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
  • Loading branch information...
fscherf committed Mar 8, 2019
1 parent 6579ec9 commit e5a217304b916186c07c9d9d68d90a791e82bf8e
Showing with 36,311 additions and 2 deletions.
  1. +1 −0 .gitattributes
  2. +1 −0 MANIFEST.in
  3. +9 −0 Makefile
  4. +130 −0 bin/_flamingo-init
  5. +7 −2 flamingo/__init__.py
  6. +30 −0 flamingo/project_templates/bootstrap4/Makefile.template
  7. 0 flamingo/project_templates/bootstrap4/README.rst
  8. +5 −0 flamingo/project_templates/bootstrap4/REQUIREMENTS.txt.template
  9. +7 −0 flamingo/project_templates/bootstrap4/content/category-1/page-1.rst
  10. +7 −0 flamingo/project_templates/bootstrap4/content/category-1/page-2.rst
  11. +7 −0 flamingo/project_templates/bootstrap4/content/category-2/page-3.rst
  12. +7 −0 flamingo/project_templates/bootstrap4/content/category-2/page-4.rst
  13. +8 −0 flamingo/project_templates/bootstrap4/content/home.rst
  14. BIN flamingo/project_templates/bootstrap4/overlay/favicon.ico
  15. +21 −0 flamingo/project_templates/bootstrap4/plugins/example.py
  16. +31 −0 flamingo/project_templates/bootstrap4/settings.py.template
  17. +3,719 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-grid.css
  18. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-grid.css.map
  19. +7 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-grid.min.css
  20. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-grid.min.css.map
  21. +331 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-reboot.css
  22. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-reboot.css.map
  23. +8 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-reboot.min.css
  24. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap-reboot.min.css.map
  25. +10,038 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap.css
  26. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap.css.map
  27. +7 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap.min.css
  28. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/css/bootstrap.min.css.map
  29. +7,013 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.bundle.js
  30. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.bundle.js.map
  31. +7 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.bundle.min.js
  32. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.bundle.min.js.map
  33. +4,435 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.js
  34. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.js.map
  35. +7 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.min.js
  36. +1 −0 flamingo/project_templates/bootstrap4/theme/static/bootstrap-4.3.1/js/bootstrap.min.js.map
  37. +32 −0 flamingo/project_templates/bootstrap4/theme/static/custom.css
  38. +10,364 −0 flamingo/project_templates/bootstrap4/theme/static/jquery/jquery-3.3.1.js
  39. +2 −0 flamingo/project_templates/bootstrap4/theme/static/jquery/jquery-3.3.1.min.js
  40. +1 −0 flamingo/project_templates/bootstrap4/theme/static/jquery/jquery-3.3.1.min.map
  41. +36 −0 flamingo/project_templates/bootstrap4/theme/templates/base.html
  42. +8 −0 flamingo/project_templates/bootstrap4/theme/templates/page.html
  43. +14 −0 flamingo/project_templates/data.ini
  44. +1 −0 setup.py
@@ -1,2 +1,3 @@
flamingo/server/lib/* linguist-vendored
flamingo/plugins/*/theme/* linguist-vendored
flamingo/project_templates/* linguist-vendored
@@ -1,3 +1,4 @@
recursive-include flamingo/server *
recursive-include flamingo/theme *
recursive-include flamingo/plugins/*/theme *
recursive-include flamingo/project_templates *
@@ -32,3 +32,12 @@ shell: env
freeze: env
. $(PYTHON_VENV)/bin/activate && \
pip freeze

test-site: env
. $(PYTHON_VENV)/bin/activate && \
rm -rf test-site && \
flamingo init test-site debug=True

server: test-site
cd test-site && \
make server
@@ -0,0 +1,130 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from configparser import ConfigParser
import shutil
import os

from jinja2 import Template

from flamingo.core.utils.cli import get_raw_parser
import flamingo


class SaveConfigParser(ConfigParser):
def save_get(self, section, option, default=None):
try:
return super().get(section, option)

except Exception:
return default


def parse_config(config_string):
parser = ConfigParser()

try:
parser.read_string('[config]\n{}'.format(config_string))

return {option: parser.get('config', option)
for option in parser.options('config')}

except Exception:
return {}


# data
data = SaveConfigParser()
data.read_file(open(flamingo.PROJECT_TEMPLATES_DATA_PATH, 'r'))

# args
parser = get_raw_parser(prog='flamingo init')

parser.add_argument('variables', nargs='*', default='.')

parser.add_argument('-t', '--project-template',
default=data.get('config', 'default_template'))

parser.add_argument('-l', '--list-templates', action='store_true')


args = parser.parse_args()

# checks
PROJECT_TEMPLATE_PATH = os.path.join(flamingo.PROJECT_TEMPLATES_ROOT,
args.project_template)

if not os.path.exists(PROJECT_TEMPLATE_PATH):
exit("no such project template '{}'".format(args.project_template))

# list templates
if args.list_templates:
for template in os.listdir(flamingo.PROJECT_TEMPLATES_ROOT):
if not os.path.isdir(os.path.join(flamingo.PROJECT_TEMPLATES_ROOT,
template)):
continue

if data.get('config', 'default_template') == template:
is_default = True

else:
is_default = False

print('{}{}'.format(template, ' (default)' if is_default else ''))

for line in data.get(template, 'description').strip().splitlines():
print(' {}'.format(line.strip()))

print()

exit()

# render template
variables = args.variables or '.'

if not isinstance(variables, list):
variables = [variables]

if '=' not in variables[0]:
output = variables[0]
variables = variables[1:]

else:
output = '.'

template_context = {
'flamingo': flamingo,
**parse_config(data.save_get(args.project_template, 'variables', '')),
**parse_config('\n'.join(variables))
}

try:
if not os.path.exists(output):
os.makedirs(output)

for root, dirs, files in os.walk(PROJECT_TEMPLATE_PATH):
for f in files:
source_path = os.path.join(root, f)

destination_path = os.path.join(
output,
os.path.relpath(source_path, PROJECT_TEMPLATE_PATH),
)

dirname = os.path.dirname(destination_path)

if not os.path.exists(dirname):
os.makedirs(dirname)

if os.path.splitext(source_path)[1] == '.template':
destination_path = os.path.splitext(destination_path)[0]
template = Template(open(source_path, 'r').read())

with open(destination_path, 'w+') as f:
f.write(template.render(**template_context))

else:
shutil.copy(source_path, destination_path)

except Exception as e:
exit(str(e))
@@ -3,6 +3,11 @@
from flamingo.core.plugins.hooks import hook # NOQA

VERSION = (0, 7)
_dirname = os.path.dirname(__file__)
VERSION_STRING = '.'.join([str(i) for i in VERSION])
SERVER_STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'server')
THEME_ROOT = os.path.join(os.path.dirname(__file__), 'theme')
SERVER_STATIC_ROOT = os.path.join(_dirname, 'server')
THEME_ROOT = os.path.join(_dirname, 'theme')
PROJECT_TEMPLATES_ROOT = os.path.join(_dirname, 'project_templates')

PROJECT_TEMPLATES_DATA_PATH = os.path.join(PROJECT_TEMPLATES_ROOT,
'data.ini')
@@ -0,0 +1,30 @@
FLAMINGO_SETTINGS=settings.py
FLAMINGO_ARGS=--log-level=INFO
FLAMINGO_SERVER_ARGS=--host=localhost --port=8080

PYTHON={{ python_version }}
PYTHON_VENV=env

$(PYTHON_VENV)/.created: REQUIREMENTS.txt
rm -rf $(PYTHON_VENV) && \
$(PYTHON) -m venv $(PYTHON_VENV) && \
. $(PYTHON_VENV)/bin/activate && \
pip install -r ./REQUIREMENTS.txt && \
date > $(PYTHON_VENV)/.created

env: $(PYTHON_VENV)/.created

clean:
rm -rf $(PYTHON_VENV)

html: env
. $(PYTHON_VENV)/bin/activate && \
flamingo build $(FLAMINGO_ARGS) -s $(FLAMINGO_SETTINGS)

server: env
. $(PYTHON_VENV)/bin/activate && \
flamingo server $(FLAMINGO_ARGS) $(FLAMINGO_SERVER_ARGS) -s $(FLAMINGO_SETTINGS)

shell: env
. $(PYTHON_VENV)/bin/activate && \
flamingo shell $(FLAMINGO_ARGS) -s $(FLAMINGO_SETTINGS)
No changes.
@@ -0,0 +1,5 @@
{%- if debug -%}
-e ..[full]
{%- else -%}
flamingo=={{flamingo.VERSION_STRING}}[full]
{%- endif -%}
@@ -0,0 +1,7 @@
author: alice


Page 1
======

Page 1
@@ -0,0 +1,7 @@
author: alice


Page 2
======

Page 2
@@ -0,0 +1,7 @@
author: alice


Page 3
======

Page 3
@@ -0,0 +1,7 @@
author: alice


Page 4
======

Page 4
@@ -0,0 +1,8 @@
author: alice
output: index.html


Home
====

Welcome
Binary file not shown.
@@ -0,0 +1,21 @@
class ExamplePlugin:
def parser_setup(self, context):
pass

def content_parsed(self, context, content):
pass

def contents_parsed(self, context):
pass

def templating_engine_setup(self, context, templating_engine):
pass

def context_setup(self, context):
pass

def pre_build(self, context):
pass

def post_build(self, context):
pass
@@ -0,0 +1,31 @@
PROJECT_NAME = '{{ project_name }}'

CONTENT_ROOT = 'content'
OUTPUT_ROOT = 'output'

THEME_PATHS = [
'theme',
]

PLUGINS = [
'flamingo.plugins.Layers',
'flamingo.plugins.SimpleMenu',

'plugins/example.py::ExamplePlugin',
]

LAYERS = [
'overlay',
]

MENU = [
['Home', 'home.rst'],
['Category 1', [
['Page 1', 'category-1/page-1.rst'],
['Page 2', 'category-1/page-2.rst'],
]],
['Category 2', [
['Page 3', 'category-2/page-3.rst'],
['Page 4', 'category-2/page-4.rst'],
]],
]

0 comments on commit e5a2173

Please sign in to comment.
You can’t perform that action at this time.