Permalink
Browse files

jumpstarts simple apps

  • Loading branch information...
0 parents commit dcb697b000f22960be3a7daf82505de8c838b32c @phaylon committed Jul 1, 2009
@@ -0,0 +1,64 @@
+use MooseX::Declare;
+
+class ReactionX::Jumpstart
+ with ReactionX::Jumpstart::Generating
+ with ReactionX::Jumpstart::Namespacing
+ with ReactionX::Jumpstart::SubBuilding
+ with ReactionX::Jumpstart::Stashing {
+
+ use MooseX::Types::Moose qw( Str Object );
+ use Path::Class qw( dir );
+
+ use signatures;
+
+ use aliased 'ReactionX::Jumpstart::Application';
+ use aliased 'ReactionX::Jumpstart::Config';
+
+
+ has application_builder => (
+ isa => Object,
+ required => 1,
+ lazy_build => 1,
+ handles => { build_application => 'JUMPSTART' },
+ );
+
+ has config_builder => (
+ isa => Object,
+ required => 1,
+ lazy_build => 1,
+ handles => { build_config => 'JUMPSTART' },
+ );
+
+
+ method JUMPSTART {
+
+ $self->build_application;
+ $self->build_config;
+ }
+
+ method find_root_path {
+
+ my $project = $self->project_namespace;
+ $project =~ s{::}{-}g;
+
+ return dir( 'test', lc $project );
+ }
+
+ method _build_application_builder {
+
+ my $project = $self->project_namespace;
+ my $ui = $self->ui_namespace;
+
+ $self->set_stash(
+ project_namespace => $project,
+ ui_namespace => $ui,
+ );
+
+ return $self->new_sub_builder(Application);
+ }
+
+ method _build_config_builder {
+
+ return $self->new_sub_builder(Config);
+ }
+}
@@ -0,0 +1,80 @@
+use MooseX::Declare;
+
+class ReactionX::Jumpstart::Application
+ with ReactionX::Jumpstart::Generating
+ with ReactionX::Jumpstart::SubBuilding
+ with ReactionX::Jumpstart::Namespacing
+ with ReactionX::Jumpstart::Stashing {
+
+
+ use MooseX::Types::Moose qw( Str Bool Object );
+ use Catalyst::Runtime;
+ use Reaction;
+
+ use aliased 'ReactionX::Jumpstart::Controller::Root';
+ use aliased 'ReactionX::Jumpstart::View';
+
+
+ has application_name => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Str,
+ question => 'Descriptive name of the application?',
+ defaults_to => sub { my $name = $_[0]->project_namespace; $name =~ s{::}{-}g; $name },
+ );
+
+ has root_controller_is_built => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Bool,
+ question => 'Create a Root Controller?',
+ help_info => "The Controller managing '/'",
+ defaults_to => 1,
+ );
+
+ has root_controller_builder => (
+ isa => Object,
+ required => 1,
+ lazy_build => 1,
+ handles => { build_root_controller => 'JUMPSTART' },
+ );
+
+ has view_builder => (
+ isa => Object,
+ required => 1,
+ lazy_build => 1,
+ handles => { build_view => 'JUMPSTART' },
+ );
+
+
+ method JUMPSTART {
+
+ my $application_package = join '::', $self->project_namespace, $self->ui_namespace;
+ my $application_name = $self->application_name;
+
+ $self->set_stash(
+ application_package => $application_package,
+ application_name => $application_name,
+ );
+
+ $self->build_package(
+ package => $application_package,
+ dist => 'ReactionX-Jumpstart',
+ template => 'application',
+ vars => {
+ catalyst_version => Catalyst::Runtime->VERSION,
+ reaction_version => Reaction->VERSION,
+ },
+ );
+
+ $self->build_view;
+
+ if ($self->root_controller_is_built) {
+ $self->build_root_controller;
+ }
+ }
+
+ method _build_root_controller_builder { $self->new_sub_builder(Root) }
+
+ method _build_view_builder { $self->new_sub_builder(View) }
+}
@@ -0,0 +1,25 @@
+use MooseX::Declare;
+
+class ReactionX::Jumpstart::Config
+ with ReactionX::Jumpstart::Generating
+ with ReactionX::Jumpstart::Stashing
+ with ReactionX::Jumpstart::Namespacing {
+
+
+ use Catalyst::Utils;
+
+
+ method JUMPSTART {
+
+ my $config_file = $self->path_to_file(
+ 'etc',
+ Catalyst::Utils::appprefix(join '::', $self->project_namespace, $self->ui_namespace) . '.conf',
+ );
+
+ $self->build_file(
+ file => $config_file,
+ dist => 'ReactionX-Jumpstart',
+ template => 'application.conf',
+ );
+ }
+}
@@ -0,0 +1,90 @@
+use MooseX::Declare;
+
+class ReactionX::Jumpstart::Controller
+ with ReactionX::Jumpstart::Namespacing
+ with ReactionX::Jumpstart::Generating
+ with ReactionX::Jumpstart::SubBuilding
+ with ReactionX::Jumpstart::Stashing {
+
+ use MooseX::Types::Moose qw( Str Bool Object );
+ use Data::Dump qw( pp );
+
+
+ has controller_namespace => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Str,
+ question => 'Name of the Controller?',
+ help_info => sub {
+ sprintf 'example: %s for %s::%s::Controller::%s',
+ $_[1] || 'Foo',
+ $_[0]->project_namespace,
+ $_[0]->ui_namespace,
+ $_[1] || 'Foo',
+ },
+ );
+
+ has base_controller_namespace => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Str,
+ question => 'ClassName of base Controller?',
+ defaults_to => 'Reaction::UI::Controller',
+ );
+
+ has base_chained_to => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Str,
+ question => 'To what action is the base action chained?',
+ help_info => 'via private path, e.g. /foo/bar',
+ defaults_to => '/',
+ );
+
+ has base_path_part => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Str,
+ question => 'What is the base (public) path part for this Controller?',
+ defaults_to => sub { lc( ( split /::/, $_[0]->base_controller_namespace )[-1] ) },
+ );
+
+
+ method JUMPSTART {
+
+ my $controller_namespace = join '::',
+ $self->project_namespace,
+ $self->ui_namespace,
+ 'Controller',
+ $self->controller_namespace;
+
+ my $base_namespace = $self->base_controller_namespace;
+ my $base_chained_to = $self->base_chained_to;
+ my $base_path_part = $self->base_path_part;
+ my $config_partial = $self->render_config({});
+
+ $self->build_controller_package(
+ package => $controller_namespace,
+ dist => 'ReactionX-Jumpstart',
+ template => 'controller',
+ vars => {
+ controller_package => $controller_namespace,
+ controller_base => $base_namespace,
+ controller_config => $config_partial,
+ base_chained_to => $base_chained_to,
+ base_path_part => $base_path_part,
+ }
+ );
+ }
+
+ method render_config (HashRef $config) {
+
+ return join "\n", map {
+ sprintf '%s => %s,',
+ pp($_),
+ pp($config->{ $_ }),
+ } keys %$config;
+ }
+
+ method build_controller_package (%args) { $self->build_package(%args) }
+}
@@ -0,0 +1,105 @@
+use MooseX::Declare;
+
+class ReactionX::Jumpstart::Controller::Root
+ extends ReactionX::Jumpstart::Controller {
+
+
+ use MooseX::Types::Moose qw( Str Bool Object );
+
+ use aliased 'ReactionX::Jumpstart::ViewGroup';
+
+
+ has '+controller_namespace' => (defaults_to => 'Root');
+
+ has site_layout_is_pushed => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Bool,
+ question => 'Do you want a base action to push the SiteLayout ViewPort?',
+ defaults_to => 1,
+ );
+
+ has site_layout_is_customized => (
+ traits => [qw( ReactionX::Jumpstart::Meta::Attribute::Trait::Prompted )],
+ is => 'rw',
+ isa => Bool,
+ question => 'Do you want a customized SiteLayout ViewPort, Widget and LayoutSet?',
+ defaults_to => 1,
+ );
+
+ has site_layout_group_builder => (
+ isa => Object,
+ required => 1,
+ lazy_build => 1,
+ handles => { build_site_layout_group => 'JUMPSTART' },
+ );
+
+
+ method _build_base_controller_namespace { 'Reaction::UI::Controller::Root' }
+
+ method _build_base_chained_to { '/' }
+
+ method _build_base_path_part { '' }
+
+ method _build_site_layout_group_builder {
+
+ return $self->new_sub_builder(ViewGroup,
+ additional => {
+ view_group_name => 'SiteLayout',
+ viewport_builder_args => {
+ viewport_base_class => 'Reaction::UI::ViewPort::SiteLayout',
+ },
+ widget_builder_args => {
+ widget_base_class => 'Reaction::UI::Widget::SiteLayout',
+ },
+ layout_set_builder_args => {
+ base_layout_set_name => 'site_layout',
+ layout_set_is_extension => 1,
+ widget_name_is_explicit => 1,
+ },
+ },
+ );
+ }
+
+
+ around render_config (HashRef $config) {
+
+ return $self->$orig({
+ %$config,
+ namespace => '',
+ view_name => $self->stash->{site_view_name},
+ });
+ }
+
+ around build_controller_package (%args) {
+
+ my $push_site_layout = $args{vars}{site_layout_is_pushed}
+ ||= $self->site_layout_is_pushed;
+
+ if ($push_site_layout) {
+
+ my $is_customized = $args{vars}{site_layout_is_customized}
+ ||= $self->site_layout_is_customized;
+
+ if ($is_customized) {
+
+ $self->build_site_layout_group;
+ $self->set_stash(site_layout_class => join '::',
+ $self->project_namespace,
+ $self->ui_namespace,
+ 'ViewPort::SiteLayout',
+ );
+ }
+ else {
+
+ $self->set_stash(site_layout_class => 'Reaction::UI::ViewPort::SiteLayout');
+ }
+ }
+
+ return $self->$orig(%args);
+ }
+
+ after JUMPSTART {
+ $self->set_stash(root_controller_namespace => $self->controller_namespace);
+ }
+}
Oops, something went wrong.

0 comments on commit dcb697b

Please sign in to comment.