can now remove repos and clone/pull from the url
[rubygit.git] / camping / gitweb.rb
blob37b0262da5083c54ba80b952496d4aa8e9cff3f3
1 require 'rubygems'
2 require 'camping'
3 require 'git'
6 # install dependencies
7 #   sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
9 # todo
10 #   - diff/patch between any two objects
12 # author : scott chacon
15 Camping.goes :GitWeb
17 module GitWeb::Models
18   class Repository < Base; end
19   
20   class CreateGitWeb < V 0.1
21     def self.up
22       create_table :gitweb_repositories, :force => true do |t|
23         t.column :name,  :string 
24         t.column :path,  :string 
25         t.column :bare,  :boolean 
26       end
27     end
28   end
29 end
31 module GitWeb::Controllers
33   class Stylesheet < R '/css/highlight.css'
34     def get
35       @headers['Content-Type'] = 'text/css'
36       ending = File.read(__FILE__).gsub(/.*__END__/m, '')
37       ending.gsub(/__JS__.*/m, '')
38     end
39   end
40   
41   class JsHighlight < R '/js/highlight.js'
42     def get
43       @headers['Content-Type'] = 'text/css'
44       File.read(__FILE__).gsub(/.*__JS__/m, '')
45     end
46   end
47   
48   
49   class Index < R '/'
50     def get
51       @repos = Repository.find :all
52       render :index
53     end
54   end
55     
56   class Add < R '/add'
57     def get
58       @repo = Repository.new
59       render :add
60     end
61     def post
62       if Git.bare(input.repository_path)
63         repo = Repository.create :name => input.repo_name, :path => input.repo_path, :bare => input.repo_bare
64         redirect View, repo
65       else
66         redirect Index
67       end
68     end
69   end
70   
71   class RemoveRepo < R '/remove/(\d+)'
72     def get repo_id
73       @repo = Repository.find repo_id
74       @repo.destroy
75       @repos = Repository.find :all
76       render :index
77     end
78   end
79   
80   
81   class View < R '/view/(\d+)'
82     def get repo_id
83       @repo = Repository.find repo_id
84       @git = Git.bare(@repo.path)      
85       render :view
86     end
87   end
88   
89   class Fetch < R '/git/(\d+)/(.*)'
90     def get repo_id, path
91       @repo = Repository.find repo_id
92       @git = Git.bare(@repo.path)
93       File.read(File.join(@git.repo.path, path))
94     end
95   end
96   
97   class Commit < R '/commit/(\d+)/(\w+)'
98     def get repo_id, sha
99       @repo = Repository.find repo_id
100       @git = Git.bare(@repo.path)      
101       @commit = @git.gcommit(sha)
102       render :commit
103     end
104   end
105   
106   class Tree < R '/tree/(\d+)/(\w+)'
107     def get repo_id, sha
108       @repo = Repository.find repo_id
109       @git = Git.bare(@repo.path)      
110       @tree = @git.gtree(sha)
111       render :tree
112     end
113   end
114   
115   class Blob < R '/blob/(\d+)/(.*?)/(\w+)'
116     def get repo_id, file, sha
117       @repo = Repository.find repo_id
118       @git = Git.bare(@repo.path)      
119       @blob = @git.gblob(sha)
120       @file = file
121       render :blob
122     end
123   end  
124   
125   class BlobRaw < R '/blob/(\d+)/(\w+)'
126      def get repo_id, sha
127        @repo = Repository.find repo_id
128        @git = Git.bare(@repo.path)      
129        @blob = @git.gblob(sha)
130        @blob.contents
131      end
132   end
133   
134   class Archive < R '/archive/(\d+)/(\w+)'
135     def get repo_id, sha
136       @repo = Repository.find repo_id
137       @git = Git.bare(@repo.path)
138       
139       file = @git.gtree(sha).archive
140       @headers['Content-Type'] = 'application/zip'
141       @headers["Content-Disposition"] = "attachment; filename=archive.zip"
142       File.new(file).read
143     end
144   end
146   class Download < R '/download/(\d+)/(.*?)/(\w+)'
147     def get repo_id, file, sha
148       @repo = Repository.find repo_id
149       @git = Git.bare(@repo.path)
150       @headers["Content-Disposition"] = "attachment; filename=#{file}"
151       @git.gblob(sha).contents
152     end
153   end
154   
155   class Diff < R '/diff/(\d+)/(\w+)/(\w+)'
156     def get repo_id, tree1, tree2
157       @repo = Repository.find repo_id
158       @git = Git.bare(@repo.path)
159       @tree1 = tree1
160       @tree2 = tree2
161       @diff = @git.diff(tree2, tree1)
162       render :diff
163     end
164   end
165   
166   class Patch < R '/patch/(\d+)/(\w+)/(\w+)'
167     def get repo_id, tree1, tree2
168       @repo = Repository.find repo_id
169       @git = Git.bare(@repo.path)
170       @diff = @git.diff(tree1, tree2).patch
171     end
172   end
173   
176 module GitWeb::Views
177   def layout
178     html do
179       head do
180         title 'test'
181         link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'
182         script '', :type => "text/javascript", :language => "JavaScript", :src => R(JsHighlight)
183       end
184       style <<-END, :type => 'text/css'
185         body { color: #333; }
186         h1 { background: #cce; padding: 10px; margin: 3px; }
187         h3 { background: #aea; padding: 5px; margin: 3px; }
188         .options { float: right; margin: 10px; }
189         p { padding: 5px; }
190         .odd { background: #eee; }
191         .tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;}
192         .indent { padding: 0px 15px;}
193       END
194       body :onload => "sh_highlightDocument();" do
195         self << yield
196       end
197     end
198   end
200   # git repo views
201   
202   def view
203     h1 @repo.name
204     h2 @repo.path
206     @tags = {}
207     @git.tags.each { |tag| @tags[tag.sha] ||= []; @tags[tag.sha] << tag.name }
208         
209     url = 'http:' + URL(Fetch, @repo.id, '').to_s
211     h3 'info'
212     table.info do
213       tr { td 'owner: '; td @git.config('user.name') }
214       tr { td 'email: '; td @git.config('user.email') }
215       tr { td 'url: '; td { a url, :href => url } }
216     end
217     
218     h3 'shortlog'
219     table.shortlog do
220       @git.log.each do |log|
221         tr do
222           td log.date.strftime("%Y-%m-%d")
223           td log.sha[0, 8]
224           td { em log.author.name }
225           td do
226             span.message log.message[0, 60]
227             @tags[log.sha].each do |t|
228               span.space ' '
229               span.tag { code t }
230             end if @tags[log.sha]
231           end
232           td { a 'commit', :href => R(Commit, @repo, log.sha) }
233           td { a 'commit-diff', :href => R(Diff, @repo, log.sha, log.parent.sha) }
234           td { a 'tree', :href => R(Tree, @repo, log.gtree.sha) }
235           td { a 'archive', :href => R(Archive, @repo, log.gtree.sha) }
236         end
237       end
238     end
239     
240     h3 'branches'
241     @git.branches.each do |branch|
242       li { a branch.full, :href => R(Commit, @repo, branch.gcommit.sha) }
243     end
244     
245     h3 'tags'
246     @git.tags.each do |tag|
247       li { a tag.name, :href => R(Commit, @repo, tag.sha) }
248     end
249     
250   end
251   
252   def commit
253     a.options 'repo', :href => R(View, @repo)
254     h1 @commit.name
255     h3 'info'
256     table.info do
257       tr { td 'author: '; td @commit.author.name + ' <' + @commit.author.email + '>'}
258       tr { td ''; td { code @commit.author.date } }
259       tr { td 'committer: '; td @commit.committer.name + ' <' + @commit.committer.email + '>'}
260       tr { td ''; td { code @commit.committer.date } }
261       tr { td 'commit sha: '; td { code @commit.sha } }
262       tr do
263         td 'tree sha: '
264         td do 
265           code { a @commit.gtree.sha, :href => R(Tree, @repo, @commit.gtree.sha) }
266           span.space ' '
267           a 'archive', :href => R(Archive, @repo, @commit.gtree.sha)
268         end
269       end
270       tr do
271         td 'parents: '
272         td do
273           @commit.parents.each do |p|
274             code { a p.sha, :href => R(Commit, @repo, p.sha) }
275             span.space ' '
276             a 'diff', :href => R(Diff, @repo, p.sha, @commit.sha)
277             span.space ' '
278             a 'archive', :href => R(Archive, @repo, p.gtree.sha)            
279             br
280           end
281         end
282       end
283     end
284     h3 'commit message'
285     p @commit.message
286   end
287   
288   def tree
289     a.options 'repo', :href => R(View, @repo)
290     h3 'tree : ' + @tree.sha
291     p { a 'archive tree', :href => R(Archive, @repo, @tree.sha) }; 
292     table do
293       @tree.children.each do |file, node|
294         tr :class => cycle('odd','even') do
295           td { code node.sha[0, 8] }
296           td node.mode
297           td file
298           if node.type == 'tree'
299             td { a node.type, :href => R(Tree, @repo, node.sha) }
300             td { a 'archive', :href => R(Archive, @repo, node.sha) }
301           else
302             td { a node.type, :href => R(Blob, @repo, file, node.sha) }
303             td { a 'raw', :href => R(BlobRaw, @repo, node.sha) }
304           end
305         end
306       end
307     end 
308   end
310   def blob
311     ext = File.extname(@file).gsub('.', '')
312     
313     case ext
314       when 'rb' : classnm = 'sh_ruby'
315     end
316     
317     a.options 'repo', :href => R(View, @repo)
318     h3 'blob : ' + @blob.sha
319     h4 @file
320     
321     a 'download file', :href => R(Download, @repo, @file, @blob.sha)
322     
323     div.indent { pre @blob.contents, :class => classnm }
324   end
325   
326   def diff
327     a.options 'repo', :href => R(View, @repo)    
328     h1 "diff"
330     p { a 'download patch file', :href => R(Patch, @repo, @tree1, @tree2) }
332     p do
333       a @tree1, :href => R(Tree, @repo, @tree1)
334       span.space ' : '
335       a @tree2, :href => R(Tree, @repo, @tree2)
336     end
337     
338     @diff.each do |file|
339       h3 file.path
340       div.indent { pre file.patch, :class => 'sh_diff' }
341     end
342   end
343   
344   # repo management views
345   
346   def add
347     _form(@repo)
348   end
349   
350   def _form(repo)
351     form(:method => 'post') do
352       label 'Path', :for => 'repo_path'; br
353       input :name => 'repo_path', :type => 'text', :value => repo.path; br
355       label 'Name', :for => 'repo_name'; br
356       input :name => 'repo_name', :type => 'text', :value => repo.name; br
358       label 'Bare', :for => 'repo_bare'; br
359       input :type => 'checkbox', :name => 'repo_bare', :value => repo.bare; br
361       input :type => 'hidden', :name => 'repo_id', :value => repo.id
362       input :type => 'submit'
363     end
364   end
365   
366   def index
367     @repos.each do | repo |
368       h1 repo.name
369       a 'remove', :href => R(RemoveRepo, repo.id)
370       span.space ' '
371       a repo.path, :href => R(View, repo.id)
372     end
373     br
374     br
375     a 'add new repo', :href => R(Add)
376   end
377   
378   # convenience functions
379   
380   def cycle(v1, v2)
381     (@value == v1) ? @value = v2 : @value = v1
382     @value
383   end
384   
387 def GitWeb.create
388   GitWeb::Models.create_schema
391 # everything below this line is the css and javascript for syntax-highlighting
392 __END__
393 pre.sh_sourceCode {
394   background-color: white;
395   color: black;
396   font-style: normal;
397   font-weight: normal;
400 pre.sh_sourceCode .sh_keyword { color: blue; font-weight: bold; }           /* language keywords */
401 pre.sh_sourceCode .sh_type { color: darkgreen; }                            /* basic types */
402 pre.sh_sourceCode .sh_string { color: red; font-family: monospace; }        /* strings and chars */
403 pre.sh_sourceCode .sh_regexp { color: orange; font-family: monospace; }     /* regular expressions */
404 pre.sh_sourceCode .sh_specialchar { color: pink; font-family: monospace; }  /* e.g., \n, \t, \\ */
405 pre.sh_sourceCode .sh_comment { color: brown; font-style: italic; }         /* comments */
406 pre.sh_sourceCode .sh_number { color: purple; }                             /* literal numbers */
407 pre.sh_sourceCode .sh_preproc { color: darkblue; font-weight: bold; }       /* e.g., #include, import */
408 pre.sh_sourceCode .sh_symbol { color: darkred; }                            /* e.g., <, >, + */
409 pre.sh_sourceCode .sh_function { color: black; font-weight: bold; }         /* function calls and declarations */
410 pre.sh_sourceCode .sh_cbracket { color: red; }                              /* block brackets (e.g., {, }) */
411 pre.sh_sourceCode .sh_todo { font-weight: bold; background-color: cyan; }   /* TODO and FIXME */
413 /* for Perl, PHP, Prolog, Python, shell, Tcl */
414 pre.sh_sourceCode .sh_variable { color: darkgreen; }
416 /* line numbers (not yet implemented) */
417 pre.sh_sourceCode .sh_linenum { color: black; font-family: monospace; }
419 /* Internet related */
420 pre.sh_sourceCode .sh_url { color: blue; text-decoration: underline; font-family: monospace; }
422 /* for ChangeLog and Log files */
423 pre.sh_sourceCode .sh_date { color: blue; font-weight: bold; }
424 pre.sh_sourceCode .sh_time, pre.sh_sourceCode .sh_file { color: darkblue; font-weight: bold; }
425 pre.sh_sourceCode .sh_ip, pre.sh_sourceCode .sh_name { color: darkgreen; }
427 /* for LaTeX */
428 pre.sh_sourceCode .sh_italics { color: darkgreen; font-style: italic; }
429 pre.sh_sourceCode .sh_bold { color: darkgreen; font-weight: bold; }
430 pre.sh_sourceCode .sh_underline { color: darkgreen; text-decoration: underline; }
431 pre.sh_sourceCode .sh_fixed { color: green; font-family: monospace; }
432 pre.sh_sourceCode .sh_argument { color: darkgreen; }
433 pre.sh_sourceCode .sh_optionalargument { color: purple; }
434 pre.sh_sourceCode .sh_math { color: orange; }
435 pre.sh_sourceCode .sh_bibtex { color: blue; }
437 /* for diffs */
438 pre.sh_sourceCode .sh_oldfile { color: orange; }
439 pre.sh_sourceCode .sh_newfile { color: darkgreen; }
440 pre.sh_sourceCode .sh_difflines { color: blue; }
442 /* for css */
443 pre.sh_sourceCode .sh_selector { color: purple; }
444 pre.sh_sourceCode .sh_property { color: blue; }
445 pre.sh_sourceCode .sh_value { color: darkgreen; font-style: italic; }
447 __JS__
449 /* Copyright (C) 2007 gnombat@users.sourceforge.net */
450 /* License: http://shjs.sourceforge.net/doc/license.html */
452 function sh_highlightString(inputString,language,builder){var patternStack={_stack:[],getLength:function(){return this._stack.length;},getTop:function(){var stack=this._stack;var length=stack.length;if(length===0){return undefined;}
453 return stack[length-1];},push:function(state){this._stack.push(state);},pop:function(){if(this._stack.length===0){throw"pop on empty stack";}
454 this._stack.pop();}};var pos=0;var currentStyle=undefined;var output=function(s,style){var length=s.length;if(length===0){return;}
455 if(!style){var pattern=patternStack.getTop();if(pattern!==undefined&&!('state'in pattern)){style=pattern.style;}}
456 if(currentStyle!==style){if(currentStyle){builder.endElement();}
457 if(style){builder.startElement(style);}}
458 builder.text(s);pos+=length;currentStyle=style;};var endOfLinePattern=/\r\n|\r|\n/g;endOfLinePattern.lastIndex=0;var inputStringLength=inputString.length;while(pos<inputStringLength){var start=pos;var end;var startOfNextLine;var endOfLineMatch=endOfLinePattern.exec(inputString);if(endOfLineMatch===null){end=inputStringLength;startOfNextLine=inputStringLength;}
459 else{end=endOfLineMatch.index;startOfNextLine=endOfLinePattern.lastIndex;}
460 var line=inputString.substring(start,end);var matchCache=null;var matchCacheState=-1;for(;;){var posWithinLine=pos-start;var pattern=patternStack.getTop();var stateIndex=pattern===undefined?0:pattern.next;var state=language[stateIndex];var numPatterns=state.length;if(stateIndex!==matchCacheState){matchCache=[];}
461 var bestMatch=null;var bestMatchIndex=-1;for(var i=0;i<numPatterns;i++){var match;if(stateIndex===matchCacheState&&(matchCache[i]===null||posWithinLine<=matchCache[i].index)){match=matchCache[i];}
462 else{var regex=state[i].regex;regex.lastIndex=posWithinLine;match=regex.exec(line);matchCache[i]=match;}
463 if(match!==null&&(bestMatch===null||match.index<bestMatch.index)){bestMatch=match;bestMatchIndex=i;}}
464 matchCacheState=stateIndex;if(bestMatch===null){output(line.substring(posWithinLine),null);break;}
465 else{if(bestMatch.index>posWithinLine){output(line.substring(posWithinLine,bestMatch.index),null);}
466 pattern=state[bestMatchIndex];var newStyle=pattern.style;var matchedString;if(newStyle instanceof Array){for(var subexpression=0;subexpression<newStyle.length;subexpression++){matchedString=bestMatch[subexpression+1];output(matchedString,newStyle[subexpression]);}}
467 else{matchedString=bestMatch[0];output(matchedString,newStyle);}
468 if('next'in pattern){patternStack.push(pattern);}
469 else{if('exit'in pattern){patternStack.pop();}
470 if('exitall'in pattern){while(patternStack.getLength()>0){patternStack.pop();}}}}}
471 if(currentStyle){builder.endElement();}
472 currentStyle=undefined;if(endOfLineMatch){builder.text(endOfLineMatch[0]);}
473 pos=startOfNextLine;}}
474 function sh_getClasses(element){var result=[];var htmlClass=element.className;if(htmlClass&&htmlClass.length>0){var htmlClasses=htmlClass.split(" ");for(var i=0;i<htmlClasses.length;i++){if(htmlClasses[i].length>0){result.push(htmlClasses[i]);}}}
475 return result;}
476 function sh_addClass(element,name){var htmlClasses=sh_getClasses(element);for(var i=0;i<htmlClasses.length;i++){if(name.toLowerCase()===htmlClasses[i].toLowerCase()){return;}}
477 htmlClasses.push(name);element.className=htmlClasses.join(" ");}
478 function sh_getText(element){if(element.nodeType===3||element.nodeType===4){return element.data;}
479 else if(element.childNodes.length===1){return sh_getText(element.firstChild);}
480 else{var result='';for(var i=0;i<element.childNodes.length;i++){result+=sh_getText(element.childNodes.item(i));}
481 return result;}}
482 function sh_isEmailAddress(url){if(/^mailto:/.test(url)){return false;}
483 return url.indexOf('@')!==-1;}
484 var sh_builder={init:function(htmlDocument,element){while(element.hasChildNodes()){element.removeChild(element.firstChild);}
485 this._document=htmlDocument;this._element=element;this._currentText=null;this._documentFragment=htmlDocument.createDocumentFragment();this._currentParent=this._documentFragment;this._span=htmlDocument.createElement("span");this._a=htmlDocument.createElement("a");},startElement:function(style){if(this._currentText!==null){this._currentParent.appendChild(this._document.createTextNode(this._currentText));this._currentText=null;}
486 var span=this._span.cloneNode(true);span.className=style;this._currentParent.appendChild(span);this._currentParent=span;},endElement:function(){if(this._currentText!==null){if(this._currentParent.className==='sh_url'){var a=this._a.cloneNode(true);a.className='sh_url';var url=this._currentText;if(url.length>0&&url.charAt(0)==='<'&&url.charAt(url.length-1)==='>'){url=url.substr(1,url.length-2);}
487 if(sh_isEmailAddress(url)){url='mailto:'+url;}
488 a.setAttribute('href',url);a.appendChild(this._document.createTextNode(this._currentText));this._currentParent.appendChild(a);}
489 else{this._currentParent.appendChild(this._document.createTextNode(this._currentText));}
490 this._currentText=null;}
491 this._currentParent=this._currentParent.parentNode;},text:function(s){if(this._currentText===null){this._currentText=s;}
492 else{this._currentText+=s;}},close:function(){if(this._currentText!==null){this._currentParent.appendChild(this._document.createTextNode(this._currentText));this._currentText=null;}
493 this._element.appendChild(this._documentFragment);}};function sh_highlightElement(htmlDocument,element,language){sh_addClass(element,"sh_sourceCode");var inputString;if(element.childNodes.length===0){return;}
494 else{inputString=sh_getText(element);}
495 sh_builder.init(htmlDocument,element);sh_highlightString(inputString,language,sh_builder);sh_builder.close();}
496 function sh_highlightHTMLDocument(htmlDocument){if(!window.sh_languages){return;}
497 var nodeList=htmlDocument.getElementsByTagName("pre");for(var i=0;i<nodeList.length;i++){var element=nodeList.item(i);var htmlClasses=sh_getClasses(element);for(var j=0;j<htmlClasses.length;j++){var htmlClass=htmlClasses[j].toLowerCase();if(htmlClass==="sh_sourcecode"){continue;}
498 var prefix=htmlClass.substr(0,3);if(prefix==="sh_"){var language=htmlClass.substring(3);if(language in sh_languages){sh_highlightElement(htmlDocument,element,sh_languages[language]);}
499 else{throw"Found <pre> element with class='"+htmlClass+"', but no such language exists";}}}}}
500 function sh_highlightDocument(){sh_highlightHTMLDocument(document);}
502 if(!this.sh_languages){this.sh_languages={};}
503 sh_languages['css']=[[{'next':1,'regex':/\/\/\//g,'style':'sh_comment'},{'next':7,'regex':/\/\//g,'style':'sh_comment'},{'next':8,'regex':/\/\*\*/g,'style':'sh_comment'},{'next':14,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/(?:\.|#)[A-Za-z0-9_]+/g,'style':'sh_selector'},{'next':15,'regex':/\{/g,'state':1,'style':'sh_cbracket'},{'regex':/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,'style':'sh_symbol'}],[{'exit':true,'regex':/$/g},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':2,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':4,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':5,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':3,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':4,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':6,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':8,'regex':/\/\*\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':9,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':11,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':12,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':10,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':11,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':13,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':14,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/\}/g,'style':'sh_cbracket'},{'next':16,'regex':/\/\/\//g,'style':'sh_comment'},{'next':22,'regex':/\/\//g,'style':'sh_comment'},{'next':23,'regex':/\/\*\*/g,'style':'sh_comment'},{'next':29,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/[A-Za-z0-9_-]+[ \t]*:/g,'style':'sh_property'},{'regex':/[.%A-Za-z0-9_-]+/g,'style':'sh_value'},{'regex':/#(?:[A-Za-z0-9_]+)/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':17,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':19,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':20,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':18,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':19,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':21,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':23,'regex':/\/\*\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':24,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':26,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':27,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':25,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':26,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':28,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':29,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}]];
505 if(!this.sh_languages){this.sh_languages={};}
506 sh_languages['diff']=[[{'next':1,'regex':/(?=^[-]{3})/g,'state':1,'style':'sh_oldfile'},{'next':6,'regex':/(?=^[*]{3})/g,'state':1,'style':'sh_oldfile'},{'next':14,'regex':/(?=^[\d])/g,'state':1,'style':'sh_difflines'}],[{'next':2,'regex':/^[-]{3}/g,'style':'sh_oldfile'},{'next':3,'regex':/^[-]/g,'style':'sh_oldfile'},{'next':4,'regex':/^[+]/g,'style':'sh_newfile'},{'next':5,'regex':/^@@/g,'style':'sh_difflines'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':7,'regex':/^[*]{3}[ \t]+[\d]/g,'style':'sh_oldfile'},{'next':9,'regex':/^[*]{3}/g,'style':'sh_oldfile'},{'next':10,'regex':/^[-]{3}[ \t]+[\d]/g,'style':'sh_newfile'},{'next':13,'regex':/^[-]{3}/g,'style':'sh_newfile'}],[{'next':8,'regex':/^[\s]/g,'style':'sh_normal'},{'exit':true,'regex':/(?=^[-]{3})/g,'style':'sh_newfile'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':11,'regex':/^[\s]/g,'style':'sh_normal'},{'exit':true,'regex':/(?=^[*]{3})/g,'style':'sh_newfile'},{'exit':true,'next':12,'regex':/^diff/g,'style':'sh_normal'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':15,'regex':/^[\d]/g,'style':'sh_difflines'},{'next':16,'regex':/^[<]/g,'style':'sh_oldfile'},{'next':17,'regex':/^[>]/g,'style':'sh_newfile'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}]];
508 if(!this.sh_languages){this.sh_languages={};}
509 sh_languages['html']=[[{'next':1,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':3,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':4,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':2,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':3,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':5,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}]];
511 if(!this.sh_languages){this.sh_languages={};}
512 sh_languages['javascript']=[[{'regex':/\b(?:import|package)\b/g,'style':'sh_preproc'},{'next':1,'regex':/\/\/\//g,'style':'sh_comment'},{'next':7,'regex':/\/\//g,'style':'sh_comment'},{'next':8,'regex':/\/\*\*/g,'style':'sh_comment'},{'next':14,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,'style':'sh_number'},{'next':15,'regex':/"/g,'style':'sh_string'},{'next':16,'regex':/'/g,'style':'sh_string'},{'regex':/(\b(?:class|interface))([ \t]+)([$A-Za-z0-9]+)/g,'style':['sh_keyword','sh_normal','sh_type']},{'regex':/\b(?:abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with)\b/g,'style':'sh_keyword'},{'regex':/\b(?:int|byte|boolean|char|long|float|double|short|void)\b/g,'style':'sh_type'},{'regex':/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,'style':'sh_symbol'},{'regex':/\{|\}/g,'style':'sh_cbracket'},{'regex':/(?:[A-Za-z]|_)[A-Za-z0-9_]*[ \t]*(?=\()/g,'style':'sh_function'}],[{'exit':true,'regex':/$/g},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':2,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':4,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':5,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':3,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':4,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':6,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':8,'regex':/\/\*\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'next':9,'regex':/<!DOCTYPE/g,'state':1,'style':'sh_preproc'},{'next':11,'regex':/<!--/g,'style':'sh_comment'},{'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,'style':'sh_keyword'},{'next':12,'regex':/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,'state':1,'style':'sh_keyword'},{'regex':/&(?:[A-Za-z0-9]+);/g,'style':'sh_preproc'},{'regex':/@[A-Za-z]+/g,'style':'sh_type'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/>/g,'style':'sh_preproc'},{'next':10,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/-->/g,'style':'sh_comment'},{'next':11,'regex':/<!--/g,'style':'sh_comment'}],[{'exit':true,'regex':/(?:\/)?>/g,'style':'sh_keyword'},{'regex':/[^=" \t>]+/g,'style':'sh_type'},{'regex':/=/g,'style':'sh_symbol'},{'next':13,'regex':/"/g,'style':'sh_string'}],[{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/\*\//g,'style':'sh_comment'},{'next':14,'regex':/\/\*/g,'style':'sh_comment'},{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:TODO|FIXME)(?:[:]?)/g,'style':'sh_todo'}],[{'exit':true,'regex':/"/g,'style':'sh_string'},{'regex':/\\./g,'style':'sh_specialchar'}],[{'exit':true,'regex':/'/g,'style':'sh_string'},{'regex':/\\./g,'style':'sh_specialchar'}]];
514 if(!this.sh_languages){this.sh_languages={};}
515 sh_languages['ruby']=[[{'regex':/\b(?:require)\b/g,'style':'sh_preproc'},{'next':1,'regex':/#/g,'style':'sh_comment'},{'regex':/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,'style':'sh_number'},{'next':2,'regex':/"/g,'style':'sh_string'},{'next':3,'regex':/'/g,'style':'sh_string'},{'next':4,'regex':/</g,'style':'sh_string'},{'regex':/\/[^\n]*\//g,'style':'sh_regexp'},{'regex':/(%r)(\{(?:\\\}|#\{[A-Za-z0-9]+\}|[^}])*\})/g,'style':['sh_symbol','sh_regexp']},{'regex':/\b(?:alias|begin|BEGIN|break|case|defined|do|else|elsif|end|END|ensure|for|if|in|include|loop|next|raise|redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield|false|nil|self|true|__FILE__|__LINE__|and|not|or|def|class|module|catch|fail|load|throw)\b/g,'style':'sh_keyword'},{'next':5,'regex':/(?:^\=begin)/g,'style':'sh_comment'},{'regex':/(?:\$[#]?|@@|@)(?:[A-Za-z0-9_]+|'|\"|\/)/g,'style':'sh_type'},{'regex':/[A-Za-z0-9]+(?:\?|!)/g,'style':'sh_normal'},{'regex':/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,'style':'sh_symbol'},{'regex':/(#)(\{)/g,'style':['sh_symbol','sh_cbracket']},{'regex':/\{|\}/g,'style':'sh_cbracket'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g},{'regex':/\\(?:\\|")/g},{'exit':true,'regex':/"/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g},{'regex':/\\(?:\\|')/g},{'exit':true,'regex':/'/g,'style':'sh_string'}],[{'exit':true,'regex':/$/g},{'exit':true,'regex':/>/g,'style':'sh_string'}],[{'exit':true,'regex':/^(?:\=end)/g,'style':'sh_comment'}]];