From 14a1b611bead14458336cf12a0862c928a429a7b Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 11:12:31 +1100 Subject: [PATCH 1/7] Now passing the full file path to the Javascript "showFile" method, so we can use the file suffix to determine which syntax highlighting to use. --- GLFileView.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GLFileView.m b/GLFileView.m index bec36c65c..fbc601e53 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -77,7 +77,7 @@ - (void) showFile if ([files count]>0) { PBGitTree *file=[files objectAtIndex:0]; - NSString *fileTxt=@""; + NSString *fileTxt = @""; if(startFile==@"fileview") fileTxt=[self parseHTML:[file textContents]]; else if(startFile==@"blame") @@ -86,7 +86,8 @@ - (void) showFile fileTxt=[file log:logFormat]; id script = [view windowScriptObject]; - [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObject:fileTxt]]; + NSString *filePath = [file fullPath]; + [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]]; } #if 0 From 4e208d5b554456b785343a00088aa4861b7ca1bc Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 11:14:21 +1100 Subject: [PATCH 2/7] Reading the full file path, extracting the suffix, then using that to pick the brush for syntax highlighting. --- html/views/fileview/fileview.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/html/views/fileview/fileview.js b/html/views/fileview/fileview.js index a8abad62d..127e9a06c 100644 --- a/html/views/fileview/fileview.js +++ b/html/views/fileview/fileview.js @@ -1,16 +1,20 @@ -var showFile = function(txt) { - $("source").style.display = ""; - $("source").innerHTML="
"+txt+"
"; - - SyntaxHighlighter.defaults['toolbar'] = false; - SyntaxHighlighter.highlight(); - - return; +var showFile = function(txt, fileName) { + $("source").style.display = ""; + var brush = "objc"; + if (fileName && fileName != '') { + brush = fileName.substr(fileName.lastIndexOf('.') + 1); + } + $("source").innerHTML="
" + txt + "
"; + + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.highlight(); + + return; } var test=function(txt) { - SyntaxHighlighter.defaults['toolbar'] = false; - SyntaxHighlighter.highlight(); - - return; + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.highlight(); + + return; } From e12180ae3e75f72913fc07c4ae1a5da871753b3d Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 11:15:15 +1100 Subject: [PATCH 3/7] Now importing all the syntax highlighting brush files, so we can use the one we need for the given file type. --- html/views/fileview/index.html | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/html/views/fileview/index.html b/html/views/fileview/index.html index 6dfb4cdcd..c00ff27ab 100644 --- a/html/views/fileview/index.html +++ b/html/views/fileview/index.html @@ -2,8 +2,35 @@ + + + + + + + + + + + + + + + - + + + + + + + + + + + + + From 09e25adfd85038f8c476d963e3a9328f4581a502 Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 11:17:43 +1100 Subject: [PATCH 4/7] Changed name of README to README.markdown, so that Github automatically formats it. --- README => README.markdown | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README => README.markdown (100%) diff --git a/README b/README.markdown similarity index 100% rename from README rename to README.markdown From 3ee7fb304237e196104f6ab698f4486cf4fdbc1c Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 13:25:35 +1100 Subject: [PATCH 5/7] Added aliases for 'm' & 'h' for objc. Added a hash of possible values to select the correct brush based on the suffix. This fixes a problem where some suffixes did not match brush aliases. --- .../syntaxhighlighter/scripts/shBrushObjC.js | 2 +- html/views/fileview/fileview.js | 38 ++++++++++++++++++- html/views/fileview/index.html | 3 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/html/lib/syntaxhighlighter/scripts/shBrushObjC.js b/html/lib/syntaxhighlighter/scripts/shBrushObjC.js index d99555d3c..8fb7c8447 100644 --- a/html/lib/syntaxhighlighter/scripts/shBrushObjC.js +++ b/html/lib/syntaxhighlighter/scripts/shBrushObjC.js @@ -55,5 +55,5 @@ SyntaxHighlighter.brushes.ObjC = function() }; SyntaxHighlighter.brushes.ObjC.prototype = new SyntaxHighlighter.Highlighter(); -SyntaxHighlighter.brushes.ObjC.aliases = ['objc']; +SyntaxHighlighter.brushes.ObjC.aliases = ['objc', 'm', 'h']; diff --git a/html/views/fileview/fileview.js b/html/views/fileview/fileview.js index 127e9a06c..6a72c02b9 100644 --- a/html/views/fileview/fileview.js +++ b/html/views/fileview/fileview.js @@ -1,9 +1,37 @@ var showFile = function(txt, fileName) { $("source").style.display = ""; + var suffix_map = { + "objc": ["m", "h"], + "ruby": ["rb", "rbx", "rjs", "Rakefile", "rake", "gemspec", "irbrc", "capfile"], + "xml": ['xml', 'tld', 'jsp', 'pt', 'cpt', 'dtml', 'rss', 'opml', 'xsl', 'xslt'], + "javascript": ['js', 'htc', 'jsx', 'jscript', 'javascript'], + "sql": ['sql', 'ddl', 'dml'], + "sass": ['sass', 'scss'], + "bash": ['sh', 'bash', 'zsh', 'bashrc', 'bash_profile', 'bash_login', 'profile', 'bash_logout'], + "diff": ['diff', 'patch'], + "java": ['java', 'bsh'], + "css": ['css', 'css.erb'], + "perl": ['pl', 'pm', 'pod', 't', 'PL'], + "erlang": ['erl', 'hrl'], + "php": ['php'], + "python": ['py', 'rpy', 'pyw', 'cpy', 'SConstruct', 'Sconstruct', 'sconstruct', 'SConscript'], + "cpp": ['cc', 'cpp', 'cp', 'cxx', 'c++', 'C', 'h', 'hh', 'hpp', 'h++', 'c'] + } var brush = "objc"; + var suffix = ""; if (fileName && fileName != '') { - brush = fileName.substr(fileName.lastIndexOf('.') + 1); + suffix = fileName.substr(fileName.lastIndexOf('.') + 1); + } + var keys = get_keys(suffix_map); + for (var key in keys) { + var suffixes = suffix_map[key]; + for (var possible_suffix in suffixes) { + if (possible_suffix == suffix) { + brush = key; + } + } } + $("source").innerHTML="
" + txt + "
"; SyntaxHighlighter.defaults['toolbar'] = false; @@ -18,3 +46,11 @@ var test=function(txt) { return; } + +var get_keys = function(obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + } + return keys; +} diff --git a/html/views/fileview/index.html b/html/views/fileview/index.html index c00ff27ab..71f878e33 100644 --- a/html/views/fileview/index.html +++ b/html/views/fileview/index.html @@ -30,7 +30,8 @@ - + + From a8ff00494b9fb09dab9b5f562316da161a6fadaf Mon Sep 17 00:00:00 2001 From: David Parry Date: Wed, 24 Nov 2010 20:59:58 +1100 Subject: [PATCH 6/7] Changed the structure of the suffix-brush mapping, so the code is much simpler and faster. --- html/views/fileview/fileview.js | 110 +++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 24 deletions(-) diff --git a/html/views/fileview/fileview.js b/html/views/fileview/fileview.js index 6a72c02b9..3db841c56 100644 --- a/html/views/fileview/fileview.js +++ b/html/views/fileview/fileview.js @@ -1,36 +1,98 @@ var showFile = function(txt, fileName) { $("source").style.display = ""; var suffix_map = { - "objc": ["m", "h"], - "ruby": ["rb", "rbx", "rjs", "Rakefile", "rake", "gemspec", "irbrc", "capfile"], - "xml": ['xml', 'tld', 'jsp', 'pt', 'cpt', 'dtml', 'rss', 'opml', 'xsl', 'xslt'], - "javascript": ['js', 'htc', 'jsx', 'jscript', 'javascript'], - "sql": ['sql', 'ddl', 'dml'], - "sass": ['sass', 'scss'], - "bash": ['sh', 'bash', 'zsh', 'bashrc', 'bash_profile', 'bash_login', 'profile', 'bash_logout'], - "diff": ['diff', 'patch'], - "java": ['java', 'bsh'], - "css": ['css', 'css.erb'], - "perl": ['pl', 'pm', 'pod', 't', 'PL'], - "erlang": ['erl', 'hrl'], - "php": ['php'], - "python": ['py', 'rpy', 'pyw', 'cpy', 'SConstruct', 'Sconstruct', 'sconstruct', 'SConscript'], - "cpp": ['cc', 'cpp', 'cp', 'cxx', 'c++', 'C', 'h', 'hh', 'hpp', 'h++', 'c'] + "m": "objc", + "h": "objc", + + "rb": "ruby", + "rbx": "ruby", + "rjs": "ruby", + "Rakefile": "ruby", + "rake": "ruby", + "gemspec": "ruby", + "irbrc": "ruby", + "capfile": "ruby", + + "xml": "xml", + "tld": "xml", + "jsp": "xml", + "pt": "xml", + "cpt": "xml", + "dtml": "xml", + "rss": "xml", + "opml": "xml", + "xsl": "xml", + "xslt": "xml", + + "js": "javascript", + "htc": "javascript", + "jsx": "javascript", + "jscript": "javascript", + "javascript": "javascript", + + "sql": "sql", + "ddl": "sql", + "dml": "sql", + + "sass": "sass", + "scss": "sass", + + "sh": "bash", + "bash": "bash", + "zsh": "bash", + "bashrc": "bash", + "bash_profile": "bash", + "bash_login": "bash", + "profile": "bash", + "bash_logout": "bash", + + "diff": "diff", + "patch": "diff", + + "java": "java", + "bsh": "java", + + "css": "css", + "css": "css.erb", + "pl": "perl", + "pm": "perl", + "pod": "perl", + "t": "perl", + "PL": "perl", + + "erl": "erlang", + "hrl": "erlang", + + "php": "php", + + "py": "python", + "rpy": "python", + "pyw": "python", + "cpy": "python", + "SConstruct": "python", + "Sconstruct": "python", + "sconstruct": "python", + "SConscript": "python", + + "cc": "cpp", + "cpp": "cpp", + "cp": "cpp", + "cxx": "cpp", + "c++":"cpp", + "C": "cpp", + "h": "cpp", + "hh": "cpp", + "hpp": "cpp", + "cpp": "h++", + "c": "cpp" } var brush = "objc"; var suffix = ""; if (fileName && fileName != '') { suffix = fileName.substr(fileName.lastIndexOf('.') + 1); } - var keys = get_keys(suffix_map); - for (var key in keys) { - var suffixes = suffix_map[key]; - for (var possible_suffix in suffixes) { - if (possible_suffix == suffix) { - brush = key; - } - } - } + + brush = suffix_map[suffix]; $("source").innerHTML="
" + txt + "
"; From 1c31a4cc1e2b5f5167e6be14f804b567f0c15d87 Mon Sep 17 00:00:00 2001 From: David Parry Date: Thu, 25 Nov 2010 12:00:40 +1100 Subject: [PATCH 7/7] Fixed silly mistake with duplicated shCore.js included. --- html/views/fileview/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/html/views/fileview/index.html b/html/views/fileview/index.html index 71f878e33..0edf8fb29 100644 --- a/html/views/fileview/index.html +++ b/html/views/fileview/index.html @@ -29,7 +29,6 @@ -