codex 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/History.txt +8 -0
  2. data/LICENSE.txt +29 -0
  3. data/Manifest.txt +95 -0
  4. data/PostInstall.txt +5 -0
  5. data/README.txt +31 -0
  6. data/Rakefile +4 -0
  7. data/app_generators/codex/USAGE +5 -0
  8. data/app_generators/codex/codex_generator.rb +106 -0
  9. data/app_generators/codex/templates/Rakefile +54 -0
  10. data/app_generators/codex/templates/bin/build_all.rb +47 -0
  11. data/app_generators/codex/templates/bin/postprocess_all.rb +5 -0
  12. data/app_generators/codex/templates/bin/pressie.rb +7 -0
  13. data/app_generators/codex/templates/code/control/basic_continuation.rb +11 -0
  14. data/app_generators/codex/templates/code/control/cc_throw_catch.rb +59 -0
  15. data/app_generators/codex/templates/code/control/closure_continuation.rb +8 -0
  16. data/app_generators/codex/templates/code/control/closure_continuation_2.rb +12 -0
  17. data/app_generators/codex/templates/dp.SyntaxHighlighter/CSS.html +115 -0
  18. data/app_generators/codex/templates/dp.SyntaxHighlighter/CSharp.html +134 -0
  19. data/app_generators/codex/templates/dp.SyntaxHighlighter/CollapseCode.html +90 -0
  20. data/app_generators/codex/templates/dp.SyntaxHighlighter/Cpp.html +190 -0
  21. data/app_generators/codex/templates/dp.SyntaxHighlighter/CrashTest.html +108 -0
  22. data/app_generators/codex/templates/dp.SyntaxHighlighter/Delphi.html +112 -0
  23. data/app_generators/codex/templates/dp.SyntaxHighlighter/FirstLine.html +90 -0
  24. data/app_generators/codex/templates/dp.SyntaxHighlighter/Index.html +80 -0
  25. data/app_generators/codex/templates/dp.SyntaxHighlighter/Java.html +122 -0
  26. data/app_generators/codex/templates/dp.SyntaxHighlighter/JavaScript.html +112 -0
  27. data/app_generators/codex/templates/dp.SyntaxHighlighter/NoControls.html +89 -0
  28. data/app_generators/codex/templates/dp.SyntaxHighlighter/NoGutter.html +89 -0
  29. data/app_generators/codex/templates/dp.SyntaxHighlighter/PHP.html +102 -0
  30. data/app_generators/codex/templates/dp.SyntaxHighlighter/Python.html +121 -0
  31. data/app_generators/codex/templates/dp.SyntaxHighlighter/Ruby.html +131 -0
  32. data/app_generators/codex/templates/dp.SyntaxHighlighter/SQL.html +98 -0
  33. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/clipboard.swf +0 -0
  34. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushCSharp.js +32 -0
  35. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushCpp.js +73 -0
  36. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushCss.js +52 -0
  37. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushDelphi.js +34 -0
  38. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushJScript.js +22 -0
  39. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushJava.js +28 -0
  40. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushPhp.js +60 -0
  41. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushPython.js +30 -0
  42. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushRuby.js +28 -0
  43. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushSql.js +42 -0
  44. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushVb.js +29 -0
  45. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shBrushXml.js +70 -0
  46. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shCore.js +414 -0
  47. data/app_generators/codex/templates/dp.SyntaxHighlighter/Scripts/shCore.uncompressed.js +674 -0
  48. data/app_generators/codex/templates/dp.SyntaxHighlighter/ShowColumns.html +89 -0
  49. data/app_generators/codex/templates/dp.SyntaxHighlighter/SmartTabs.html +88 -0
  50. data/app_generators/codex/templates/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css +158 -0
  51. data/app_generators/codex/templates/dp.SyntaxHighlighter/Styles/TestPages.css +63 -0
  52. data/app_generators/codex/templates/dp.SyntaxHighlighter/Templates/Test.dwt +80 -0
  53. data/app_generators/codex/templates/dp.SyntaxHighlighter/VB.html +115 -0
  54. data/app_generators/codex/templates/dp.SyntaxHighlighter/XML.html +136 -0
  55. data/app_generators/codex/templates/html/all.html +0 -0
  56. data/app_generators/codex/templates/readme.txt +4 -0
  57. data/app_generators/codex/templates/slides/basics.slides +37 -0
  58. data/app_generators/codex/templates/slides/building.slides +27 -0
  59. data/app_generators/codex/templates/slides/example.slides +80 -0
  60. data/app_generators/codex/templates/slides/including_code.slides +80 -0
  61. data/app_generators/codex/templates/slides/metadata.yml +4 -0
  62. data/app_generators/codex/templates/slides/table_of_contents.slides +14 -0
  63. data/app_generators/codex/templates/ui/default/blank.gif +0 -0
  64. data/app_generators/codex/templates/ui/default/bodybg.gif +0 -0
  65. data/app_generators/codex/templates/ui/default/framing.css +23 -0
  66. data/app_generators/codex/templates/ui/default/iepngfix.htc +42 -0
  67. data/app_generators/codex/templates/ui/default/opera.css +7 -0
  68. data/app_generators/codex/templates/ui/default/outline.css +15 -0
  69. data/app_generators/codex/templates/ui/default/pretty.css +86 -0
  70. data/app_generators/codex/templates/ui/default/print.css +1 -0
  71. data/app_generators/codex/templates/ui/default/s5-core.css +9 -0
  72. data/app_generators/codex/templates/ui/default/slides.css +3 -0
  73. data/app_generators/codex/templates/ui/default/slides.js +553 -0
  74. data/bin/codex +17 -0
  75. data/codex.gemspec +30 -0
  76. data/config/hoe.rb +75 -0
  77. data/config/requirements.rb +15 -0
  78. data/lib/codex.rb +7 -0
  79. data/lib/codex/content.rb +160 -0
  80. data/lib/codex/pressie.rb +108 -0
  81. data/lib/codex/version.rb +9 -0
  82. data/lib/stylesheets/pressie.css +196 -0
  83. data/lib/stylesheets/print.css +149 -0
  84. data/lib/stylesheets/ruby.png +0 -0
  85. data/script/console +10 -0
  86. data/script/destroy +14 -0
  87. data/script/generate +14 -0
  88. data/setup.rb +1585 -0
  89. data/tasks/deployment.rake +34 -0
  90. data/tasks/environment.rake +7 -0
  91. data/tasks/website.rake +9 -0
  92. data/test/test_codex.rb +11 -0
  93. data/test/test_codex_generator.rb +78 -0
  94. data/test/test_generator_helper.rb +29 -0
  95. data/test/test_helper.rb +2 -0
  96. metadata +163 -0
