From: Stevan Little Date: Sun, 28 Mar 2010 15:56:32 +0000 (-0400) Subject: first swipe at this X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7476895d0a8ed47ed834022bb42bad3e6abb018f;p=gitmo%2Fmoose-website.git first swipe at this --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/bin/build_site.pl b/bin/build_site.pl new file mode 100644 index 0000000..89bee90 --- /dev/null +++ b/bin/build_site.pl @@ -0,0 +1,10 @@ +#!perl + +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; + +use Moose::Website; + +Moose::Website->new_with_options->run; \ No newline at end of file diff --git a/data/pages.yml b/data/pages.yml new file mode 100644 index 0000000..04b14c0 --- /dev/null +++ b/data/pages.yml @@ -0,0 +1,43 @@ +--- +- name : home + template : index.tt + outfile : index.html +- name : about + template : about.tt + outfile : about.html +- name : download + template : download.tt + outfile : download.html + data : + CPAN: + - name : Moose + url : http://search.cpan.org/dist/Moose/ + - name : Class::MOP + url : http://search.cpan.org/dist/Class-MOP/ + - name : Task::Moose + url : http://search.cpan.org/dist/Task-Moose/ + - name : Task::Kensho + url : http://search.cpan.org/dist/Task-Kensho/ + - name : MooseX::* + url : http://search.cpan.org/search?query=MooseX&mode=dist + git: + public : git://git.moose.perl.org/Moose.git + commiter : gitmo@git.moose.perl.org:Moose.git + web_view : http://git.shadowcat.co.uk/gitweb/gitweb.cgi +- name : articles + template : articles.tt + outfile : articles.html + data : + - year : 2010 + articles : + - title : Moose 1.00 is Released + url : http://stevan-little.blogspot.com/2010/03/moose-100-is-released.html + - year : 2009 + articles : [] + - year : 2008 + articles : [] + - year : 2007 + articles : [] + - year : 2006 + articles : [] + diff --git a/lib/Moose/Website.pm b/lib/Moose/Website.pm new file mode 100644 index 0000000..a83d763 --- /dev/null +++ b/lib/Moose/Website.pm @@ -0,0 +1,154 @@ +package Moose::Website; +use Moose; +use MooseX::Types::Path::Class; + +use Template; +use YAML::XS 'LoadFile'; +use Moose::Website::I18N; + +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; + +with 'MooseX::Getopt'; + +has 'page_file' => ( + is => 'ro', + isa => 'Path::Class::File', + coerce => 1, + required => 1, +); + +has 'outdir' => ( + is => 'ro', + isa => 'Path::Class::Dir', + coerce => 1, + required => 1, +); + +has 'template_root' => ( + is => 'ro', + isa => 'Path::Class::Dir', + coerce => 1, + required => 1, +); + +has 'template_config' => ( + is => 'ro', + isa => 'HashRef', + lazy => 1, + default => sub { +{} }, +); + +has 'locale' => ( + is => 'ro', + isa => 'Str', + default => sub { 'en' }, +); + +# .... + +has 'i18n' => ( + is => 'ro', + isa => 'Object', + lazy => 1, + default => sub { + my $self = shift; + Moose::Website::I18N->get_handle( $self->locale ) + } +); + +has 'pages' => ( + traits => [ 'NoGetopt' ], + is => 'ro', + isa => 'ArrayRef[HashRef]', + lazy => 1, + default => sub { + my $self = shift; + LoadFile( $self->page_file->stringify ); + } +); + +has 'tt' => ( + traits => [ 'NoGetopt' ], + is => 'ro', + isa => 'Template', + lazy => 1, + default => sub { + my $self = shift; + Template->new( + INCLUDE_PATH => $self->template_root, + %{ $self->template_config } + ) + } +); + +sub log { shift; warn @_, "\n" } + +sub run { + my $self = shift; + + foreach my $page ( @{ $self->pages } ) { + $self->tt->process( + $page->{template}, + $self->build_template_params( current_page => $page ), + $self->outdir->file( $page->{outfile} )->stringify + ) || confess $self->tt->error; + } +} + +sub build_template_params { + my ($self, %params) = @_; + + $params{ pages } = $self->pages; + $params{ loc } = sub { $self->i18n->loc( @_ ) }; + + \%params; +} + + +__PACKAGE__->meta->make_immutable; + +no Moose; 1; + +__END__ + +=pod + +=head1 NAME + +Moose::Website - A Moosey solution to this problem + +=head1 SYNOPSIS + + use Moose::Website; + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B<> + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2010 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/Moose/Website/I18N.pm b/lib/Moose/Website/I18N.pm new file mode 100644 index 0000000..ffa085d --- /dev/null +++ b/lib/Moose/Website/I18N.pm @@ -0,0 +1,72 @@ +package Moose::Website::I18N; +use Moose; + +use Path::Class; + +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; + +BEGIN { extends 'Locale::Maketext' }; + +use Locale::Maketext::Lexicon { + '*' => [ Gettext => file(__FILE__)->parent->file("I18N", "po", "*.po")->stringify ], + _auto => 1, + _decode => 1, +}; + +sub loc { + my ( $self, $item, @args ) = @_; + + if ( @args == 0 and ref($item) eq 'ARRAY') { + ( $item, @args ) = @$item; + } + + return $self->maketext( $item, @args ); +} + +__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); + +no Moose; 1; + +__END__ + +=pod + +=head1 NAME + +Moose::Website::I18N - A Moosey solution to this problem + +=head1 SYNOPSIS + + use Moose::Website::I18N; + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B<> + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2010 Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/Moose/Website/I18N/po/en.po b/lib/Moose/Website/I18N/po/en.po new file mode 100644 index 0000000..41e191b --- /dev/null +++ b/lib/Moose/Website/I18N/po/en.po @@ -0,0 +1,70 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "global page title" +msgstr "Moose - A Post Modern Object System for Perl" + +msgid "moose" +msgstr "Moose" + +msgid "moose subtitle" +msgstr "A Post Modern Object System for Perl" + +# nav + +msgid "nav home" +msgstr "Home" + +msgid "nav about" +msgstr "About" + +msgid "nav articles" +msgstr "Articles" + +msgid "nav download" +msgstr "Download" + +# about + +msgid "about title" +msgstr "About Moose" + +msgid "about body" +msgstr "" +"

