process SCS_PAGES_DIR etc. env vars equivalently to --pages_dir config option
[scpubgit/SCS.git] / lib / SCSite.pm
old mode 100644 (file)
new mode 100755 (executable)
index 76c7414..a6b1abf
@@ -1,3 +1,5 @@
+#!/usr/bin/env perl
+
 package SCSite;
 
 use IO::All;
@@ -19,8 +21,9 @@ has _feed_generator => (
 
 sub default_config {
   (
-    pages_dir => 'share/content',
-    template_dir => 'share/skin',
+    pages_dir => 'share/pages',
+    template_dir => 'share/templates',
+    static_dir => 'share/static',
     feed_id_prefix => 'http://shadow.cat',
   )
 }
@@ -118,9 +121,19 @@ sub _render_page {
   my $zoom = $self->_layout_zoom;
   my %filters = %{$self->filters};
   $zoom->select('.page.title')->replace_content($page->title)
-       ->select('meta[name=description]')->replace_content($page->description)
-       ->select('meta[name=keywords]')->replace_content($page->keywords)
-       ->select('.main')->replace_content(\$page->body)
+       ->select('.page.subtitle')->${\sub {
+           $page->subtitle
+             ? $_[0]->replace_content($page->subtitle)
+             : $_[0]->replace('')
+         }}
+       ->select('.page.published_at')->replace_content($page->published_at)
+       ->select('meta[name=description]')
+         ->set_attribute(content => $page->description)
+       ->select('meta[name=keywords]')
+         ->set_attribute(content => $page->keywords)
+       ->select('meta[name=created]')
+         ->set_attribute(content => $page->created)
+       ->select('.page.body')->replace_content(\$page->body)
        ->apply(sub {
            foreach my $fname (sort keys %filters) {
              my $cb = $filters{$fname}->callback_for($page);
@@ -145,7 +158,7 @@ sub run_if_script {
   my $class = shift;
   my @config_keys = keys %{{$class->default_config}};
   require Getopt::Long;
-  my %config;
+  my %config = map +($_ => $ENV{"SCS_${\uc $_}"}), @config_keys;
   Getopt::Long::GetOptions(
     map +("$_=s" => \$config{$_}), @config_keys
   );
@@ -154,4 +167,14 @@ sub run_if_script {
   $new->run(@_)
 }
 
+around _run_cli => sub {
+  my ($orig, $self) = (shift, shift);
+  if (@_ >= 2 and $_[0] eq 'dev' and $_[1] eq 'server') {
+    require SCSite::DevMode;
+    Moo::Role->apply_roles_to_object($self, 'SCSite::DevMode');
+    return $self->_run_dev_server(@_[2..$#_]);
+  }
+  return $self->$orig(@_);
+};
+
 __PACKAGE__->run_if_script;