@@ -0,0 +1,674 @@
1
+ /**
2
+ * Code Syntax Highlighter.
3
+ * Version 1.5
4
+ * Copyright (C) 2004-2007 Alex Gorbatchev.
5
+ * http://www.dreamprojections.com/syntaxhighlighter/
6
+ *
7
+ * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
8
+ * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9
+ * any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
12
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13
+ * details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
16
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+
19
+ //
20
+ // create namespaces
21
+ //
22
+ var dp = {
23
+ sh :
24
+ {
25
+ Toolbar : {},
26
+ Utils : {},
27
+ RegexLib: {},
28
+ Brushes : {},
29
+ Strings : {
30
+ AboutDialog : '<html><head><title>About...</title></head><body class="dp-about"><table cellspacing="0"><tr><td class="copy"><p class="title">dp.SyntaxHighlighter</div><div class="para">Version: {V}</p><p><a href="http://www.dreamprojections.com/syntaxhighlighter/?ref=about" target="_blank">http://www.dreamprojections.com/syntaxhighlighter</a></p>&copy;2004-2007 Alex Gorbatchev.</td></tr><tr><td class="footer"><input type="button" class="close" value="OK" onClick="window.close()"/></td></tr></table></body></html>'
31
+ },
32
+ ClipboardSwf : null,
33
+ Version : '1.5'
34
+ }
35
+ };
36
+
37
+ // make an alias
38
+ dp.SyntaxHighlighter = dp.sh;
39
+
40
+ //
41
+ // Toolbar functions
42
+ //
43
+
44
+ dp.sh.Toolbar.Commands = {
45
+ ExpandSource: {
46
+ label: '+ expand source',
47
+ check: function(highlighter) { return highlighter.collapse; },
48
+ func: function(sender, highlighter)
49
+ {
50
+ sender.parentNode.removeChild(sender);
51
+ highlighter.div.className = highlighter.div.className.replace('collapsed', '');
52
+ }
53
+ },
54
+
55
+ // opens a new windows and puts the original unformatted source code inside.
56
+ ViewSource: {
57
+ label: 'view plain',
58
+ func: function(sender, highlighter)
59
+ {
60
+ var code = highlighter.originalCode.replace(/</g, '&lt;');
61
+ var wnd = window.open('', '_blank', 'width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=0');
62
+ wnd.document.write('<textarea style="width:99%;height:99%">' + code + '</textarea>');
63
+ wnd.document.close();
64
+ }
65
+ },
66
+
67
+ // Copies the original source code in to the clipboard. Uses either IE only method or Flash object if ClipboardSwf is set
68
+ CopyToClipboard: {
69
+ label: 'copy to clipboard',
70
+ check: function() { return window.clipboardData != null || dp.sh.ClipboardSwf != null; },
71
+ func: function(sender, highlighter)
72
+ {
73
+ var code = highlighter.originalCode;
74
+
75
+ if(window.clipboardData)
76
+ {
77
+ window.clipboardData.setData('text', code);
78
+ }
79
+ else if(dp.sh.ClipboardSwf != null)
80
+ {
81
+ var flashcopier = highlighter.flashCopier;
82
+
83
+ if(flashcopier == null)
84
+ {
85
+ flashcopier = document.createElement('div');
86
+ highlighter.flashCopier = flashcopier;
87
+ highlighter.div.appendChild(flashcopier);
88
+ }
89
+
90
+ flashcopier.innerHTML = '<embed src="' + dp.sh.ClipboardSwf + '" FlashVars="clipboard='+encodeURIComponent(code)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
91
+ }
92
+
93
+ alert('The code is in your clipboard now');
94
+ }
95
+ },
96
+
97
+ // creates an invisible iframe, puts the original source code inside and prints it
98
+ PrintSource: {
99
+ label: 'print',
100
+ func: function(sender, highlighter)
101
+ {
102
+ var iframe = document.createElement('IFRAME');
103
+ var doc = null;
104
+
105
+ // this hides the iframe
106
+ iframe.style.cssText = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
107
+
108
+ document.body.appendChild(iframe);
109
+ doc = iframe.contentWindow.document;
110
+
111
+ dp.sh.Utils.CopyStyles(doc, window.document);
112
+ doc.write('<div class="' + highlighter.div.className.replace('collapsed', '') + ' printing">' + highlighter.div.innerHTML + '</div>');
113
+ doc.close();
114
+
115
+ iframe.contentWindow.focus();
116
+ iframe.contentWindow.print();
117
+
118
+ alert('Printing...');
119
+
120
+ document.body.removeChild(iframe);
121
+ }
122
+ },
123
+
124
+ About: {
125
+ label: '?',
126
+ func: function(highlighter)
127
+ {
128
+ var wnd = window.open('', '_blank', 'dialog,width=300,height=150,scrollbars=0');
129
+ var doc = wnd.document;
130
+
131
+ dp.sh.Utils.CopyStyles(doc, window.document);
132
+
133
+ doc.write(dp.sh.Strings.AboutDialog.replace('{V}', dp.sh.Version));
134
+ doc.close();
135
+ wnd.focus();
136
+ }
137
+ }
138
+ };
139
+
140
+ // creates a <div /> with all toolbar links
141
+ dp.sh.Toolbar.Create = function(highlighter)
142
+ {
143
+ var div = document.createElement('DIV');
144
+
145
+ div.className = 'tools';
146
+
147
+ for(var name in dp.sh.Toolbar.Commands)
148
+ {
149
+ var cmd = dp.sh.Toolbar.Commands[name];
150
+
151
+ if(cmd.check != null && !cmd.check(highlighter))
152
+ continue;
153
+
154
+ div.innerHTML += '<a href="#" onclick="dp.sh.Toolbar.Command(\'' + name + '\',this);return false;">' + cmd.label + '</a>';
155
+ }
156
+
157
+ return div;
158
+ }
159
+
160
+ // executes toolbar command by name
161
+ dp.sh.Toolbar.Command = function(name, sender)
162
+ {
163
+ var n = sender;
164
+
165
+ while(n != null && n.className.indexOf('dp-highlighter') == -1)
166
+ n = n.parentNode;
167
+
168
+ if(n != null)
169
+ dp.sh.Toolbar.Commands[name].func(sender, n.highlighter);
170
+ }
171
+
172
+ // copies all <link rel="stylesheet" /> from 'target' window to 'dest'
173
+ dp.sh.Utils.CopyStyles = function(destDoc, sourceDoc)
174
+ {
175
+ var links = sourceDoc.getElementsByTagName('link');
176
+
177
+ for(var i = 0; i < links.length; i++)
178
+ if(links[i].rel.toLowerCase() == 'stylesheet')
179
+ destDoc.write('<link type="text/css" rel="stylesheet" href="' + links[i].href + '"></link>');
180
+ }
181
+
182
+ //
183
+ // Common reusable regular expressions
184
+ //
185
+ dp.sh.RegexLib = {
186
+ MultiLineCComments : new RegExp('/\\*[\\s\\S]*?\\*/', 'gm'),
187
+ SingleLineCComments : new RegExp('//.*$', 'gm'),
188
+ SingleLinePerlComments : new RegExp('#.*$', 'gm'),
189
+ DoubleQuotedString : new RegExp('"(?:\\.|(\\\\\\")|[^\\""])*"','g'),
190
+ SingleQuotedString : new RegExp("'(?:\\.|(\\\\\\')|[^\\''])*'", 'g')
191
+ };
192
+
193
+ //
194
+ // Match object
195
+ //
196
+ dp.sh.Match = function(value, index, css)
197
+ {
198
+ this.value = value;
199
+ this.index = index;
200
+ this.length = value.length;
201
+ this.css = css;
202
+ }
203
+
204
+ //
205
+ // Highlighter object
206
+ //
207
+ dp.sh.Highlighter = function()
208
+ {
209
+ this.noGutter = false;
210
+ this.addControls = true;
211
+ this.collapse = false;
212
+ this.tabsToSpaces = true;
213
+ this.wrapColumn = 80;
214
+ this.showColumns = true;
215
+ }
216
+
217
+ // static callback for the match sorting
218
+ dp.sh.Highlighter.SortCallback = function(m1, m2)
219
+ {
220
+ // sort matches by index first
221
+ if(m1.index < m2.index)
222
+ return -1;
223
+ else if(m1.index > m2.index)
224
+ return 1;
225
+ else
226
+ {
227
+ // if index is the same, sort by length
228
+ if(m1.length < m2.length)
229
+ return -1;
230
+ else if(m1.length > m2.length)
231
+ return 1;
232
+ }
233
+ return 0;
234
+ }
235
+
236
+ dp.sh.Highlighter.prototype.CreateElement = function(name)
237
+ {
238
+ var result = document.createElement(name);
239
+ result.highlighter = this;
240
+ return result;
241
+ }
242
+
243
+ // gets a list of all matches for a given regular expression
244
+ dp.sh.Highlighter.prototype.GetMatches = function(regex, css)
245
+ {
246
+ var index = 0;
247
+ var match = null;
248
+
249
+ while((match = regex.exec(this.code)) != null)
250
+ this.matches[this.matches.length] = new dp.sh.Match(match[0], match.index, css);
251
+ }
252
+
253
+ dp.sh.Highlighter.prototype.AddBit = function(str, css)
254
+ {
255
+ if(str == null || str.length == 0)
256
+ return;
257
+
258
+ var span = this.CreateElement('SPAN');
259
+
260
+ // str = str.replace(/&/g, '&amp;');
261
+ str = str.replace(/ /g, '&nbsp;');
262
+ str = str.replace(/</g, '&lt;');
263
+ // str = str.replace(/&lt;/g, '<');
264
+ // str = str.replace(/>/g, '&gt;');
265
+ str = str.replace(/\n/gm, '&nbsp;<br>');
266
+
267
+ // when adding a piece of code, check to see if it has line breaks in it
268
+ // and if it does, wrap individual line breaks with span tags
269
+ if(css != null)
270
+ {
271
+ if((/br/gi).test(str))
272
+ {
273
+ var lines = str.split('&nbsp;<br>');
274
+
275
+ for(var i = 0; i < lines.length; i++)
276
+ {
277
+ span = this.CreateElement('SPAN');
278
+ span.className = css;
279
+ span.innerHTML = lines[i];
280
+
281
+ this.div.appendChild(span);
282
+
283
+ // don't add a <BR> for the last line
284
+ if(i + 1 < lines.length)
285
+ this.div.appendChild(this.CreateElement('BR'));
286
+ }
287
+ }
288
+ else
289
+ {
290
+ span.className = css;
291
+ span.innerHTML = str;
292
+ this.div.appendChild(span);
293
+ }
294
+ }
295
+ else
296
+ {
297
+ span.innerHTML = str;
298
+ this.div.appendChild(span);
299
+ }
300
+ }
301
+
302
+ // checks if one match is inside any other match
303
+ dp.sh.Highlighter.prototype.IsInside = function(match)
304
+ {
305
+ if(match == null || match.length == 0)
306
+ return false;
307
+
308
+ for(var i = 0; i < this.matches.length; i++)
309
+ {
310
+ var c = this.matches[i];
311
+
312
+ if(c == null)
313
+ continue;
314
+
315
+ if((match.index > c.index) && (match.index < c.index + c.length))
316
+ return true;
317
+ }
318
+
319
+ return false;
320
+ }
321
+
322
+ dp.sh.Highlighter.prototype.ProcessRegexList = function()
323
+ {
324
+ for(var i = 0; i < this.regexList.length; i++)
325
+ this.GetMatches(this.regexList[i].regex, this.regexList[i].css);
326
+ }
327
+
328
+ dp.sh.Highlighter.prototype.ProcessSmartTabs = function(code)
329
+ {
330
+ var lines = code.split('\n');
331
+ var result = '';
332
+ var tabSize = 4;
333
+ var tab = '\t';
334
+
335
+ // This function inserts specified amount of spaces in the string
336
+ // where a tab is while removing that given tab.
337
+ function InsertSpaces(line, pos, count)
338
+ {
339
+ var left = line.substr(0, pos);
340
+ var right = line.substr(pos + 1, line.length); // pos + 1 will get rid of the tab
341
+ var spaces = '';
342
+
343
+ for(var i = 0; i < count; i++)
344
+ spaces += ' ';
345
+
346
+ return left + spaces + right;
347
+ }
348
+
349
+ // This function process one line for 'smart tabs'
350
+ function ProcessLine(line, tabSize)
351
+ {
352
+ if(line.indexOf(tab) == -1)
353
+ return line;
354
+
355
+ var pos = 0;
356
+
357
+ while((pos = line.indexOf(tab)) != -1)
358
+ {
359
+ // This is pretty much all there is to the 'smart tabs' logic.
360
+ // Based on the position within the line and size of a tab,
361
+ // calculate the amount of spaces we need to insert.
362
+ var spaces = tabSize - pos % tabSize;
363
+
364
+ line = InsertSpaces(line, pos, spaces);
365
+ }
366
+
367
+ return line;
368
+ }
369
+
370
+ // Go through all the lines and do the 'smart tabs' magic.
371
+ for(var i = 0; i < lines.length; i++)
372
+ result += ProcessLine(lines[i], tabSize) + '\n';
373
+
374
+ return result;
375
+ }
376
+
377
+ dp.sh.Highlighter.prototype.SwitchToList = function()
378
+ {
379
+ // thanks to Lachlan Donald from SitePoint.com for this <br/> tag fix.
380
+ var html = this.div.innerHTML.replace(/<(br)\/?>/gi, '\n');
381
+ var lines = html.split('\n');
382
+
383
+ if(this.addControls == true)
384
+ this.bar.appendChild(dp.sh.Toolbar.Create(this));
385
+
386
+ // add columns ruler
387
+ if(this.showColumns)
388
+ {
389
+ var div = this.CreateElement('div');
390
+ var columns = this.CreateElement('div');
391
+ var showEvery = 10;
392
+ var i = 1;
393
+
394
+ while(i <= 150)
395
+ {
396
+ if(i % showEvery == 0)
397
+ {
398
+ div.innerHTML += i;
399
+ i += (i + '').length;
400
+ }
401
+ else
402
+ {
403
+ div.innerHTML += '&middot;';
404
+ i++;
405
+ }
406
+ }
407
+
408
+ columns.className = 'columns';
409
+ columns.appendChild(div);
410
+ this.bar.appendChild(columns);
411
+ }
412
+
413
+ for(var i = 0, lineIndex = this.firstLine; i < lines.length - 1; i++, lineIndex++)
414
+ {
415
+ var li = this.CreateElement('LI');
416
+ var span = this.CreateElement('SPAN');
417
+
418
+ // uses .line1 and .line2 css styles for alternating lines
419
+ li.className = (i % 2 == 0) ? 'alt' : '';
420
+ span.innerHTML = lines[i] + '&nbsp;';
421
+
422
+ li.appendChild(span);
423
+ this.ol.appendChild(li);
424
+ }
425
+
426
+ this.div.innerHTML = '';
427
+ }
428
+
429
+ dp.sh.Highlighter.prototype.Highlight = function(code)
430
+ {
431
+ function Trim(str)
432
+ {
433
+ return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
434
+ }
435
+
436
+ function Chop(str)
437
+ {
438
+ return str.replace(/\n*$/, '').replace(/^\n*/, '');
439
+ }
440
+
441
+ function Unindent(str)
442
+ {
443
+ var lines = str.split('\n');
444
+ var indents = new Array();
445
+ var regex = new RegExp('^\\s*', 'g');
446
+ var min = 1000;
447
+
448
+ // go through every line and check for common number of indents
449
+ for(var i = 0; i < lines.length && min > 0; i++)
450
+ {
451
+ if(Trim(lines[i]).length == 0)
452
+ continue;
453
+
454
+ var matches = regex.exec(lines[i]);
455
+
456
+ if(matches != null && matches.length > 0)
457
+ min = Math.min(matches[0].length, min);
458
+ }
459
+
460
+ // trim minimum common number of white space from the begining of every line
461
+ if(min > 0)
462
+ for(var i = 0; i < lines.length; i++)
463
+ lines[i] = lines[i].substr(min);
464
+
465
+ return lines.join('\n');
466
+ }
467
+
468
+ // This function returns a portions of the string from pos1 to pos2 inclusive
469
+ function Copy(string, pos1, pos2)
470
+ {
471
+ return string.substr(pos1, pos2 - pos1);
472
+ }
473
+
474
+ var pos = 0;
475
+
476
+ if(code == null)
477
+ code = '';
478
+
479
+ this.originalCode = code;
480
+ this.code = Chop(Unindent(code));
481
+ this.div = this.CreateElement('DIV');
482
+ this.bar = this.CreateElement('DIV');
483
+ this.ol = this.CreateElement('OL');
484
+ this.matches = new Array();
485
+
486
+ this.div.className = 'dp-highlighter';
487
+ this.div.highlighter = this;
488
+
489
+ this.bar.className = 'bar';
490
+
491
+ // set the first line
492
+ this.ol.start = this.firstLine;
493
+
494
+ if(this.CssClass != null)
495
+ this.ol.className = this.CssClass;
496
+
497
+ if(this.collapse)
498
+ this.div.className += ' collapsed';
499
+
500
+ if(this.noGutter)
501
+ this.div.className += ' nogutter';
502
+
503
+ // replace tabs with spaces
504
+ if(this.tabsToSpaces == true)
505
+ this.code = this.ProcessSmartTabs(this.code);
506
+
507
+ this.ProcessRegexList();
508
+
509
+ // if no matches found, add entire code as plain text
510
+ if(this.matches.length == 0)
511
+ {
512
+ this.AddBit(this.code, null);
513
+ this.SwitchToList();
514
+ this.div.appendChild(this.ol);
515
+ return;
516
+ }
517
+
518
+ // sort the matches
519
+ this.matches = this.matches.sort(dp.sh.Highlighter.SortCallback);
520
+
521
+ // The following loop checks to see if any of the matches are inside
522
+ // of other matches. This process would get rid of highligted strings
523
+ // inside comments, keywords inside strings and so on.
524
+ for(var i = 0; i < this.matches.length; i++)
525
+ if(this.IsInside(this.matches[i]))
526
+ this.matches[i] = null;
527
+
528
+ // Finally, go through the final list of matches and pull the all
529
+ // together adding everything in between that isn't a match.
530
+ for(var i = 0; i < this.matches.length; i++)
531
+ {
532
+ var match = this.matches[i];
533
+
534
+ if(match == null || match.length == 0)
535
+ continue;
536
+
537
+ this.AddBit(Copy(this.code, pos, match.index), null);
538
+ this.AddBit(match.value, match.css);
539
+
540
+ pos = match.index + match.length;
541
+ }
542
+
543
+ this.AddBit(this.code.substr(pos), null);
544
+
545
+ this.SwitchToList();
546
+ this.div.appendChild(this.bar);
547
+ this.div.appendChild(this.ol);
548
+ }
549
+
550
+ dp.sh.Highlighter.prototype.GetKeywords = function(str)
551
+ {
552
+ return '\\b' + str.replace(/ /g, '\\b|\\b') + '\\b';
553
+ }
554
+
555
+ // highlightes all elements identified by name and gets source code from specified property
556
+ dp.sh.HighlightAll = function(name, showGutter /* optional */, showControls /* optional */, collapseAll /* optional */, firstLine /* optional */, showColumns /* optional */)
557
+ {
558
+ function FindValue()
559
+ {
560
+ var a = arguments;
561
+
562
+ for(var i = 0; i < a.length; i++)
563
+ {
564
+ if(a[i] == null)
565
+ continue;
566
+
567
+ if(typeof(a[i]) == 'string' && a[i] != '')
568
+ return a[i] + '';
569
+
570
+ if(typeof(a[i]) == 'object' && a[i].value != '')
571
+ return a[i].value + '';
572
+ }
573
+
574
+ return null;
575
+ }
576
+
577
+ function IsOptionSet(value, list)
578
+ {
579
+ for(var i = 0; i < list.length; i++)
580
+ if(list[i] == value)
581
+ return true;
582
+
583
+ return false;
584
+ }
585
+
586
+ function GetOptionValue(name, list, defaultValue)
587
+ {
588
+ var regex = new RegExp('^' + name + '\\[(\\w+)\\]$', 'gi');
589
+ var matches = null;
590
+
591
+ for(var i = 0; i < list.length; i++)
592
+ if((matches = regex.exec(list[i])) != null)
593
+ return matches[1];
594
+
595
+ return defaultValue;
596
+ }
597
+
598
+ function FindTagsByName(list, name, tagName)
599
+ {
600
+ var tags = document.getElementsByTagName(tagName);
601
+
602
+ for(var i = 0; i < tags.length; i++)
603
+ if(tags[i].getAttribute('name') == name)
604
+ list.push(tags[i]);
605
+ }
606
+
607
+ var elements = [];
608
+ var highlighter = null;
609
+ var registered = {};
610
+ var propertyName = 'innerHTML';
611
+
612
+ // for some reason IE doesn't find <pre/> by name, however it does see them just fine by tag name...
613
+ FindTagsByName(elements, name, 'pre');
614
+ FindTagsByName(elements, name, 'textarea');
615
+
616
+ if(elements.length == 0)
617
+ return;
618
+
619
+ // register all brushes
620
+ for(var brush in dp.sh.Brushes)
621
+ {
622
+ var aliases = dp.sh.Brushes[brush].Aliases;
623
+
624
+ if(aliases == null)
625
+ continue;
626
+
627
+ for(var i = 0; i < aliases.length; i++)
628
+ registered[aliases[i]] = brush;
629
+ }
630
+
631
+ for(var i = 0; i < elements.length; i++)
632
+ {
633
+ var element = elements[i];
634
+ var options = FindValue(
635
+ element.attributes['class'], element.className,
636
+ element.attributes['language'], element.language
637
+ );
638
+ var language = '';
639
+
640
+ if(options == null)
641
+ continue;
642
+
643
+ options = options.split(':');
644
+
645
+ language = options[0].toLowerCase();
646
+
647
+ if(registered[language] == null)
648
+ continue;
649
+
650
+ // instantiate a brush
651
+ highlighter = new dp.sh.Brushes[registered[language]]();
652
+
653
+ // hide the original element
654
+ element.style.display = 'none';
655
+
656
+ highlighter.noGutter = (showGutter == null) ? IsOptionSet('nogutter', options) : !showGutter;
657
+ highlighter.addControls = (showControls == null) ? !IsOptionSet('nocontrols', options) : showControls;
658
+ highlighter.collapse = (collapseAll == null) ? IsOptionSet('collapse', options) : collapseAll;
659
+ highlighter.showColumns = (showColumns == null) ? IsOptionSet('showcolumns', options) : showColumns;
660
+
661
+ // write out custom brush style
662
+ if(highlighter.Style)
663
+ document.write('<style>' + highlighter.Style + '</style>');
664
+
665
+ // first line idea comes from Andrew Collington, thanks!
666
+ highlighter.firstLine = (firstLine == null) ? parseInt(GetOptionValue('firstline', options, 1)) : firstLine;
667
+
668
+ highlighter.Highlight(element[propertyName]);
669
+
670
+ highlighter.source = element;
671
+
672
+ element.parentNode.insertBefore(highlighter.div, element);
673
+ }
674
+ }