html head title - yield "!" + " !"
!doctype/ html html head title | Page Title body h1 {'class': ' '.join(['main', 'content'], 'ng-app': 'Application'} "Page Header" div.content - yield from options['content_block']() div.footer "Backslant © 2015"
doctype
ends in /
, which means the tag should not be closed through </doctype>
."
, you need to finish the grammar so that you can immediately after the tag body, later.h1
arguments are passed to the usual python dict
, in which any code that can be in the declaration of the dictionary.yield from
the call to some content_block
, which lies in some options
. What can I say - options
is kwargs
, since we don’t have template parameter declarations here. Maybe nothing by the way what is not.content_block
- here we expect that some kind of callback will be passed to us in the parameter, and we believe that there will be a generator - we have all the templates are generators. This means that some template will want to use our base.bs, and cause it to render, and give it a callback. - from . import base :call base.render(*options) :content_block - for i in range(10): p - yield 'Paragraph {}'.format(i) :footer_block p "Index page"
:call
will sort out its child nodes, check that all of them are function declarations, and pop them into parameters. A :content_block
just declares a function without arguments with the name content_block
, and with the same name :call
will send it to the arguments. import backslant sys.meta_path.insert(0, backslant.PymlFinder('./templates', hook='backslant_import')) from backslant_import.home import index for chunk in index.render(title='The Real Thing'): print(chunk)
- def func(a=True)
and so on. for
, if
, elif
, else
- just a pure python. Of course, you can and should use yield
and yield from
. You can import anything you like and use.try: except: ...
The current version of the parser is not very friendly, it is necessary to redo the parsing.send
, not only next
. The truth is that from this you can get, well, I do not know, you can dream up. It can somehow feed data and give portions to the output.yield
and yield from
, compiled via ast
, there is nothing to optimize.Source: https://habr.com/ru/post/254567/
All Articles