{ "info": { "author": "Jay Carlson", "author_email": "nop@nop.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "\n# Jinja2 and YAML for Jupyter\n\n### Please see [the full HTML version](https://nopdotcom.github.io/jinja-straight-demo.html).\n\nThe rest of this file is just the `nbconvert` into Markdown; it's hard to read. See [the HTML version](https://nopdotcom.github.io/jinja-straight-demo.html).\n\n------\n\nPeople use YAML and Jinja2 together; they're the core of Ansible. Sometimes you need a playground to figure out details of how they work. This magic provides both.\n\n**In:**\n\n```python\n%load_ext jinja_yaml_magic\n%reload_ext jinja_yaml_magic\n```\n\n(Ignore the warning for `%load_ext`/`%reload_ext`.)\n\n## YAML\n\n`%%yaml variable` parses the YAML in a cell into the named *variable*. \nIf you omit `variable`, the YAML is parsed into the variable `jinja_env`; it's also\nthen available through the history mechanism: `Out[3]` or `_3`.\n\n**In:**\n\n```python\n%%yaml\nnames:\n- Jay\n- Chris\n- Pat\n```\n\n\n**Out:**\n\n {'names': ['Jay', 'Chris', 'Pat']}\n\n\n\n**In:**\n\n```python\n%%jinja\n{{ names }}\n```\n\n**Out:**\n\n\n ['Jay', 'Chris', 'Pat']\n\n\n\n## Jinja2\n\nIf you just want to try out a quick template, write `%%jinja` at the top of a cell. Both the contents of `jinja_env` and notebook variables are available. Below, we're using `names` from the `%%yaml` above, and `separator` from the notebook.\n\n**In:**\n\n```python\nseparator = \", \"\n```\n\n**In:**\n\n```python\n%%jinja\n{{ names|sort|join(separator) }}\n```\n\n\n**Out:**\n\n Chris, Jay, Pat\n\n\n\n### Named templates\n\nYou may want to store Jinja2 code as a template.\n\n* You can reuse the template later in the notebook;\n* You can use Jinja2's powerful `extends`, `import`, and `include` mechanisms.\n\nThe template below is available under the name `fancy_names`. *Files in the current directory are also available as templates.*\n\n\n**In:**\n\n```python\n%%jinja_template fancy_names\n{% for name in names %}\n{{ name }}
\n{%- endfor %}\n```\n\n**In:**\n\n```python\n%jinja --template fancy_names\n```\n\n**Out:**\n\n\n\n Jay
\n Chris
\n Pat
\n\n\n\n### Formatting\n\nBy default, the result of running a `%jinja` template is formatted as \"pretty\" text.\nYou can choose other formats.\n\n|Type|...displays as|\n|----|----|\n|`--pretty`|A string, without quotes|\n|`--plain`|Python string literal|\n|`--html`|HTML|\n|`--svg`|SVG|\n|`--latex`|LaTeX|\n|`--markdown`|Markdown|\n|`--code`|Syntax-highlighted code|\n\n`--latex` requires MathJax to be loaded; it is by default. `--code` requires\na recent version of IPython.\n\n**In:**\n\n```python\n%jinja --template fancy_names --html\n```\n\n**Out:**\n\n\n\nJay
\nChris
\nPat
\n\n\n\n### An SVG example\n\nFrom [https://medium.com/@heyoka/scratch-made-svg-donut-pie-charts-in-html5-2c587e935d72](https://medium.com/@heyoka/scratch-made-svg-donut-pie-charts-in-html5-2c587e935d72). This template does math, so you may not want to follow its example. \n\n\n**In:**\n\n```python\n# Percent of circle to be filled\nfull = 60\n# Percent distance from top to start\noffset = 12.5\n```\n\n**In:**\n\n```python\n%%jinja_template svg_example\n\n \n \n \n\n```\n\n**In:**\n\n```python\n%jinja --template svg_example --svg\n```\n\n*(There is an SVG image in the actual notebook.)*\n\n![svg](jinja-straight-demo_files/jinja-straight-demo_17_0.svg)\n\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nopdotcom/jupyter-jinja-yaml-magic", "keywords": "jupyter,ipython,yaml,jinja,jinja2", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "jinja-yaml-magic", "package_url": "https://pypi.org/project/jinja-yaml-magic/", "platform": "", "project_url": "https://pypi.org/project/jinja-yaml-magic/", "project_urls": { "Homepage": "https://github.com/nopdotcom/jupyter-jinja-yaml-magic" }, "release_url": "https://pypi.org/project/jinja-yaml-magic/0.1.2/", "requires_dist": [ "PyYAML", "jinja2", "ipython (>=1.0)" ], "requires_python": "", "summary": "Support Jinja2 and YAML in IPython/Jupyter notebooks", "version": "0.1.2" }, "last_serial": 4998935, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "d747165d42998b2e6a0875f6c6ba4f4a", "sha256": "d996056bac938b206e49cf7296c3064eaa164770b1eb5fad3a246b2cf1b3ca8c" }, "downloads": -1, "filename": "jinja_yaml_magic-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d747165d42998b2e6a0875f6c6ba4f4a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7438, "upload_time": "2019-03-28T17:32:56", "url": "https://files.pythonhosted.org/packages/66/f1/2521f7e1c7b37106b6cd8124fde00a787a3720ec57b96397a40954939951/jinja_yaml_magic-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b969504a765adc323c0c84af029d84d3", "sha256": "7f9895f9ffc9026e609885b146eb8feecd24b412f25fcb01460b4a61ce08e27d" }, "downloads": -1, "filename": "jinja-yaml-magic-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b969504a765adc323c0c84af029d84d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6499, "upload_time": "2019-03-28T17:32:58", "url": "https://files.pythonhosted.org/packages/f9/8c/a7c6a7e0fd4fe3e862b27790074b32f92b6aa6eb73f515100965655727e5/jinja-yaml-magic-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d747165d42998b2e6a0875f6c6ba4f4a", "sha256": "d996056bac938b206e49cf7296c3064eaa164770b1eb5fad3a246b2cf1b3ca8c" }, "downloads": -1, "filename": "jinja_yaml_magic-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d747165d42998b2e6a0875f6c6ba4f4a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7438, "upload_time": "2019-03-28T17:32:56", "url": "https://files.pythonhosted.org/packages/66/f1/2521f7e1c7b37106b6cd8124fde00a787a3720ec57b96397a40954939951/jinja_yaml_magic-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b969504a765adc323c0c84af029d84d3", "sha256": "7f9895f9ffc9026e609885b146eb8feecd24b412f25fcb01460b4a61ce08e27d" }, "downloads": -1, "filename": "jinja-yaml-magic-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b969504a765adc323c0c84af029d84d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6499, "upload_time": "2019-03-28T17:32:58", "url": "https://files.pythonhosted.org/packages/f9/8c/a7c6a7e0fd4fe3e862b27790074b32f92b6aa6eb73f515100965655727e5/jinja-yaml-magic-0.1.2.tar.gz" } ] }