5 require 'syntax/convertors/html'
7 require File
.dirname(__FILE__
) + '/../lib/zcc/version.rb'
9 version = Zcc
::VERSION::STRING
10 download
= 'http://rubyforge.org/projects/zcc'
15 return 'th' if (10..19).include?(self % 100)
28 return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
32 def convert_syntax(syntax
, source
)
33 return Syntax
::Convertors::HTML.for_syntax(syntax
).convert(source
).gsub(%r
!^
<pre
>|</pre
>$
!,'')
38 template
||= File
.dirname(__FILE__
) + '/../website/template.rhtml'
41 puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
45 template
= ERB
.new(File
.open(template
).read
)
49 File
.open(src
) do |fsrc
|
50 title_text
= fsrc
.readline
53 body_text
.gsub
!(%r
!<(pre
|code
)[^
>]*?syntax
=['"]([^'"]+)[^>]*>(.*?)</\x01>!m){
54 ident = syntax_items.length
55 element, syntax, source = $1, $2, $3
56 syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57 "syntax-temp-#{ident}"
59 title
= RedCloth
.new(title_text
).to_html
.gsub(%r
!<.*?>!,'').strip
60 body
= RedCloth
.new(body_text
).to_html
61 body
.gsub
!(%r
!(?:<pre
><code
>)?syntax-temp-
(d
+)(?:</code></pre
>)?!){ syntax_items
[$1.to_i
] }
67 $stdout << template
.result(binding
)