Merge pull request #1196 from pallets/remove-vim
remove vim syntax file
This commit is contained in:
commit
6478c22f29
@ -4,6 +4,5 @@ graft artwork
|
||||
graft docs
|
||||
prune docs/_build
|
||||
graft examples
|
||||
graft ext
|
||||
graft tests
|
||||
global-exclude *.pyc
|
||||
|
||||
@ -1,35 +1,31 @@
|
||||
Integration
|
||||
===========
|
||||
|
||||
Jinja provides some code for integration into other tools such as frameworks,
|
||||
the `Babel`_ library or your favourite editor for fancy code highlighting.
|
||||
This is a brief description of whats included.
|
||||
|
||||
Files to help integration are available
|
||||
`here. <https://github.com/pallets/jinja/tree/master/ext>`_
|
||||
|
||||
.. _babel-integration:
|
||||
|
||||
Babel Integration
|
||||
-----------------
|
||||
Babel
|
||||
-----
|
||||
|
||||
Jinja provides support for extracting gettext messages from templates via a
|
||||
`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel
|
||||
support is implemented as part of the :ref:`i18n-extension` extension.
|
||||
Jinja provides support for extracting gettext messages from templates
|
||||
via a `Babel`_ extractor entry point called
|
||||
``jinja2.ext.babel_extract``. The support is implemented as part of the
|
||||
:ref:`i18n-extension` extension.
|
||||
|
||||
Gettext messages extracted from both `trans` tags and code expressions.
|
||||
Gettext messages are extracted from both ``trans`` tags and code
|
||||
expressions.
|
||||
|
||||
To extract gettext messages from templates, the project needs a Jinja section
|
||||
in its Babel extraction method `mapping file`_:
|
||||
To extract gettext messages from templates, the project needs a Jinja
|
||||
section in its Babel extraction method `mapping file`_:
|
||||
|
||||
.. sourcecode:: ini
|
||||
|
||||
[jinja2: **/templates/**.html]
|
||||
encoding = utf-8
|
||||
|
||||
The syntax related options of the :class:`Environment` are also available as
|
||||
configuration values in the mapping file. For example to tell the extraction
|
||||
that templates use ``%`` as `line_statement_prefix` you can use this code:
|
||||
The syntax related options of the :class:`Environment` are also
|
||||
available as configuration values in the mapping file. For example, to
|
||||
tell the extractor that templates use ``%`` as
|
||||
``line_statement_prefix`` you can use this code:
|
||||
|
||||
.. sourcecode:: ini
|
||||
|
||||
@ -37,70 +33,43 @@ that templates use ``%`` as `line_statement_prefix` you can use this code:
|
||||
encoding = utf-8
|
||||
line_statement_prefix = %
|
||||
|
||||
:ref:`jinja-extensions` may also be defined by passing a comma separated list
|
||||
of import paths as `extensions` value. The i18n extension is added
|
||||
automatically.
|
||||
:ref:`jinja-extensions` may also be defined by passing a comma separated
|
||||
list of import paths as the ``extensions`` value. The i18n extension is
|
||||
added automatically.
|
||||
|
||||
.. versionchanged:: 2.7
|
||||
Template syntax errors are ignored by default. The assumption is that
|
||||
tests will catch syntax errors in templates. If you don't want to ignore
|
||||
errors, add ``silent = false`` to the settings.
|
||||
|
||||
Until 2.7 template syntax errors were always ignored. This was done
|
||||
since many people are dropping non template html files into the
|
||||
templates folder and it would randomly fail. The assumption was that
|
||||
testsuites will catch syntax errors in templates anyways. If you don't
|
||||
want that behavior you can add ``silent=false`` to the settings and
|
||||
exceptions are propagated.
|
||||
.. _Babel: https://babel.readthedocs.io/
|
||||
.. _mapping file: https://babel.readthedocs.io/en/latest/messages.html#extraction-method-mapping-and-configuration
|
||||
|
||||
.. _mapping file: http://babel.pocoo.org/en/latest/messages.html#extraction-method-mapping-and-configuration
|
||||
|
||||
Pylons
|
||||
------
|
||||
|
||||
With `Pylons`_ 0.9.7 onwards it's incredible easy to integrate Jinja into a
|
||||
Pylons powered application.
|
||||
It's easy to integrate Jinja into a `Pylons`_ application.
|
||||
|
||||
The template engine is configured in `config/environment.py`. The configuration
|
||||
for Jinja looks something like that::
|
||||
The template engine is configured in ``config/environment.py``. The
|
||||
configuration for Jinja looks something like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from jinja2 import Environment, PackageLoader
|
||||
config['pylons.app_globals'].jinja_env = Environment(
|
||||
loader=PackageLoader('yourapplication', 'templates')
|
||||
)
|
||||
|
||||
After that you can render Jinja templates by using the `render_jinja` function
|
||||
from the `pylons.templating` module.
|
||||
After that you can render Jinja templates by using the ``render_jinja``
|
||||
function from the ``pylons.templating`` module.
|
||||
|
||||
Additionally it's a good idea to set the Pylons' `c` object into strict mode.
|
||||
Per default any attribute to not existing attributes on the `c` object return
|
||||
an empty string and not an undefined object. To change this just use this
|
||||
snippet and add it into your `config/environment.py`::
|
||||
Additionally it's a good idea to set the Pylons ``c`` object to strict
|
||||
mode. By default attribute access on missing attributes on the ``c``
|
||||
object returns an empty string and not an undefined object. To change
|
||||
this add this to ``config/environment.py``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
config['pylons.strict_c'] = True
|
||||
|
||||
.. _Pylons: https://pylonshq.com/
|
||||
|
||||
TextMate
|
||||
--------
|
||||
|
||||
There is a `bundle for TextMate`_ that supports syntax highlighting for Jinja 1
|
||||
and Jinja 2 for text based templates as well as HTML. It also contains a few
|
||||
often used snippets.
|
||||
|
||||
.. _bundle for TextMate: https://github.com/mitsuhiko/jinja2-tmbundle
|
||||
|
||||
Vim
|
||||
---
|
||||
|
||||
A syntax plugin for `Vim`_ is available `from the jinja repository
|
||||
<https://github.com/pallets/jinja/blob/master/ext/Vim/jinja.vim>`_. The script
|
||||
supports Jinja 1 and Jinja 2. Once installed, two file types are available
|
||||
(``jinja`` and ``htmljinja``). The first one is for text-based templates and the
|
||||
second is for HTML templates. For HTML documents, the plugin attempts to
|
||||
automatically detect Jinja syntax inside of existing HTML documents.
|
||||
|
||||
If you are using a plugin manager like `Pathogen`_, see the `vim-jinja
|
||||
<https://github.com/mitsuhiko/vim-jinja>`_ repository for installing in the
|
||||
``bundle/`` directory.
|
||||
|
||||
.. _Babel: http://babel.pocoo.org/
|
||||
.. _Vim: https://www.vim.org/
|
||||
.. _Pathogen: https://github.com/tpope/vim-pathogen
|
||||
|
||||
@ -1,135 +0,0 @@
|
||||
" Vim syntax file
|
||||
" Language: Jinja template
|
||||
" Maintainer: Armin Ronacher <armin.ronacher@active-4.com>
|
||||
" Last Change: 2008 May 9
|
||||
" Version: 1.1
|
||||
"
|
||||
" Known Bugs:
|
||||
" because of odd limitations dicts and the modulo operator
|
||||
" appear wrong in the template.
|
||||
"
|
||||
" Changes:
|
||||
"
|
||||
" 2008 May 9: Added support for Jinja 2 changes (new keyword rules)
|
||||
|
||||
" .vimrc variable to disable html highlighting
|
||||
if !exists('g:jinja_syntax_html')
|
||||
let g:jinja_syntax_html=1
|
||||
endif
|
||||
|
||||
" For version 5.x: Clear all syntax items
|
||||
" For version 6.x: Quit when a syntax file was already loaded
|
||||
if !exists("main_syntax")
|
||||
if v:version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
let main_syntax = 'jinja'
|
||||
endif
|
||||
|
||||
" Pull in the HTML syntax.
|
||||
if g:jinja_syntax_html
|
||||
if v:version < 600
|
||||
so <sfile>:p:h/html.vim
|
||||
else
|
||||
runtime! syntax/html.vim
|
||||
unlet b:current_syntax
|
||||
endif
|
||||
endif
|
||||
|
||||
syntax case match
|
||||
|
||||
" Jinja template built-in tags and parameters (without filter, macro, is and raw, they
|
||||
" have special threatment)
|
||||
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained and if else in not or recursive as import
|
||||
|
||||
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained is filter skipwhite nextgroup=jinjaFilter
|
||||
syn keyword jinjaStatement containedin=jinjaTagBlock contained macro skipwhite nextgroup=jinjaFunction
|
||||
syn keyword jinjaStatement containedin=jinjaTagBlock contained block skipwhite nextgroup=jinjaBlockName
|
||||
|
||||
" Variable Names
|
||||
syn match jinjaVariable containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
syn keyword jinjaSpecial containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained false true none False True None loop super caller varargs kwargs
|
||||
|
||||
" Filters
|
||||
syn match jinjaOperator "|" containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained skipwhite nextgroup=jinjaFilter
|
||||
syn match jinjaFilter contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
syn match jinjaFunction contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
syn match jinjaBlockName contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
|
||||
" Jinja template constants
|
||||
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/"/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\"/ end=/"/
|
||||
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/'/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\'/ end=/'/
|
||||
syn match jinjaNumber containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[0-9]\+\(\.[0-9]\+\)\?/
|
||||
|
||||
" Operators
|
||||
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[+\-*\/<>=!,:]/
|
||||
syn match jinjaPunctuation containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[()\[\]]/
|
||||
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /\./ nextgroup=jinjaAttribute
|
||||
syn match jinjaAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
|
||||
" Jinja template tag and variable blocks
|
||||
syn region jinjaNested matchgroup=jinjaOperator start="(" end=")" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
||||
syn region jinjaNested matchgroup=jinjaOperator start="\[" end="\]" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
||||
syn region jinjaNested matchgroup=jinjaOperator start="{" end="}" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
|
||||
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
|
||||
|
||||
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
|
||||
|
||||
" Jinja template 'raw' tag
|
||||
syn region jinjaRaw matchgroup=jinjaRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,jinjaComment
|
||||
|
||||
" Jinja comments
|
||||
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,jinjaComment
|
||||
|
||||
" Block start keywords. A bit tricker. We only highlight at the start of a
|
||||
" tag block and only if the name is not followed by a comma or equals sign
|
||||
" which usually means that we have to deal with an assignment.
|
||||
syn match jinjaStatement containedin=jinjaTagBlock contained /\({%-\?\s*\)\@<=\<[a-zA-Z_][a-zA-Z0-9_]*\>\(\s*[,=]\)\@!/
|
||||
|
||||
" and context modifiers
|
||||
syn match jinjaStatement containedin=jinjaTagBlock contained /\<with\(out\)\?\s\+context\>/
|
||||
|
||||
|
||||
" Define the default highlighting.
|
||||
" For version 5.7 and earlier: only when not done already
|
||||
" For version 5.8 and later: only when an item doesn't have highlighting yet
|
||||
if v:version >= 508 || !exists("did_jinja_syn_inits")
|
||||
if v:version < 508
|
||||
let did_jinja_syn_inits = 1
|
||||
command -nargs=+ HiLink hi link <args>
|
||||
else
|
||||
command -nargs=+ HiLink hi def link <args>
|
||||
endif
|
||||
|
||||
HiLink jinjaPunctuation jinjaOperator
|
||||
HiLink jinjaAttribute jinjaVariable
|
||||
HiLink jinjaFunction jinjaFilter
|
||||
|
||||
HiLink jinjaTagDelim jinjaTagBlock
|
||||
HiLink jinjaVarDelim jinjaVarBlock
|
||||
HiLink jinjaCommentDelim jinjaComment
|
||||
HiLink jinjaRawDelim jinja
|
||||
|
||||
HiLink jinjaSpecial Special
|
||||
HiLink jinjaOperator Normal
|
||||
HiLink jinjaRaw Normal
|
||||
HiLink jinjaTagBlock PreProc
|
||||
HiLink jinjaVarBlock PreProc
|
||||
HiLink jinjaStatement Statement
|
||||
HiLink jinjaFilter Function
|
||||
HiLink jinjaBlockName Function
|
||||
HiLink jinjaVariable Identifier
|
||||
HiLink jinjaString Constant
|
||||
HiLink jinjaNumber Constant
|
||||
HiLink jinjaComment Comment
|
||||
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
let b:current_syntax = "jinja"
|
||||
|
||||
if main_syntax ==# 'jinja'
|
||||
unlet main_syntax
|
||||
endif
|
||||
Loading…
Reference in New Issue
Block a user