scout 2.0.4 → 2.0.5
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/AUTHORS +4 -0
- data/{History.txt → CHANGELOG} +7 -3
- data/COPYING +340 -0
- data/INSTALL +18 -0
- data/{License.txt → LICENSE} +1 -2
- data/{README.txt → README} +21 -21
- data/Rakefile +158 -4
- data/TODO +6 -0
- data/lib/scout.rb +4 -1
- data/lib/scout/command.rb +1 -1
- data/lib/scout/server.rb +1 -1
- data/setup.rb +574 -799
- data/test/scout_test.rb +91 -0
- metadata +36 -57
- data/Manifest.txt +0 -33
- data/PostInstall.txt +0 -7
- data/config/hoe.rb +0 -73
- data/config/requirements.rb +0 -15
- data/lib/scout/version.rb +0 -9
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -82
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/test_helper.rb +0 -2
- data/test/test_scout.rb +0 -11
- data/website/index.html +0 -138
- data/website/index.txt +0 -81
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.html.erb +0 -48
data/test/scout_test.rb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require File.dirname(__FILE__) + '/../lib/scout'
|
|
3
|
+
require "logger"
|
|
4
|
+
|
|
5
|
+
class ScoutTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
SCOUT_TEST_SERVER = "http://localhost:4000/"
|
|
8
|
+
SCOUT_TEST_VALID_CLIENT_KEY = "valid key goes here"
|
|
9
|
+
SCOUT_TEST_VALID_PLUGIN_ID = "valid plugin id goes here"
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
@log = Logger.new('test.log')
|
|
13
|
+
@scout_server = create_scout_server(SCOUT_TEST_SERVER,
|
|
14
|
+
SCOUT_TEST_VALID_CLIENT_KEY)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def teardown
|
|
18
|
+
File.delete('test.log')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_create
|
|
22
|
+
assert @scout_server
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_should_initialize_new_server
|
|
26
|
+
["@history_file", "@client_key", "@logger", "@server", "@history"].each do |var|
|
|
27
|
+
assert @scout_server.instance_variables.include?(var)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_should_send_report
|
|
32
|
+
report = {:server_load => "99.99"}
|
|
33
|
+
assert_does_not_exit { @scout_server.send_report(report, SCOUT_TEST_VALID_PLUGIN_ID) }
|
|
34
|
+
assert_log_contains("Report sent")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_should_not_send_report_with_invalid_client_key
|
|
38
|
+
@scout_server_invalid_client_key = create_scout_server(SCOUT_TEST_SERVER,
|
|
39
|
+
"1111-2222-3333-4444-5555")
|
|
40
|
+
report = {:server_load => "99.99"}
|
|
41
|
+
assert_does_exit { @scout_server_invalid_client_key.send_report(report, SCOUT_TEST_VALID_PLUGIN_ID) }
|
|
42
|
+
assert_log_contains("Unable to send report to server")
|
|
43
|
+
assert_log_contains("An HTTP error occurred: exit")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_should_not_send_report_with_invalid_plugin_id
|
|
47
|
+
report = {:server_load => "99.99"}
|
|
48
|
+
assert_does_exit { @scout_server.send_report(report, 9999999999) }
|
|
49
|
+
assert_log_contains("Unable to send report to server")
|
|
50
|
+
assert_log_contains("An HTTP error occurred: exit")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_should_not_send_report_with_plugin_not_belonging_to_client
|
|
54
|
+
report = {:server_load => "99.99"}
|
|
55
|
+
assert_does_exit { @scout_server.send_report(report, 4) }
|
|
56
|
+
assert_log_contains("Unable to send report to server")
|
|
57
|
+
assert_log_contains("An HTTP error occurred: exit")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def create_scout_server(server, client_key, history=File.join("/tmp", "client_history.yaml"), logger=@log)
|
|
61
|
+
Scout::Server.new(server, client_key, history, logger)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def assert_log_contains(pattern)
|
|
65
|
+
@log_file = File.read('test.log')
|
|
66
|
+
assert @log_file.include?(pattern), "log does not include the pattern:\n#{pattern}\nlog contains:\n#{@log_file}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# asserts that the program actually exits, terminating.
|
|
70
|
+
def assert_does_exit(&block)
|
|
71
|
+
begin
|
|
72
|
+
yield
|
|
73
|
+
rescue SystemExit
|
|
74
|
+
assert true, "Expected program to not exit, but program did exit."
|
|
75
|
+
return
|
|
76
|
+
end
|
|
77
|
+
flunk "Expected program to exit, but program did not exit."
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# asserts that the program does not exit.
|
|
81
|
+
def assert_does_not_exit(&block)
|
|
82
|
+
begin
|
|
83
|
+
yield
|
|
84
|
+
rescue SystemExit
|
|
85
|
+
flunk "Expected program to not exit, but program did exit."
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
assert true, "Expected program to not exit, but program did exit."
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
metadata
CHANGED
|
@@ -1,88 +1,68 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: scout
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Highgroove Studios
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-07-
|
|
12
|
+
date: 2008-07-31 00:00:00 -04:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
17
|
-
type: :
|
|
16
|
+
name: elif
|
|
17
|
+
type: :runtime
|
|
18
18
|
version_requirement:
|
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
|
20
20
|
requirements:
|
|
21
21
|
- - ">="
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version:
|
|
23
|
+
version: "0"
|
|
24
24
|
version:
|
|
25
|
-
description: Scout
|
|
26
|
-
email:
|
|
27
|
-
- hello@highgroove.com
|
|
25
|
+
description: Scout makes monitoring and reporting on your web applications as flexible and simple as possible. Scout is a product of Highgroove Studios.
|
|
26
|
+
email: scout@highgroove.com
|
|
28
27
|
executables:
|
|
29
28
|
- scout
|
|
30
29
|
extensions: []
|
|
31
30
|
|
|
32
31
|
extra_rdoc_files:
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
32
|
+
- AUTHORS
|
|
33
|
+
- COPYING
|
|
34
|
+
- README
|
|
35
|
+
- INSTALL
|
|
36
|
+
- TODO
|
|
37
|
+
- CHANGELOG
|
|
38
|
+
- LICENSE
|
|
39
39
|
files:
|
|
40
|
-
- History.txt
|
|
41
|
-
- License.txt
|
|
42
|
-
- Manifest.txt
|
|
43
|
-
- PostInstall.txt
|
|
44
|
-
- README.txt
|
|
45
|
-
- Rakefile
|
|
46
|
-
- bin/scout
|
|
47
|
-
- config/hoe.rb
|
|
48
|
-
- config/requirements.rb
|
|
49
|
-
- lib/scout.rb
|
|
50
|
-
- lib/scout/version.rb
|
|
51
|
-
- lib/scout/server.rb
|
|
52
|
-
- lib/scout/plugin.rb
|
|
53
|
-
- lib/scout/command.rb
|
|
54
40
|
- lib/scout/command/clone.rb
|
|
55
41
|
- lib/scout/command/install.rb
|
|
56
42
|
- lib/scout/command/run.rb
|
|
57
43
|
- lib/scout/command/test.rb
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
44
|
+
- lib/scout/command.rb
|
|
45
|
+
- lib/scout/plugin.rb
|
|
46
|
+
- lib/scout/server.rb
|
|
47
|
+
- lib/scout.rb
|
|
48
|
+
- test/scout_test.rb
|
|
49
|
+
- Rakefile
|
|
62
50
|
- setup.rb
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
- website/javascripts/rounded_corners_lite.inc.js
|
|
71
|
-
- website/stylesheets/screen.css
|
|
72
|
-
- website/template.html.erb
|
|
51
|
+
- AUTHORS
|
|
52
|
+
- COPYING
|
|
53
|
+
- README
|
|
54
|
+
- INSTALL
|
|
55
|
+
- TODO
|
|
56
|
+
- CHANGELOG
|
|
57
|
+
- LICENSE
|
|
73
58
|
has_rdoc: true
|
|
74
|
-
homepage: http://
|
|
75
|
-
post_install_message:
|
|
76
|
-
|
|
77
|
-
For more information on scout, see http://scout.rubyforge.org
|
|
78
|
-
|
|
79
|
-
NOTE: Change this information in PostInstall.txt
|
|
80
|
-
You can also delete it if you don't want it.
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
homepage: http://scoutapp.com
|
|
60
|
+
post_install_message:
|
|
83
61
|
rdoc_options:
|
|
62
|
+
- --title
|
|
63
|
+
- Scout Client Documentation
|
|
84
64
|
- --main
|
|
85
|
-
- README
|
|
65
|
+
- README
|
|
86
66
|
require_paths:
|
|
87
67
|
- lib
|
|
88
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -103,7 +83,6 @@ rubyforge_project: scout
|
|
|
103
83
|
rubygems_version: 1.2.0
|
|
104
84
|
signing_key:
|
|
105
85
|
specification_version: 2
|
|
106
|
-
summary: Scout
|
|
107
|
-
test_files:
|
|
108
|
-
|
|
109
|
-
- test/test_scout.rb
|
|
86
|
+
summary: Scout makes monitoring and reporting on your web applications as flexible and simple as possible.
|
|
87
|
+
test_files: []
|
|
88
|
+
|
data/Manifest.txt
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
History.txt
|
|
2
|
-
License.txt
|
|
3
|
-
Manifest.txt
|
|
4
|
-
PostInstall.txt
|
|
5
|
-
README.txt
|
|
6
|
-
Rakefile
|
|
7
|
-
bin/scout
|
|
8
|
-
config/hoe.rb
|
|
9
|
-
config/requirements.rb
|
|
10
|
-
lib/scout.rb
|
|
11
|
-
lib/scout/version.rb
|
|
12
|
-
lib/scout/server.rb
|
|
13
|
-
lib/scout/plugin.rb
|
|
14
|
-
lib/scout/command.rb
|
|
15
|
-
lib/scout/command/clone.rb
|
|
16
|
-
lib/scout/command/install.rb
|
|
17
|
-
lib/scout/command/run.rb
|
|
18
|
-
lib/scout/command/test.rb
|
|
19
|
-
script/console
|
|
20
|
-
script/destroy
|
|
21
|
-
script/generate
|
|
22
|
-
script/txt2html
|
|
23
|
-
setup.rb
|
|
24
|
-
tasks/deployment.rake
|
|
25
|
-
tasks/environment.rake
|
|
26
|
-
tasks/website.rake
|
|
27
|
-
test/test_helper.rb
|
|
28
|
-
test/test_scout.rb
|
|
29
|
-
website/index.html
|
|
30
|
-
website/index.txt
|
|
31
|
-
website/javascripts/rounded_corners_lite.inc.js
|
|
32
|
-
website/stylesheets/screen.css
|
|
33
|
-
website/template.html.erb
|
data/PostInstall.txt
DELETED
data/config/hoe.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require 'scout/version'
|
|
2
|
-
|
|
3
|
-
AUTHOR = 'Charles Brian Quinn'
|
|
4
|
-
EMAIL = "hello@highgroove.com"
|
|
5
|
-
DESCRIPTION = "Scout is a simple web monitoring and reporting client. It can connect to a plugin server, download plugins (written in Ruby) and run them on at specified intervals."
|
|
6
|
-
GEM_NAME = 'scout'
|
|
7
|
-
RUBYFORGE_PROJECT = 'scout'
|
|
8
|
-
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
9
|
-
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
10
|
-
EXTRA_DEPENDENCIES = [
|
|
11
|
-
['elif', '>= 0.1.0']
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
@config_file = "~/.rubyforge/user-config.yml"
|
|
15
|
-
@config = nil
|
|
16
|
-
RUBYFORGE_USERNAME = "seebq"
|
|
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 = YAML.load(`svn info`)['Revision']
|
|
37
|
-
VERS = Scout::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
38
|
-
RDOC_OPTS = ['--quiet', '--title', 'scout 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
|
-
end
|
|
68
|
-
|
|
69
|
-
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
|
70
|
-
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
71
|
-
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
72
|
-
$hoe.rsync_args = '-av --delete --ignore-errors'
|
|
73
|
-
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
data/config/requirements.rb
DELETED
|
@@ -1,15 +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]))
|
data/lib/scout/version.rb
DELETED
data/script/console
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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/scout.rb'}"
|
|
9
|
-
puts "Loading scout gem"
|
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
GEM_NAME = 'scout' # what ppl will type to install your gem
|
|
4
|
-
RUBYFORGE_PROJECT = 'scout'
|
|
5
|
-
|
|
6
|
-
require 'rubygems'
|
|
7
|
-
begin
|
|
8
|
-
require 'newgem'
|
|
9
|
-
require 'rubyforge'
|
|
10
|
-
rescue LoadError
|
|
11
|
-
puts "\n\nGenerating the website requires the newgem RubyGem"
|
|
12
|
-
puts "Install: gem install newgem\n\n"
|
|
13
|
-
exit(1)
|
|
14
|
-
end
|
|
15
|
-
require 'redcloth'
|
|
16
|
-
require 'syntax/convertors/html'
|
|
17
|
-
require 'erb'
|
|
18
|
-
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
|
19
|
-
|
|
20
|
-
version = Scout::VERSION::STRING
|
|
21
|
-
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
22
|
-
|
|
23
|
-
def rubyforge_project_id
|
|
24
|
-
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Fixnum
|
|
28
|
-
def ordinal
|
|
29
|
-
# teens
|
|
30
|
-
return 'th' if (10..19).include?(self % 100)
|
|
31
|
-
# others
|
|
32
|
-
case self % 10
|
|
33
|
-
when 1: return 'st'
|
|
34
|
-
when 2: return 'nd'
|
|
35
|
-
when 3: return 'rd'
|
|
36
|
-
else return 'th'
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class Time
|
|
42
|
-
def pretty
|
|
43
|
-
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def convert_syntax(syntax, source)
|
|
48
|
-
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
if ARGV.length >= 1
|
|
52
|
-
src, template = ARGV
|
|
53
|
-
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
|
54
|
-
else
|
|
55
|
-
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
|
56
|
-
exit!
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
template = ERB.new(File.open(template).read)
|
|
60
|
-
|
|
61
|
-
title = nil
|
|
62
|
-
body = nil
|
|
63
|
-
File.open(src) do |fsrc|
|
|
64
|
-
title_text = fsrc.readline
|
|
65
|
-
body_text_template = fsrc.read
|
|
66
|
-
body_text = ERB.new(body_text_template).result(binding)
|
|
67
|
-
syntax_items = []
|
|
68
|
-
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
|
69
|
-
ident = syntax_items.length
|
|
70
|
-
element, syntax, source = $1, $2, $3
|
|
71
|
-
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
|
72
|
-
"syntax-temp-#{ident}"
|
|
73
|
-
}
|
|
74
|
-
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
|
75
|
-
body = RedCloth.new(body_text).to_html
|
|
76
|
-
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
|
77
|
-
end
|
|
78
|
-
stat = File.stat(src)
|
|
79
|
-
created = stat.ctime
|
|
80
|
-
modified = stat.mtime
|
|
81
|
-
|
|
82
|
-
$stdout << template.result(binding)
|