Skip to content
Browse files

adding code snippets

  • Loading branch information...
1 parent 09f214d commit df2948ff7d281748eb8588208fe239b781fb3336 @yanick committed
Showing with 23 additions and 0 deletions.
  1. +4 −0 galuga.conf
  2. +19 −0 lib/Galuga/Controller/Entry.pm
View
4 galuga.conf
@@ -15,6 +15,10 @@ blog_author yanick@babyl.dyndns.org (Yanick Champoux)
template_extension .mason
</View::Mason>
+<disqus>
+ development 1
+</disqus>
+
<Model::DB>
<connect_info>
dsn dbi:SQLite:dbname=/home/yanick/work/perl-modules/Galuga/db.sqlite
View
19 lib/Galuga/Controller/Entry.pm
@@ -3,6 +3,7 @@ use Moose;
use namespace::autoclean;
use List::MoreUtils qw/ uniq /;
+use File::Slurp qw/ slurp /;
BEGIN {extends 'Catalyst::Controller'; }
@@ -69,6 +70,8 @@ sub index :Chained('base') :PathPart('') :Args(0) {
# __ENTRY_DIR__
$body =~ s#__ENTRY_DIR__# $c->uri_for( "/entry/" . $rs->url . "/files" ) #eg;
+ $body =~ s#(<galuga_code.*?</galuga_code>)#code_snippet( $c, $rs, $1 )#eg;
+
my @syntax;
while ( $body =~ s#<pre \s+ code=(['"])(.*?)\1#<pre class="brush: $2" #xg ) {
push @syntax, $2;
@@ -88,6 +91,22 @@ sub index :Chained('base') :PathPart('') :Args(0) {
}
+sub code_snippet {
+ my ($c, $entry, $tag) =@_;
+
+ $tag =~ />(.*?)</;
+
+ my $content = slurp( join '/', $c->config->{blog_root}, $entry->path,
+ 'files', $1 );
+
+ $content =~ s/</&lt;/g;
+ $content =~ s/>/&gt;/g;
+
+ my ( undef, $lang ) = $tag =~ /code=(['"])(.*?)\1/;
+
+ return "<pre code='$lang'>$content</pre>";
+}
+
sub entry_tag {
my $c = shift;
my $entry = shift;

0 comments on commit df2948f

Please sign in to comment.
Something went wrong with that request. Please try again.