The blob action now has simple (but functioning) syntax highlighting (thanks to jrock...
broquaint [Thu, 22 Oct 2009 09:47:09 +0000 (10:47 +0100)]
TODO
lib/Gitalist/Controller/Root.pm
lib/Gitalist/View/Default.pm
lib/Gitalist/View/SyntaxHighlight.pm [new file with mode: 0644]
root/static/css/syntax-dark.css [new file with mode: 0644]
templates/blob.tt2

diff --git a/TODO b/TODO
index 8976ebc..852b6e1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +1,3 @@
 * Fix git_blob_plain i.e don't use the wrapper.
+* An action to find what branches have been merged, either as a list or through a search mechanism.
+* An action to find which branches a given commit is on.
index 75f5e5f..7f54f8c 100644 (file)
@@ -78,6 +78,8 @@ sub blob : Local {
       blob   => $c->model('GPP')->get_object($c->req->param('h'))->content,
       action => 'blob',
   );
+
+  $c->forward('View::Syntax');
 }
 
 sub reflog : Local {
index 2c65caa..e418acf 100644 (file)
@@ -34,4 +34,10 @@ __PACKAGE__->config(
        WRAPPER            => 'default.tt2',
 );
 
+# before end => sub {
+#     my ( $self, $c ) = @_;
+#     return unless $c->stash->{syntax_highlight};
+#     $c->forward( 'View::SyntaxHighlight', $c->stash->{syntax_highlight} );
+# };
+
 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
diff --git a/lib/Gitalist/View/SyntaxHighlight.pm b/lib/Gitalist/View/SyntaxHighlight.pm
new file mode 100644 (file)
index 0000000..642599f
--- /dev/null
@@ -0,0 +1,49 @@
+package Gitalist::View::SyntaxHighlight;
+use Moose;
+use Gitalist; # ->path_to
+use namespace::autoclean;
+
+extends 'Catalyst::View';
+
+use Syntax::Highlight::Engine::Kate ();
+use Syntax::Highlight::Engine::Kate::Perl ();
+
+sub process {
+    my($self, $c) = @_;
+    # via
+    # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
+    eval {
+        no warnings 'redefine';
+        local *Syntax::Highlight::Engine::Kate::Template::logwarning
+          = sub { die @_ }; # i really don't care
+        my $hl = Syntax::Highlight::Engine::Kate->new(
+            language      => 'Perl',
+            substitutions => {
+                "<"  => "&lt;",
+                ">"  => "&gt;",
+                "&"  => "&amp;",
+                q{'} => "&apos;",
+                q{"} => "&quot;",
+            },
+            format_table => {
+                # convert Kate's internal representation into
+                # <span class="<internal name>"> value </span>
+                map {
+                    $_ => [ qq{<span class="$_">}, '</span>' ]
+                }
+                  qw/Alert BaseN BString Char Comment DataType
+                     DecVal Error Float Function IString Keyword
+                     Normal Operator Others RegionMarker Reserved
+                     String Variable Warning/,
+            },
+        );
+
+        $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
+    };
+
+    warn $@ if $@;
+
+    $c->forward('View::Default');
+}
+
+1;
diff --git a/root/static/css/syntax-dark.css b/root/static/css/syntax-dark.css
new file mode 100644 (file)
index 0000000..3d2e533
--- /dev/null
@@ -0,0 +1,69 @@
+span.Alert {\r
+ color: #0000ff;\r
+}\r
+span.BaseN {\r
+ color: #007f00;\r
+}\r
+span.BString {\r
+ color: #c9a7ff;\r
+}\r
+span.Char {\r
+ color: #ff00ff;\r
+}\r
+span.Comment {\r
+ color: #cc9900;\r
+}\r
+span.DataType {\r
+ color: #00ff55;\r
+}\r
+span.DecVal {\r
+ color: #00ffff;\r
+}\r
+span.Error {\r
+ color: #ff0000;\r
+}\r
+span.Float {\r
+ color: #5599ff;\r
+}\r
+span.Function {\r
+ color: #3344ff;\r
+}\r
+span.IString {\r
+ color: #ff0000;\r
+}\r
+span.Keyword {\r
+ color: #11ffff;\r
+ font-weight: bold;\r
+}\r
+span.Operator {\r
+ color: #00ff33;\r
+ font-weight: bold;\r
+}\r
+span.Others {\r
+ color: #b03060;\r
+}\r
+span.RegionMarker {\r
+ color: #96b9ff;\r
+}\r
+span.Reserved {\r
+ color: #9b30ff;\r
+ font-weight: bold;\r
+}\r
+span.String {\r
+ color: #ffaa55;\r
+}\r
+span.Variable {\r
+ color: #ffff00;\r
+}\r
+span.Warning {\r
+ color: #0000ff;\r
+}\r
+\r
+pre.blob {\r
+    background-color: #333;\r
+    color: #ddd;\r
+    border-left: solid 3px #c33;\r
+    padding: 5px;\r
+    padding-left: 15px;\r
+    margin: 10px 15px;\r
+}\r
index 6a85d6c..44c03ed 100644 (file)
@@ -1,5 +1,6 @@
+<link rel="stylesheet" type="text/css" href="/static/css/syntax-dark.css"/>
 <div>
-<pre>
-[% blob | html %]
+<pre class='blob'>
+[% blob %]
 </pre>
 </div>