Sha256: fc716d1425996eb04a1890ee0545f5bebc85bf955bd2774b7dc08ceeebfe4c3c

Contents?: true

Size: 1.82 KB

Versions: 299

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

load File.dirname(__FILE__) + "/../Rakefile"
require 'rubyforge'
require 'redcloth'
require 'syntax/convertors/html'
require 'erb'

download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
version  = $hoe.version

def rubyforge_project_id
  RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
end

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.html.erb')
else
  puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > 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_template = fsrc.read
  body_text = ERB.new(body_text_template).result(binding)
  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

299 entries across 279 versions & 58 rubygems

Version Path
workpattern-0.6.0 script/txt2html
workpattern-0.5.0 script/txt2html
random_data_despegar-2.1 script/txt2html
activefacts-1.6.0 script/txt2html
activefacts-1.5.3 script/txt2html
activefacts-1.5.2 script/txt2html
activefacts-1.5.1 script/txt2html
activefacts-1.5.0 script/txt2html
activefacts-1.3.0 script/txt2html
activefacts-1.2.1 script/txt2html
activefacts-1.2.0 script/txt2html
activefacts-1.1.0 script/txt2html
activefacts-1.0.2 script/txt2html
activefacts-1.0.1 script/txt2html
activefacts-1.0.0 script/txt2html
agilisto-smartcall-0.0.1 script/txt2html
hookercookerman-amee-0.0.2 script/txt2html
hookercookerman-amee-0.0.3 script/txt2html
hookercookerman-amee-0.0.4 script/txt2html
hookercookerman-amee-0.0.5 script/txt2html