[Bps-public-commit] SD - A distributed issue tracker branch, master, updated. 2e58c0922b51f1d3eb261f330faf01edd3cffff9
jesse
jesse at bestpractical.com
Sat Jan 31 02:26:55 EST 2009
The branch, master has been updated
via 2e58c0922b51f1d3eb261f330faf01edd3cffff9 (commit)
via 9a6805493efd231e795b2a6ab3dec6728443e01f (commit)
via 7c3a5e43351c2b2b64a6cb4b27ef18d4276e91c4 (commit)
via 0303c71d6ed97feb671c6fec59ad07bcb57aa542 (commit)
via 0be1a19795c6577441a06b55e6a64945fde00119 (commit)
from 3d0e69e535739c122e75e8608965368ad3a285a5 (commit)
Summary of changes:
Makefile.PL | 1 +
lib/App/SD/CLI/Command/Publish.pm | 184 +++++++++++++++++++++++++++++++++++++
lib/App/SD/Server/Dispatcher.pm | 4 +-
lib/App/SD/Server/View.pm | 24 ++++-
4 files changed, 206 insertions(+), 7 deletions(-)
create mode 100644 lib/App/SD/CLI/Command/Publish.pm
- Log -----------------------------------------------------------------
commit 0be1a19795c6577441a06b55e6a64945fde00119
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 31 01:35:17 2009 -0500
warning silencing
diff --git a/Makefile.PL b/Makefile.PL
index 39b69b4..627f009 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -10,6 +10,7 @@ requires 'Prophet'; # URI UNIVERSAL::require Params::Validate Class::Accessor Te
requires('Moose'); # Moose::Role
requires('HTTP::Date');
requires('DateTime::Format::Natural');
+requires('HTML::Tree');
features(
'RT sync' => [
-default => 0,
diff --git a/lib/App/SD/Server/View.pm b/lib/App/SD/Server/View.pm
index 8c81fe3..2a5c040 100644
--- a/lib/App/SD/Server/View.pm
+++ b/lib/App/SD/Server/View.pm
@@ -467,7 +467,7 @@ template 'no_component' => sub {show 'component' => undef};
template 'component' => page { 'Component: ' . ( $_[1] || '<i>none</i>' ) }
content {
my $self = shift;
- my $component = shift;
+ my $component = shift || '' ;
$self->show_tickets(
sub {my $item = shift;
@@ -672,10 +672,24 @@ template header => sub {
template '/tickets/hot' => sub {
my $self = shift;
-
- my $current_milestone = $self->app_handle->setting(label => 'default_milestone')->get()->[0];
- $self->show_tickets (sub { my $item = shift; return ($item->has_active_status && $item->prop('milestone') eq $current_milestone && ($item->prop('owner') eq $item->app_handle->config->get('email_address')|| !$item->prop('owner'))) ? 1 : 0; });
+ my $current_milestone = $self->app_handle->setting( label => 'default_milestone' )->get()->[0];
+
+ $self->show_tickets(
+ sub {
+ my $item = shift;
+ if ( $item->has_active_status
+ && ( $item->prop('milestone') || '' ) eq $current_milestone
+ && ( ( $item->prop('owner') || '' ) eq
+ $item->app_handle->config->get('email_address') || !$item->prop('owner') )
+ )
+ {
+ return 1;
+ } else {
+ return undef;
+ }
+ }
+ );
};
commit 0303c71d6ed97feb671c6fec59ad07bcb57aa542
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 31 01:37:33 2009 -0500
First pass of a modern html publish for sd
diff --git a/lib/App/SD/CLI/Command/Publish.pm b/lib/App/SD/CLI/Command/Publish.pm
new file mode 100644
index 0000000..40d1ac3
--- /dev/null
+++ b/lib/App/SD/CLI/Command/Publish.pm
@@ -0,0 +1,169 @@
+package App::SD::CLI::Command::Publish;
+use Moose;
+extends 'Prophet::CLI::Command::Publish';
+use Prophet::Util;
+use File::Path;
+use File::Spec;
+use HTML::TreeBuilder;
+use URI::file;
+
+sub export_html {
+ my $self = shift;
+ my $path = $self->arg('path');
+
+ # if they specify both html and replica, then stick rendered templates
+ # into a subdirectory. if they specify only html, assume they really
+ # want to publish directly into the specified directory
+ if ( $self->has_arg('replica') ) {
+ $path = File::Spec->catdir( $path => 'html' );
+ mkpath( [$path] );
+ }
+
+ $self->render_templates_into($path);
+}
+
+# helper methods for rendering templates
+sub render_templates_into {
+ my $self = shift;
+ my $dir = shift;
+
+ require App::SD::Server;
+ my $server = App::SD::Server::Static->new( read_only => 1, static => 1 );
+ $server->app_handle( $self->app_handle );
+ $server->setup_template_roots();
+ use CGI;
+ my $file = "/";
+ {
+
+ local $ENV{'REMOTE_ADDR'} = '127.0.0.1';
+ local $ENV{'REQUEST_METHOD'} = 'GET';
+ my $cgi = CGI->new();
+
+ my @links = ('/');
+ my $seen = {};
+ while ( my $file = shift @links ) {
+ next if $seen->{$file};
+ eval {
+ $cgi->path_info($file);
+ my $content = $server->handle_request($cgi);
+ my $page_links = [];
+ ( $content, $page_links ) = $self->work_with_urls( $file, $content );
+
+ push @links, grep { !$seen->{$_} } @$page_links;
+
+ $self->write_file( $dir, $file, $content );
+
+ $seen->{$file}++;
+ };
+
+ if ( $@ =~ /^REDIRECT (.*)$/ ) {
+ my $new_file = $1;
+ chomp($new_file);
+ $self->handle_redirect( $dir, $file, $new_file );
+ unshift @links, $new_file;
+ } elsif ($@) {
+ die $@;
+ }
+ }
+ }
+}
+
+sub work_with_urls {
+ my $self = shift;
+ my $current_url = shift;
+ my $content = shift;
+
+ #Extract Links from the file
+ my $h = HTML::TreeBuilder->new;
+ $h->parse_content($content);
+
+ my $link_elements = $h->extract_links(qw(img href script style a link ));
+ return ($content, []) unless @$link_elements;
+
+ my $all_links = {};
+
+ #Grab each img src and re-write them so they are relative URL's
+ foreach my $link_element (@$link_elements) {
+
+ my $link = shift @$link_element; #URL value
+ my $element = shift @$link_element; #HTML::Element Object
+
+ $all_links->{$link}++;
+
+ my $url = URI::file->new($link)->rel("file://$current_url");
+ $url .= "index.html" if ( $url =~ m|/$| );
+ my ($attr)
+ = grep { defined $element->attr($_) and $link eq $element->attr($_) }
+ @{ $HTML::Tagset::linkElements{ $element->tag } };
+
+ #Re-write the attribute in the HTML::Element Tree
+ $element->attr( $attr, $url );
+
+ }
+
+ return $h->as_HTML, [ keys %$all_links ];
+}
+
+sub handle_redirect {
+ my $self = shift;
+ my $dir = shift;
+ my $file = shift;
+ my $new_file = shift;
+ my $redirected_from = File::Spec->catfile( $dir => $file );
+ my $redirected_to = File::Spec->catfile( $dir => $new_file );
+ {
+ my $parent = Prophet::Util->updir($redirected_from);
+ unless ( -d $parent ) {
+ eval { mkpath( [$parent] ) };
+ die "Failed to create directory " . $parent . " - for $redirected_to " . $@;
+ }
+ }
+ if ( -d $redirected_from ) { $redirected_from .= "/index.html"; }
+ link( $redirected_to, $redirected_from );
+}
+
+sub write_file {
+ my $self = shift;
+ my $dir = shift;
+ my $file = shift;
+ my $content = shift;
+
+ $file .= "index.html" if ( $file =~ qr|/$| );
+ Prophet::Util->write_file( file => File::Spec->catfile( $dir => $file ), content => $content );
+
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+package App::SD::Server::Static;
+use base 'App::SD::Server';
+use Params::Validate;
+use JSON;
+
+sub log_request { }
+
+sub send_content {
+ my $self = shift;
+ my %args = validate( @_, { content => 1, content_type => 0, encode_as => 0, static => 0 } );
+
+ if ( $args{'encode_as'} && $args{'encode_as'} eq 'json' ) {
+ $args{'content'} = to_json( $args{'content'} );
+ }
+
+ return $args{'content'};
+}
+
+sub _send_redirect {
+ my $self = shift;
+ my %args = validate( @_, { to => 1 } );
+ die "REDIRECT " . $args{to} . "\n";
+}
+
+sub _send_404 {}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
commit 7c3a5e43351c2b2b64a6cb4b27ef18d4276e91c4
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 31 01:44:41 2009 -0500
Don't show any features requiring a server in when publishing
diff --git a/lib/App/SD/CLI/Command/Publish.pm b/lib/App/SD/CLI/Command/Publish.pm
index 40d1ac3..98c61cf 100644
--- a/lib/App/SD/CLI/Command/Publish.pm
+++ b/lib/App/SD/CLI/Command/Publish.pm
@@ -30,6 +30,7 @@ sub render_templates_into {
require App::SD::Server;
my $server = App::SD::Server::Static->new( read_only => 1, static => 1 );
$server->app_handle( $self->app_handle );
+ $server->static(1);
$server->setup_template_roots();
use CGI;
my $file = "/";
diff --git a/lib/App/SD/Server/Dispatcher.pm b/lib/App/SD/Server/Dispatcher.pm
index 7e87d04..2cb261e 100644
--- a/lib/App/SD/Server/Dispatcher.pm
+++ b/lib/App/SD/Server/Dispatcher.pm
@@ -15,7 +15,7 @@ on qr'.' => sub {
on qr'.' => sub {
my $self = shift;
my $tickets = $self->server->nav->child( tickets => label => 'Tickets', url => '/');
- $tickets->child( go => label => '<form method="GET" action="/ticket"><a href="#">Show ticket # <input type=text name=id size=3></a></form>', escape_label => 0);
+ $tickets->child( go => label => '<form method="GET" action="/ticket"><a href="#">Show ticket # <input type=text name=id size=3></a></form>', escape_label => 0) unless($self->server->static);
my $milestones = $tickets->child( milestones => label => 'Milestones', url => '/milestones');
@@ -40,7 +40,7 @@ on qr'.' => sub {
}
$components->child('None' => label => 'None', url => '/no_component');
- $self->server->nav->child( create => label => 'New ticket', url => '/ticket/new');
+ $self->server->nav->child( create => label => 'New ticket', url => '/ticket/new') unless($self->server->static);
$self->server->nav->child( home => label => 'Home', url => '/');
diff --git a/lib/App/SD/Server/View.pm b/lib/App/SD/Server/View.pm
index 2a5c040..8a31f15 100644
--- a/lib/App/SD/Server/View.pm
+++ b/lib/App/SD/Server/View.pm
@@ -803,7 +803,7 @@ sub ticket_page_actions {
ul { {class is 'actions'};
li { a {{ href is '/ticket/'.$ticket->uuid.'/view'}; 'Show'}; };
- li { a {{ href is '/ticket/'.$ticket->uuid.'/edit'}; 'Update'}; };
+ li { a {{ href is '/ticket/'.$ticket->uuid.'/edit'}; 'Update'}; } unless($self->server->static);
li { a {{ href is '/ticket/'.$ticket->uuid.'/history'}; 'History'}; };
};
commit 9a6805493efd231e795b2a6ab3dec6728443e01f
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 31 02:17:38 2009 -0500
Export file names to end in .html by default
diff --git a/lib/App/SD/CLI/Command/Publish.pm b/lib/App/SD/CLI/Command/Publish.pm
index 98c61cf..6ed7687 100644
--- a/lib/App/SD/CLI/Command/Publish.pm
+++ b/lib/App/SD/CLI/Command/Publish.pm
@@ -76,6 +76,8 @@ sub work_with_urls {
#Extract Links from the file
my $h = HTML::TreeBuilder->new;
+ $h->no_space_compacting(1);
+ $h->ignore_ignorable_whitespace(0);
$h->parse_content($content);
my $link_elements = $h->extract_links(qw(img href script style a link ));
@@ -92,7 +94,11 @@ sub work_with_urls {
$all_links->{$link}++;
my $url = URI::file->new($link)->rel("file://$current_url");
- $url .= "index.html" if ( $url =~ m|/$| );
+ if ( $url =~ m|/$| ) {
+ $url .= "index.html"
+ } elsif ($url !~ /\.html$/) {
+ $url .= ".html";
+ }
my ($attr)
= grep { defined $element->attr($_) and $link eq $element->attr($_) }
@{ $HTML::Tagset::linkElements{ $element->tag } };
@@ -129,7 +135,11 @@ sub write_file {
my $file = shift;
my $content = shift;
- $file .= "index.html" if ( $file =~ qr|/$| );
+ if ( $file =~ qr|/$| ) {
+ $file .= "index.html"
+ } elsif ($file !~ /\.html$/) {
+ $file .= ".html";
+ }
Prophet::Util->write_file( file => File::Spec->catfile( $dir => $file ), content => $content );
}
commit 2e58c0922b51f1d3eb261f330faf01edd3cffff9
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Sat Jan 31 02:26:42 2009 -0500
Don't try to create .js.html files
diff --git a/lib/App/SD/CLI/Command/Publish.pm b/lib/App/SD/CLI/Command/Publish.pm
index 6ed7687..91ccbb7 100644
--- a/lib/App/SD/CLI/Command/Publish.pm
+++ b/lib/App/SD/CLI/Command/Publish.pm
@@ -92,13 +92,17 @@ sub work_with_urls {
my $element = shift @$link_element; #HTML::Element Object
$all_links->{$link}++;
-
+
my $url = URI::file->new($link)->rel("file://$current_url");
+
if ( $url =~ m|/$| ) {
$url .= "index.html"
- } elsif ($url !~ /\.html$/) {
+ } elsif ($url !~ /\.\w{2,4}$/) {
$url .= ".html";
}
+
+
+
my ($attr)
= grep { defined $element->attr($_) and $link eq $element->attr($_) }
@{ $HTML::Tagset::linkElements{ $element->tag } };
@@ -137,7 +141,7 @@ sub write_file {
if ( $file =~ qr|/$| ) {
$file .= "index.html"
- } elsif ($file !~ /\.html$/) {
+ } elsif ($file !~ /\.\w{2,4}$/) {
$file .= ".html";
}
Prophet::Util->write_file( file => File::Spec->catfile( $dir => $file ), content => $content );
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list