Add ljdc (les joies du code) generator
This commit is contained in:
85
dynastie/generators/ljdc.py
Executable file
85
dynastie/generators/ljdc.py
Executable file
@@ -0,0 +1,85 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright 2012-2014 Grégory Soutadé
|
||||
|
||||
This file is part of Dynastie.
|
||||
|
||||
Dynastie is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Dynastie is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Dynastie. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
import os
|
||||
from xml.dom.minidom import parse, parseString
|
||||
import xml.parsers.expat
|
||||
from dynastie.generators.generator import DynastieGenerator
|
||||
from dynastie.generators.index import Index
|
||||
from django.db import models
|
||||
|
||||
class LJDC(Index):
|
||||
|
||||
cur_page = 0
|
||||
nb_pages = 0
|
||||
cur_post = 0
|
||||
posts_per_page = 20
|
||||
filename = 'index'
|
||||
dirname = '/ljdc'
|
||||
cur_category = None
|
||||
|
||||
def createPost(self, posts, dom, post_elem, root):
|
||||
new_elem = self.createElement(dom, 'ljdc')
|
||||
|
||||
address = self.cur_post_obj.getElementsByTagName('address')[0]
|
||||
a = dom.createElement('a')
|
||||
a.setAttribute('href', address.childNodes[0].nodeValue)
|
||||
|
||||
title_value = self.cur_post_obj.getElementsByTagName('title')[0]
|
||||
title = self.createElement(dom, 'title', title_value.childNodes[0].nodeValue)
|
||||
a.appendChild(title)
|
||||
|
||||
img_src = self.cur_post_obj.getElementsByTagName('img')[0]
|
||||
img = dom.createElement('img')
|
||||
img.setAttribute('src', img_src.childNodes[0].nodeValue)
|
||||
|
||||
a.appendChild(img)
|
||||
|
||||
new_elem.appendChild(a)
|
||||
|
||||
self.cur_post_obj = None
|
||||
|
||||
return new_elem
|
||||
|
||||
def generate(self, blog, src, output):
|
||||
from dynastie.models import Post, Blog, Category
|
||||
|
||||
name = '_ljdc.xml'
|
||||
if not os.path.exists(src + '/%s' % name):
|
||||
self.addWarning('No %s found, exiting' % name)
|
||||
return None
|
||||
|
||||
try:
|
||||
srcdom = parse(src + '/%s' % name)
|
||||
except xml.dom.DOMException as e:
|
||||
self.addError('Error parsing %s : ' + e)
|
||||
return None
|
||||
|
||||
posts = srcdom.getElementsByTagName("entry")
|
||||
|
||||
dom = self.parseTemplate(blog, src, output, 'ljdc', 'ljdc')
|
||||
if dom is None: return self.report
|
||||
|
||||
self.generatePages(dom, posts, src, output, 'ljdc')
|
||||
|
||||
if not self.somethingWrote:
|
||||
self.addReport('Nothing changed')
|
||||
|
||||
return self.report
|
||||
|
||||
Reference in New Issue
Block a user