serve 0.9.10 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → CHANGELOG.rdoc} +9 -0
- data/{License.txt → LICENSE} +1 -1
- data/{Quickstart.textile → QUICKSTART.rdoc} +61 -80
- data/{README.txt → README.rdoc} +10 -13
- data/Rakefile +11 -13
- data/VERSION +1 -0
- data/bin/serve +6 -0
- data/lib/serve.rb +2 -8
- data/lib/serve/application.rb +13 -6
- data/lib/serve/file_resolver.rb +48 -0
- data/lib/serve/handlers/dynamic_handler.rb +31 -21
- data/lib/serve/handlers/file_type_handler.rb +23 -32
- data/lib/serve/handlers/markdown_handler.rb +1 -1
- data/lib/serve/handlers/redirect_handler.rb +6 -5
- data/lib/serve/handlers/sass_handler.rb +4 -3
- data/lib/serve/rack.rb +57 -0
- data/lib/serve/rails.rb +4 -0
- data/lib/serve/rails/configuration.rb +69 -0
- data/lib/serve/rails/mount.rb +38 -0
- data/lib/serve/rails/routing.rb +25 -0
- data/lib/serve/rails/serve_controller.rb +52 -0
- data/lib/serve/response_cache.rb +170 -0
- data/lib/serve/version.rb +4 -9
- data/lib/serve/webrick/extensions.rb +80 -15
- data/lib/serve/webrick/server.rb +17 -0
- data/lib/serve/webrick/servlet.rb +19 -0
- data/rails/init.rb +6 -0
- data/spec/{serve_application_spec.rb → application_spec.rb} +5 -4
- data/spec/response_cache_spec.rb +248 -0
- data/spec/serve_spec.rb +1 -0
- data/spec/spec_helper.rb +10 -9
- metadata +51 -69
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -44
- data/config/hoe.rb +0 -70
- data/config/requirements.rb +0 -17
- data/log/debug.log +0 -0
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -74
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -27
- data/tasks/environment.rake +0 -7
- data/tasks/rspec.rake +0 -21
- data/tasks/undefine.rake +0 -5
- data/tasks/website.rake +0 -17
- data/test_project/_layout.haml +0 -12
- data/test_project/erb/_footer.html.erb +0 -2
- data/test_project/erb/_layout.html.erb +0 -28
- data/test_project/erb/index.html.erb +0 -10
- data/test_project/haml/_footer.haml +0 -2
- data/test_project/haml/_layout.haml +0 -20
- data/test_project/haml/index.haml +0 -9
- data/test_project/test.haml +0 -3
- data/test_project/test.html.erb +0 -3
- data/test_project/view_helpers.rb +0 -5
- metadata.gz.sig +0 -0
data/spec/serve_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
3
3
|
describe "Serve" do
|
4
4
|
|
5
5
|
it "should register all of the file type handlers" do
|
6
|
+
Serve::WEBrick::Server.register_handlers
|
6
7
|
handlers = ["cgi", "email", "erb", "haml", "html.erb", "html.haml", "markdown", "redirect", "rhtml", "sass", "textile"]
|
7
8
|
table = WEBrick::HTTPServlet::FileHandler::HandlerTable
|
8
9
|
table.keys.sort.should == handlers
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
gem 'rspec'
|
6
|
-
require 'spec'
|
7
|
-
end
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
2
|
|
9
|
-
|
3
|
+
require 'rubygems'
|
4
|
+
gem 'activesupport'
|
10
5
|
|
11
|
-
require 'serve'
|
6
|
+
require 'serve'
|
7
|
+
require 'spec'
|
8
|
+
require 'spec/autorun'
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John W. Long
|
8
|
+
- Adam I. Williams
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
- |
|
12
|
-
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQswCQYDVQQDDAJtZTEZ
|
14
|
-
MBcGCgmSJomT8ixkARkWCWpvaG53bG9uZzETMBEGCgmSJomT8ixkARkWA2NvbTAe
|
15
|
-
Fw0wNzA5MjUwNTA3MDNaFw0wODA5MjQwNTA3MDNaMD0xCzAJBgNVBAMMAm1lMRkw
|
16
|
-
FwYKCZImiZPyLGQBGRYJam9obndsb25nMRMwEQYKCZImiZPyLGQBGRYDY29tMIIB
|
17
|
-
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8MjmSgpGWiy+PyyumoFLnA/w
|
18
|
-
gOymrqEIoHwlNRV8Z2RcZkrUHuKnFcH8ShqRww+/1BBnDJlx2rGrQ8d2W75f+xKj
|
19
|
-
hxVwA+eFbLtpMMe1E0qfD69F2sQk5/+dB7WwtF4kI0vt/rHne4hYj7dN/OeJ248q
|
20
|
-
dfZbxohWzSlPg0zopxlQ7WuFjZKclkUNx9Euv7K04imu4i7Q5ThCldV3VVrBFqCq
|
21
|
-
VhI8lAeg7Yln1t6SaPLQ3AqQlq2hk8MA7APy4LdWaN03cunfKwkHVVwPaSD8ualr
|
22
|
-
wrBQsmIrc4f3h9hJq0Ri1u/k4B2CTxaRLA34mb7MrpwZo5RqFd3x512MJaqfhQID
|
23
|
-
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU2eSXhP+B
|
24
|
-
7zF3qc5Rrb75aLF7BXowDQYJKoZIhvcNAQEFBQADggEBAFdj2/TsGJSaeFXoMixS
|
25
|
-
ojVHMctKErQkA2pRM7URVyeLljJweAies3qlfpPSuUTcWFLpJf7+So1CNrU7OzXa
|
26
|
-
UNAIhlWzz+knSeMahQWyMQvNGW3nt07PEkaosVdsi/Y6hO+YKNiZicBFuKw7fFUl
|
27
|
-
1FQHJMmy4+bTXxWl6RUymFiDhIjagLHbr09igGHaIOptys1k7Fxpx3xBDNr/IC0H
|
28
|
-
c5GbUePwwNafnjsl9cQo3Xka285/d0IOT4grVUmAeLAh601oR/YGtsHDC7B0jWqq
|
29
|
-
S4yE0yydTjVFpgazHI/CP2fneTHKbaf+H6jwNRzKN9HtcDpP2yO0tYhtmMotuZUd
|
30
|
-
qXI=
|
31
|
-
-----END CERTIFICATE-----
|
11
|
+
cert_chain: []
|
32
12
|
|
33
|
-
date:
|
34
|
-
default_executable:
|
13
|
+
date: 2009-12-28 00:00:00 -05:00
|
14
|
+
default_executable: serve
|
35
15
|
dependencies:
|
36
16
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
17
|
+
name: activesupport
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.2
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
38
28
|
type: :development
|
39
29
|
version_requirement:
|
40
30
|
version_requirements: !ruby/object:Gem::Requirement
|
41
31
|
requirements:
|
42
32
|
- - ">="
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.
|
34
|
+
version: 1.2.9
|
45
35
|
version:
|
46
|
-
description: Serve is a small
|
36
|
+
description: Serve is a small web server (based on WEBrick) that makes it easy to serve ERB or HAML from any directory. Serve is an ideal tool for building HTML prototypes of Rails applications. Serve can also handle SASS, Textile, and Markdown if the appropriate gems are installed.
|
47
37
|
email: me@johnwlong.com
|
48
38
|
executables:
|
49
39
|
- serve
|
50
40
|
extensions: []
|
51
41
|
|
52
42
|
extra_rdoc_files:
|
53
|
-
-
|
54
|
-
-
|
55
|
-
- Manifest.txt
|
56
|
-
- README.txt
|
43
|
+
- LICENSE
|
44
|
+
- README.rdoc
|
57
45
|
files:
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
- README.txt
|
46
|
+
- CHANGELOG.rdoc
|
47
|
+
- LICENSE
|
48
|
+
- QUICKSTART.rdoc
|
49
|
+
- README.rdoc
|
63
50
|
- Rakefile
|
51
|
+
- VERSION
|
64
52
|
- bin/serve
|
65
|
-
- config/hoe.rb
|
66
|
-
- config/requirements.rb
|
67
53
|
- lib/serve.rb
|
68
54
|
- lib/serve/application.rb
|
55
|
+
- lib/serve/file_resolver.rb
|
69
56
|
- lib/serve/handlers/dynamic_handler.rb
|
70
57
|
- lib/serve/handlers/email_handler.rb
|
71
58
|
- lib/serve/handlers/file_type_handler.rb
|
@@ -73,38 +60,30 @@ files:
|
|
73
60
|
- lib/serve/handlers/redirect_handler.rb
|
74
61
|
- lib/serve/handlers/sass_handler.rb
|
75
62
|
- lib/serve/handlers/textile_handler.rb
|
63
|
+
- lib/serve/rack.rb
|
64
|
+
- lib/serve/rails.rb
|
65
|
+
- lib/serve/rails/configuration.rb
|
66
|
+
- lib/serve/rails/mount.rb
|
67
|
+
- lib/serve/rails/routing.rb
|
68
|
+
- lib/serve/rails/serve_controller.rb
|
69
|
+
- lib/serve/response_cache.rb
|
76
70
|
- lib/serve/version.rb
|
77
71
|
- lib/serve/webrick/extensions.rb
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
- spec/serve_application_spec.rb
|
72
|
+
- lib/serve/webrick/server.rb
|
73
|
+
- lib/serve/webrick/servlet.rb
|
74
|
+
- rails/init.rb
|
75
|
+
- spec/application_spec.rb
|
76
|
+
- spec/response_cache_spec.rb
|
84
77
|
- spec/serve_spec.rb
|
85
78
|
- spec/spec.opts
|
86
79
|
- spec/spec_helper.rb
|
87
|
-
- tasks/deployment.rake
|
88
|
-
- tasks/environment.rake
|
89
|
-
- tasks/rspec.rake
|
90
|
-
- tasks/undefine.rake
|
91
|
-
- tasks/website.rake
|
92
|
-
- test_project/_layout.haml
|
93
|
-
- test_project/erb/_layout.html.erb
|
94
|
-
- test_project/erb/_footer.html.erb
|
95
|
-
- test_project/erb/index.html.erb
|
96
|
-
- test_project/haml/_footer.haml
|
97
|
-
- test_project/haml/_layout.haml
|
98
|
-
- test_project/haml/index.haml
|
99
|
-
- test_project/test.haml
|
100
|
-
- test_project/test.html.erb
|
101
|
-
- test_project/view_helpers.rb
|
102
80
|
has_rdoc: true
|
103
|
-
homepage: http://serve
|
81
|
+
homepage: http://github.com/jlong/serve
|
82
|
+
licenses: []
|
83
|
+
|
104
84
|
post_install_message:
|
105
85
|
rdoc_options:
|
106
|
-
- --
|
107
|
-
- README.txt
|
86
|
+
- --charset=UTF-8
|
108
87
|
require_paths:
|
109
88
|
- lib
|
110
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -121,10 +100,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
100
|
version:
|
122
101
|
requirements: []
|
123
102
|
|
124
|
-
rubyforge_project:
|
125
|
-
rubygems_version: 1.
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.5
|
126
105
|
signing_key:
|
127
|
-
specification_version:
|
128
|
-
summary: Serve is a small
|
129
|
-
test_files:
|
130
|
-
|
106
|
+
specification_version: 3
|
107
|
+
summary: Serve is a small web server that makes it easy to serve ERB or HAML from any directory.
|
108
|
+
test_files:
|
109
|
+
- spec/application_spec.rb
|
110
|
+
- spec/response_cache_spec.rb
|
111
|
+
- spec/serve_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
data.tar.gz.sig
DELETED
Binary file
|
data/Manifest.txt
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
License.txt
|
3
|
-
Manifest.txt
|
4
|
-
Quickstart.textile
|
5
|
-
README.txt
|
6
|
-
Rakefile
|
7
|
-
bin/serve
|
8
|
-
config/hoe.rb
|
9
|
-
config/requirements.rb
|
10
|
-
lib/serve.rb
|
11
|
-
lib/serve/application.rb
|
12
|
-
lib/serve/handlers/dynamic_handler.rb
|
13
|
-
lib/serve/handlers/email_handler.rb
|
14
|
-
lib/serve/handlers/file_type_handler.rb
|
15
|
-
lib/serve/handlers/markdown_handler.rb
|
16
|
-
lib/serve/handlers/redirect_handler.rb
|
17
|
-
lib/serve/handlers/sass_handler.rb
|
18
|
-
lib/serve/handlers/textile_handler.rb
|
19
|
-
lib/serve/version.rb
|
20
|
-
lib/serve/webrick/extensions.rb
|
21
|
-
log/debug.log
|
22
|
-
script/destroy
|
23
|
-
script/generate
|
24
|
-
script/txt2html
|
25
|
-
setup.rb
|
26
|
-
spec/serve_application_spec.rb
|
27
|
-
spec/serve_spec.rb
|
28
|
-
spec/spec.opts
|
29
|
-
spec/spec_helper.rb
|
30
|
-
tasks/deployment.rake
|
31
|
-
tasks/environment.rake
|
32
|
-
tasks/rspec.rake
|
33
|
-
tasks/undefine.rake
|
34
|
-
tasks/website.rake
|
35
|
-
test_project/_layout.haml
|
36
|
-
test_project/erb/_layout.html.erb
|
37
|
-
test_project/erb/_footer.html.erb
|
38
|
-
test_project/erb/index.html.erb
|
39
|
-
test_project/haml/_footer.haml
|
40
|
-
test_project/haml/_layout.haml
|
41
|
-
test_project/haml/index.haml
|
42
|
-
test_project/test.haml
|
43
|
-
test_project/test.html.erb
|
44
|
-
test_project/view_helpers.rb
|
data/config/hoe.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'serve/version'
|
2
|
-
|
3
|
-
AUTHOR = 'John W. Long' # can also be an array of Authors
|
4
|
-
EMAIL = "me@johnwlong.com"
|
5
|
-
DESCRIPTION = "Serve is a small Ruby script that makes it easy to start up a WEBrick server in any directory. Serve is ideal for HTML prototyping and simple file sharing. If the haml, redcloth, and bluecloth gems are installed serve can handle Haml, Sass, Textile, and Markdown (in addition to HTML)."
|
6
|
-
GEM_NAME = 'serve' # what ppl will type to install your gem
|
7
|
-
RUBYFORGE_PROJECT = 'serve' # The unix name for your project
|
8
|
-
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
-
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
-
|
11
|
-
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
-
@config = nil
|
13
|
-
RUBYFORGE_USERNAME = "jlong"
|
14
|
-
def rubyforge_username
|
15
|
-
unless @config
|
16
|
-
begin
|
17
|
-
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
-
rescue
|
19
|
-
puts <<-EOS
|
20
|
-
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
-
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
-
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
-
EOS
|
24
|
-
exit
|
25
|
-
end
|
26
|
-
end
|
27
|
-
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
REV = nil
|
32
|
-
# UNCOMMENT IF REQUIRED:
|
33
|
-
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
-
VERS = Serve::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
-
RDOC_OPTS = ['--quiet', '--title', 'serve documentation',
|
36
|
-
"--opname", "index.html",
|
37
|
-
"--line-numbers",
|
38
|
-
"--main", "README.txt",
|
39
|
-
"--inline-source"]
|
40
|
-
|
41
|
-
class Hoe
|
42
|
-
def extra_deps
|
43
|
-
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
-
@extra_deps
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Generate all the Rake tasks
|
49
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
-
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
-
p.author = AUTHOR
|
52
|
-
p.description = DESCRIPTION
|
53
|
-
p.email = EMAIL
|
54
|
-
p.summary = DESCRIPTION
|
55
|
-
p.url = HOMEPATH
|
56
|
-
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
-
p.test_globs = ["test/**/test_*.rb"]
|
58
|
-
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
-
|
60
|
-
# == Optional
|
61
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
|
62
|
-
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
-
|
64
|
-
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
-
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
-
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
data/config/requirements.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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]))
|
16
|
-
|
17
|
-
require 'serve'
|
data/log/debug.log
DELETED
File without changes
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = 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]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = 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]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
DELETED
@@ -1,74 +0,0 @@
|
|
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/serve/version.rb'
|
15
|
-
|
16
|
-
version = Serve::VERSION::STRING
|
17
|
-
download = 'http://rubyforge.org/projects/serve'
|
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)
|