Factorize hooks management (only overwrite)

Manage link attribute for title tag
Update copyright and CSS
This commit is contained in:
Grégory Soutadé 2013-01-06 12:10:29 +01:00
parent 7ea8fd9280
commit e31795efb2
10 changed files with 67 additions and 38 deletions

View File

@ -24,11 +24,7 @@ class Archive(Index):
def generate(self, blog, src, output): def generate(self, blog, src, output):
from dynastie.models import Post, Blog from dynastie.models import Post, Blog
self.hooks = {'posts' : self.createPosts, self.hooks['archive'] = self.createArchive
'navigation' : self.createNavigation,
'archive' : self.createArchive,
'tags' : self.createTags,
'replace' : self.createReplace}
dom = self.parseTemplate(blog, src, output, 'archive', 'archive') dom = self.parseTemplate(blog, src, output, 'archive', 'archive')
if dom is None: return self.report if dom is None: return self.report

View File

@ -24,11 +24,7 @@ class Category(Index):
def generate(self, blog, src, output): def generate(self, blog, src, output):
from dynastie.models import Post, Blog, Category from dynastie.models import Post, Blog, Category
self.hooks = {'posts' : self.createPosts, self.hooks['category'] = self.createCategory
'navigation' : self.createNavigation,
'category' : self.createCategory,
'tags' : self.createTags,
'replace' : self.createReplace}
dom = self.parseTemplate(blog, src, output, 'category', 'category') dom = self.parseTemplate(blog, src, output, 'category', 'category')
if dom is None: return self.report if dom is None: return self.report

View File

@ -11,11 +11,22 @@ class Index(DynastieGenerator):
cur_page = 0 cur_page = 0
nb_pages = 0 nb_pages = 0
cur_post = 0 cur_post = 0
cur_post_obj = None
posts_per_page = 0 posts_per_page = 0
filename = 'index' filename = 'index'
dirname = '' dirname = ''
blog = None blog = None
def __init__(self, hash_posts=None):
DynastieGenerator.__init__(self, hash_posts)
self.hooks = {'posts' : self.createPosts,
'title' : self.createTitle,
'navigation' : self.createNavigation,
'recents' : self.createRecents,
'tags' : self.createTags,
'replace' : self.createReplace}
def createReplace(self, posts, dom, root, replace_elem): def createReplace(self, posts, dom, root, replace_elem):
if not replace_elem.hasAttribute('div_name'): if not replace_elem.hasAttribute('div_name'):
self.addError('No attribute div_name for a replace tag') self.addError('No attribute div_name for a replace tag')
@ -82,9 +93,20 @@ class Index(DynastieGenerator):
return res return res
def createPost(self, post, dom, post_elem, root): def createTitle(self, posts, dom, root, title_elem):
create_link = (title_elem.getAttribute('link') == '1')
post = self.cur_post_obj
if create_link == True:
node = self.createElement(dom, 'title')
node.appendChild(self.createLinkElem(dom, post.getPath(), post.title))
else:
node = self.createElement(dom, 'title', post.title)
root.replaceChild(node, title_elem)
def createPost(self, posts, dom, post_elem, root):
post = self.cur_post_obj
values = {} values = {}
values['title'] = self.createLinkElem(dom, post.getPath(), post.title)
values['author'] = post.author.first_name + ' ' + post.author.last_name values['author'] = post.author.first_name + ' ' + post.author.last_name
values['date'] = post.creation_date.strftime('%A, %d %B %Y %H:%m') values['date'] = post.creation_date.strftime('%A, %d %B %Y %H:%m')
values['post_content'] = '' values['post_content'] = ''
@ -108,9 +130,9 @@ class Index(DynastieGenerator):
while True: while True:
start = post_content.find('<dyn:code') start = post_content.find('<dyn:code')
end = post_content.find('</dyn:code>')
if start == -1: break if start == -1: break
end = post_content.find('</dyn:code>')
if end < start: if end < start:
self.addError('Invalid <dyn:code> tags in ' + filename) self.addError('Invalid <dyn:code> tags in ' + filename)
@ -138,12 +160,15 @@ class Index(DynastieGenerator):
def createPosts(self, posts, dom, root, node): def createPosts(self, posts, dom, root, node):
posts_elem = self.createElement(dom, 'posts') posts_elem = self.createElement(dom, 'posts')
create_link = (node.getAttribute('link') == '1')
for i in range(0, self.posts_per_page): for i in range(0, self.posts_per_page):
post_elem = self.createElement(dom, 'post') post_elem = self.createElement(dom, 'post')
if len(posts) > self.cur_post: if len(posts) > self.cur_post:
self.createPost(posts[self.cur_post], dom, post_elem, node) self.cur_post_obj = posts[self.cur_post]
self.createPost(posts, dom, post_elem, node)
else: else:
post_elem = self.createElement(dom, '', '<b>No posts yet</b>') post_elem = self.createElement(dom, '', '<b>No posts yet</b>')
self.cur_post_obj = None
posts_elem.appendChild(post_elem) posts_elem.appendChild(post_elem)
# Parse inner HTML # Parse inner HTML
@ -344,13 +369,6 @@ class Index(DynastieGenerator):
def generate(self, blog, src, output): def generate(self, blog, src, output):
from dynastie.models import Post, Blog from dynastie.models import Post, Blog
self.hooks = {'posts' : self.createPosts,
'navigation' : self.createNavigation,
'recents' : self.createRecents,
'tags' : self.createTags,
'replace' : self.createReplace}
dom = self.parseTemplate(blog, src, output, 'index') dom = self.parseTemplate(blog, src, output, 'index')
if dom is None: return self.report if dom is None: return self.report

