1 package Moose::Website;
3 use MooseX::Types::Path::Class;
7 use YAML::XS 'LoadFile';
9 use Moose::Website::I18N;
10 use Moose::Website::Resource::Templates;
11 use Moose::Website::Resource::WebFiles;
13 our $VERSION = '0.01';
14 our $AUTHORITY = 'cpan:STEVAN';
16 with 'MooseX::Getopt';
20 isa => 'Path::Class::Dir',
28 default => sub { 'en' },
33 isa => 'Path::Class::File',
36 file(__FILE__)->parent->parent->parent->file('data', 'pages.yml')
42 has 'template_resource' => (
43 traits => [ 'NoGetopt' ],
45 isa => 'Moose::Website::Resource::Templates',
48 Moose::Website::Resource::Templates->new
53 shift->template_resource->fetch('template_dir')->install_from_absolute;
56 has 'web_file_resource' => (
57 traits => [ 'NoGetopt' ],
59 isa => 'Moose::Website::Resource::WebFiles',
62 Moose::Website::Resource::WebFiles->new(install_to => shift->outdir)
67 traits => [ 'NoGetopt' ],
73 Moose::Website::I18N->get_handle( $self->locale )
78 traits => [ 'NoGetopt' ],
80 isa => 'ArrayRef[HashRef]',
84 LoadFile( $self->page_file->stringify );
89 traits => [ 'NoGetopt' ],
96 INCLUDE_PATH => $self->template_root,
97 %{ $self->template_config }
102 has 'template_config' => (
103 traits => [ 'NoGetopt' ],
112 sub log { shift; warn @_, "\n" }
117 foreach my $page ( @{ $self->pages } ) {
119 next unless exists $page->{template};
121 my $outfile = $self->outdir->file( $page->{outfile} )->stringify;
123 $self->log( "Writing page " . $page->{name} . " to $outfile using template " . $page->{template} );
127 $self->build_template_params( current_page => $page ),
129 { binmode => ':encoding(UTF-8)' },
130 ) || confess $self->tt->error;
133 $self->log( "Copying web resources to " . $self->outdir );
134 $self->web_file_resource->install;
137 sub build_template_params {
138 my ($self, %params) = @_;
140 $params{ pages } = $self->pages;
141 $params{ loc } = sub { $self->i18n->loc( @_ ) };
142 $params{ locale } = $self->locale;
148 __PACKAGE__->meta->make_immutable;
158 Moose::Website - A Moosey solution to this problem
176 All complex software has bugs lurking in it, and this module is no
177 exception. If you find a bug please either email me, or add the bug
182 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
184 =head1 COPYRIGHT AND LICENSE
186 Copyright 2010 Infinity Interactive, Inc.
188 L<http://www.iinteractive.com>
190 This library is free software; you can redistribute it and/or modify
191 it under the same terms as Perl itself.