本文整理汇总了Python中post.Post.render方法的典型用法代码示例。如果您正苦于以下问题:Python Post.render方法的具体用法?Python Post.render怎么用?Python Post.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.render方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import render [as 别名]
def main():
# READ TEMPATE HTML FILES
base_html = open("templates/base.html")
post_html = open("templates/post.html")
# CREATE PAGE
page = base_html.readlines()
posts = []
# OPEN POST TXT FILES
postfiles = [ f for f in listdir("posts") if isfile(join("posts",f)) ]
for postfile in postfiles:
temp = open("posts/" + postfile, "r")
postlines = temp.readlines()
post_obj = Post(postlines[0], postlines[1], postlines[2:])
posts.append("".join(post_obj.render(post_html)))
post_html.seek(0)
temp.close()
# INSERT POSTS INTO PAGE
for i in range(len(page)):
page[i] = page[i].replace("[[posts]]", "\n\n".join(posts))
# WRITE PAGE TO OUTPUT HTML FILE
final = open("output/final.html", "a+")
final.write("".join(page))
# CLOSE FILES
base_html.close()
post_html.close()
示例2: render_latest_posts
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import render [as 别名]
def render_latest_posts(self, limit):
accu = ''
for post_path in self.latest_posts(limit):
post = Post(post_path)
accu += post.render('short-post')
output = open(os.path.join(
self.__render_base_path, 'latest_posts.rst'), 'w')
output.write(accu)
output.close()
示例3: render_latest_posts
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import render [as 别名]
def render_latest_posts(self, limit):
accu = ''
for post_path in self.latest_posts(limit):
post = Post(post_path)
accu += post.render("short-post")
output = open(os.path.join(
self.__render_base_path, "latest_posts.rst"), "w", encoding='utf-8')
output.write(accu)
output.close()
示例4: render_archive
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import render [as 别名]
def render_archive(self):
accu = 'Archive\n=======\n\n'
tmpl_file = open(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'templates', '%s.rst' % 'archive-subtitle'))
template = Template(tmpl_file.read())
tmpl_file.close()
for key in self.posts_archive():
year = key.split("/")[0]
month = self.__months[int(key.split("/")[1])-1]
accu += template.render(title="%s %s" % (month, year))
for post_path in self.posts_archive()[key]:
post = Post(post_path)
accu += post.render("title-post")
output = open(os.path.join(
self.__render_base_path, "archive.rst"), "w")
output.write(accu)
output.close()
示例5: render_archive
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import render [as 别名]
def render_archive(self):
accu = 'Archive\n=======\n\n'
tmpl_file = open(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'templates', '%s.rst' % 'archive-subtitle'))
template = Template(tmpl_file.read())
tmpl_file.close()
monthkey = None
for post_path in self.posts():
post = Post(post_path)
if post.date_key != monthkey:
monthkey = post.date_key
year = monthkey.split('/')[0]
month = self.__months[int(monthkey.split('/')[1]) - 1]
accu += template.render(title="%s %s" % (month, year))
accu += post.render('title-post')
output = open(os.path.join(
self.__render_base_path, 'archive.rst'), 'w')
output.write(accu)
output.close()