make code & notebook directories configurable

This commit is contained in:
Jake Vanderplas
2013-05-03 07:36:36 -07:00
parent a934cde442
commit 790fe92e3e
3 changed files with 16 additions and 10 deletions

View File

@@ -8,8 +8,11 @@ Syntax
------
{% include_code path/to/code [Title text] %}
The "path to code" is relative to the code subdirectory of
the content directory (TODO: allow this to be set in configs).
The "path to code" is specified relative to the ``code`` subdirectory of
the content directory Optionally, this subdirectory can be specified in the
config file:
CODE_DIR = 'code'
Example
-------
@@ -52,8 +55,7 @@ def include_code(preprocessor, tag, markup):
raise ValueError("Error processing input, "
"expected syntax: {0}".format(SYNTAX))
# TODO: make this directory a configurable setting
code_dir = 'code'
code_dir = preprocessor.configs.config['code_dir']
code_path = os.path.join('content', code_dir, src)
if not os.path.exists(code_path):

View File

@@ -8,7 +8,10 @@ def addLiquidTags(gen):
gen.settings['MD_EXTENSIONS'] = MDReader.default_extensions
if LiquidTags not in gen.settings['MD_EXTENSIONS']:
gen.settings['MD_EXTENSIONS'].append(LiquidTags())
configs = dict(code_dir=gen.settings.get('CODE_DIR', 'code'),
notebook_dir=gen.settings.get('NOTEBOOK_DIR',
'notebooks'))
gen.settings['MD_EXTENSIONS'].append(LiquidTags(configs))
def register():
signals.initialized.connect(addLiquidTags)

View File

@@ -8,9 +8,11 @@ Syntax
------
{% notebook filename.ipynb %}
The file should be specified relative to the ``notebook`` subdirectory of the
content directory. [TODO: make this configurable].
This will include the IPython notebook in the file.
The file should be specified relative to the ``notebooks`` subdirectory of the
content directory. Optionally, this subdirectory can be specified in the
config file:
NOTEBOOK_DIR = 'notebooks'
Details
-------
@@ -109,8 +111,7 @@ def notebook(preprocessor, tag, markup):
raise ValueError("Error processing input, "
"expected syntax: {0}".format(SYNTAX))
# TODO: make the notebook directory a configurable setting
nb_dir = 'notebooks'
nb_dir = preprocessor.configs.config['notebook_dir']
nb_path = os.path.join('content', nb_dir, src)
url = '/{0}/{1}/{2}'.format('static', nb_dir, src)