Sha256: 5a65f46193a7a4aeff22ef85f1ab210726809f608326cc7a766c062f10cca041

Contents?: true

Size: 1.83 KB

Versions: 24

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
begin
  require 'newgem'
rescue LoadError
  puts "\n\nGenerating the website requires the newgem RubyGem"
  puts "Install: gem install newgem\n\n"
  exit(1)
end
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'
require File.dirname(__FILE__) + '/../lib/sproutcore/version.rb'

version  = SproutCore::VERSION::STRING
download = 'http://rubyforge.org/projects/sproutcore'

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.join(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=['"]([^'"]+)[^>]*>(.*?)</\1>!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

24 entries across 24 versions & 1 rubygems

Version Path
sproutcore-0.9.10 script/txt2html
sproutcore-0.9.12 script/txt2html
sproutcore-0.9.11 script/txt2html
sproutcore-0.9.1 script/txt2html
sproutcore-0.9.0 script/txt2html
sproutcore-0.9.14 script/txt2html
sproutcore-0.9.15 script/txt2html
sproutcore-0.9.13 script/txt2html
sproutcore-0.9.16 script/txt2html
sproutcore-0.9.18 script/txt2html
sproutcore-0.9.19 script/txt2html
sproutcore-0.9.17 script/txt2html
sproutcore-0.9.2 script/txt2html
sproutcore-0.9.21 script/txt2html
sproutcore-0.9.20 script/txt2html
sproutcore-0.9.23 script/txt2html
sproutcore-0.9.22 script/txt2html
sproutcore-0.9.5 script/txt2html
sproutcore-0.9.3 script/txt2html
sproutcore-0.9.4 script/txt2html