本文整理汇总了Python中Preprocessor.Preprocessor.process_tpl_name_with_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocessor.process_tpl_name_with_dict方法的具体用法?Python Preprocessor.process_tpl_name_with_dict怎么用?Python Preprocessor.process_tpl_name_with_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preprocessor.Preprocessor
的用法示例。
在下文中一共展示了Preprocessor.process_tpl_name_with_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPreprocessor
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import process_tpl_name_with_dict [as 别名]
class TestPreprocessor(unittest.TestCase):
def setUp(self):
cur_dir = os.path.dirname(os.path.realpath(__file__))
self.tpl_dir = os.path.join(cur_dir,'..','UnitTests','test_templates')
self.preprocessor = Preprocessor(self.tpl_dir)
def process_content(self,content,dict,expected):
actual = self.preprocessor.process_content_with_dict(content,dict)
self.assertEqual(actual,expected)
def test_ifs(self):
dict = {'basic_key':'_trivial_', 'yes_key':True, 'no_key':False}
self.process_content("basic%basic_key%basic",dict,"basic_trivial_basic")
self.process_content("%if yes_key%%basic_key%%endif%",dict,"_trivial_")
self.process_content("%if no_key%%basic_key%%endif%",dict,"")
self.process_content("aa%if yes_key%%if no_key%%basic_key%%endif%%endif%bb",dict,"aabb")
self.process_content("start %if non_existant_key%non_existant%endif% finish",dict,"start finish")
self.process_content("start %if non_existant_key%%if yes_key%%basic_key%%endif%%endif% finish",dict,"start finish")
self.process_content("start %if yes_key%yes%else%no%endif%",dict,"start yes")
self.process_content("start %if no_key%yes%else%no%endif%",dict,"start no")
self.process_content("start %if non_existant_key%yes%else%non_exist%endif%",dict,"start non_exist")
self.process_content("%if yes_key%%if no_key%yes%else%no%endif%%endif%",dict,"no")
self.process_content("%if no_key% hello1 %else% %if yes_key% hello2 %else% hello3 %endif% %endif%",dict," hello2 ")
def test_includes(self):
content = self.preprocessor.process_tpl_name_with_dict('test_include',{'a':True,'aa':'a'})
self.assertEqual(content,'<html><body> a </body></html>')
示例2: pictures_html_block
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import process_tpl_name_with_dict [as 别名]
def pictures_html_block(self):
pictures_preprocessor = Preprocessor(tpl_dir)
dict = {
"img_size_l": "1836x2448",
"img_size_m": "1224x1632",
"img_size_s": "612x816",
"img_width_t": 150,
"img_height_t": 150,
}
text = ""
for i in xrange(1, 16):
text = text + pictures_preprocessor.process_tpl_name_with_dict("asset", dict)
return text
示例3: album_list_html_block
# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import process_tpl_name_with_dict [as 别名]
def album_list_html_block(self):
albums_preprocessor = Preprocessor(tpl_dir)
dict = {
"number_of_pictures": 152,
"album_name": "My Photos",
"album_share_href": "/album.html",
"img_width_t": 150,
"img_height_t": 150,
"poster_image_src": "/test_image.jpeg",
}
text = ""
for i in xrange(1, 4):
text = text + albums_preprocessor.process_tpl_name_with_dict("album_list_item", dict)
return text