Moose is a postmodern object system for Perl 5 that takes the tedium out of writing object-oriented Perl. It borrows all the best features from Perl 6, CLOS (LISP), Smalltalk, Java, BETA, OCaml, Ruby and more, while still keeping true to its Perl 5 roots.

" +"

Moose is 100% production ready and in heavy use in a number of systems and growing every day. Try it today!

" + +# articles + +msgid "articles title" +msgstr "Articles About Moose" + +# download + +msgid "download title" +msgstr "Download" + +msgid "cpan" +msgstr "CPAN" + +msgid "git" +msgstr "Git" + +msgid "git public" +msgstr "Git Public Repo URL" + +msgid "git commiter" +msgstr "Git URL for Commiters" + +msgid "git web view" +msgstr "Git Web View" + + + + + + + diff --git a/templates/about.tt b/templates/about.tt new file mode 100644 index 0000000..912f840 --- /dev/null +++ b/templates/about.tt @@ -0,0 +1,6 @@ +[% WRAPPER 'wrapper/sub_page.tt' %] + +

[% loc('about title') %]

+ [% loc('about body') %] + +[% END %] \ No newline at end of file diff --git a/templates/articles.tt b/templates/articles.tt new file mode 100644 index 0000000..3e82963 --- /dev/null +++ b/templates/articles.tt @@ -0,0 +1,18 @@ +[% WRAPPER 'wrapper/sub_page.tt' %] + +

[% loc('articles title') %]

+ +
    + [% FOREACH item IN current_page.data %] +
  • + [% loc(item.year) %] + +
  • + [% END %] +
+ +[% END %] \ No newline at end of file diff --git a/templates/download.tt b/templates/download.tt new file mode 100644 index 0000000..5cd954d --- /dev/null +++ b/templates/download.tt @@ -0,0 +1,24 @@ +[% WRAPPER 'wrapper/sub_page.tt' %] + +

[% loc('download title') %]

+ +

[% loc('cpan') %]

+ + + +

[% loc('git') %]

+ +
    +
  • [% loc('git public') %] — [% current_page.data.git.public %]
  • + +
  • [% loc('git commiter') %] — [% current_page.data.git.commiter %]
  • + +
  • [% loc('git web view') %]
  • +
+ + +[% END %] \ No newline at end of file diff --git a/templates/index.tt b/templates/index.tt new file mode 100644 index 0000000..43b68b3 --- /dev/null +++ b/templates/index.tt @@ -0,0 +1,7 @@ +[% WRAPPER 'wrapper/root.tt' %] + +

[% loc('moose') %]

+

[% loc('moose subtitle') %]

+ [% INCLUDE 'shared/nav.tt' %] + +[% END %] \ No newline at end of file diff --git a/templates/shared/nav.tt b/templates/shared/nav.tt new file mode 100644 index 0000000..13a8cbd --- /dev/null +++ b/templates/shared/nav.tt @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/templates/wrapper/root.tt b/templates/wrapper/root.tt new file mode 100644 index 0000000..0ad1bf4 --- /dev/null +++ b/templates/wrapper/root.tt @@ -0,0 +1,8 @@ + + +[% loc('global page title') %] + + +[% content %] + + \ No newline at end of file diff --git a/templates/wrapper/sub_page.tt b/templates/wrapper/sub_page.tt new file mode 100644 index 0000000..1b76281 --- /dev/null +++ b/templates/wrapper/sub_page.tt @@ -0,0 +1,4 @@ +[% WRAPPER 'wrapper/root.tt' %] +[% INCLUDE 'shared/nav.tt' %] +[% content %] +[% END %] \ No newline at end of file