VDS-Badges

Aus C3D2
Wechseln zu: Navigation, Suche

Generiert Schilder zum Umhängen auf der Demo gegen die Vorratsdatenspeicherung. Nutzung:

ruby vds-badges.rb 23 > vds-badges.fo && fop -fo vds-badges.fo -pdf vds-badges.pdf

Dabei sollte chaosknoten.jpg im Verzeichnis liegen. <source lang="ruby">

  1. !/usr/bin/env ruby

require 'cgi' NAMEN = ['Wolfgang Schäuble',

        'Rudolf Seiters',
        'Manfred Kanther',
        'Otto Schily',
        'Wolfgang Schäuble',
        'Heribert Rech',
        'Günther Beckstein',
        'Ehrhart Körting',
        'Jörg Schönbohm',
        'Willi Lemke',
        'Udo Nagel',
        'Volker Bouffier',
        'Lorenz Caffier',
        'Uwe Schünemann',
        'Ingo Wolf',
        'Karl Peter Bruch',
        'Klaus Meiser',
        'Albrecht Buttolo',
        'Holger Hövelmann',
        'Ralf Stegner',
        'Karl Heinz Gasser']

namen1 = NAMEN.collect { |n| n.split(' ')[0..-2].join(' ') } namen2 = NAMEN.collect { |n| n.split(' ')[-1] } class Array

 def any_one
   self[(rand * size)]
 end

end class Symbol

 def u2m
   to_s.gsub('_', '-')
 end

end class Fixnum

 def rjust(*a)
   to_s.rjust(*a)
 end

end class Builder

 def self.print
   puts '<?xml version="1.0" encoding="utf-8"?>'
   yield new($stdout)
   puts
 end
 def initialize(output)
   @o = output
 end
 def method_missing(fname, attrs={})
   @o << "<#{fname.u2m}"
   @o << attrs.collect { |k,v| " #{k}=\"#{CGI::escapeHTML(v)}\"" }.to_s
   if block_given?
     @o << '>'
     @o << yield.to_s
     @o << "</#{fname.u2m}>"
   else
     @o << '/>'
   end
   nil
 end

end class BadgeMaker

 def initialize(fo)
   @fo = fo
 end
 def make(text)
   @fo.page_sequence('master-reference' => 'A4') {
     @fo.static_content('flow-name' => 'xsl-region-after') {
       @fo.block('text-align' => 'right',
                 'margin-right' => '1cm') {
         @fo.external_graphic('src' => 'url("chaosknoten.jpg")',
                              'content-width' => '3cm',
                              'content-height' => '2.75cm')
       }
     }
     @fo.flow('font-size' => '2.5cm',
              'text-align' => 'center',
              'flow-name' => 'xsl-region-body') {
       @fo.block { text }
     }
   }
 end

end n = (ARGV.shift || 1).to_i XMLNS_FO = 'http://www.w3.org/1999/XSL/Format' Builder.print { |fo|

 fo.root('xmlns' => XMLNS_FO) {
   fo.layout_master_set {
     fo.simple_page_master('master-name' => 'A4',
                           'page-width' => '297mm',
                           'page-height' => '210mm') {
       fo.region_body('margin' => '1cm 1cm 1cm 1cm',
                      'display-align' => 'center')
       fo.region_after('extent' => '4cm',
                       'display-align' => 'after',
                       'margin-bottom' => '1.5cm')
     }
   }
   n.times {
     name = namen1.any_one + ' ' + namen2.any_one
     datum = ((rand * 29).to_i + 1).to_s + '.' +
             ((rand * 12).to_i + 1).to_s + '.' +
             ((rand * 5).to_i + 2008).to_s + ' um ' +
             (rand * 24).to_i.rjust(2, '0') + ':' +
             (rand * 60).to_i.rjust(2, '0') + ':' +
             (rand * 60).to_i.rjust(2, '0')
     text = case (rand * 5).to_i
            when 0
              "Hat am #{datum} #{name} angerufen"
            when 1
              "Hat am #{datum} eine E-Mail an #{name} geschrieben"
            when 2
              "Hat am #{datum} das Weblog von #{name} gelesen"
            when 3
              "Hat sich am #{datum} in der Nähe von #{name} aufgehalten"
            when 4
              "Hat am #{datum} eine Kurznachricht an #{name} gesendet"
            end
     BadgeMaker.new(fo).make(text)
   }
 }

} </source>


Speed metal coding 64x64.jpg
Rübÿ Spëëd Mëtäl Cödïng
Coders: Astro | Conny | Sven
Projects: CacaANSICam | Date Determinator | DVB-Scraping | Filmnächte-Scraping | GeeKal | Gruntmaster | Harvester | Hirn | Irb | Jargon-File | Ruby-MediaWiki | Miniwebserver | Momomoto | Pentabarf | Podcast-fetching | Ruby | Ruby-Geekend | Ruby und Ruby on Rails | Sedusa | VDS-Badges | Xmotoctl | Youtube-Scraping