Skip to content

Commit 6830a48

Browse files
committed
add jinja helper to access parameter variables
1 parent 681f141 commit 6830a48

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

ioc/extra/jinja2/helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__author__ = 'rande'
2+
3+
class JinjaHelper(object):
4+
def __init__(self, container):
5+
self.container = container
6+
7+
def get_parameter(self, name, default=None):
8+
if self.container.parameters.has(name):
9+
return self.container.parameters.get(name)
10+
11+
return default

tests/ioc/extra/jinja/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright 2014 Thomas Rabaix <[email protected]>
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2014 Thomas Rabaix <[email protected]>
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
import unittest
17+
18+
from ioc.extra.jinja2.helper import JinjaHelper
19+
from ioc.component import Container, ParameterHolder
20+
class JinjaHelperTest(unittest.TestCase):
21+
def test_get_parameter(self):
22+
23+
container = Container()
24+
container.parameters.set('hello', 'world')
25+
26+
helper = JinjaHelper(container)
27+
28+
self.assertEquals('world', helper.get_parameter('hello'))
29+
self.assertEquals(None, helper.get_parameter('fake'))
30+
self.assertEquals('for real', helper.get_parameter('fake', 'for real'))

0 commit comments

Comments
 (0)