[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
expand_aliases-0.1 (mediawiki calls these templates)
From: |
boud |
Subject: |
expand_aliases-0.1 (mediawiki calls these templates) |
Date: |
Wed, 6 Dec 2006 05:45:43 +0100 (CET) |
hi samizdat-devel,
Something which is very powerful in mediawiki is what they call templates,
e.g. http://en.wikipedia.org/wiki/Template:NPOV
Here i've included a very primitive version of this. i'm not really sure
what a good name should be (for clarity, to avoid confusion with related
notions, etc etc.) For the moment i'm calling it expand_aliases, but i
think it should be changed reasonably early if we have a good reason to.
This is clearly a hack only useful while the number of "aliases" remains
very small and maintainable by sysadmin. So then my questions would be:
* should aliases be openly publishable? (on wikipedia many are semi-protected)
* should they be in the config file?
in an additional config file in yaml format?
i also was wondering whether these aliases should be xml-ised?
e.g. <LZR> instead of {{LZR}} to be cleaned up by html tidy into
<LZR /> except that it gets expanded anyway. But this might teach bad
habits, get people confused about what's a standard xml command or not
etc etc. Namespaces need to be kept separate.
Anyway, here it is - a rough hack but it does seem to work for anyone
needing a quick hack. (And might inspire something more sensible).
cheers
boud
----------------------------------------------------------------------
(1) patch engine/template.rb
--- /usr/lib/ruby/1.8/samizdat/engine/template.rb~ 2006-11-29
18:46:48.000000000 +0100
+++ /usr/lib/ruby/1.8/samizdat/engine/template.rb 2006-12-06
05:34:54.722275344 +0100
@@ -10,6 +10,8 @@
require 'samizdat/engine'
+require 'samizdat/engine/expand_aliases'
+
begin
require 'redcloth'
@@ -428,6 +430,7 @@
}.join
end
+ expand_aliases(html)
Samizdat::Sanitize.new(config.xhtml).sanitize(html)
end
(2) engine/expand_aliases.rb
#!/usr/bin/env ruby
#
# Samizdat expand aliases
#
# Copyright (c) 2002-2006 Dmitry Borodaenko <address@hidden>,
# Boud (Indymedia) <boud at riseup.net>
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU General Public License version 2 or later.
#
# vim: et sw=2 sts=2 ts=8 tw=0
require 'samizdat/engine'
def expand_aliases(content)
# content.gsub!(/\{\{NPOV\}\}/,'This article is suspected of being racist')
aliases ={
# Lamanie Zasady Redakcyjnych
/\{\{LZR\}\}/ =>
'<p style="background-color: yellow; color: black; border: 2px dashed
red;">' +
' <b>Ten artykuĹ/komentarz jest podejrzany byÄ niezgodny z ' +
' <a href="/82">zasadami redakcyjnymi</a>.</b></p>',
/\{\{ĹZR\}\}/ =>
'<p style="background-color: yellow; color: black; border: 2px dashed
red;">' +
' <b>Ten artykuĹ/komentarz jest podejrzany byÄ niezgodny z ' +
' <a href="/82">zasadami redakcyjnymi</a>.</b></p>'
}
aliases.each {|alias_key, alias_value| content.gsub!(alias_key, alias_value)}
# content.gsub!(/\{\{LZR\}\}/) { |match|
# '<p style="background-color: yellow; color: black; border: 2px dashed red;">' +
# ' <b>Ten artykuĹ/komentarz jest podejrzany byÄ niezgodny z ' +
# ' <a href="/82">zasadami redakcyjnymi</a>.</b></p>' }
end
----------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- expand_aliases-0.1 (mediawiki calls these templates),
boud <=