NAME

Publishable - publishable component interface (super class)


SYNOPSIS

Should not be used directly, see synopsys of subclasses. Although this component class is not pure virtual, it is hard to use directly, because it does not contain any useful non-publishing-mechanism property.


DESCRIPTION

Publishable components usualy contain other publishable components. This package provides methods to manage, publish and preview publishable components recursively.


REQUIREMENTS

the Exception manpage, the Debug manpage, the Podius::Component manpage, the Podius::Property::ScalarTable manpage, the Podius::Template manpage, the File::Operations manpage, the Parse::PerlConf manpage.


CONSTRUCTORS

new

description
Class constructor.

parameters
  * class name like all constructors
  * optional init hash, see L<Podius::Component>
returns
New formed publishable component reference.


METHODS

parse_template

usage
  $ok = $component->parse_template(\"<h1><{get_name}></h1>");
description
This method can be used to parse template for this component given by template content.

This method calls Podius::Template::set_template_home() to set the component template home directory.

After that it calls Podius::Template::parse_template() with the same parameters.

parameters
  * template content to parse - scalar ref
  * optional template stash - hash ref
returns
Scalar ref of parsed template content.

parse_template_page

usage
  $ok = $component->parse_template_page("template.html");
description
This method can be used to parse template for this component given by template file-name. $TEMPLATE_HOME/ is prefixed to file-name.

Calls parse_template method, see above.

parameters
  * template file-name to parse (scalar)
  * optional template stash (hashref)
returns
Scalar ref of parsed template content.

save_published_page

usage
  $ok = $component->save_published_page("index2.html", \"<HTML></HTML>");
description
This method can be used to save published page given by its file-name and content. $PUBLISH_NAME/ is prefixed to file-name.

parameters
  * published file-name to save to - scalar
  * published page content to save - scalar ref
returns
1 on success, otherwise throws exception.

publish_self

usage
  $component->publish_self();
  $component->publish_self({
    unpublish    => 1,
    templates    => ['Master1.html', 'Master2.html'],
    published    => undef,
    published_cb => undef,
    extra_stash  => {},
    update_lastdate => 0,
  });
description
This method is used to non-recursive publish the publishable component. The entire process of publish includes publishing multimedia for all properties of type Multimedia and publishing static pages from templates for all row values in page_names table.

Property last_published is updated to hold the appropriate time unless update_lastdate flag is set to 0 (but the time is updated once for the first publish anyway) or if it is set to 2 (then the time is forced to be always undefined).

This method is equivalent to publish(0, 1), but without debugging messages.

parameters
Optional argument hash with the keys:
  * unpublish  (0 (default) or 1) - publish (create) or unpublish (remove)
  * templates (array ref) - process only these template pages;
    default is undef - process all template pages
  * published (array ref) - process only these published pages;
    default is undef - process all published pages
  * published_cb (code ref) - if specified, call the callback when every
    single page is published with parameters:
    (I<$component, $template, $published, $stash, $unpublish>) -
    (I<Podius::Component, scalar, scalar, hash, boolean>)
  * extra_stash (hash ref) - add to configured stash of page_names entries
  * reset_pagenames (0 or 1) - reset pagenames
    default is PUBLISH_RESETS_PAGENAMES in project.cfg
  * update_lastdate (0 skip, 1 set, 2 null) - update last_published property
    default is PUBLISH_UPDATES_LASTDATE in project.cfg
  * properties (0 or 1 or undef) - publish properties too
    default is undef - lazy publish
  * property_names (array ref) - limit to these properties only

see also
Method publish, which uses this method; used methods save_published_page, parse_template_page.

returns
1 on success, otherwise throws exception.

publish_sons

usage
  $num_published = $component->publish_sons();
  $num_published = $component->publish_sons(1, 20);
  $num_published = $component->publish_sons({
    unpublish    => 1,
    templates    => ['Master1.html', 'Master2.html'],
    published    => undef,
    published_cb => undef,
  });
description
This method is used to publish the contained publishable components.

Optional argument hash is not used directly, it is passed to publish method for all sons.

The recursive argument (usually must be non zero) is not used directly, it is passed to publish method for all sons.

Can be limited to the given number of recursive publish's. When limiting, DFS is used, not BFS, this means sons can be processed, even if not all brothers are going to be published. This feature can be changed later.

see also
Method publish, which uses this method and which is used in this method.

parameters
  * optional argument hash (see C<publish_self>)
  * recursive - optional
   -1: publish sons after the component itself (default)
    0: don't publish sons (== contained publishable components)
    1: publish sons before the component itself
  * limit - optional total number of components to publish, when recursive,
default is -1 - unlimited.
returns
Total number of processed publish's (limit if limited) on success, otherwise throws exception.

If called in array context, two scalars are returned - total number of published components and total number of published direct sons.

publish

usage
  $num_published = $component->publish();
  $num_published = $component->publish(1, 20);
  $num_published = $component->publish({
    unpublish    => 1,
    templates    => ['Master1.html', 'Master2.html'],
    published    => undef,
    published_cb => undef,
  });
description
This method is used to publish the publishable component. The entire process of publish includes publishing multimedia for all properties of type Multimedia and publishing static pages from templates for all row values in page_names table.

Property last_published is updated by default, but see the description of update_lastdate flag above; if this flag is not explicitly passed then it defaults to the project constant PUBLISH_UPDATES_LASTDATE.

Optional argument hash is not used directly, it is passed to publish_self method.

This method calls publish method of all contained publishable components, if recursive.

Can be limited to the given number of recursive publish's. When limiting, DFS is used, not BFS, this means sons can be processed, even if not all brothers are going to be published. This feature can be changed later.

The component itself is always published (last or first) unless the given limit is 0, use publish_sons to publish only its sons.

see also
Method parse of the Podius::Template manpage.

parameters
  * optional argument hash (see C<publish_self>)
  * recursive - optional
   -1: publish sons after the component itself (default)
    0: don't publish sons (== contained publishable components)
    1: publish sons before the component itself
  * limit - optional total number of components to publish, when recursive,
default is -1 - unlimited.
returns
Total number of processed publish's (limit if limited, 1 if not recursive) on success, otherwise throws exception.

preview

usage
 $num_previewed = $component->preview();
description
This method is used to preview the publishable component.

The method actually calls publish method but in PREVIEW_HOME directory.

parameters
  * recursive - optional, if 0, don't publish contained publishable components (default 1).
  * limit - optional total number of components to publish, when recursive.
default is -1 - unlimited.
returns
Total number of processed publish's (limit if limited, 1 if not recursive) on success, otherwise throws exception.

get_backdir_to_publish_home

usage
In template:
  <img src="<{ @t get_backdir_to_publish_home }>/images/some.png">

or even shorter:

  <link rel="stylesheet" href="<{~backdir}>/style.css">

description
This method returns a relative path from the published page of this component to the publish_home (see get_publish_home).

The return value is either ``.'' (if the published filename contains no slashes), or one or more ``..'' separated with ``/''.

parameters
  * optional index of page_names row (default: 0)
returns
String representing a relative directory (starting and ending with ``.'').