Package: kamidana
kamidana is yet another jinja2’s cli wrapper.featuresusing jinja2 file as template file (basic feature)various input formats support (json, yaml, toml, …)the way of lookup template is changed, relative to parent template pathgentle error messagebatch execution for speed-up (viakamidana-batch)rendering with individual filters (via–additionalsoption)(useful additionals modules (e.g.kamidana.additionals.naming…)usageusage: kamidana [-h] [--driver DRIVER] [--loader LOADER] [-d DATA]
                [--logging {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}] [-a ADDITIONALS] [-e EXTENSION]
                [-i {yaml,json,toml,csv,tsv,raw,env,md,markdown,spreadsheet}] [-o OUTPUT_FORMAT] [--dump-context]
                [--list-info] [--debug] [--quiet] [--dst DST]
                [template]

positional arguments:
  template

optional arguments:
  -h, --help            show this help message and exit
  --driver DRIVER       default: kamidana.driver:Driver
  --loader LOADER       default: kamidana.loader:TemplateLoader
  -d DATA, --data DATA  support yaml, json, toml
  --logging {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}
  -a ADDITIONALS, --additionals ADDITIONALS
  -e EXTENSION, --extension EXTENSION
  -i {yaml,json,toml,csv,tsv,raw,env,md,markdown,spreadsheet}, --input-format {yaml,json,toml,csv,tsv,raw,env,md,markdown,spreadsheet}
  -o OUTPUT_FORMAT, --output-format OUTPUT_FORMAT
  --dump-context        dumping loading data (used by jinja2 template)
  --list-info           listting information (for available extensions and additional modules)
  --debug
  --quiet
  --dst DSTexamplesexample (basic)$kamidanaexamples/readme/src/00/nginx.jinja2--dataexamples/readme/src/00/data.jsonserver {
  listen 80;
  server_name localhost;

  root /var/www/project;
  index index.htm;

  access_log /var/log/nginx/http.access.log combined;
  error_log  /var/log/nginx/http.error.log;
}examples/readme/src/00/nginx.jinja2server {
  listen 80;
  server_name {{ nginx.hostname }};

  root {{ nginx.webroot }};
  index index.htm;

  access_log {{ nginx.logdir }}/http.access.log combined;
  error_log  {{ nginx.logdir }}/http.error.log;
}examples/readme/src/00/data.json{"nginx":{"hostname":"localhost","webroot":"/var/www/project","logdir":"/var/log/nginx"}}More over, passing data with stdin. (please doen’t forget to add–input-formatoption)$echo'{"nginx": {"logdir": "/tmp/logs/nginx"}}'|kamidana--input-formatjsonexamples/readme/src/00/nginx.jinja2--dataexamples/readme/src/00/data.jsonserver {
  listen 80;
  server_name localhost;

  root /var/www/project;
  index index.htm;

  access_log /tmp/logs/nginx/http.access.log combined;
  error_log  /tmp/logs/nginx/http.error.log;
}gentle error messageif using include, but the included template is not found.$treeexamples/readme/src/11examples/readme/src/11
├── header.html.j2
└── main.html.j2

0 directories, 2 files$kamidanaexamples/readme/src/11/main.html.j2------------------------------------------------------------
exception: kamidana._path.XTemplatePathNotFound
message: [Errno 2] No such file or directory: 'footer-404.html.j2'
where: examples/readme/src/11/main.html.j2
------------------------------------------------------------
examples/readme/src/11/main.html.j2:
      2: <main>
      3:   this is main contents
      4: </main>
  ->  5: {% include "footer-404.html.j2" %}

Traceback:
  File "SITE-PACKAGES/jinja2/loaders.py", line 314, in get_source
    rv = self.load_func(template)
  File "HERE/my/kamidana/kamidana/loader.py", line 27, in load
    raise XTemplatePathNotFound(filename, exc=e).with_traceback(e.__traceback__)
  File "HERE/my/kamidana/kamidana/loader.py", line 23, in load
    with open(filename) as rf:example2 (–additionals)builtin addtional modules$kamidana--additionals=kamidana.additionals.namingexamples/readme/src/01/use-naming.jinja2singular, plurals

- days|singularize -> day
- day|pluralize -> days

- people|singularize -> person
- person|pluralize -> people

to {snake_case, kebab-case, camelCase}

- fooBarBoo|snakecase -> foo_bar_boo
- fooBarBoo|kebabcase -> foo-bar-boo
- foo_bar_boo|camelcase -> fooBarBoo


more information: see kamidana.additionals.naming moduleexamples/readme/src/01/use-naming.jinja2singular, plurals

- days|singularize -> {{"days"|singularize}}
- day|pluralize -> {{"day"|pluralize}}

- people|singularize -> {{"people"|singularize}}
- person|pluralize -> {{"person"|pluralize}}

to {snake_case, kebab-case, camelCase}

- fooBarBoo|snakecase -> {{"fooBarBoo"|snakecase}}
- fooBarBoo|kebabcase -> {{"fooBarBoo"|kebabcase}}
- foo_bar_boo|camelcase -> {{"foo_bar_boo"|camelcase}}


more information: see kamidana.additionals.naming moduleorkamidana -a namingis also OK (shortcut).individual additional modules$kamidana--additionals=examples/readme/src/01/additionals.py--data=examples/readme/src/01/data.yamlexamples/readme/src/01/hello.jinja2bye, world!!examples/readme/src/01/hello.jinja2{% if 19 is night %}
  {{night}}, {{name|surprised}}
{% else %}
  {{daytime}}, {{name|surprised}}
{% endif %}examples/readme/src/01/additionals.pyfromkamidanaimport(as_filter,as_globals_generator,as_test,)@as_filterdefsurprised(v):return"{}!!".format(v)@as_globals_generatordefgenerate_globals():return{"daytime":"hello","night":"bye"}@as_testdefnight(hour):return19<=hourorhour<3examples/readme/src/01/data.yamlname:worldexample3 (using jinja2 extensions)$kamidana-ewith_-edo-eloopcontrolsexamples/readme/src/02/use-extension.jinja2hello
  world
hello## counting- 1
- 2
- 4## do[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]examples/readme/src/02/use-extension.jinja2{# with with. with_ extension is used. #}
{%- with msg = "hello"%}
{{msg}}
{%- with msg = "world"%}
  {{msg}}
{%- endwith %}
{{msg}}
{%- endwith %}

## counting
{#- with break and continue. loopcontrolls extension is used. #}

{%- for i in range(10) %}
{%- if i % 3 == 0 %}{% continue %} {% endif %}
{%- if i == 5 %}{% break %} {% endif %}
- {{i}}
{%- endfor %}

## do

{%- set xs = [] %}
{%- for i in range(10) %}
{%- do xs.append(i) %}
{%- endfor %}
{{xs}}example4 (batch execution)TODO.see thisdebugging–dump-context–debugdump context$kamidana--dump-context--data=examples/readme/src/10/data.yaml{
  "name": "foo",
  "age": 20,
  "friends": [
    "bar",
    "boo"
  ],
  "template_filename": null
}and be able to merge two files.$kamidana--dump-context--data=examples/readme/src/10/data.yaml--data=examples/readme/src/10/data2.yaml{
  "name": "foo",
  "age": 21,
  "friends": [
    "bar",
    "baz"
  ],
  "template_filename": null
}thenexamples/readme/src/10/data.yamlname:fooage:20friends:-bar-booexamples/readme/src/10/data2.yamlage:21friends:-bar-bazavailable info (extensions and additional modules)$ kamidana --list-info
extensions are used by `-e`, additional modules are used by `-a`.
{
  "extensions": {
    "jinja2.ext.i18n": "This extension adds gettext support to Jinja2.",
    "jinja2.ext.do": "Adds a `do` tag to Jinja2 that works like the print statement just",
    "jinja2.ext.loopcontrols": "Adds break and continue to the template engine.",
    "jinja2.ext.with_": "Extensions can be used to add extra functionality to the Jinja template",
    "jinja2.ext.autoescape": "Extensions can be used to add extra functionality to the Jinja template",
    "kamidana.extensions.NamingModuleExtension": "extension create from kamidana.additionals.naming",
    "kamidana.extensions.ReaderModuleExtension": "extension create from kamidana.additionals.reader",
    "kamidana.extensions.CookiecutterAdditionalModulesExtension": "activate additional modules, see context['cookiecutter']['_additional_modules'], created from your cookiecutter.json"
  },
  "additional_modules": {
    "kamidana.additionals.reader": "Reading from other resources (e.g. read_from_file, read_from_command)",
    "kamidana.additionals.naming": "Naming helpers (e.g. snakecase, kebabcase, ... pluralize, singularize)",
    "kamidana.additionals.env": "accessing environemt variable, via env()"
  }
}with other packagesuse kamidana’s additional modules withcookiecutter. (seeexamples/extensions/src/02with-cookiecutter)0.9.1catch up magicalimport 0.8.10.9.0python 3.8 support (#43)0.8.2more aggressive support for cookiecutter, enable to use relative phisical path0.8.1refine kamidana.additionals.naming implementation0.8.0add creating jinja2’s extension mini-framework, and cookiecutter supportadd kamidana.additionals.envadd–list-infooption0.7.2on error message, skipping almost duplicated jinja2 frame’s output0.7.1update readme.rst0.7.0gentle error messagechanging template path lookup mechanismadding newline at end of filedrop trim block=True0.6.2template is not passed, act as –dump-context (#21)same behaviour-a kamidana.additonals.readerand-a reader(shortcuts) (#18)update readme.rst0.6.1kamidana, fix: –dst option is ignoredkamidana-batch, fix: kamidana-batch ignore –logging option0.6.0kamidana.additionals.naming0.5.0new kamidana-batch commandchanging addtionals.reader’s current working directory path0.4.1fix bug (multi -a option)0.4.0add kamidana.additionals.reader0.3.0add–extensionoptionadd–dump-contextoption0.2.1rename Loader to TemplateLoader0.2.0–loader option is addedinterfaces are defined0.1.0first release