clickatell 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/{README.txt → RDOC_README.txt} +0 -0
- data/lib/clickatell/api.rb +24 -4
- data/lib/clickatell/api/command.rb +6 -5
- data/lib/clickatell/api/command_executor.rb +33 -5
- data/lib/clickatell/response.rb +2 -0
- data/lib/clickatell/version.rb +1 -1
- data/spec/api_spec.rb +64 -11
- data/spec/command_executor_spec.rb +75 -0
- data/spec/response_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -0
- metadata +24 -36
- data/Manifest.txt +0 -36
- data/Rakefile +0 -160
- data/scripts/txt2html +0 -67
- data/setup.rb +0 -1585
- data/website/images/footer_bg.gif +0 -0
- data/website/index.html +0 -186
- data/website/index.txt +0 -117
- data/website/javascripts/codehighlighter/code_highlighter.js +0 -188
- data/website/javascripts/codehighlighter/ruby.js +0 -18
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/specs.html +0 -280
- data/website/stylesheets/limechoc.css +0 -266
- data/website/stylesheets/rdoc.css +0 -208
- data/website/stylesheets/screen.css +0 -460
- data/website/template.rhtml +0 -42
Binary file
|
data/website/index.html
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
-
<link rel="stylesheet" href="stylesheets/limechoc.css" type="text/css" media="screen" />
|
7
|
-
<script type="text/javascript" charset="utf-8" src="javascripts/codehighlighter/code_highlighter.js"></script>
|
8
|
-
<script type="text/javascript" charset="utf-8" src="javascripts/codehighlighter/ruby.js"></script>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
10
|
-
<title>Clickatell Ruby API</title>
|
11
|
-
</head>
|
12
|
-
<body>
|
13
|
-
|
14
|
-
<div id="wrapper">
|
15
|
-
<div id="container">
|
16
|
-
|
17
|
-
<div id="header">
|
18
|
-
|
19
|
-
<h1>Clickatell Ruby API <span class="version">0.5.0</span>
|
20
|
-
<span class="tagline">gem install clickatell</span></h1>
|
21
|
-
|
22
|
-
</div>
|
23
|
-
|
24
|
-
<div id="content">
|
25
|
-
<div class="article"><h3>What is it?</h3>
|
26
|
-
|
27
|
-
|
28
|
-
<p>A Ruby interface to the <a href="http://www.clickatell.com">Clickatell</a> SMS gateway <span class="caps">API</span>.</p>
|
29
|
-
|
30
|
-
|
31
|
-
<h3>Installing</h3>
|
32
|
-
|
33
|
-
|
34
|
-
<p><strong>Please note:</strong> this gem has been tested on *nix based systems including Linux, <span class="caps">BSD</span> and <span class="caps">OSX</span>. The <code>sms</code> utility was written with these systems in mind and will not work out of the box on Windows. The <span class="caps">API</span> should still work but has not been tested at this time. If you would like Windows support, please submit patches.</p>
|
35
|
-
|
36
|
-
<p>Download the <a href="http://rubyforge.org/projects/clickatell">latest version of gem</a> or install using RubyGems.</p>
|
37
|
-
|
38
|
-
<pre><code>$ sudo gem install clickatell</code></pre>
|
39
|
-
|
40
|
-
<h4>Clickatell on GitHub</h4>
|
41
|
-
|
42
|
-
|
43
|
-
<p>The source repository for clickatell has been <a href="http://github.com/lukeredpath/clickatell/">moved to GitHub</a>.</p>
|
44
|
-
|
45
|
-
|
46
|
-
<pre><code>git clone git://github.com/lukeredpath/clickatell.git</code></pre>
|
47
|
-
|
48
|
-
<p>You can still access the old subversion repository although this is unlikely to be updated:</p>
|
49
|
-
|
50
|
-
|
51
|
-
<pre><code>$ svn co svn://lukeredpath.co.uk/var/svn/opensource/clickatell/trunk clickatell-trunk</code></pre>
|
52
|
-
|
53
|
-
<p>You can view the <a href="/rdoc">RDoc documentation</a> and the <a href="/specs.html">code specs</a>.</p>
|
54
|
-
|
55
|
-
|
56
|
-
<h3>The basics</h3>
|
57
|
-
|
58
|
-
|
59
|
-
<p>To use this gem, you will need sign up for an account at <a href="http://www.clickatell.com">the Clickatell website</a>.
|
60
|
-
Once you are registered and logged into your account centre, you should add
|
61
|
-
an <span class="caps">HTTP API</span> connection to your account. This will give you your <span class="caps">API</span>_ID.</p>
|
62
|
-
|
63
|
-
|
64
|
-
<h3>Demonstration of usage</h3>
|
65
|
-
|
66
|
-
|
67
|
-
<p>You can now use the library directly. You will need your <span class="caps">API</span>_ID as well as your
|
68
|
-
account username and password.</p>
|
69
|
-
|
70
|
-
|
71
|
-
<pre><code class="ruby">
|
72
|
-
require 'rubygems'
|
73
|
-
require 'clickatell'
|
74
|
-
|
75
|
-
api = Clickatell::API.authenticate('your_api_id', 'your_username', 'your_password')
|
76
|
-
api.send_message('447771234567', 'Hello from clickatell')
|
77
|
-
</code></pre>
|
78
|
-
|
79
|
-
<p>Full documentation for the <span class="caps">API</span> is available in the <a href="rdoc/">RDocs</a>.</p>
|
80
|
-
|
81
|
-
|
82
|
-
<p>For debugging purposes, the <span class="caps">API</span> allows you to view gateway URIs as they are requested, printed to $stdout. You can enable this by turning on <ins>debug_mode</ins>.</p>
|
83
|
-
|
84
|
-
|
85
|
-
<pre><code class="ruby">
|
86
|
-
Clickatell::API.debug_mode = true
|
87
|
-
</code></pre>
|
88
|
-
|
89
|
-
<h4>Command-line <span class="caps">SMS</span> Utility</h4>
|
90
|
-
|
91
|
-
|
92
|
-
<p>The Clickatell gem also comes with a command-line utility that will allow you
|
93
|
-
to send an <span class="caps">SMS</span> directly from the command-line.</p>
|
94
|
-
|
95
|
-
|
96
|
-
<p>You will need to create a <span class="caps">YAML</span> configuration file in your home directory, in a
|
97
|
-
file called .clickatell that resembles the following:</p>
|
98
|
-
|
99
|
-
|
100
|
-
<pre><code>
|
101
|
-
# ~/.clickatell
|
102
|
-
api_key: your_api_id
|
103
|
-
username: your_username
|
104
|
-
password: your_password
|
105
|
-
</code></pre>
|
106
|
-
|
107
|
-
<p>You can then use the <ins>sms</ins> utility to send a message to a single recipient:</p>
|
108
|
-
|
109
|
-
|
110
|
-
<pre><code>
|
111
|
-
$ sms 447771234567 'Hello from clickatell'
|
112
|
-
</code></pre>
|
113
|
-
|
114
|
-
<p>Alternatively, you can specify your authentication details manually by passing in options to the <ins>sms</ins> command.</p>
|
115
|
-
|
116
|
-
|
117
|
-
<pre><code>
|
118
|
-
$ sms -u your_username -p your_password -k your_api_key 447771234567 'Hello from clickatell'
|
119
|
-
</code></pre>
|
120
|
-
|
121
|
-
<p>These values will take presedence over any values in your ~/.clickatell file.</p>
|
122
|
-
|
123
|
-
|
124
|
-
<p>You can also specify a custom Sender ID – the name or number that will appear in the “From” label on the recipients phone. You can either add a “from” key to your .clickatell file or manually using the—from option:</p>
|
125
|
-
|
126
|
-
|
127
|
-
<pre><code>
|
128
|
-
$ sms --from 'Luke Redpath' 447771234567 'Hello from clickatell'
|
129
|
-
</code></pre>
|
130
|
-
|
131
|
-
<p>The “from” option can either be a 16 digit number or an 11 character alpha-numeric string.</p>
|
132
|
-
|
133
|
-
|
134
|
-
<p><strong>Important note about custom sender IDs:</strong> Since November 2007, Clickatell have implemented a policy whereby all Sender IDs must be registered in your account centre before they can be used (the mobile number that you signed up with will have automatically been registered). If you try to specify a custom sender ID that has not been registered, the <span class="caps">SMS</span> will not be delivered.</p>
|
135
|
-
|
136
|
-
|
137
|
-
<p>In addition, if you do not specify a sender ID, a default Clickatell number will be used instead. If you are using the sms utility to send messages from your own number, make sure you have added the ‘from’ field to your .clickatell file otherwise you will need to specify it every time you send a message.</p>
|
138
|
-
|
139
|
-
|
140
|
-
<p>You can also use the <ins>sms</ins> utility to check your Clickatell account balance:</p>
|
141
|
-
|
142
|
-
|
143
|
-
<pre><code>
|
144
|
-
$ sms --show-balance
|
145
|
-
</code></pre>
|
146
|
-
|
147
|
-
<p>Whenever you send a message with the <ins>sms</ins> utility, it will return an alpha-numeric message ID. You can use this message ID to retrieve the message’s current status using the—status option:</p>
|
148
|
-
|
149
|
-
|
150
|
-
<pre><code>
|
151
|
-
$ sms --status 30b7d15bffb38695ba26e77c9c20f4ec
|
152
|
-
</code></pre>
|
153
|
-
|
154
|
-
<p>This will return a message status and message status code.</p>
|
155
|
-
|
156
|
-
|
157
|
-
<p>Run <ins>sms</ins> without any arguments for a full list of options.</p>
|
158
|
-
|
159
|
-
|
160
|
-
<h3>License</h3>
|
161
|
-
|
162
|
-
|
163
|
-
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
164
|
-
|
165
|
-
|
166
|
-
<h3>Contact</h3>
|
167
|
-
|
168
|
-
|
169
|
-
<p>Comments are welcome. Send an email to <a href="mailto:contact@lukeredpath.co.uk">Luke Redpath</a> email.</p></div>
|
170
|
-
</div>
|
171
|
-
|
172
|
-
</div>
|
173
|
-
|
174
|
-
<div id="footer_wrapper">
|
175
|
-
<div id="footer">
|
176
|
-
<p class="copyright">
|
177
|
-
<a href="http://rubyforge.org/projects/clickatell">Rubyforge Project Page</a> |
|
178
|
-
<a href="http://rubyforge.org/frs/?group_id=4295&release_id=13922">Download latest version (0.5.0)</a> |
|
179
|
-
<a href="rdoc/">RDoc</a>
|
180
|
-
</p>
|
181
|
-
</div>
|
182
|
-
</div>
|
183
|
-
</div>
|
184
|
-
|
185
|
-
</body>
|
186
|
-
</html>
|
data/website/index.txt
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
h1. Clickatell Ruby API
|
2
|
-
|
3
|
-
h3. What is it?
|
4
|
-
|
5
|
-
A Ruby interface to the "Clickatell":http://www.clickatell.com SMS gateway API.
|
6
|
-
|
7
|
-
h3. Installing
|
8
|
-
|
9
|
-
<p><strong>Please note:</strong> this gem has been tested on *nix based systems including Linux, BSD and OSX. The <code>sms</code> utility was written with these systems in mind and will not work out of the box on Windows. The API should still work but has not been tested at this time. If you would like Windows support, please submit patches.</p>
|
10
|
-
|
11
|
-
<p>Download the <a href="http://rubyforge.org/projects/clickatell">latest version of gem</a> or install using RubyGems.</p>
|
12
|
-
|
13
|
-
<pre><code>$ sudo gem install clickatell</code></pre>
|
14
|
-
|
15
|
-
h4. Clickatell on GitHub
|
16
|
-
|
17
|
-
The source repository for clickatell has been <a href="http://github.com/lukeredpath/clickatell/">moved to GitHub</a>.
|
18
|
-
|
19
|
-
<pre><code>git clone git://github.com/lukeredpath/clickatell.git</code></pre>
|
20
|
-
|
21
|
-
You can still access the old subversion repository although this is unlikely to be updated:
|
22
|
-
|
23
|
-
<pre><code>$ svn co svn://lukeredpath.co.uk/var/svn/opensource/clickatell/trunk clickatell-trunk</code></pre>
|
24
|
-
|
25
|
-
You can view the <a href="/rdoc">RDoc documentation</a> and the <a href="/specs.html">code specs</a>.
|
26
|
-
|
27
|
-
h3. The basics
|
28
|
-
|
29
|
-
To use this gem, you will need sign up for an account at "the Clickatell website":http://www.clickatell.com.
|
30
|
-
Once you are registered and logged into your account centre, you should add
|
31
|
-
an HTTP API connection to your account. This will give you your API_ID.
|
32
|
-
|
33
|
-
h3. Demonstration of usage
|
34
|
-
|
35
|
-
You can now use the library directly. You will need your API_ID as well as your
|
36
|
-
account username and password.
|
37
|
-
|
38
|
-
<pre><code class="ruby">
|
39
|
-
require 'rubygems'
|
40
|
-
require 'clickatell'
|
41
|
-
|
42
|
-
api = Clickatell::API.authenticate('your_api_id', 'your_username', 'your_password')
|
43
|
-
api.send_message('447771234567', 'Hello from clickatell')
|
44
|
-
</code></pre>
|
45
|
-
|
46
|
-
Full documentation for the API is available in the <a href="rdoc/">RDocs</a>.
|
47
|
-
|
48
|
-
For debugging purposes, the API allows you to view gateway URIs as they are requested, printed to $stdout. You can enable this by turning on +debug_mode+.
|
49
|
-
|
50
|
-
<pre><code class="ruby">
|
51
|
-
Clickatell::API.debug_mode = true
|
52
|
-
</code></pre>
|
53
|
-
|
54
|
-
h4. Command-line SMS Utility
|
55
|
-
|
56
|
-
The Clickatell gem also comes with a command-line utility that will allow you
|
57
|
-
to send an SMS directly from the command-line.
|
58
|
-
|
59
|
-
You will need to create a YAML configuration file in your home directory, in a
|
60
|
-
file called .clickatell that resembles the following:
|
61
|
-
|
62
|
-
<pre><code>
|
63
|
-
# ~/.clickatell
|
64
|
-
api_key: your_api_id
|
65
|
-
username: your_username
|
66
|
-
password: your_password
|
67
|
-
</code></pre>
|
68
|
-
|
69
|
-
You can then use the +sms+ utility to send a message to a single recipient:
|
70
|
-
|
71
|
-
<pre><code>
|
72
|
-
$ sms 447771234567 'Hello from clickatell'
|
73
|
-
</code></pre>
|
74
|
-
|
75
|
-
Alternatively, you can specify your authentication details manually by passing in options to the +sms+ command.
|
76
|
-
|
77
|
-
<pre><code>
|
78
|
-
$ sms -u your_username -p your_password -k your_api_key 447771234567 'Hello from clickatell'
|
79
|
-
</code></pre>
|
80
|
-
|
81
|
-
These values will take presedence over any values in your ~/.clickatell file.
|
82
|
-
|
83
|
-
You can also specify a custom Sender ID - the name or number that will appear in the "From" label on the recipients phone. You can either add a "from" key to your .clickatell file or manually using the --from option:
|
84
|
-
|
85
|
-
<pre><code>
|
86
|
-
$ sms --from 'Luke Redpath' 447771234567 'Hello from clickatell'
|
87
|
-
</code></pre>
|
88
|
-
|
89
|
-
The "from" option can either be a 16 digit number or an 11 character alpha-numeric string.
|
90
|
-
|
91
|
-
<strong>Important note about custom sender IDs:</strong> Since November 2007, Clickatell have implemented a policy whereby all Sender IDs must be registered in your account centre before they can be used (the mobile number that you signed up with will have automatically been registered). If you try to specify a custom sender ID that has not been registered, the SMS will not be delivered.
|
92
|
-
|
93
|
-
In addition, if you do not specify a sender ID, a default Clickatell number will be used instead. If you are using the sms utility to send messages from your own number, make sure you have added the 'from' field to your .clickatell file otherwise you will need to specify it every time you send a message.
|
94
|
-
|
95
|
-
You can also use the +sms+ utility to check your Clickatell account balance:
|
96
|
-
|
97
|
-
<pre><code>
|
98
|
-
$ sms --show-balance
|
99
|
-
</code></pre>
|
100
|
-
|
101
|
-
Whenever you send a message with the +sms+ utility, it will return an alpha-numeric message ID. You can use this message ID to retrieve the message's current status using the --status option:
|
102
|
-
|
103
|
-
<pre><code>
|
104
|
-
$ sms --status 30b7d15bffb38695ba26e77c9c20f4ec
|
105
|
-
</code></pre>
|
106
|
-
|
107
|
-
This will return a message status and message status code.
|
108
|
-
|
109
|
-
Run +sms+ without any arguments for a full list of options.
|
110
|
-
|
111
|
-
h3. License
|
112
|
-
|
113
|
-
This code is free to use under the terms of the MIT license.
|
114
|
-
|
115
|
-
h3. Contact
|
116
|
-
|
117
|
-
Comments are welcome. Send an email to "Luke Redpath":mailto:contact@lukeredpath.co.uk email.
|
@@ -1,188 +0,0 @@
|
|
1
|
-
/* Unobtrustive Code Highlighter By Dan Webb 11/2005
|
2
|
-
Version: 0.4
|
3
|
-
|
4
|
-
Usage:
|
5
|
-
Add a script tag for this script and any stylesets you need to use
|
6
|
-
to the page in question, add correct class names to CODE elements,
|
7
|
-
define CSS styles for elements. That's it!
|
8
|
-
|
9
|
-
Known to work on:
|
10
|
-
IE 5.5+ PC
|
11
|
-
Firefox/Mozilla PC/Mac
|
12
|
-
Opera 7.23 + PC
|
13
|
-
Safari 2
|
14
|
-
|
15
|
-
Known to degrade gracefully on:
|
16
|
-
IE5.0 PC
|
17
|
-
|
18
|
-
Note: IE5.0 fails due to the use of lookahead in some stylesets. To avoid script errors
|
19
|
-
in older browsers use expressions that use lookahead in string format when defining stylesets.
|
20
|
-
|
21
|
-
This script is inspired by star-light by entirely cunning Dean Edwards
|
22
|
-
http://dean.edwards.name/star-light/.
|
23
|
-
*/
|
24
|
-
|
25
|
-
// replace callback support for safari.
|
26
|
-
if ("a".replace(/a/, function() {return "b"}) != "b") (function(){
|
27
|
-
var default_replace = String.prototype.replace;
|
28
|
-
String.prototype.replace = function(search,replace){
|
29
|
-
// replace is not function
|
30
|
-
if(typeof replace != "function"){
|
31
|
-
return default_replace.apply(this,arguments)
|
32
|
-
}
|
33
|
-
var str = "" + this;
|
34
|
-
var callback = replace;
|
35
|
-
// search string is not RegExp
|
36
|
-
if(!(search instanceof RegExp)){
|
37
|
-
var idx = str.indexOf(search);
|
38
|
-
return (
|
39
|
-
idx == -1 ? str :
|
40
|
-
default_replace.apply(str,[search,callback(search, idx, str)])
|
41
|
-
)
|
42
|
-
}
|
43
|
-
var reg = search;
|
44
|
-
var result = [];
|
45
|
-
var lastidx = reg.lastIndex;
|
46
|
-
var re;
|
47
|
-
while((re = reg.exec(str)) != null){
|
48
|
-
var idx = re.index;
|
49
|
-
var args = re.concat(idx, str);
|
50
|
-
result.push(
|
51
|
-
str.slice(lastidx,idx),
|
52
|
-
callback.apply(null,args).toString()
|
53
|
-
);
|
54
|
-
if(!reg.global){
|
55
|
-
lastidx += RegExp.lastMatch.length;
|
56
|
-
break
|
57
|
-
}else{
|
58
|
-
lastidx = reg.lastIndex;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
result.push(str.slice(lastidx));
|
62
|
-
return result.join("")
|
63
|
-
}
|
64
|
-
})();
|
65
|
-
|
66
|
-
var CodeHighlighter = { styleSets : new Array };
|
67
|
-
|
68
|
-
CodeHighlighter.addStyle = function(name, rules) {
|
69
|
-
// using push test to disallow older browsers from adding styleSets
|
70
|
-
if ([].push) this.styleSets.push({
|
71
|
-
name : name,
|
72
|
-
rules : rules,
|
73
|
-
ignoreCase : arguments[2] || false
|
74
|
-
})
|
75
|
-
|
76
|
-
function setEvent() {
|
77
|
-
// set highlighter to run on load (use LowPro if present)
|
78
|
-
if (typeof Event != 'undefined' && typeof Event.onReady == 'function')
|
79
|
-
return Event.onReady(CodeHighlighter.init.bind(CodeHighlighter));
|
80
|
-
|
81
|
-
var old = window.onload;
|
82
|
-
|
83
|
-
if (typeof window.onload != 'function') {
|
84
|
-
window.onload = function() { CodeHighlighter.init() };
|
85
|
-
} else {
|
86
|
-
window.onload = function() {
|
87
|
-
old();
|
88
|
-
CodeHighlighter.init();
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
// only set the event when the first style is added
|
94
|
-
if (this.styleSets.length==1) setEvent();
|
95
|
-
}
|
96
|
-
|
97
|
-
CodeHighlighter.init = function() {
|
98
|
-
if (!document.getElementsByTagName) return;
|
99
|
-
if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function
|
100
|
-
// throw out older browsers
|
101
|
-
|
102
|
-
var codeEls = document.getElementsByTagName("CODE");
|
103
|
-
// collect array of all pre elements
|
104
|
-
codeEls.filter = function(f) {
|
105
|
-
var a = new Array;
|
106
|
-
for (var i = 0; i < this.length; i++) if (f(this[i])) a[a.length] = this[i];
|
107
|
-
return a;
|
108
|
-
}
|
109
|
-
|
110
|
-
var rules = new Array;
|
111
|
-
rules.toString = function() {
|
112
|
-
// joins regexes into one big parallel regex
|
113
|
-
var exps = new Array;
|
114
|
-
for (var i = 0; i < this.length; i++) exps.push(this[i].exp);
|
115
|
-
return exps.join("|");
|
116
|
-
}
|
117
|
-
|
118
|
-
function addRule(className, rule) {
|
119
|
-
// add a replace rule
|
120
|
-
var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;
|
121
|
-
// converts regex rules to strings and chops of the slashes
|
122
|
-
rules.push({
|
123
|
-
className : className,
|
124
|
-
exp : "(" + exp + ")",
|
125
|
-
length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule
|
126
|
-
replacement : rule.replacement || null
|
127
|
-
});
|
128
|
-
}
|
129
|
-
|
130
|
-
function parse(text, ignoreCase) {
|
131
|
-
// main text parsing and replacement
|
132
|
-
return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {
|
133
|
-
var i = 0, j = 1, rule;
|
134
|
-
while (rule = rules[i++]) {
|
135
|
-
if (arguments[j]) {
|
136
|
-
// if no custom replacement defined do the simple replacement
|
137
|
-
if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";
|
138
|
-
else {
|
139
|
-
// replace $0 with the className then do normal replaces
|
140
|
-
var str = rule.replacement.replace("$0", rule.className);
|
141
|
-
for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);
|
142
|
-
return str;
|
143
|
-
}
|
144
|
-
} else j+= rule.length;
|
145
|
-
}
|
146
|
-
});
|
147
|
-
}
|
148
|
-
|
149
|
-
function highlightCode(styleSet) {
|
150
|
-
// clear rules array
|
151
|
-
var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)");
|
152
|
-
rules.length = 0;
|
153
|
-
|
154
|
-
// get stylable elements by filtering out all code elements without the correct className
|
155
|
-
var stylableEls = codeEls.filter(function(item) { return clsRx.test(item.className) });
|
156
|
-
|
157
|
-
// add style rules to parser
|
158
|
-
for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);
|
159
|
-
|
160
|
-
|
161
|
-
// replace for all elements
|
162
|
-
for (var i = 0; i < stylableEls.length; i++) {
|
163
|
-
// EVIL hack to fix IE whitespace badness if it's inside a <pre>
|
164
|
-
if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {
|
165
|
-
stylableEls[i] = stylableEls[i].parentNode;
|
166
|
-
|
167
|
-
parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {
|
168
|
-
return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"
|
169
|
-
});
|
170
|
-
parsed = parsed.replace(/\n( *)/g, function() {
|
171
|
-
var spaces = "";
|
172
|
-
for (var i = 0; i < arguments[1].length; i++) spaces+= " ";
|
173
|
-
return "\n" + spaces;
|
174
|
-
});
|
175
|
-
parsed = parsed.replace(/\t/g, " ");
|
176
|
-
parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");
|
177
|
-
|
178
|
-
} else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);
|
179
|
-
|
180
|
-
stylableEls[i].innerHTML = parsed;
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
// run highlighter on all stylesets
|
185
|
-
for (var i=0; i < this.styleSets.length; i++) {
|
186
|
-
highlightCode(this.styleSets[i]);
|
187
|
-
}
|
188
|
-
}
|