View File

@ -120,7 +120,9 @@ class Post(Index):
def _createPost(self, post, dom, post_elem, root): def _createPost(self, post, dom, post_elem, root):
import sys, traceback import sys, traceback
self.createPost(post, dom, post_elem, root) self.cur_post_obj = post
posts = [post]
self.createPost(posts, dom, post_elem, root)
# Post are appended by index. Remove template # Post are appended by index. Remove template
post_nodes = dom.getElementsByTagNameNS(self.URI, 'post') post_nodes = dom.getElementsByTagNameNS(self.URI, 'post')
@ -139,11 +141,12 @@ class Post(Index):
def _generate(self, blog, src, output, posts): def _generate(self, blog, src, output, posts):
import xml import xml
self.hooks = {'post' : self._createPost,
'meta' : self.createMetas, self.hooks['post'] = self._createPost
'comments' : self.createComments, self.hooks['meta'] = self.createMetas
'replace' : self.createReplace, self.hooks['comments'] = self.createComments
'tags' : self.createTags} self.hooks['replace'] = self.createReplace
del self.hooks['navigation']
self.blog = blog self.blog = blog
name = 'post' name = 'post'
@ -217,6 +220,7 @@ class Post(Index):
def preview(self, src, values): def preview(self, src, values):
from dynastie.models import Blog from dynastie.models import Blog
# Override all hooks
self.hooks = {'post' : self.createPreview, self.hooks = {'post' : self.createPreview,
'tags' : self.createTags} 'tags' : self.createTags}

View File

@ -17,9 +17,6 @@ class Search(Index):
self.blog = blog self.blog = blog
self.hooks = {'posts' : self.createPosts,
'replace' : self.createReplace}
if not os.path.exists(src + '/_search.html'): if not os.path.exists(src + '/_search.html'):
self.addError('No _search.html found, exiting') self.addError('No _search.html found, exiting')
return self.report return self.report

View File

@ -24,11 +24,7 @@ class Tag(Index):
def generate(self, blog, src, output): def generate(self, blog, src, output):
from dynastie.models import Post, Blog, Tag from dynastie.models import Post, Blog, Tag
self.hooks = {'posts' : self.createPosts, self.hooks['tag'] = self.createTag
'navigation' : self.createNavigation,
'tag' : self.createTag,
'tags' : self.createTags,
'replace' : self.createReplace}
dom = self.parseTemplate(blog, src, output, 'tag', 'tag') dom = self.parseTemplate(blog, src, output, 'tag', 'tag')
if dom is None: return self.report if dom is None: return self.report

View File

@ -77,7 +77,7 @@
</div> </div>
</div> </div>
<div class="footer"> <div class="footer">
Copyright © 2010-2012 Grégory Soutadé.<br/> Copyright © 2010-2013 Grégory Soutadé.<br/>
All Rights Reserved. All Rights Reserved.
</div> </div>
</div> </div>

View File

@ -79,7 +79,7 @@
</div> </div>
</div> </div>
<div class="footer"> <div class="footer">
Copyright © 2010-2012 Grégory Soutadé.<br/> Copyright © 2010-2013 Grégory Soutadé.<br/>
All Rights Reserved. All Rights Reserved.
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
<dyn:base file="_base.html" block="content" xmlns:dyn="http://indefero.soutade.fr/p/dynastie"> <dyn:base file="_base.html" block="content" xmlns:dyn="http://indefero.soutade.fr/p/dynastie">
<dyn:posts limit="5"> <dyn:posts limit="5">
<div class="post_header"> <div class="post_header">
<dyn:title/> <dyn:title link="1"/>
<div class="post_sub_header"> <div class="post_sub_header">
<dyn:date/> | <div class="author_icon"> Écrit par <dyn:author/> </div> <dyn:date/> | <div class="author_icon"> Écrit par <dyn:author/> </div>
</div> </div>

View File

@ -167,6 +167,28 @@ div.post > div.post_header
padding-bottom:5px; padding-bottom:5px;
} }
div.post > div.post_header > div.title
{
display:block;
text-decoration:none;
margin: 0.2em 0;
padding: 0;
font-weight:normal;
font-style:normal;
letter-spacing:normal;
word-spacing:normal;
font-variant:normal;
text-decoration:none;
font-variant:normal;
text-transform:none;
text-align:left;
text-indent:0;
line-height:inherit;
font-family: Verdana, Geneva, Arial, Helvetica, Sans-Serif;
font-size: 26px;
color: #181B0D;
}
div.post > div.post_header > div.title > a div.post > div.post_header > div.title > a
{ {
display:block; display:block;