script/txt2html in newgem-0.23.1 vs script/txt2html in newgem-0.24.0
- old
+ new
@@ -1,12 +1,31 @@
#!/usr/bin/env ruby
+GEM_NAME = 'newgem' # what ppl will type to install your gem
+RUBYFORGE_PROJECT = 'newgem'
+
require 'rubygems'
+begin
+ require 'newgem'
+ require 'rubyforge'
+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/#{GEM_NAME}/version.rb"
+version = Newgem::VERSION::STRING
+download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
+
+def rubyforge_project_id
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
+end
+
class Fixnum
def ordinal
# teens
return 'th' if (10..19).include?(self % 100)
# others
@@ -27,19 +46,13 @@
def convert_syntax(syntax, source)
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
end
-require File.join(File.dirname(__FILE__), '/../lib/newgem/version.rb')
-
-version = Newgem::VERSION::STRING
-download = ENV['DOWNLOAD_PATH']
-
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
@@ -47,10 +60,11 @@
title = nil
body = nil
File.open(src) do |fsrc|
title_text = fsrc.readline
- body_text = fsrc.read
+ 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}>"