Sha256: 9472799f7acadf97f34439011fbb1cb75a1a49077a641c2c332c830b3aa68606

Contents?: true

Size: 1.64 KB

Versions: 32

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'
require File.dirname(__FILE__) + '/../lib/rad/version.rb'

version  = Rad::VERSION::STRING
download = 'http://rubyforge.org/projects/rad'

class Fixnum
  def ordinal
    # teens
    return 'th' if (10..19).include?(self % 100)
    # others
    case self % 10
    when 1: return 'st'
    when 2: return 'nd'
    when 3: return 'rd'
    else    return 'th'
    end
  end
end

class Time
  def pretty
    return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
  end
end

def convert_syntax(syntax, source)
  return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
end

if ARGV.length >= 1
  src, template = ARGV
  template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
  
else
  puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
  exit!
end

template = ERB.new(File.open(template).read)

title = nil
body = nil
File.open(src) do |fsrc|
  title_text = fsrc.readline
  body_text = fsrc.read
  syntax_items = []
  body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
    ident = syntax_items.length
    element, syntax, source = $1, $2, $3
    syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
    "syntax-temp-#{ident}"
  }
  title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
  body = RedCloth.new(body_text).to_html
  body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
end
stat = File.stat(src)
created = stat.ctime
modified = stat.mtime

$stdout << template.result(binding)

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
neo_rad-0.4.0 scripts/txt2html
atduskgreg-rad-0.2.5 scripts/txt2html
atduskgreg-rad-0.3.0.1 scripts/txt2html
atduskgreg-rad-0.3.1 scripts/txt2html
madrona-rad-0.2.2 scripts/txt2html
madrona-rad-0.2.3 scripts/txt2html
madrona-rad-0.2.4 scripts/txt2html
madrona-rad-0.2.5 scripts/txt2html
madrona-rad-0.2.6 scripts/txt2html
madrona-rad-0.2.7 scripts/txt2html
madrona-rad-0.3.1.1 scripts/txt2html
madrona-rad-0.3.1 scripts/txt2html
madrona-rad-0.3.2 scripts/txt2html
madrona-rad-0.3.3 scripts/txt2html
madrona-rad-0.3.4 scripts/txt2html
madrona-rad-0.3.5 scripts/txt2html
madrona-rad-0.3.6 scripts/txt2html
madrona-rad-0.3.7 scripts/txt2html
madrona-rad-0.3.8 scripts/txt2html
madrona-rad-0.3.9 scripts/txt2html