Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9d690f

Browse files
committed
[proxy] add a basic proxy to support esi tag, and note to run element with varnish or nginx
1 parent 83156e4 commit f9d690f

File tree

14 files changed

+384
-23
lines changed

14 files changed

+384
-23
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ test:
1212
nosetests
1313
cd element/standalone/skeleton && nosetests
1414
cd docs && sphinx-build -nW -b html -d _build/doctrees . _build/html
15+
#for f in $$(find . -name '*.py'); do pyflakes $$f; done
1516

1617
install:
1718
pip install -r requirements_test.txt
18-
cd element/standalone/skeleton && bower update
19+
cd element/standalone/skeleton && bower install
1920

2021
doc:
2122
cd docs && sphinx-build -nW -b html -d _build/doctrees . _build/html
2223

2324
dev:
2425
cd element/standalone/skeleton && python start.py tornado:start --verbose -d --bind element.vagrant
2526

27+
proxy:
28+
cd element/standalone/skeleton && python proxy.py 5000
29+
2630
prod:
2731
cd element/standalone/skeleton && python start.py tornado:start -np 8
2832

2933
bower:
30-
cd element/standalone/skeleton && bower update
34+
cd element/standalone/skeleton && bower install
3135

3236
fixtures:
3337
cd element/standalone/skeleton && python start.py element:demo:fixtures

docs/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.. IoC documentation master file, created by
2-
sphinx-quickstart on Fri Mar 29 01:43:00 2013.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
5-
61
Python Element's documentation!
72
===============================
83

@@ -16,6 +11,7 @@ References
1611

1712
install
1813
architecture
14+
running-element
1915
node
2016
events
2117
managers

docs/plugins/node.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ The node plugin is a core plugin as it provides main features to render a node.
66
Configuration
77
-------------
88

9-
There is no configuration option. You only need to enable the plugin by adding this line into the IoC configuration file.
10-
119
.. code-block:: yaml
1210
1311
element.plugins.node:
12+
render_type: esi # or ssi
1413
1514
Usage
1615
-----
@@ -43,11 +42,13 @@ render_node_event
4342

4443
This helper allows to create a place holder inside a template where listeners can generate some contents.
4544

46-
A good example is a blog post where comments are required. However, the comment mechanism might not be implemented as many solutions exist. The solution is to used the ``render_node_event`` helper to raise a specific event with proper option like the ``subject``.
45+
A good example is a blog post where comments are required. However, the comment mechanism might not be implemented as
46+
many solutions exist. The solution is to used the ``render_node_event`` helper to raise a specific event with proper
47+
option like the ``subject``.
4748

4849
.. code-block:: jinja
4950
50-
{{ render_node_event('node.comment.list', options={'subject': context.node})|safe }}
51+
{{ render_node_event('node.comment.list', options={'subject': context.node}) }}
5152
5253
render_node
5354
~~~~~~~~~~~
@@ -56,7 +57,18 @@ This helper renders a node instance.
5657

5758
.. code-block:: jinja
5859
59-
{{ render_node(node)|safe }}
60+
{{ render_node(node) }}
61+
62+
render
63+
~~~~~~
64+
65+
This helper render an ESI tag or a SSI tag. This can be useful if you want to reuse a controller. It is a valid solution
66+
if you don't have a node to render.
67+
68+
69+
.. code-block:: jinja
70+
71+
{{ render(path('element_profiler_wdt', token=token, position='normal')) }}
6072
6173
6274
Jinja Filters
@@ -86,5 +98,6 @@ This filter take a node and return a formatted string.
8698
Events
8799
------
88100

89-
The plugin listen to two events: ``element.node.load.success`` and ``element.nodes.load.success`` for normalizing a node. The normalization make sure that all :doc:`required fields</architecture>` are set.
101+
The plugin listen to two events: ``element.node.load.success`` and ``element.nodes.load.success`` for normalizing a
102+
node. The normalization make sure that all :doc:`required fields</architecture>` are set.
90103

element/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def build(self, node, handler, defaults=None):
1111
settings = {}
1212

1313
settings.update(self.defaults)
14-
settings.update(node.data)
1514
settings.update(handler.get_defaults(node))
15+
settings.update(node.data)
1616
settings.update(defaults or {})
1717

