Sha256: bd6b0dce4a98517e1048fe35b7de01d55970d8595eb561da8cb91bab833a525e

Contents?: true

Size: 1.81 KB

Versions: 82

Compression:

Stored size: 1.81 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
gem 'RedCloth'
gem 'syntax'

require 'redcloth'
require 'syntax/convertors/html'
require 'erb'

version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
require File.expand_path(version_path)

version  = CompositePrimaryKeys::VERSION::STRING
download = 'http://rubygems.org/gems/composite_primary_keys'

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

82 entries across 82 versions & 1 rubygems

Version Path
composite_primary_keys-11.0.0.beta4 scripts/txt2html
composite_primary_keys-11.0.0.beta3 scripts/txt2html
composite_primary_keys-11.0.0.beta2 scripts/txt2html
composite_primary_keys-11.0.0.beta1 scripts/txt2html
composite_primary_keys-10.0.2 scripts/txt2html
composite_primary_keys-10.0.1 scripts/txt2html
composite_primary_keys-9.0.8 scripts/txt2html
composite_primary_keys-10.0.0 scripts/txt2html
composite_primary_keys-9.0.7 scripts/txt2html
composite_primary_keys-8.1.6 scripts/txt2html
composite_primary_keys-9.0.6 scripts/txt2html
composite_primary_keys-9.0.5 scripts/txt2html
composite_primary_keys-8.1.5 scripts/txt2html
composite_primary_keys-9.0.4 scripts/txt2html
composite_primary_keys-9.0.2 scripts/txt2html
composite_primary_keys-9.0.1 scripts/txt2html
composite_primary_keys-8.1.4 scripts/txt2html
composite_primary_keys-9.0.0 scripts/txt2html
composite_primary_keys-9.0.0.beta1 scripts/txt2html
composite_primary_keys-8.1.3 scripts/txt2html