diff --git a/Makefile b/Makefile
index 1744b1a..3278646 100644
--- a/Makefile
+++ b/Makefile
@@ -43,9 +43,6 @@ install: clean
uninstall:
pip uninstall -y logya
-reinstall: uninstall
- make install
-
lint:
flake8 logya tests
@@ -83,7 +80,3 @@ dist: clean
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
-
-# Reinstall and test shortcut
-rt: reinstall
- make test-all
\ No newline at end of file
diff --git a/docs/changes.rst b/docs/changes.rst
index e07c06a..6e07724 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -6,6 +6,7 @@ Changes
4.0.0 to 4.1.0
--------------
+* Added raw keyword argument to filesource function, which defaults to False.
* Added keep option for `generate` command, which does not remove an existing deploy directory.
* Load newer versions of bootstrap, fontawesome and jquery via CDN.
* Set meta noindex,follow for index pages in starter site.
diff --git a/docs/templates.rst b/docs/templates.rst
index d3dcc66..538f28f 100644
--- a/docs/templates.rst
+++ b/docs/templates.rst
@@ -8,7 +8,7 @@ The template engine that comes with Logya is `jinja2
{{ filesource(data, lines=6) }}...+To not escape the content, you can set raw to True. + +:: + +
{{ filesource(data, raw=True) }}...+ +This can be used for example to inline SVG code when using SVG sprites. + get_doc ------- diff --git a/logya/template.py b/logya/template.py index 32909df..5621c7d 100644 --- a/logya/template.py +++ b/logya/template.py @@ -5,13 +5,16 @@ from jinja2 import Environment, BaseLoader, TemplateNotFound, escape -def filesource(logya_inst, name, lines=None): +def filesource(logya_inst, name, lines=None, raw=False): """Read and return source of text files. A template function that reads the source of the given file and returns it. - The text is escaped so it can be rendered safely on a Web page. + The content is escaped by default so it can be rendered safely on a Web page. + The lines keyword argument is used to limit the number of lines returned. + To not escape the content you can set the raw keyword argument to False. + A use case is for documentation projects to show the source code used to render the current example. """ @@ -22,6 +25,9 @@ def filesource(logya_inst, name, lines=None): content = f.read() else: content = ''.join(f.readlines()[:lines]) + if raw: + return content + return escape(content) @@ -54,8 +60,8 @@ def __init__(self, logya_inst): self.env.trim_blocks = True # Add filesource global to allow for including the source of a file. - self.env.globals['filesource'] = lambda x, lines=None: filesource( - logya_inst, x, lines=lines) + self.env.globals['filesource'] = lambda x, lines=None, raw=False: filesource( + logya_inst, x, lines=lines, raw=raw) self.env.globals['get_doc'] = lambda x: get_doc(logya_inst, x) diff --git a/requirements-base.txt b/requirements-base.txt new file mode 100644 index 0000000..48f24d8 --- /dev/null +++ b/requirements-base.txt @@ -0,0 +1,3 @@ +Jinja2 +Markdown +PyYAML \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3608aa6..3f21063 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,8 @@ -Jinja2==2.8 -Markdown==2.6.6 -PyYAML==3.11 \ No newline at end of file +appdirs==1.4.3 +Jinja2==2.9.5 +Markdown==2.6.8 +MarkupSafe==1.0 +packaging==16.8 +pyparsing==2.2.0 +PyYAML==3.12 +six==1.10.0