scratch/content/html/en/blog/01_nanoc/uvtest.md
2010-03-30 16:39:12 +02:00

3.4 KiB

kind created_at title multiTitle multiSubTitle
article 01/02/2008 An ultraviolet test
en fr
Ultraviolet Ultraviolet
fr en
les test du plugin ruby ruby plugin tests

How to integrate Ultraviolet with nanoc

I searched on Internet and I founded some hits, but which work no more with the last nanoc version.

fr: J'ai cherché sur Internet et j'ai trouver plusieurs indications, malheureusement, elles ne sont plus d'actualité avec la dernière version de nanoc. :

First, you need to install Ultraviolet:

#!/usr/bin/zsh

wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.1.tar.gz tar zxvf onig-5.9.1.tar.gz cd onig-5.9.1 ./configure make sudo make install sudo gem install ultraviolet

newcorps

A ruby codeDu code Ruby

A first simple test. Voilà le premier exemple simple.

['1','2','3'].each{ |x| puts 'chiffre '+x }

Avec création et téléchargement de fichier. With file creation and download.

class UltraVioletFilter < Nanoc::Filter identifier :ultraviolet def run(content) require 'rio' require 'rubygems' require 'uv' code_rule = %r{((.+?)<}+%{/code>)}m content.gsub!(code_rule) do |full| # original, lang, filename, code = full[0], full[1], full[3], full[4] original, lang, filename, code = $1, $2, $4, $5 if lang =~ /^(zsh|bash|sh|csh|shell)$/ lang='shell-unix-generic' end # Create a plaintext file version for download. codeprefix='' codesuffix='' if filename webpath = '/Scratch/multi'+@page.path code_path = [@site.config[:output_dir], webpath, 'code'] url = webpath + 'code/' + filename if (url == @url) puts %{erreur de redo : #{url}} break end @url=url copy_text_to_file(code, filename, code_path) codeprefix=%{
\n} codesuffix=%{\n
} end # Substitute the un-highlighted code with the highlighted code. codeprefix+Uv.parse(code, "xhtml", lang, false, @site.config[:ultraviolet_theme])+codesuffix end content end
private
def copy_text_to_file(str, fname, dir)
    if @page_rep.name == :default then
        dest_rio = rio(dir).mkpath
        frio = rio(dir, fname).delete
        frio << str
        puts "\t\twrote file #{dir}/#{fname}"
    end
end

end

newcorps

A zsh code Du code zsh

Un exemple en zsh. J'ai fait en sorte de pouvoir utiliser le tag zsh au lieu du compliqué shell-unix-generic

A simple zsh example. I made some modification in order to use the zsh tag instead of the too much complicated shell-unix-generic

for fic in **/*(.); do if [[ ! -x $fic ]]; then chmod u+x $fic fi exec $fic done