From 2f6300af46229f58c5477d929aa04950381a0f59 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Wed, 5 Jan 2011 14:27:46 +0100 Subject: [PATCH] Do not create a general function for "update_object_content". --- pelican/generators.py | 27 --------------------------- pelican/writers.py | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index f43c7c2a..49d5a887 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -4,7 +4,6 @@ from functools import partial from datetime import datetime from collections import defaultdict import os -import re from jinja2 import Environment, FileSystemLoader from jinja2.exceptions import TemplateNotFound @@ -17,32 +16,6 @@ _TEMPLATES = ('index', 'tag', 'tags', 'article', 'category', 'categories', 'archives', 'page') _DIRECT_TEMPLATES = ('index', 'tags', 'categories', 'archives') -def update_object_content(name, input): - """Change all the relatives paths of the input content to relatives paths - suitable fot the ouput content - - :param name: path of the output. - :param input: input resource that will be passed to the templates. - """ - content = input._content - - hrefs = re.compile(r'<\s*[^\>]*href\s*=\s*(["\'])(.*?)\1') - srcs = re.compile(r'<\s*[^\>]*src\s*=\s*(["\'])(.*?)\1') - - matches = hrefs.findall(content) - matches.extend(srcs.findall(content)) - relative_paths = [] - for found in matches: - found = found[1] - if found not in relative_paths: - relative_paths.append(found) - - for relative_path in relative_paths: - if not relative_path.startswith("http://"): - dest_path = os.sep.join((get_relative_path(name), "static", relative_path)) - content = content.replace(relative_path, dest_path) - - return content class Generator(object): """Baseclass generator""" diff --git a/pelican/writers.py b/pelican/writers.py index 138ccd8d..5d443f09 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- import os +import re from codecs import open +from functools import partial from feedgenerator import Atom1Feed, Rss201rev2Feed -from functools import partial - from pelican.utils import get_relative_path -from pelican.generators import update_object_content + class Writer(object): @@ -127,6 +127,34 @@ class Writer(object): """Replace the content attribute getter of an element by a function that will deals with its relatives paths. """ + + def _update_object_content(name, input): + """Change all the relatives paths of the input content to relatives paths + suitable fot the ouput content + + :param name: path of the output. + :param input: input resource that will be passed to the templates. + """ + content = input._content + + hrefs = re.compile(r'<\s*[^\>]*href\s*=\s*(["\'])(.*?)\1') + srcs = re.compile(r'<\s*[^\>]*src\s*=\s*(["\'])(.*?)\1') + + matches = hrefs.findall(content) + matches.extend(srcs.findall(content)) + relative_paths = [] + for found in matches: + found = found[1] + if found not in relative_paths: + relative_paths.append(found) + + for relative_path in relative_paths: + if not relative_path.startswith("http://"): + dest_path = os.sep.join((get_relative_path(name), "static", relative_path)) + content = content.replace(relative_path, dest_path) + + return content + if item: setattr(item, "_get_content", - partial(update_object_content, name, item)) + partial(_update_object_content, name, item))