Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jshirley committed Apr 11, 2010
1 parent 87057ad commit 2aecf7f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
20 changes: 20 additions & 0 deletions lib/StyleGuide.pm
Expand Up @@ -43,6 +43,26 @@ __PACKAGE__->config(
# Start the application
__PACKAGE__->setup();

sub static_uri {
my ( $c, $asset, $query ) = @_;
my $static_path = $c->stash->{page}->{static_root} ||
$c->view('TT')->config->{static_root} || '/static';
my $uri;
if ( $static_path =~ /^https?/ ) {
$static_path =~ s/\/$//;
$uri = URI->new( "$static_path/$asset" );
if ( ref $query eq 'HASH' ) {
$uri->query_form( $query );
}
} else {
if ( $query and $query eq 'HASH' ) {
$uri = $c->uri_for( $static_path, $asset, $query );
} else {
$uri = $c->uri_for( $static_path, $asset );
}
}
return $uri;
}

=head1 NAME
Expand Down
8 changes: 6 additions & 2 deletions shared/site/global.tt
Expand Up @@ -41,8 +41,12 @@ MACRO ad_slot(zone, slot) BLOCK;
END;

MACRO run_widget(name, args) BLOCK;
SET w = widget.load(name, args);
INCLUDE "widgets/${w.template}" args = w.run(args);
SET w = widget.load(name, args);
IF w.template;
INCLUDE "widgets/${w.template}" args = w.run(args);
ELSE;
"Widget: $name not running (no template)";
END;
END;

MACRO select_field(info) BLOCK;
Expand Down
7 changes: 3 additions & 4 deletions shared/site/html.tt
Expand Up @@ -25,7 +25,7 @@ FOREACH script IN page.head.scripts;
NEXT UNLESS script;
script = script.match('^(https?://|/)') ?
script :
static("scripts/$script", 1); -%]
c.static_uri("scripts/$script", 1); -%]
<script type="text/javascript" src="[% script %]"></script>
[%
END;
Expand All @@ -36,10 +36,9 @@ FOREACH stylesheet IN page.head.stylesheets;
NEXT UNLESS stylesheet;
stylesheet = stylesheet.match('^(https?://|/)') ?
stylesheet :
static("css/$stylesheet", 1); -%]
c.static_uri("css/$stylesheet", 1); -%]
<link rel="stylesheet" href="[% stylesheet %]" type="text/css" media="screen">
[% END %]
<link rel="stylesheet" href="[% static( 'css/screen.css', 1 ) %]" type="text/css" media="screen">
<style type="text/css" id="styleoverrides"></style>
</head>
[%
Expand All @@ -54,7 +53,7 @@ FOREACH stylesheet IN page.head.stylesheets;
NEXT UNLESS script;
script = script.match('^(https?://|/)') ?
script :
static("scripts/$script", undef, 1); -%]
c.static_uri("scripts/$script", undef, 1); -%]
<script type="text/javascript" src="[% script %]"></script>
[% END %]
</body>
Expand Down

0 comments on commit 2aecf7f

Please sign in to comment.