1818
if not settings['base_template']:

element/plugins/node/di.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ def load(self, config, container_builder):
99
loader = YamlLoader()
1010
loader.load("%s/resources/config/services_node.yml" % path, container_builder)
1111

12+
definition = container_builder.get ('element.plugins.node.jinja2.master')
13+
definition.arguments[4] = config.get('render_type', 'esi')
14+
1215
def post_build(self, container_builder, container):
1316
"""
1417
The build is over, register services-as-methods

element/plugins/node/jinja.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
import element.node
2-
import markdown
31
from tornado.web import RequestHandler
42
from tornado.httpserver import HTTPRequest
3+
import jinja2
4+
5+
try:
6+
from urllib.parse import urlparse
7+
except ImportError:
8+
from urlparse import urlparse
59

610
class SubRequestHandler(RequestHandler):
711
def get_buffer(self):
812
return b"".join(self._write_buffer)
913

1014
class Core(object):
11-
def __init__(self, node_manager, context_creator, dispatcher, application):
15+
def __init__(self, node_manager, context_creator, dispatcher, application, render_type):
1216
self.node_manager = node_manager
1317
self.context_creator = context_creator
1418
self.dispatcher = dispatcher
1519
self.application = application
20+
self.render_type = render_type
1621

1722
def render_node(self, node, defaults=None):
1823
defaults = defaults or {}
@@ -48,6 +53,18 @@ def render_node_event(self, event_name, options=None):
4853

4954
return self.unicode(self.render_node(event.get('node')))
5055

56+
def render(self, path, type=None):
57+
if not type:
58+
type = self.render_type
59+
60+
if type == 'esi':
61+
return jinja2.Markup('<esi:include src="%s" />' % path)
62+
63+
elif type == 'ssi':
64+
o = urlparse(path)
65+
return jinja2.Markup('<!--# include virtual="%s?%s&_element=no-debug" -->' % (o.path, o.query))
66+
67+
5168
def unicode(self, content):
5269
if isinstance(content, unicode):
5370
return content

element/plugins/node/resources/config/services_node.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ services:
3333
- '@element.context.creator'
3434
- '@ioc.extra.event_dispatcher'
3535
- '@ioc.extra.tornado.application'
36+
- 'esi'
3637
tags:
3738
jinja2.global:
3839
- { name: render_node, method: render_node}
3940
- { name: render_node_event, method: render_node_event}
41+
- { name: render, method: render}
4042

4143
element.plugins.node.mapper.meta_collection:
4244
class: element.plugins.node.mapper.MetaCollection

element/plugins/profiler/profiler.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,25 @@ def on_response(self, event):
100100
if len(content_type) < 9 or content_type[0:9] != 'text/html':
101101
return
102102

103+
if request_handler.request.headers.get('Surrogate-Capability'):
104+
return
105+
106+
if request_handler.get_query_argument('_element', default=False) == 'no-debug':
107+
return
108+
103109
## inject the toolbar to the response
104110
content = self.templating.get_template('element.plugins.profiler:profiler/toolbar_js.html').render({
105111
'token': str(request_handler.run.id)
106112
})
107113

108-
chunk = request_handler.get_chunk_buffer()
114+
chunk = request_handler.get_chunk_buffer().decode('utf-8')
109115
request_handler.reset_chunk_buffer()
110116

111117
k = chunk.rfind('</body>')
112118

113-
request_handler.write(chunk[:k] + content + chunk[k:])
119+
request_handler.write(chunk[:k])
120+
request_handler.write(content)
121+
request_handler.write(chunk[k:])
114122

115123
for name, collector in self.profiler.collectors.iteritems():
116124
collector.on_response(request_handler, request_handler.run)

element/plugins/profiler/resources/templates/profiler/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% block body %}
44

5-
{#{ render(path('element_profiler_wdt', token=token, position='normal')) }#}
5+
{{ render(path('element_profiler_wdt', token=token, position='normal')) }}
66

77
<div id="content">
88
{% include 'element.plugins.profiler:profiler/header.html' %}

0 commit comments

Comments
 (0)