79 lines
2.4 KiB
Markdown
79 lines
2.4 KiB
Markdown
+++
|
||
title = "Dokumentation in Textile schreiben"
|
||
date = "2011-01-20T17:00:00+00:00"
|
||
author = "Gibheer"
|
||
draft = false
|
||
+++
|
||
|
||
Da ich mal Dokumentation schreiben musste, OpenOffice aber schon beim
|
||
ersten Tastenschlag keine Lust mehr hatte, ich mich bei HTML staendig
|
||
verschrieben habe, bin ich einfach auf Textile umgestiegen und hab
|
||
erfolgreich Dokumetation schreiben koennen.
|
||
|
||
Textile ist ein einfaches Wikiaehnliches Markup. Zusammen mit Ruby ist
|
||
daraus ein kleines Script geschrieben, welches mir mein textile File in
|
||
ein HTML-Grundgeruest stopft, den Code etwas aufhuebscht und dann
|
||
einfach schnell arbeitet.
|
||
|
||
Als Bibliotheken kamen dabei [RedCloth](http://redcloth.org/),
|
||
[RedclothCoderay](http://redclothcoderay.rubyforge.org/) und
|
||
[CodeRay](http://coderay.rubychan.de/) zum Einsatz.
|
||
|
||
Damit das Script funktioniert muessen die Gems CodeRay, RedCloth und
|
||
RedclothCoderay installiert sein.
|
||
|
||
Als naechstes muss im Verzeichniss des Scriptes eine
|
||
index\_template.html angelegt werden. Darin kann
|
||
&\#123;&\#123;content&\#125;&\#125; als Platzhalter fuer den Content des
|
||
textile-Files benutzt werden. In die index.textile kommt dann das Markup
|
||
rein. Mit &\#123;&\#123;toc&\#125;&\#125; kann in diesem File eine
|
||
Inhaltsangabe aus den `h[1-3].` erstellt werden.
|
||
|
||
Speichert einfach das folgende Script in einer Datei und ruft es mit
|
||
ruby auf und schon bekommt ihr euer textile umgewandelt.
|
||
|
||
<source:ruby>\# To change this template, choose Tools | Templates\
|
||
\# and open the template in the editor.
|
||
|
||
require ‘rubygems’\
|
||
require ‘redcloth’\
|
||
require ‘coderay’\
|
||
require ‘redclothcoderay’
|
||
|
||
RedclothCoderay.coderay\_options :css =\> :class\
|
||
search\_headlines = /h([1-3])\.
|
||
s(.
|
||
*)/
|
||
|
||
def build\_menu array, depth\
|
||
result = “”\
|
||
if array.length \> 0 then\
|
||
array.each do |el|\
|
||
result \<\< ‘**’** (depth + 1) +’ "‘+
|
||
el[:bez]*“\":\#\#{el[:bez].gsub(/\\s/,‘\_’)}\\n”\
|
||
if el.length \> 0 then\
|
||
result \<\< build\_menu\
|
||
end\
|
||
end\
|
||
end\
|
||
result\
|
||
end
|
||
\
|
||
File.open ’index.html’, ’w’ do |file|\
|
||
index = File.read\
|
||
code = File.read\
|
||
toc = \
|
||
if match[0] 1.to\_s then
|
||
toc \<\< {:bez =\> match[1], :toc =\> []}
|
||
elsif match[0] 2.to\_s then\
|
||
toc.last \<\< \
|
||
elsif match[0] == 3.to\_s then\
|
||
toc.last.last \<\< \
|
||
end\
|
||
’h’*match[0]+’(\#‘+match[1].gsub(/\\s/,’\_‘)*’). ’*match[1]\
|
||
end\
|
||
code = code.gsub(/{{toc}}/, build\_menu(toc, 0)+“\n”)\
|
||
file.write(index.gsub /{{content}}/, RedCloth.new(code).to\_html)\
|
||
end\
|
||
puts ’ready’</source>
|