tranexp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +29 -0
- data/README.txt +120 -0
- data/Rakefile +4 -0
- data/bin/tranexp +9 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/tranexp/codes.rb +34 -0
- data/lib/tranexp/command.rb +7 -0
- data/lib/tranexp/http.rb +44 -0
- data/lib/tranexp/version.rb +9 -0
- data/lib/tranexp.rb +17 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_command.rb +10 -0
- data/test/test_helper.rb +16 -0
- data/test/test_tranexp_http.rb +38 -0
- data/website/index.html +190 -0
- data/website/index.txt +113 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +97 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Dr Nic Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
bin/tranexp
|
7
|
+
config/hoe.rb
|
8
|
+
config/requirements.rb
|
9
|
+
lib/tranexp.rb
|
10
|
+
lib/tranexp/codes.rb
|
11
|
+
lib/tranexp/command.rb
|
12
|
+
lib/tranexp/http.rb
|
13
|
+
lib/tranexp/version.rb
|
14
|
+
script/console
|
15
|
+
script/destroy
|
16
|
+
script/generate
|
17
|
+
script/txt2html
|
18
|
+
setup.rb
|
19
|
+
tasks/deployment.rake
|
20
|
+
tasks/environment.rake
|
21
|
+
tasks/website.rake
|
22
|
+
test/test_command.rb
|
23
|
+
test/test_helper.rb
|
24
|
+
test/test_tranexp_http.rb
|
25
|
+
website/index.html
|
26
|
+
website/index.txt
|
27
|
+
website/javascripts/rounded_corners_lite.inc.js
|
28
|
+
website/stylesheets/screen.css
|
29
|
+
website/template.rhtml
|
data/README.txt
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
= tranexp
|
2
|
+
|
3
|
+
* http://tranexp.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Translates words or phrases from one language to another, using
|
8
|
+
http://www.tranexp.com:2000/Translate/result.shtml
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
Has a command-line and API.
|
13
|
+
|
14
|
+
=== Command Line
|
15
|
+
|
16
|
+
To translate some text from Danish to English:
|
17
|
+
|
18
|
+
cat some_danish_text.txt | tranexp dan eng
|
19
|
+
|
20
|
+
echo "jeg ville like en flaske vin" | tranexp nor
|
21
|
+
I would like a bottle of wine
|
22
|
+
|
23
|
+
That is, you pass the input text via STDIN. The default target language is English ('eng').
|
24
|
+
|
25
|
+
=== API
|
26
|
+
|
27
|
+
To translate some text from English to Norwegian:
|
28
|
+
|
29
|
+
translate = Tranexp::Http.new
|
30
|
+
english = translate.translate("metoder", Tranexp::Http::Norwegian, Tranexp::Http::English)
|
31
|
+
english = translate.translate("metoder", "nor", "eng")
|
32
|
+
|
33
|
+
Or use the dynamic helper:
|
34
|
+
|
35
|
+
translate.from_nor_to_eng("metoder")
|
36
|
+
|
37
|
+
== SYNOPSIS
|
38
|
+
|
39
|
+
* Translates between the following languages:
|
40
|
+
"English" => "eng",
|
41
|
+
"BrazilianPortuguese" => "pob",
|
42
|
+
"Bulgarian" => "bul",
|
43
|
+
"Croatian" => "cro",
|
44
|
+
"Czech" => "che",
|
45
|
+
"Danish" => "dan",
|
46
|
+
"Dutch" => "dut",
|
47
|
+
"Spanish" => "spa",
|
48
|
+
"Finnish" => "fin",
|
49
|
+
"French" => "fre",
|
50
|
+
"German" => "ger",
|
51
|
+
"Greek" => "grk",
|
52
|
+
"Hungarian" => "hun",
|
53
|
+
"Icelandic" => "ice",
|
54
|
+
"Italian" => "ita",
|
55
|
+
"Japanese" => "jpn",
|
56
|
+
"Latin American Spanish" => "spl",
|
57
|
+
"Norwegian" => "nor",
|
58
|
+
"Filipino" => "tag",
|
59
|
+
"Polish" => "pol",
|
60
|
+
"Portuguese" => "poe",
|
61
|
+
"Romanian" => "rom",
|
62
|
+
"Russian" => "rus",
|
63
|
+
"Serbian" => "sel",
|
64
|
+
"Slovenian" => "slo",
|
65
|
+
"Swedish" => "swe",
|
66
|
+
"Welsh" => "wel",
|
67
|
+
"Turkish" => "tur",
|
68
|
+
"Latin" => "ltt"
|
69
|
+
|
70
|
+
Future versions might support the 2 character abbreviations for languages; currently
|
71
|
+
it just supports the 3 character codes used within tranexp.
|
72
|
+
|
73
|
+
== REQUIREMENTS:
|
74
|
+
|
75
|
+
* mechanize rubygem
|
76
|
+
* internet connection
|
77
|
+
|
78
|
+
== INSTALL:
|
79
|
+
|
80
|
+
* gem install tranexp
|
81
|
+
|
82
|
+
Or fetch the source from:
|
83
|
+
|
84
|
+
* github: http://github.com/drnic/tranexp/tree/master
|
85
|
+
|
86
|
+
git clone git://github.com/drnic/tranexp.git
|
87
|
+
cd tranexp
|
88
|
+
rake test
|
89
|
+
rake install_gem
|
90
|
+
|
91
|
+
* rubyforge: http://rubyforge.org/scm/?group_id=6064
|
92
|
+
|
93
|
+
git clone git://rubyforge.org/tranexp.git
|
94
|
+
cd tranexp
|
95
|
+
rake test
|
96
|
+
rake install_gem
|
97
|
+
|
98
|
+
|
99
|
+
== LICENSE:
|
100
|
+
|
101
|
+
Copyright (c) 2008 Dr Nic Williams
|
102
|
+
|
103
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
104
|
+
a copy of this software and associated documentation files (the
|
105
|
+
"Software"), to deal in the Software without restriction, including
|
106
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
107
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
108
|
+
permit persons to whom the Software is furnished to do so, subject to
|
109
|
+
the following conditions:
|
110
|
+
|
111
|
+
The above copyright notice and this permission notice shall be
|
112
|
+
included in all copies or substantial portions of the Software.
|
113
|
+
|
114
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
115
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
116
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
117
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
118
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
119
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
120
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/tranexp
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'tranexp/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Dr Nic Williams' # can also be an array of Authors
|
4
|
+
EMAIL = "drnicwilliams@gmail.com"
|
5
|
+
DESCRIPTION = "Uses tranexp.com to perform translations between languages"
|
6
|
+
GEM_NAME = 'tranexp' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'tranexp' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['mechanize', '>=0.7.5']
|
12
|
+
] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
37
|
+
VERS = Tranexp::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'tranexp documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
71
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
72
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
73
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Tranexp::Codes
|
2
|
+
@@codes = {
|
3
|
+
"English" => "eng",
|
4
|
+
"Brazilian Portuguese" => "pob",
|
5
|
+
"Bulgarian" => "bul",
|
6
|
+
"Croatian" => "cro",
|
7
|
+
"Czech" => "che",
|
8
|
+
"Danish" => "dan",
|
9
|
+
"Dutch" => "dut",
|
10
|
+
"Spanish" => "spa",
|
11
|
+
"Finnish" => "fin",
|
12
|
+
"French" => "fre",
|
13
|
+
"German" => "ger",
|
14
|
+
"Greek" => "grk",
|
15
|
+
"Hungarian" => "hun",
|
16
|
+
"Icelandic" => "ice",
|
17
|
+
"Italian" => "ita",
|
18
|
+
"Japanese" => "jpn",
|
19
|
+
"Latin American Spanish" => "spl",
|
20
|
+
"Norwegian" => "nor",
|
21
|
+
"Filipino" => "tag",
|
22
|
+
"Polish" => "pol",
|
23
|
+
"Portuguese" => "poe",
|
24
|
+
"Romanian" => "rom",
|
25
|
+
"Russian" => "rus",
|
26
|
+
"Serbian" => "sel",
|
27
|
+
"Slovenian" => "slo",
|
28
|
+
"Swedish" => "swe",
|
29
|
+
"Welsh" => "wel",
|
30
|
+
"Turkish" => "tur",
|
31
|
+
"Latin" => "ltt"
|
32
|
+
}
|
33
|
+
@@codes.each_pair { |name, code| self.const_set(name.gsub(/\s+/, ''), code) }
|
34
|
+
end
|
data/lib/tranexp/http.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
class Tranexp::Http
|
2
|
+
include Tranexp::Codes
|
3
|
+
PostURL = "http://www.tranexp.com:2000/Translate/result.shtml"
|
4
|
+
|
5
|
+
def translate(text, from, to="eng")
|
6
|
+
@agent ||= WWW::Mechanize.new
|
7
|
+
page = @agent.post(PostURL, {
|
8
|
+
:from => from,
|
9
|
+
:to => to,
|
10
|
+
:text => text,
|
11
|
+
:keyb => "non",
|
12
|
+
"Submit.x" => 33,
|
13
|
+
"Submit.y" => 9,
|
14
|
+
:translation => ""
|
15
|
+
})
|
16
|
+
clean_up page.forms[1]['translation']
|
17
|
+
end
|
18
|
+
|
19
|
+
# Support calls like #from_nor_to_eng, or #from_eng_to_
|
20
|
+
def method_missing(meth, *args, &blk)
|
21
|
+
if meth.to_s =~ /^from_([a-z]+)_to_([a-z]+)$/
|
22
|
+
from, to = $1, $2
|
23
|
+
return translate(args.first, from, to)
|
24
|
+
end
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def clean_up dirty_text
|
30
|
+
newstr = ""
|
31
|
+
dirty_text.length.times do |i|
|
32
|
+
character = dirty_text[i]
|
33
|
+
newstr += if character < 0x80
|
34
|
+
character.chr
|
35
|
+
elsif character < 0xC0
|
36
|
+
"\xC2" + character.chr
|
37
|
+
else
|
38
|
+
"\xC3" + (character - 64).chr
|
39
|
+
end
|
40
|
+
end
|
41
|
+
newstr
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/tranexp.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
$KCODE='u'
|
5
|
+
|
6
|
+
module Tranexp; end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'mechanize'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
gem 'mechanize', '>=0.7.5'
|
13
|
+
require 'mechanize'
|
14
|
+
end
|
15
|
+
|
16
|
+
require "tranexp/codes"
|
17
|
+
require "tranexp/http"
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/tranexp.rb'}"
|
9
|
+
puts "Loading tranexp gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/tranexp/version.rb'
|
15
|
+
|
16
|
+
version = Tranexp::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/tranexp'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|