Browse files

add top and dynamic variables to generated article templates

also re-work the pod a little
  • Loading branch information...
1 parent 1358aec commit 22b20d7a608689520f8038109a0f6cd201e5bea0 @tonycoz committed Feb 25, 2013
Showing with 103 additions and 48 deletions.
  1. +75 −45 site/cgi-bin/modules/Generate/Article.pm
  2. +15 −2 t/050-local/050-dyncat.t
  3. +13 −1 t/060-generate/010-generate.t
View
120 site/cgi-bin/modules/Generate/Article.pm
@@ -16,7 +16,50 @@ use Carp 'confess';
use BSE::Util::Iterate;
use BSE::CfgInfo qw(cfg_dist_image_uri cfg_image_uri);
-our $VERSION = "1.008";
+our $VERSION = "1.009";
+
+=head1 NAME
+
+ Generate::Article - generates articles.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 TAGS
+
+
+=head2 Tag notes
+
+In your HTML each tag will be preceded by <: and followed by :>
+
+Tags marked as conditional will require a little more. Conditional
+tags can be used in two ways:
+
+<:ifName args:>true text<:or:>false text<:eif:>
+
+or:
+
+<:if Name args:>true text<:or Name:>false text<:eif Name:>
+
+Tags starting iterator ... are used as iterators, like:
+
+<:iterator begin name:>
+repeated text
+<:iterator separator name:>
+separator text
+<:iterator end name:>
+
+In general, a parameter I<which> can be any one of 'article', 'parent'
+or 'section'. In a child iterator it can also be 'child'. In a
+crumbs iterator it can also be 'crumbs'. If I<which> is missing it
+means the current article.
+
+=head2 Normal tags
+
+=over 4
+
+=cut
my $excerptSize = 300;
@@ -249,7 +292,7 @@ Reference an article attached file by name.
C<filen name> will display a link to the file.
-C<<filen name I<field> >> will display the given field from the file
+C<< filen name I<field> >> will display the given field from the file
record. A I<field> of C<url> will be a URL to the file.
If the file identifier given doesn't exist for the current article the
@@ -378,6 +421,7 @@ sub baseActs {
$self->set_variable(article => $article);
$self->set_variable(embedded => $embedded);
+ $self->set_variable(top => $self->{top});
# used to generate the list (or not) of children to this article
my $child_index = -1;
my @children = $articles->listedChildren($article->{id});
@@ -421,6 +465,7 @@ sub baseActs {
my $dynamic = $self->{force_dynamic}
|| (UNIVERSAL::isa($top, 'Article') ? $top->is_dynamic : 0);
+ $self->set_variable(dynamic => $dynamic);
my @stepkids;
my @allkids;
@@ -814,47 +859,6 @@ sub _find_articles {
__END__
-=head1 NAME
-
- Generate::Article - generates articles.
-
-=head1 SYNOPSIS
-
-=head1 DESCRIPTION
-
-=head1 TAGS
-
-
-=head2 Tag notes
-
-In your HTML each tag will be preceded by <: and followed by :>
-
-Tags marked as conditional will require a little more. Conditional
-tags can be used in two ways:
-
-<:ifName args:>true text<:or:>false text<:eif:>
-
-or:
-
-<:if Name args:>true text<:or Name:>false text<:eif Name:>
-
-Tags starting iterator ... are used as iterators, like:
-
-<:iterator begin name:>
-repeated text
-<:iterator separator name:>
-separator text
-<:iterator end name:>
-
-In general, a parameter I<which> can be any one of 'article', 'parent'
-or 'section'. In a child iterator it can also be 'child'. In a
-crumbs iterator it can also be 'crumbs'. If I<which> is missing it
-means the current article.
-
-=head2 Normal tags
-
-=over 4
-
=item article I<name>
Access to fields of the article. See L<Article attributes>.
@@ -1298,10 +1302,10 @@ Controls whether the article inherits its parents access controls.
=head2 Admin tags
-=over 4
-
The following tags produce output only in admin mode.
+=over 4
+
=item admin
Produces buttons and links used for administering the article.
@@ -1361,4 +1365,30 @@ article, in this context.
=back
+=head1 Variables
+
+=over
+
+=item *
+
+X<article, template variable>article - the article being processed.
+An object of type L<Article>.
+
+=item *
+
+X<top, template variable>top - when C<article> is being embedded, the
+very top article being generated. An object of type L<Article>.
+
+=item *
+
+X<embedded, template variable>embedded - whether the current article
+is embedded.
+
+=item *
+
+X<dynamic, template variable>dynamic - whether the page is being
+generated for dynamic display.
+
+=back
+
=cut
View
17 t/050-local/050-dyncat.t
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use BSE::Test ();
-use Test::More tests => 95;
+use Test::More tests => 98;
use File::Spec;
use FindBin;
my $cgidir = File::Spec->catdir(BSE::Test::base_dir, 'cgi-bin');
@@ -44,7 +44,8 @@ my $parent = bse_make_catalog
(
cfg => $cfg,
title => "test catalog",
- body => "Test catalog for catalog tests"
+ body => "Test catalog for catalog tests",
+ force_dynamic => 1,
);
ok($parent, "made a catalog");
@@ -502,6 +503,18 @@ Pages: 1fn2 2cn3p1 3lp2
EXPECTED
+dyn_template_test "template vars", $parent, <<TEMPLATE, <<EXPECTED;
+Article Title: [<:= article.title |html :>]
+Top Title: [<:= top.title |html :>]
+Embedded: [<:= embedded | html :>]
+Dynamic: [<:= dynamic | html :>]
+TEMPLATE
+Article Title: [test catalog]
+Top Title: [test catalog]
+Embedded: [0]
+Dynamic: [1]
+EXPECTED
+
$prod4->remove($cfg);
for my $prod (@prods) {
$prod->remove($cfg);
View
14 t/060-generate/010-generate.t
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use BSE::Test ();
-use Test::More tests=>164;
+use Test::More tests=>167;
use File::Spec;
use FindBin;
use Cwd;
@@ -663,6 +663,18 @@ One
EXPECTED
+template_test "template vars", $parent, <<TEMPLATE, <<EXPECTED;
+Article Title: [<:= article.title |html :>]
+Top Title: [<:= top.title |html :>]
+Embedded: [<:= embedded | html :>]
+Dynamic: [<:= dynamic | html :>]
+TEMPLATE
+Article Title: [Parent]
+Top Title: [Parent]
+Embedded: [0]
+Dynamic: [0]
+EXPECTED
+
############################################################
# Cleanup

0 comments on commit 22b20d7

Please sign in to comment.