cliaws 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +28 -0
- data/README.txt +75 -0
- data/Rakefile +4 -0
- data/bin/clis3 +98 -0
- data/config/hoe.rb +74 -0
- data/config/requirements.rb +15 -0
- data/lib/cliaws/s3.rb +50 -0
- data/lib/cliaws/version.rb +9 -0
- data/lib/cliaws.rb +17 -0
- data/log/.gitignore +0 -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_cliaws.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/website/index.html +93 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- data.tar.gz.sig +1 -0
- metadata +134 -0
- metadata.gz.sig +2 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
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,28 @@
|
|
1
|
+
.gitignore
|
2
|
+
History.txt
|
3
|
+
License.txt
|
4
|
+
Manifest.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/clis3
|
8
|
+
config/hoe.rb
|
9
|
+
config/requirements.rb
|
10
|
+
lib/cliaws.rb
|
11
|
+
lib/cliaws/s3.rb
|
12
|
+
lib/cliaws/version.rb
|
13
|
+
log/.gitignore
|
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_cliaws.rb
|
23
|
+
test/test_helper.rb
|
24
|
+
website/index.html
|
25
|
+
website/index.txt
|
26
|
+
website/javascripts/rounded_corners_lite.inc.js
|
27
|
+
website/stylesheets/screen.css
|
28
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= cliaws
|
2
|
+
|
3
|
+
* http://rubyforge.org/projects/cliaws
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A command-line client for Amazon Web Services.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Amazon keys are read from the environment only. They environment keys must
|
12
|
+
be named: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
|
13
|
+
* Minimal amount of error checking is done. Check the command's status after
|
14
|
+
each call.
|
15
|
+
* No logging.
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
|
19
|
+
Usage from the command line:
|
20
|
+
|
21
|
+
$ clis3 list my_awesome_bucket/a_glob
|
22
|
+
$ clis3 put my_awesome_bucket/a_key_name a_local_file
|
23
|
+
$ cat a_local_file | clis3 put my_awesome_bucket/a_key_name
|
24
|
+
$ clis3 put --data "this is the data" my_awesome_bucket/a_key_name
|
25
|
+
$ clis3 get my_awesome_bucket/a_key_name a_local_file
|
26
|
+
$ clis3 get my_awesome_bucket/a_key_name # Outputs to STDOUT
|
27
|
+
$ clis3 cat my_awesome_bucket/a_key_name # Outputs to STDOUT, but adds an extra newline
|
28
|
+
$ clis3 head my_awesome_bucket/a_key_name
|
29
|
+
# Returns a YAML representation of response and metadata headers
|
30
|
+
$ clis3 rm my_awesome_bucket/a_key_name
|
31
|
+
|
32
|
+
Cliaws may also be used from Ruby:
|
33
|
+
|
34
|
+
Cliaws.s3.list("my_awesome_bucket/a_glob") # Returns an array of names
|
35
|
+
Cliaws.s3.put(File.open("a_local_file", "rb"), "my_awesome_bucket/a_key_name")
|
36
|
+
Cliaws.s3.put(STDIN, "my_awesome_bucket/a_key_name")
|
37
|
+
Cliaws.s3.put("this is the data", "my_awesome_bucket/a_key_name")
|
38
|
+
Cliaws.s3.get("my_awesome_bucket/a_key_name")
|
39
|
+
Cliaws.s3.head("my_awesome_bucket/a_key_name")
|
40
|
+
Cliaws.s3.rm("my_awesome_bucket/a_key_name")
|
41
|
+
|
42
|
+
== REQUIREMENTS:
|
43
|
+
|
44
|
+
* main
|
45
|
+
* activesupport
|
46
|
+
* right_aws
|
47
|
+
|
48
|
+
== INSTALL:
|
49
|
+
|
50
|
+
* sudo gem install cliaws
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
(The MIT License)
|
55
|
+
|
56
|
+
Copyright (c) 2008 François Beausoleil (francois@teksol.info)
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
'Software'), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
72
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
73
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
74
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
75
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/clis3
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-4-12.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require "main"
|
13
|
+
require "cliaws"
|
14
|
+
|
15
|
+
Main {
|
16
|
+
argument("s3_object") do
|
17
|
+
required
|
18
|
+
argument_required
|
19
|
+
end
|
20
|
+
|
21
|
+
mode("list") do
|
22
|
+
def run
|
23
|
+
puts Cliaws.s3.list(params["s3_object"].value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
mode("touch") do
|
28
|
+
def run
|
29
|
+
Cliaws.s3.put("", params["s3_object"].value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
mode("put") do
|
34
|
+
argument("local_file") do
|
35
|
+
optional
|
36
|
+
argument_required
|
37
|
+
end
|
38
|
+
|
39
|
+
option("data") do
|
40
|
+
optional
|
41
|
+
argument_required
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
if params["local_file"].given? && params["data"].given? then
|
46
|
+
abort "Cannot give both the --data and local_file parameters at the same time"
|
47
|
+
elsif !params["local_file"].given? && !params["data"].given? then
|
48
|
+
source = STDIN
|
49
|
+
elsif params["local_file"].given? then
|
50
|
+
source = File.open(params["local_file"].value, "rb")
|
51
|
+
else
|
52
|
+
source = params["data"].value
|
53
|
+
end
|
54
|
+
|
55
|
+
Cliaws.s3.put(source, params["s3_object"].value)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
mode("rm") do
|
60
|
+
def run
|
61
|
+
Cliaws.s3.rm(params["s3_object"].value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
mode("cat") do
|
66
|
+
def run
|
67
|
+
Cliaws.s3.get(params["s3_object"].value, STDOUT)
|
68
|
+
puts
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
mode("get") do
|
73
|
+
argument("local_file") do
|
74
|
+
argument_required
|
75
|
+
optional
|
76
|
+
end
|
77
|
+
|
78
|
+
def run
|
79
|
+
if params["local_file"].given? then
|
80
|
+
dest = File.open(params["local_file"].value, "wb")
|
81
|
+
else
|
82
|
+
dest = STDOUT
|
83
|
+
end
|
84
|
+
|
85
|
+
Cliaws.s3.get(params["s3_object"].value, dest)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
mode("head") do
|
90
|
+
def run
|
91
|
+
Cliaws.s3.head(params["s3_object"].value)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def run
|
96
|
+
abort "Required action argument missing. Run '#{$0} help' for details."
|
97
|
+
end
|
98
|
+
}
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'cliaws/version'
|
2
|
+
|
3
|
+
AUTHOR = 'François Beausoleil' # can also be an array of Authors
|
4
|
+
EMAIL = "francois@teksol.info"
|
5
|
+
DESCRIPTION = "A command-line suite of tools to access Amazon Web Services, using the RightAws gems."
|
6
|
+
GEM_NAME = 'cliaws' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'cliaws' # 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 = "unknown"
|
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 = YAML.load(`svn info`)['Revision']
|
34
|
+
VERS = Cliaws::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'cliaws documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
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.developer(AUTHOR, EMAIL)
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.summary = DESCRIPTION
|
54
|
+
p.url = HOMEPATH
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
58
|
+
|
59
|
+
# == Optional
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
61
|
+
p.extra_deps = [
|
62
|
+
["main", "~> 2.8.0"],
|
63
|
+
["right_aws", "~> 1.7.1"],
|
64
|
+
["activesupport", "~> 2.0.2"]
|
65
|
+
]
|
66
|
+
|
67
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
72
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
73
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
74
|
+
$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]))
|
data/lib/cliaws/s3.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "right_aws"
|
2
|
+
require "activesupport"
|
3
|
+
|
4
|
+
module Cliaws
|
5
|
+
class S3
|
6
|
+
def initialize(access_key_id, secret_access_key)
|
7
|
+
@s3 = RightAws::S3.new(access_key_id, secret_access_key, :logger => Logger.new("/dev/null"))
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(glob)
|
11
|
+
bucket, path = bucket_and_key_name(glob)
|
12
|
+
options = Hash.new
|
13
|
+
options["prefix"] = path unless path.blank?
|
14
|
+
bucket.keys(options).map(&:full_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(s3_object, dest=nil)
|
18
|
+
bucket, keyname = bucket_and_key_name(s3_object)
|
19
|
+
if dest.nil? then
|
20
|
+
bucket.get(keyname)
|
21
|
+
else
|
22
|
+
dest.write(bucket.get(keyname))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def head(s3_object)
|
27
|
+
bucket, keyname = bucket_and_key_name(s3_object)
|
28
|
+
key = bucket.key(keyname, true)
|
29
|
+
headers = key.headers
|
30
|
+
puts headers.merge(key.meta_headers).to_yaml
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(source, s3_object)
|
34
|
+
bucket, keyname = bucket_and_key_name(s3_object)
|
35
|
+
bucket.put(keyname, source)
|
36
|
+
end
|
37
|
+
|
38
|
+
def rm(s3_object)
|
39
|
+
bucket, keyname = bucket_and_key_name(s3_object)
|
40
|
+
bucket.key(keyname).delete
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
def bucket_and_key_name(full_name)
|
45
|
+
bucket_name, path = full_name.split("/", 2)
|
46
|
+
bucket = @s3.bucket(bucket_name, false)
|
47
|
+
[bucket, path]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/cliaws.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require "cliaws/s3"
|
4
|
+
|
5
|
+
module Cliaws
|
6
|
+
def self.access_key_id
|
7
|
+
ENV["AWS_ACCESS_KEY_ID"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.secret_access_key
|
11
|
+
ENV["AWS_SECRET_ACCESS_KEY"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.s3
|
15
|
+
@@s3 ||= Cliaws::S3.new(access_key_id, secret_access_key)
|
16
|
+
end
|
17
|
+
end
|
data/log/.gitignore
ADDED
File without changes
|
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/cliaws.rb'}"
|
9
|
+
puts "Loading cliaws 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/cliaws/version.rb'
|
15
|
+
|
16
|
+
version = Cliaws::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/cliaws'
|
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.html.erb')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > 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)
|