autoreload 0.3.1 → 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/.gitignore +6 -0
- data/.ruby +31 -26
- data/.yardopts +5 -0
- data/Assembly +40 -0
- data/COPYING.rdoc +371 -12
- data/HISTORY.rdoc +40 -0
- data/MANIFEST +14 -0
- data/PROFILE +28 -0
- data/README.rdoc +31 -17
- data/Rakefile +9 -0
- data/VERSION +1 -0
- data/autoreload.gemspec +143 -0
- data/lib/autoreload.rb +3 -2
- data/lib/autoreload/reloader.rb +46 -33
- data/lib/autoreload/version.rb +1 -1
- data/site/assets/icon.png +0 -0
- data/site/assets/screen.css +149 -0
- data/site/index.html +135 -0
- data/site/index.page +80 -0
- data/site/template.layout +77 -0
- data/spec/autoreload_spec.rb +8 -29
- data/spec/helper.rb +29 -0
- data/spec/require_spec.rb +37 -0
- data/try/changeme.rb +5 -0
- data/try/start.rb +20 -0
- data/work/autoreload.rb +115 -0
- data/work/consider/autoreload.rb +115 -0
- data/work/deprecated/Changes.txt +56 -0
- data/work/deprecated/Rakefile +80 -0
- data/work/deprecated/default_task.rb +129 -0
- data/work/deprecated/lookup.rb +174 -0
- data/work/deprecated/meta/authors +2 -0
- data/work/deprecated/meta/description +3 -0
- data/work/deprecated/meta/name +1 -0
- data/work/deprecated/meta/summary +1 -0
- data/work/deprecated/meta/version +1 -0
- data/work/deprecated/scripts/lib-txt2html.rb +133 -0
- data/work/deprecated/scripts/makemanifest.rb +20 -0
- data/work/deprecated/scripts/txt2html +10 -0
- data/work/deprecated/setup.rb +1585 -0
- metadata +59 -30
- data/GPL3.txt +0 -674
- data/lib/autoreload/lookup.rb +0 -91
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
require File.join(File.dirname(__FILE__), 'default_task')
|
4
|
+
require File.join(File.dirname(__FILE__), 'lib', 'autoreload')
|
5
|
+
|
6
|
+
AUTHOR = 'FIXME full name' # can also be an array of Authors
|
7
|
+
EMAIL = "FIXME email"
|
8
|
+
DESCRIPTION = "description of gem"
|
9
|
+
GEM_NAME = 'autoreload' # what ppl will type to install your gem
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
def rubyforge_username
|
14
|
+
unless @config
|
15
|
+
begin
|
16
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
17
|
+
rescue
|
18
|
+
puts <<-EOS
|
19
|
+
ERROR: No rubyforge config file found: #{@config_file}"
|
20
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
21
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
22
|
+
EOS
|
23
|
+
# "
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@rubyforge_username ||= @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
RUBYFORGE_PROJECT = 'autoreload' # The unix name for your project
|
31
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
32
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
33
|
+
|
34
|
+
NAME = "autoreload"
|
35
|
+
REV = nil
|
36
|
+
# UNCOMMENT IF REQUIRED:
|
37
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
38
|
+
VERS = AutoReload::VERSION::STRING + (REV ? ".#{REV}" : "")
|
39
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
|
40
|
+
RDOC_OPTS = ['--quiet', '--title', 'autoreload documentation',
|
41
|
+
"--opname", "index.html",
|
42
|
+
"--line-numbers",
|
43
|
+
"--main", "README",
|
44
|
+
"--inline-source"]
|
45
|
+
|
46
|
+
# Generate all the Rake tasks
|
47
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
48
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
49
|
+
p.author = AUTHOR
|
50
|
+
p.description = DESCRIPTION
|
51
|
+
p.email = EMAIL
|
52
|
+
p.summary = DESCRIPTION
|
53
|
+
p.url = HOMEPATH
|
54
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
55
|
+
p.test_globs = ["test/**/test_*.rb"]
|
56
|
+
p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
|
57
|
+
|
58
|
+
# == Optional
|
59
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
60
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
61
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
62
|
+
end
|
63
|
+
|
64
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
|
65
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
66
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
67
|
+
|
68
|
+
# clear current task
|
69
|
+
t = Rake.application.lookup(:install_gem)
|
70
|
+
t.clear_actions if t
|
71
|
+
|
72
|
+
# redefine task
|
73
|
+
task :install_gem => [:clean, :package] do
|
74
|
+
if /mswin32/ =~ RUBY_PLATFORM || /cygwin/ =~ RUBY_PLATFORM
|
75
|
+
sh "gem.cmd install pkg/*.gem" # for Cygwin
|
76
|
+
else
|
77
|
+
sh "sudo gem install pkg/*.gem"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'hoe'
|
10
|
+
begin
|
11
|
+
require 'spec/rake/spectask'
|
12
|
+
rescue LoadError
|
13
|
+
puts 'To use rspec for testing you must install rspec gem:'
|
14
|
+
puts '$ sudo gem install rspec'
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
class Hoe
|
19
|
+
def extra_deps
|
20
|
+
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Generate website files'
|
25
|
+
task :website_generate do
|
26
|
+
require 'scripts/lib-txt2html'
|
27
|
+
t2h = Txt2Html.new
|
28
|
+
Dir['website/**/*.txt'].each do |txt|
|
29
|
+
puts txt
|
30
|
+
version = VERS
|
31
|
+
download = DOWNLOAD_PATH
|
32
|
+
t2h.translate(txt, txt.gsub(/txt$/, 'html'), version, download)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# add chmod.
|
37
|
+
task :website_generate do
|
38
|
+
sh %{ chmod -R go+rx website }
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Upload website files to rubyforge'
|
42
|
+
task :website_upload do
|
43
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
44
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
45
|
+
local_dir = 'website'
|
46
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Generate and upload website files'
|
50
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
51
|
+
|
52
|
+
desc 'Release the website and new gem version'
|
53
|
+
task :deploy => [:check_version, :website, :release] do
|
54
|
+
puts "Remember to create SVN tag:"
|
55
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
56
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
57
|
+
puts "Suggested comment:"
|
58
|
+
puts "Tagging release #{CHANGES}"
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
62
|
+
task :local_deploy => [:website_generate, :install_gem]
|
63
|
+
|
64
|
+
task :check_version do
|
65
|
+
unless ENV['VERSION']
|
66
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
unless ENV['VERSION'] == VERS
|
70
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Run the specs under spec/models"
|
76
|
+
Spec::Rake::SpecTask.new do |t|
|
77
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
78
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
79
|
+
t.libs << "lib"
|
80
|
+
end
|
81
|
+
|
82
|
+
# add chmod.
|
83
|
+
task :docs do
|
84
|
+
sh %{ chmod -R go+rx doc }
|
85
|
+
end
|
86
|
+
|
87
|
+
# clear current task
|
88
|
+
module Rake
|
89
|
+
class Task
|
90
|
+
def clear_actions
|
91
|
+
@actions.clear
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
task :clean => [:chmod]
|
97
|
+
|
98
|
+
CHMOD644 = FileList[%w(
|
99
|
+
Rakefile Change*
|
100
|
+
**/*.txt
|
101
|
+
**/*.html
|
102
|
+
**/*.rhtml
|
103
|
+
**/*.js
|
104
|
+
**/*.css
|
105
|
+
**/*.rb
|
106
|
+
**/*.opts
|
107
|
+
)]
|
108
|
+
CHMOD755 = FileList[%w(scripts/*)]
|
109
|
+
|
110
|
+
desc 'Chmod all files.'
|
111
|
+
task :chmod do
|
112
|
+
CHMOD644.each {|f|
|
113
|
+
File.chmod 0644, f if File.exist? f
|
114
|
+
}
|
115
|
+
CHMOD755.each {|f|
|
116
|
+
File.chmod 0755, f if File.exist? f
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
desc 'Create Manifest.txt file.'
|
121
|
+
task :manifest => [:chmod, :clean] do
|
122
|
+
ruby "scripts/makemanifest.rb"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Add tasks to gem
|
126
|
+
task :gem => [:manifest]
|
127
|
+
|
128
|
+
desc "Default task is to run specs"
|
129
|
+
task :default => [:spec]
|
@@ -0,0 +1,174 @@
|
|
1
|
+
module AutoReload
|
2
|
+
|
3
|
+
# = Library Lookup
|
4
|
+
#
|
5
|
+
# This library is a slightly modified copy of the +plugin+ library.
|
6
|
+
#
|
7
|
+
module Lookup
|
8
|
+
|
9
|
+
extend self
|
10
|
+
|
11
|
+
# Find plugins, searching through standard $LOAD_PATH,
|
12
|
+
# Roll Libraries and RubyGems.
|
13
|
+
#
|
14
|
+
# Provide a +match+ file glob to find plugins.
|
15
|
+
#
|
16
|
+
# Lookup.find('syckle/*')
|
17
|
+
#
|
18
|
+
def find(match, options={})
|
19
|
+
plugins = []
|
20
|
+
plugins.concat find_roll(match, options)
|
21
|
+
plugins.concat find_loadpath(match, options)
|
22
|
+
plugins.concat find_gems(match, options)
|
23
|
+
plugins.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
# Shortcut for #find.
|
27
|
+
#
|
28
|
+
# Lookup['syckle/*']
|
29
|
+
#
|
30
|
+
alias_method :[], :find
|
31
|
+
|
32
|
+
# Search roll for current or latest libraries.
|
33
|
+
def find_roll(match, options={})
|
34
|
+
plugins = []
|
35
|
+
#directory = options[:directory] || DIRECTORY
|
36
|
+
if defined?(::Roll)
|
37
|
+
# Not ::Roll::Library ?
|
38
|
+
::Library.ledger.each do |name, lib|
|
39
|
+
lib = lib.sort.first if Array===lib
|
40
|
+
lib.loadpath.each do |path|
|
41
|
+
#find = File.join(lib.location, path, directory, match)
|
42
|
+
find = File.join(lib.location, path, match)
|
43
|
+
list = Dir.glob(find)
|
44
|
+
list = list.map{ |d| d.chomp('/') }
|
45
|
+
plugins.concat(list)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
plugins
|
50
|
+
end
|
51
|
+
|
52
|
+
# Search standard $LOAD_PATH.
|
53
|
+
#
|
54
|
+
# Activated gem versions are in here too.
|
55
|
+
|
56
|
+
def find_loadpath(match, options={})
|
57
|
+
plugins = []
|
58
|
+
#directory = options[:directory] || DIRECTORY
|
59
|
+
$LOAD_PATH.uniq.each do |path|
|
60
|
+
path = File.expand_path(path)
|
61
|
+
#list = Dir.glob(File.join(path, directory, match))
|
62
|
+
list = Dir.glob(File.join(path, match))
|
63
|
+
list = list.map{ |d| d.chomp('/') }
|
64
|
+
plugins.concat(list)
|
65
|
+
end
|
66
|
+
plugins
|
67
|
+
end
|
68
|
+
|
69
|
+
# # Search latest gem versions.
|
70
|
+
# #
|
71
|
+
# # TODO: Is there anyway to skip active gems?
|
72
|
+
#
|
73
|
+
# def find_gems(match, options={})
|
74
|
+
# plugins = []
|
75
|
+
# #directory = options[:directory] || DIRECTORY
|
76
|
+
# if defined?(::Gem)
|
77
|
+
# ::Gem.latest_load_paths do |path|
|
78
|
+
# #list = Dir.glob(File.join(path, directory, match))
|
79
|
+
# list = Dir.glob(File.join(path, match))
|
80
|
+
# list = list.map{ |d| d.chomp('/') }
|
81
|
+
# plugins.concat(list)
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# plugins
|
85
|
+
# end
|
86
|
+
|
87
|
+
# Find the highest versions of unactived gems.
|
88
|
+
#
|
89
|
+
# TODO: Skip active gems.
|
90
|
+
#
|
91
|
+
# @returns Array<String>
|
92
|
+
def find_gems(match, options={})
|
93
|
+
#directory = options[:directory] || DIRECTORY
|
94
|
+
plugins = []
|
95
|
+
if defined?(::Gem)
|
96
|
+
latest_load_paths = []
|
97
|
+
Gem.path.each do |path|
|
98
|
+
libs = Dir[File.join(path, 'gems', '*', 'lib')]
|
99
|
+
latest_load_paths.concat(libs)
|
100
|
+
end
|
101
|
+
latest_load_paths.sort!{ |a,b| natcmp(a,b) }
|
102
|
+
# TODO: reduce latest_load_paths to highest versions
|
103
|
+
latest_load_paths.each do |path| #::Gem.latest_load_paths do |path|
|
104
|
+
#list = Dir.glob(File.join(path, directory, match))
|
105
|
+
list = Dir.glob(File.join(path, match))
|
106
|
+
list = list.map{ |d| d.chomp('/') }
|
107
|
+
plugins.concat(list)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
plugins
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
# 'Natural order' comparison of strings, e.g. ...
|
116
|
+
#
|
117
|
+
# "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
|
118
|
+
#
|
119
|
+
# which does not follow alphabetically. A secondary
|
120
|
+
# parameter, if set to _true_, makes the comparison
|
121
|
+
# case insensitive.
|
122
|
+
#
|
123
|
+
# "Hello.1".natcmp("Hello.10") #=> -1
|
124
|
+
#
|
125
|
+
# TODO: Invert case flag?
|
126
|
+
#
|
127
|
+
# CREDIT: Alan Davies, Martin Pool
|
128
|
+
|
129
|
+
def natcmp(str1, str2, caseInsensitive=false)
|
130
|
+
str1 = str1.dup
|
131
|
+
str2 = str2.dup
|
132
|
+
compareExpression = /^(\D*)(\d*)(.*)$/
|
133
|
+
|
134
|
+
if caseInsensitive
|
135
|
+
str1.downcase!
|
136
|
+
str2.downcase!
|
137
|
+
end
|
138
|
+
|
139
|
+
# -- remove all whitespace
|
140
|
+
str1.gsub!(/\s*/, '')
|
141
|
+
str2.gsub!(/\s*/, '')
|
142
|
+
|
143
|
+
while (str1.length > 0) or (str2.length > 0) do
|
144
|
+
# -- extract non-digits, digits and rest of string
|
145
|
+
str1 =~ compareExpression
|
146
|
+
chars1, num1, str1 = $1.dup, $2.dup, $3.dup
|
147
|
+
str2 =~ compareExpression
|
148
|
+
chars2, num2, str2 = $1.dup, $2.dup, $3.dup
|
149
|
+
# -- compare the non-digits
|
150
|
+
case (chars1 <=> chars2)
|
151
|
+
when 0 # Non-digits are the same, compare the digits...
|
152
|
+
# If either number begins with a zero, then compare alphabetically,
|
153
|
+
# otherwise compare numerically
|
154
|
+
if (num1[0] != 48) and (num2[0] != 48)
|
155
|
+
num1, num2 = num1.to_i, num2.to_i
|
156
|
+
end
|
157
|
+
case (num1 <=> num2)
|
158
|
+
when -1 then return -1
|
159
|
+
when 1 then return 1
|
160
|
+
end
|
161
|
+
when -1 then return -1
|
162
|
+
when 1 then return 1
|
163
|
+
end # case
|
164
|
+
end # while
|
165
|
+
|
166
|
+
# -- strings are naturally equal
|
167
|
+
return 0
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
# Copyright (C) 2010 Thomas Sawyer
|
@@ -0,0 +1 @@
|
|
1
|
+
autoreload
|
@@ -0,0 +1 @@
|
|
1
|
+
Automatically reload library files.
|
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'redcloth'
|
5
|
+
require 'syntax/convertors/html'
|
6
|
+
require 'erb'
|
7
|
+
|
8
|
+
class Fixnum
|
9
|
+
def ordinal
|
10
|
+
# teens
|
11
|
+
return 'th' if (10..19).include?(self % 100)
|
12
|
+
# others
|
13
|
+
case self % 10
|
14
|
+
when 1: return 'st'
|
15
|
+
when 2: return 'nd'
|
16
|
+
when 3: return 'rd'
|
17
|
+
else return 'th'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Time
|
23
|
+
def pretty
|
24
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Txt2Html
|
29
|
+
def self.main(argv)
|
30
|
+
self.new.main(argv)
|
31
|
+
end
|
32
|
+
|
33
|
+
DEFAULT_TEMPLATE = File.dirname(__FILE__) + '/../website/template.rhtml'
|
34
|
+
|
35
|
+
def main(argv)
|
36
|
+
if argv.length >= 1
|
37
|
+
src, template = argv
|
38
|
+
template ||= DEFAULT_TEMPLATE
|
39
|
+
else
|
40
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
41
|
+
exit!
|
42
|
+
end
|
43
|
+
|
44
|
+
version = VERS
|
45
|
+
download = DOWNLOAD_PATH
|
46
|
+
result = generate2(template, src, version, download)
|
47
|
+
$stdout << result
|
48
|
+
end
|
49
|
+
|
50
|
+
def translate(src, dest, version, download)
|
51
|
+
template = DEFAULT_TEMPLATE
|
52
|
+
result = generate2(template, src, version, download)
|
53
|
+
File.open(dest, 'wb') {|f| f.print result }
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate2(template, src, version, download)
|
57
|
+
template_text = File.open(template).read
|
58
|
+
src_text = File.open(src) {|fsrc| fsrc.read }
|
59
|
+
modified = File.stat(src).mtime
|
60
|
+
result = generate(template_text, src_text, modified, version, download)
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate(template_text, src_text, modified, version, download)
|
64
|
+
title_text, body_text = parse_title_body(src_text)
|
65
|
+
title = create_title(title_text)
|
66
|
+
body = create_body(body_text)
|
67
|
+
template = ERB.new(template_text)
|
68
|
+
result = template.result(binding)
|
69
|
+
return result
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_title_body(str)
|
73
|
+
/\A(.*?)\n(.*)/m =~ str
|
74
|
+
return $1, $2
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_title(title_text)
|
78
|
+
return RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_body(body_text)
|
82
|
+
syntax_items = []
|
83
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m) {
|
84
|
+
ident = syntax_items.length
|
85
|
+
element, syntax, source = $1, $2, $3
|
86
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
87
|
+
"syntax-temp-#{ident}"
|
88
|
+
}
|
89
|
+
body = RedCloth.new(body_text).to_html
|
90
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
91
|
+
return body
|
92
|
+
end
|
93
|
+
|
94
|
+
def convert_syntax(syntax, source)
|
95
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!, '')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if $0 == __FILE__
|
100
|
+
require "test/unit"
|
101
|
+
$__test_txt2html__ = true
|
102
|
+
end
|
103
|
+
|
104
|
+
if defined?($__test_txt2html__) && $__test_txt2html__
|
105
|
+
class TestTxt2Html < Test::Unit::TestCase #:nodoc:
|
106
|
+
def test_fixnum_ordinal
|
107
|
+
assert_equal 'st', 1.ordinal
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_time_pretty
|
111
|
+
assert_equal '1st January 1970', Time.at(0).pretty
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_all
|
115
|
+
# test_txt2html
|
116
|
+
t2h = Txt2Html.new
|
117
|
+
|
118
|
+
# test_parse_title_body
|
119
|
+
assert_equal ["title", "body\n"], t2h.parse_title_body("title\nbody\n")
|
120
|
+
assert_equal ["title", "b\nb\n"], t2h.parse_title_body("title\nb\nb\n")
|
121
|
+
|
122
|
+
# test_create_title
|
123
|
+
assert_equal 'title', t2h.create_title('h1. title')
|
124
|
+
|
125
|
+
# test_create_body
|
126
|
+
assert_equal '<h2>body</h2>', t2h.create_body('h2. body')
|
127
|
+
|
128
|
+
# test_convert_syntax
|
129
|
+
assert_equal '<span class="number">0</span>',
|
130
|
+
t2h.convert_syntax('ruby', '0')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|