Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
narusemotoki committed Mar 13, 2015
1 parent 5e1ca7f commit f123acb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`Replacer <https://github.com/narusemotoki/replacer>`_
======================================================

This is plugin of Pelican. You can replace a text of a generated HTML. You can write replacing rule in your pelicanconf.py.

Example
=======

This example is replacing from '<table border="1" class="docutils">' to '<table class="table table-striped table-bordered table-hover">'.

::

REPLACES = (
(u'<table border="1" class="docutils">', u'<table class="table table-striped table-bordered table-hover">'),
)
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .replacer import *
23 changes: 23 additions & 0 deletions replacer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import pelican


def init(pelican_object):
# I have no good idea. Pass settings to replace function.
global replaces
replaces = pelican_object.settings.get('REPLACES', ())


def replace(path, context):
with open(path, 'r') as f:
s = f.read()
for src, tgt in replaces:
s = s.decode('utf-8').replace(src.decode('utf-8'), tgt.decode('utf-8'))

with open(path, 'w') as f:
f.write(s.encode('utf-8'))


def register():
pelican.signals.initialized.connect(init)
pelican.signals.content_written.connect(replace)

0 comments on commit f123acb

Please sign in to comment.