Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding run_widget support

  • Loading branch information...
commit 7989551ffb9dc9b1b7b594de930797c06eeee896 1 parent af656ea
@jshirley jshirley authored
View
2  designs/ems/root/index.tt
@@ -1 +1 @@
-[% PROCESS "site/global.tt" %]
+<h1>Wee</h1>
View
51 designs/ems/root/site/footer/default.tt
@@ -1 +1,50 @@
-designs/ems/site/footer/default.tt
+<div class="footer">
+ <div class="links">
+ <div class="alpha column">
+ <ul>
+ <li class="title"><h4>About NASA</h4></li>
+ <li><a href="#">About NASA</a></li>
+ <li><a href="#">News</a></li>
+ <li><a href="#">Photos &amp; Videos</a></li>
+ <li><a href="#">Our Members</a></li>
+ <li><a href="#">Member Benefits</a></li>
+ <li><a href="#">Regions</a></li>
+ <li><a href="#">Contact Us</a></li>
+ <li><a href="#">Help!</a></li>
+ </ul>
+ </div>
+ <div class="column">
+ <ul>
+ <li class="title"><h4>Racing with us</h4></li>
+ <li><a href="#">HPDE/Open Track</a></li>
+ <li><a href="http://www.nasa-tt.com/">Time Trial</a></li>
+ <li><a href="#">Competition Racing</a></li>
+ <li><a href="http://www.nasarallysport.com/">Rally Sport</a></li>
+ <li><a href="http://www.nasasimracing.com">NASA SimRacing</a></li>
+ </ul>
+ </div>
+ <div class="column">
+ <ul>
+ <li class="title"><h4>NASA Marketplace</h4></li>
+ <li><a href="http://www.gogogear.com/gogo_nasa.html" target="_blank">NASA Merchandise</a></li>
+ <li><a href="http://nasa.racingjunk.com" target="_blank">Classifieds</a></li>
+ </ul>
+ </div>
+ <div class="column omega">
+ <ul>
+ <li class="title"><h4>Events</h4></li>
+ <li><a href="#">Event Calendar</a></li>
+ <li><a href="#">Event Registration</a></li>
+ <li><a href="#">Event Results</a></li>
+ <li><a href="#">Forms &amp; Contingency</a></li>
+ <li><a href="#">Cash Awards</a></li>
+ <li><a href="#">Rules</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="disclaimer">
+ <p>Not Affiliated with the National Aeronautics and Space Administration
+. For that NASA, <a href="http://www.nasa.gov" class="disclaim" target="_blank"
+>click here.</a></p> <p>National Office P.O. Box 21555 Richmond CA 94520&nbsp;&nbsp;|&nbsp;&nbsp;Ph: 510-232-NASA (6272)&nbsp;&nbsp;|&nbsp;&nbsp;Fax: 510-277-0657</p>
+ </div>
+</div>
View
57 lib/StyleGuide/Model/Widget.pm
@@ -0,0 +1,57 @@
+package StyleGuide::Model::Widget;
+
+use Try::Tiny;
+use Moose;
+
+use Carp;
+
+with 'Catalyst::Component::InstancePerContext';
+
+extends 'Catalyst::Model';
+
+has 'app' => (
+ is => 'rw',
+ isa => 'Catalyst',
+ handles => {
+ 'log' => 'log'
+ }
+);
+
+sub build_per_context_instance {
+ my ($self, $c) = @_;
+
+ $self->app($c);
+ return $self;
+}
+
+sub load {
+ my ($self, $name) = @_;
+
+ my $aname = $self->app->context_class;
+ my $class = "$aname\::Widget\::$name";
+ try {
+ Class::MOP::load_class( $class )
+ } catch {
+ $self->log->error("Can't load widget $class: $_");
+ return undef;
+ };
+ $self->log->debug("Successfully loaded widget: $class")
+ if $self->app->debug;
+
+ my %options = ();
+ if ( exists $self->{$name} and ref $self->{$name} eq 'HASH' ) {
+ %options = %{ $self->{$name} };
+ }
+
+ my $widget;
+ try {
+ $widget = $class->new( %options );
+ $widget->app( $self->app );
+ } catch {
+ $self->log->error("Error loading widget: $name: $_");
+ };
+ return $widget;
+}
+
+1;
+
View
27 lib/StyleGuide/Widget.pm
@@ -0,0 +1,27 @@
+package StyleGuide::Widget;
+
+use Moose;
+
+has 'template' => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has 'app' => (
+ is => 'rw',
+ isa => 'Catalyst',
+);
+
+has 'classes' => (
+ is => 'rw',
+ isa => 'ArrayRef[Str]',
+ default => sub { [ ] },
+ lazy => 1
+);
+
+sub run {
+ die('Virtual Method: ' . __PACKAGE__ . ' must implement a run method');
+}
+
+1;
+
View
109 lib/StyleGuide/Widget/ContextMenu.pm
@@ -0,0 +1,109 @@
+package StyleGuide::Widget::ContextMenu;
+
+use Moose;
+
+use Catalyst::Utils;
+
+extends 'EMS::Widget';
+
+has '+template' => ( default => 'context_menu.tt' );
+has '+classes' => ( default => sub { [ 'context-menu' ] } );
+
+has 'menus' => (
+ is => 'rw',
+ isa => 'ArrayRef',
+ required => 1
+);
+
+sub _process_item {
+ my ( $self, $c, $i ) = @_;
+
+ my $item = { %$i }; # shallow copy;
+
+ # If we have an action, forward and merge the result into our current
+ # item.
+ if ( $item->{action} ) {
+ $c->log->debug("Forwarding to update current menu: $item->{action}")
+ if $c->debug;
+ my $ret = $c->forward( $item->{action} );
+ $item = Catalyst::Utils::merge_hashes( $item, $ret )
+ if ref $ret eq 'HASH';
+ }
+
+ # Let the item itself determine if it should be expanded. This can be done
+ # in one of three ways:
+ # 1 - The item has 'expand => 1' in the config.
+ # 2 - The item has an 'action', which does it
+ # 3 - There is a 'match' parameter (regex) that matches the current
+ # action.
+ my $expand = 0;
+ if ( $item->{expand} ) {
+ $expand = 1;
+ }
+ elsif ( $item->{match} and $c->action->reverse =~ $item->{match} ) {
+ $expand = 1;
+ }
+ # ignore this one
+ elsif ( $item->{namespace} and $c->action->namespace eq $item->{namespace} ) {
+ $expand = 1;
+ }
+
+ # Now, to href interpolation to determine if we have a link or not, and
+ # then how to render that link
+ if ( $item->{href} ) {
+ if ( ref $item->{href} eq 'CODE' ) {
+ $item->{href} = $item->{href}->($c, $item)
+ }
+ elsif ( not ref $item->{href} ) {
+ if ( $item->{href} =~ /^(#|http)/ ) {
+ # If we just want to anchor to a point on the page, this will
+ # bypass the uri_for_action... just a quicker lookup I suppose
+ } else {
+ # Call out for this, with an href_params. In the case of
+ # captures or whatever, it is probably better to define
+ # an 'action' to populate the href directly.
+ $item->{href} = $c->uri_for_action(
+ $item->{href},
+ @{ $item->{href_params} || [] }
+ );
+ }
+ }
+ }
+
+ # If we're going to expand, then iterate through the children and add
+ # them in accordingly.
+ if ( $expand and $item->{children} and ref $item->{children} eq 'ARRAY') {
+ my @final;
+ $item->{expand} = 1;
+ foreach my $child ( @{ $item->{children} } ) {
+ my $ret = $self->_process_item($c, $child);
+ push @final, $ret if defined $ret;
+ }
+ $item->{children} = \@final;
+ }
+ return $item;
+}
+
+sub run {
+ my ( $self, $args ) = @_;
+ $args = {} unless $args and ref $args eq 'HASH';
+
+ my $c = $self->app;
+
+ my $menus = $self->menus;
+ my @final = ();
+
+ foreach my $item ( @{ $self->menus } ) {
+ my $ret = $self->_process_item($c, $item);
+ push @final, $ret if defined $ret;
+ }
+ $args->{action} = $c->action;
+ $args->{controller} = $c->controller;
+ $args->{menu} = \@final;
+
+ return $args;
+}
+
+
+1;
+
Please sign in to comment.
Something went wrong with that request. Please try again.