rubypulse 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +2 -0
- data/README.rdoc +48 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/rubypulse.rb +194 -0
- data/lib/rubypulse/version.rb +10 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -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_helper.rb +2 -0
- data/test/test_rubypulse.rb +11 -0
- data/website/index.html +84 -0
- data/website/index.txt +84 -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
- metadata +93 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/rubypulse.rb
|
9
|
+
lib/rubypulse/version.rb
|
10
|
+
script/console
|
11
|
+
script/destroy
|
12
|
+
script/generate
|
13
|
+
script/txt2html
|
14
|
+
setup.rb
|
15
|
+
tasks/deployment.rake
|
16
|
+
tasks/environment.rake
|
17
|
+
tasks/website.rake
|
18
|
+
test/test_helper.rb
|
19
|
+
test/test_rubypulse.rb
|
20
|
+
website/index.html
|
21
|
+
website/index.txt
|
22
|
+
website/javascripts/rounded_corners_lite.inc.js
|
23
|
+
website/stylesheets/screen.css
|
24
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= rubypulse
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubypulse/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Phil Kates' # can also be an array of Authors
|
4
|
+
EMAIL = "hawk684@gmail.com"
|
5
|
+
DESCRIPTION = "Provides Ruby methods to access the VoicePulse Connect API"
|
6
|
+
GEM_NAME = 'rubypulse' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'rubypulse' # 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
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "philk"
|
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 = Rubypulse::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'rubypulse 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 ""
|
@@ -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/rubypulse.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
A Ruby interface to VoicePulse's SOAP interface.
|
3
|
+
=end
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
6
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
7
|
+
|
8
|
+
require 'soap/wsdlDriver'
|
9
|
+
|
10
|
+
class VoicePulse
|
11
|
+
|
12
|
+
# When you create a VoicePulseApi.new class it creates a SOAP::WSDLDriverFactory class called @driver. It also creates a variable @apikey to store the ApiKey from VoicePulse.
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# obj = VoicePulseApi.new
|
16
|
+
def initialize()
|
17
|
+
wsdl = 'http://connect.voicepulse.com/secure/services/Api0605.asmx?WSDL'
|
18
|
+
@driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
|
19
|
+
@apikey = API_KEY
|
20
|
+
end
|
21
|
+
|
22
|
+
# Requires a single hash in the format:
|
23
|
+
# (:ApiKey => String, :StartYear => Integer, :StartMonth => Integer, :StartDay => Integer, :EndYear => Integer, :EndMonth => Integer, :EndDay => Integer, :Filename => String)
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
# datehash = {:ApiKey => @apikey, :StartYear => 2007, :StartMonth => 03, :StartDay => 01, :EndYear => 2007, :EndMonth => 04, :EndDay => 02, :Filename => "vpreport"}
|
27
|
+
# obj.generateReport(datehash) => "vpreport.zip"
|
28
|
+
# Returns the name of the Filename created (will always be a .zip file because of the way VoicePulse processes the report).
|
29
|
+
def generateReport(dates)
|
30
|
+
result = @driver.GenerateReport(dates)
|
31
|
+
if result.generateReport.errorCode == "0" then
|
32
|
+
output = result.generateReport.filename
|
33
|
+
else
|
34
|
+
output = "Error Generating Report: #{result.generateReportResult.errorMessage}"
|
35
|
+
end
|
36
|
+
return output
|
37
|
+
end
|
38
|
+
|
39
|
+
# Requires a filename as a String (the one returned from generateReport). Returns a https URL to download the file from.
|
40
|
+
def getReport(filename)
|
41
|
+
result = @driver.GetGeneratedReports(:ApiKey => @apikey)
|
42
|
+
if result.getGeneratedReportsResult.errorCode == "0" then
|
43
|
+
response = result.getGeneratedReportsResult.items.apiResponseItem
|
44
|
+
@reportlist = Hash.new
|
45
|
+
response.each do |res|
|
46
|
+
@reportlist.update(res.filename => res.fullPath)
|
47
|
+
end
|
48
|
+
output = @reportlist[filename]
|
49
|
+
else
|
50
|
+
output = result.getGeneratedReportsResult.errorMessage
|
51
|
+
end
|
52
|
+
return output
|
53
|
+
end
|
54
|
+
|
55
|
+
# Gets the current balance of the account and returns it as a String
|
56
|
+
def getBalance
|
57
|
+
result = @driver.GetBalance(:ApiKey => @apikey)
|
58
|
+
if result.getBalanceResult.errorCode == "0" then
|
59
|
+
output = result.getBalanceResult.balance
|
60
|
+
else
|
61
|
+
output = result.getBalanceResult.errorMessage
|
62
|
+
end
|
63
|
+
return output
|
64
|
+
end
|
65
|
+
|
66
|
+
# Requires a phone number with no formatting as a String and returns a String for the rate per-minute.
|
67
|
+
def getRate(phonenumber)
|
68
|
+
result = @driver.GetFlexRate(:ApiKey => @apikey, :PhoneNumber => phonenumber)
|
69
|
+
if result.getFlexRateResult.errorCode == "0" then
|
70
|
+
output = result.getFlexRateResult.flexRate
|
71
|
+
else
|
72
|
+
output = "Error Getting FlexRate: #{result.getFlexRateResult.errorMessage}"
|
73
|
+
end
|
74
|
+
return output
|
75
|
+
end
|
76
|
+
|
77
|
+
# TODO: Need to test this when account balance gets low
|
78
|
+
# Requires a CCV Code (3 digit number from back of Credit Card) and an amount as Strings. Returns success or failure message.
|
79
|
+
def refill(ccvcode, amount)
|
80
|
+
result = @driver.RefillNow(:ApiKey => @apikey, :CreditCardCode => ccvcode, :Amount => amount)
|
81
|
+
return result.refillNowResult.refillNow
|
82
|
+
end
|
83
|
+
|
84
|
+
# TODO: activatePhoneNumbers = {:ApiKey => @apikey, :PhoneNumbers => Array, :AccountNumber1 => String, :AccountNumber2 => String}
|
85
|
+
def activatePhoneNumbers
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
# TODO: deactivatePhoneNumbers = {:ApiKey => @apikey, :PhoneNumbers => Array, :AccountNumber1 => String, :AccountNumber2 => String}
|
90
|
+
def deactivatePhoneNumbers
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: getActivePhoneNumbers = {:ApiKey => @apikey} THE API FOR THIS IS CURRENTLY BROKEN
|
95
|
+
# def getActivePhoneNumbers
|
96
|
+
# result = @driver.GetActivePhoneNumbers(:ApiKey => @apikey)
|
97
|
+
# if result.getActivePhoneNumbersResult.errorCode == "0" then
|
98
|
+
# output = result.getActivePhoneNumbersResult.phoneNumber
|
99
|
+
# else
|
100
|
+
# output = result.getActivePhoneNumbersResult.errorMessage
|
101
|
+
# end
|
102
|
+
# return output
|
103
|
+
# end
|
104
|
+
|
105
|
+
# Requires input of state as a string (two digit code). Returns list of available area codes.
|
106
|
+
def getAvailablePhoneNumberAreaCodes(state)
|
107
|
+
result = @driver.GetAvailablePhoneNumberAreaCodes(:ApiKey => @apikey, :State => state)
|
108
|
+
if result.getAvailablePhoneNumberAreaCodesResult.errorCode == "0" then
|
109
|
+
response = result.getAvailablePhoneNumberAreaCodesResult.items.apiResponseItem
|
110
|
+
@arealist = Array.new
|
111
|
+
response.each do |res|
|
112
|
+
@arealist += res.areaCode.to_a
|
113
|
+
end
|
114
|
+
output = @arealist
|
115
|
+
else
|
116
|
+
output = result.getAvailablePhoneNumberAreaCodesResult.errorMessage
|
117
|
+
end
|
118
|
+
return output
|
119
|
+
end
|
120
|
+
|
121
|
+
# Requires two strings for input ('state', 'areacode') and returns a hash of {'rate center' => 'city'}
|
122
|
+
def getAvailablePhoneNumberRateCenters(state, areacode)
|
123
|
+
result = @driver.GetAvailablePhoneNumberRateCenters(:ApiKey => @apikey, :State => state, :AreaCode => areacode)
|
124
|
+
if result.getAvailablePhoneNumberRateCentersResult.errorCode == "0" then
|
125
|
+
response = result.getAvailablePhoneNumberRateCentersResult.items.apiResponseItem
|
126
|
+
@reportlist = Hash.new
|
127
|
+
response.each do |res|
|
128
|
+
@reportlist.update(res.rateCenter => res.city)
|
129
|
+
end
|
130
|
+
output = @reportlist
|
131
|
+
else
|
132
|
+
output = result.getAvailablePhoneNumberRateCentersResult.errorMessage
|
133
|
+
end
|
134
|
+
return output
|
135
|
+
end
|
136
|
+
|
137
|
+
# TODO: getAvailablePhoneNumberStates = {:ApiKey => @apikey}
|
138
|
+
# Accepts no input and returns an array of available states (two digit codes)
|
139
|
+
def getAvailablePhoneNumberStates
|
140
|
+
result = @driver.GetAvailablePhoneNumberStates(:ApiKey => @apikey)
|
141
|
+
if result.getAvailablePhoneNumberStatesResult.errorCode == "0" then
|
142
|
+
response = result.getAvailablePhoneNumberStatesResult.items.apiResponseItem
|
143
|
+
@statelist = Array.new
|
144
|
+
response.each do |res|
|
145
|
+
@statelist += res.state.to_a
|
146
|
+
end
|
147
|
+
output = @statelist
|
148
|
+
else
|
149
|
+
output = result.getAvailablePhoneNumberStatesResult.errorMessage
|
150
|
+
end
|
151
|
+
return output
|
152
|
+
end
|
153
|
+
|
154
|
+
# TODO: getAvailablePhoneNumbers = {:ApiKey => @apikey, :State => String, :AreaCode => String, :RateCenter => String}
|
155
|
+
# Requires inputs of state, areacode, and ratecenter as strings. Returns and array of available phone numbers.
|
156
|
+
def getAvailablePhoneNumbers(state, areacode, ratecenter)
|
157
|
+
result = @driver.GetAvailablePhoneNumbers(:ApiKey => @apikey, :State => state, :AreaCode => areacode, :RateCenter => ratecenter)
|
158
|
+
if result.getAvailablePhoneNumbersResult.errorCode == "0" then
|
159
|
+
response = result.getAvailablePhoneNumbersResult.items.apiResponseItem
|
160
|
+
@numberlist = Array.new
|
161
|
+
response.each do |res|
|
162
|
+
@numberlist += res.phoneNumber.to_a
|
163
|
+
end
|
164
|
+
output = @numberlist
|
165
|
+
else
|
166
|
+
output = result.getAvailablePhoneNumbersResult.errorMessage
|
167
|
+
end
|
168
|
+
return output
|
169
|
+
end
|
170
|
+
|
171
|
+
# TODO: getCredentials = {:ApiKey => @apikey}
|
172
|
+
# Accepts no inputs and returns an array of [login, password] for use in your sip.conf or iax2.conf
|
173
|
+
def getCredentials
|
174
|
+
result = @driver.GetCredentials(:ApiKey => @apikey)
|
175
|
+
if result.getCredentialsResult.errorCode == "0" then
|
176
|
+
output = [result.getCredentialsResult.items.apiResponseItem.login, result.getCredentialsResult.items.apiResponseItem.password]
|
177
|
+
else
|
178
|
+
output = "Error Getting FlexRate: #{result.getUserResult.errorMessage}"
|
179
|
+
end
|
180
|
+
return output
|
181
|
+
end
|
182
|
+
|
183
|
+
# Accepts no input and returns and array of [username, email]
|
184
|
+
def getUser
|
185
|
+
result = @driver.GetUser(:ApiKey => @apikey)
|
186
|
+
if result.getUserResult.errorCode == "0" then
|
187
|
+
output = [result.getUserResult.items.apiResponseItem.username, result.getUserResult.items.apiResponseItem.email]
|
188
|
+
else
|
189
|
+
output = "Error Getting FlexRate: #{result.getUserResult.errorMessage}"
|
190
|
+
end
|
191
|
+
return output
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
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/rubypulse.rb'}"
|
9
|
+
puts "Loading rubypulse 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,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
GEM_NAME = 'rubypulse' # what ppl will type to install your gem
|
4
|
+
RUBYFORGE_PROJECT = 'rubypulse'
|
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 = Rubypulse::VERSION::STRING
|
21
|
+
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
22
|
+
|
23
|
+
def rubyforge_project_id
|
24
|
+
RubyForge.new.configure.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)
|