From: Stevan Little Date: Fri, 2 Apr 2010 19:49:49 +0000 (-0400) Subject: adding code colorizing support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d44d2b16c7cd0fe5d140b874532ffdd5fb3aea9;hp=05fc1e7cd49735d7bbe85975048cf1adf0c7a960;p=gitmo%2Fmoose-website.git adding code colorizing support --- diff --git a/bin/colorize_code.pl b/bin/colorize_code.pl new file mode 100644 index 0000000..27adda4 --- /dev/null +++ b/bin/colorize_code.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Syntax::Highlight::Perl; + +my $color_table = { + 'Variable_Scalar' => 'color:#080;', + 'Variable_Array' => 'color:#f70;', + 'Variable_Hash' => 'color:#80f;', + 'Variable_Typeglob' => 'color:#f03;', + 'Subroutine' => 'color:#980;', + 'Quote' => 'color:#00a;', + 'String' => 'color:#00a;', + 'Comment_Normal' => 'color:#069;font-style:italic;', + 'Comment_POD' => 'color:#014;font-size:11pt;', + 'Bareword' => 'color:#3A3;', + 'Package' => 'color:#900;', + 'Number' => 'color:#f0f;', + 'Operator' => 'color:#000;', + 'Symbol' => 'color:#000;', + 'Keyword' => 'color:#000;', + 'Builtin_Operator' => 'color:#300;', + 'Builtin_Function' => 'color:#001;', + 'Character' => 'color:#800;', + 'Directive' => 'color:#399;font-style:italic;', + 'Label' => 'color:#939;font-style:italic;', + 'Line' => 'color:#000;', +}; + +my $formatter = Syntax::Highlight::Perl->new(); + +$formatter->define_substitution( + '<' => '<', + '>' => '>', + '&' => '&' +); + +while ( my ( $type, $style ) = each %{$color_table} ) { + $formatter->set_format( + $type, + [ + qq||, + '' + ] + ); +} + +my $file = shift || die "Give me a perl file to colorize!\n"; +-e $file or die "There's no such file: $file\n"; + +open F, '<', $file or die $!; + +print '
';
+while () {
+    print $formatter->format_string;
+}
+print "
"; +close F; + +exit 0; + +1; diff --git a/data/code_samples/point.txt b/data/code_samples/point.txt new file mode 100644 index 0000000..7b1617d --- /dev/null +++ b/data/code_samples/point.txt @@ -0,0 +1,23 @@ +package Point; +use Moose; # automatically turns on strict and warnings + +has 'x' => (is => 'rw', isa => 'Int'); +has 'y' => (is => 'rw', isa => 'Int'); + +sub clear { + my $self = shift; + $self->x(0); + $self->y(0); +} + +package Point3D; +use Moose; + +extends 'Point'; + +has 'z' => (is => 'rw', isa => 'Int'); + +after 'clear' => sub { + my $self = shift; + $self->z(0); +}; \ No newline at end of file diff --git a/lib/Moose/Website/I18N/po/en.po b/lib/Moose/Website/I18N/po/en.po index 676dbef..7b4424f 100644 --- a/lib/Moose/Website/I18N/po/en.po +++ b/lib/Moose/Website/I18N/po/en.po @@ -33,36 +33,6 @@ msgstr "Support" msgid "nav presentations" msgstr "Presentations" -# misc - -msgid "moose code sample" -msgstr "" -"
"
-"package Point;\n"
-"use Moose;\n"
-"\n"
-"has 'x' => (is => 'rw', isa => 'Int');\n"
-"has 'y' => (is => 'rw', isa => 'Int');\n"
-"\n"
-"sub clear {\n"
-"    my $self = shift;\n"
-"    $self->x(0);\n"
-"    $self->y(0);\n"
-"}\n"
-"\n"
-"package Point3D;\n"
-"use Moose;\n"
-"\n"
-"extends 'Point';\n"
-"\n"
-"has 'z' => (is => 'rw', isa => 'Int');\n"
-"\n"
-"after 'clear' => sub {\n"
-"    my $self = shift;\n"
-"    $self->z(0);\n"
-"};\n"
-"
" - # home msgid "home body" diff --git a/lib/Moose/Website/Resource/Templates/code/point.tt b/lib/Moose/Website/Resource/Templates/code/point.tt new file mode 100644 index 0000000..843a3e1 --- /dev/null +++ b/lib/Moose/Website/Resource/Templates/code/point.tt @@ -0,0 +1,23 @@ +
package Point;
+use Moose; # automatically turns on strict and warnings
+
+has 'x' => (is => 'rw', isa => 'Int');
+has 'y' => (is => 'rw', isa => 'Int');
+
+sub clear {
+    my $self = shift;
+    $self->x(0);
+    $self->y(0);
+}
+
+package Point3D;
+use Moose;
+
+extends 'Point';
+
+has 'z' => (is => 'rw', isa => 'Int');
+
+after 'clear' => sub {
+    my $self = shift;
+    $self->z(0);
+};
\ No newline at end of file diff --git a/lib/Moose/Website/Resource/Templates/wrapper/root.tt b/lib/Moose/Website/Resource/Templates/wrapper/root.tt index 5995f29..b22778a 100644 --- a/lib/Moose/Website/Resource/Templates/wrapper/root.tt +++ b/lib/Moose/Website/Resource/Templates/wrapper/root.tt @@ -25,7 +25,7 @@ jQuery(document).ready(function($) { [% INCLUDE 'shared/footer.tt' %] \ No newline at end of file diff --git a/lib/Moose/Website/Resource/WebFiles/css/style.css b/lib/Moose/Website/Resource/WebFiles/css/style.css index 3a06cb7..a497097 100644 --- a/lib/Moose/Website/Resource/WebFiles/css/style.css +++ b/lib/Moose/Website/Resource/WebFiles/css/style.css @@ -99,7 +99,7 @@ pre { padding : 10px; border : 1px dotted #aaaaaa; color : #333333; - width : 550px; + width : 500px; } ul {