##// END OF EJS Templates
templateContext: improve the context object idea
ergo -
r395:52964495 default
parent child Browse files
Show More
@@ -640,8 +640,8 b' class PullrequestsController(BaseRepoCon'
640 pull_request_id = safe_int(pull_request_id)
640 pull_request_id = safe_int(pull_request_id)
641 c.pull_request = PullRequest.get_or_404(pull_request_id)
641 c.pull_request = PullRequest.get_or_404(pull_request_id)
642
642
643 if hasattr(c, 'pylons_dispatch_info'):
643 c.template_context['pull_request_data']['pull_request_id'] = \
644 c.pylons_dispatch_info['extra']['pull_request'] = pull_request_id
644 pull_request_id
645
645
646 # pull_requests repo_name we opened it against
646 # pull_requests repo_name we opened it against
647 # ie. target_repo must match
647 # ie. target_repo must match
@@ -425,9 +425,29 b' class BaseController(WSGIController):'
425 _route_name = '.'.join([environ['pylons.routes_dict']['controller'],
425 _route_name = '.'.join([environ['pylons.routes_dict']['controller'],
426 environ['pylons.routes_dict']['action']])
426 environ['pylons.routes_dict']['action']])
427
427
428 c.pylons_dispatch_info = {
428 c.template_context = {
429 'controller': environ['pylons.routes_dict']['controller'],
429 'repo_name': None,
430 'action': environ['pylons.routes_dict']['action'],
430 'repo_type': None,
431 'repo_landing_commit': None,
432 'rhodecode_user': {
433 'username': None,
434 'email': None,
435 },
436 'visual': {
437 'default_renderer': None
438 },
439 'commit_data': {
440 'commit_id': None
441 },
442 'pull_request_data': {'pull_request_id': None},
443 'timeago': {
444 'refresh_time': 120 * 1000,
445 'cutoff_limit': 1000*60*60*24*7
446 },
447 'pylons_dispatch':{
448 'controller': environ['pylons.routes_dict']['controller'],
449 'action': environ['pylons.routes_dict']['action'],
450 },
431 'extra': {'plugins': {}}
451 'extra': {'plugins': {}}
432 }
452 }
433
453
@@ -1,55 +1,19 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <!DOCTYPE html>
2 <!DOCTYPE html>
3
3
4 <%def name="get_template_context()" filter="n, trim">{
4 <%
5
5 c.template_context['repo_name'] = getattr(c, 'repo_name', '')
6 ## repo data
7 repo_name: "${getattr(c, 'repo_name', '')}",
8 % if hasattr(c, 'rhodecode_db_repo'):
9 repo_type: "${c.rhodecode_db_repo.repo_type}",
10 repo_landing_commit: "${c.rhodecode_db_repo.landing_rev[1]}",
11 % else:
12 repo_type: null,
13 repo_landing_commit: null,
14 % endif
15
6
16 ## user data
7 if hasattr(c, 'rhodecode_db_repo'):
17 % if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id:
8 c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type
18 rhodecode_user: {
9 c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1]
19 username: "${c.rhodecode_user.username}",
20 email: "${c.rhodecode_user.email}",
21 },
22 % else:
23 rhodecode_user: {
24 username: null,
25 email: null,
26 },
27 % endif
28
10
29 ## visual settings
11 if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id:
30 visual: {
12 c.template_context['rhodecode_user']['username'] = c.rhodecode_user.username
31 default_renderer: "${h.get_visual_attr(c, 'default_renderer')}"
13 c.template_context['rhodecode_user']['email'] = c.rhodecode_user.email
32 },
33
34 ## current commit context, filled inside templates that expose that
35 commit_data: {
36 commit_id: null,
37 },
38
14
39 ## current pr context, filled inside templates that expose that
15 c.template_context['visual']['default_renderer'] = h.get_visual_attr(c, 'default_renderer')
40 pull_request_data: {
16 %>
41 pull_request_id: null,
42 },
43
44 ## timeago settings, can be overwritten by custom user settings later
45 timeago: {
46 refresh_time: ${120 * 1000},
47 cutoff_limit: ${1000*60*60*24*7}
48 },
49 dispatch_info: ${h.json.dumps(getattr(c, 'pylons_dispatch_info', {}))|n}
50 }
51
52 </%def>
53
17
54 <html xmlns="http://www.w3.org/1999/xhtml">
18 <html xmlns="http://www.w3.org/1999/xhtml">
55 <head>
19 <head>
@@ -81,7 +45,7 b''
81 <script src="${h.url('/js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script>
45 <script src="${h.url('/js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script>
82 <script type="text/javascript">
46 <script type="text/javascript">
83 // register templateContext to pass template variables to JS
47 // register templateContext to pass template variables to JS
84 var templateContext = ${get_template_context()};
48 var templateContext = ${h.json.dumps(c.template_context)|n};
85
49
86 var REPO_NAME = "${getattr(c, 'repo_name', '')}";
50 var REPO_NAME = "${getattr(c, 'repo_name', '')}";
87 %if hasattr(c, 'rhodecode_db_repo'):
51 %if hasattr(c, 'rhodecode_db_repo'):
General Comments 0
You need to be logged in to leave comments. Login now