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