HTML-Obj2HTML

 view release on metacpan or  search on metacpan

lib/HTML/Obj2HTML.pm  view on Meta::CPAN

  my $m = new Text::Markdown;
  my $val = $m->markdown(HTML::Entities::encode($txt));
  return $val;
}

sub print {
  my $o = shift;
  print gen($o);
}

sub format {
  my $plain = shift;
  $plain =~ s/\n/<br \/>/g;
  return [ raw => $plain ];
}

sub register_extension {
  my $tag = shift;
  my $def = shift;
  my $flags = shift;
  $extensions{$tag} = $def;
  if (defined $flags) {
    $tags{$tag} = $flags;
  } else {
    $tags{$tag} = END_TAG_OPTIONAL;
  }
}

1;
__END__

=pod

=head1 NAME

HTML::Obj2HTML - Create HTML from a arrays and hashes

=head1 SYNOPSYS

    use HTML::Obj2HTML (components => 'path/to/components', default_currency => 'GBP', mode => 'XHTML', warn_on_unknown_tag => 1, html_fromarrayref_format => 0)

=over 4

=item * C<components>

This is the relative path from the current working directory to components.
Obj2HTML will find all *.po files and automatically register elements that when
called within your object executes the file. (See C<fetch()>);

Note, you can change the extension searched for with an import argument:

    use HTML::Obj2HTML file_extension => ".po"

=item * C<default_currency>

Which currency to format output for when encountering the built in C<currency>
element.

=item * C<mode>

XHTML or HTML

=item * C<warn_on_unknown_tag>

Whether or not to print a warning to STDERR (using carp) when encountering an
element that doesn't look like an HTML element, or registered extension element

=item * C<html_fromarrayref_format>

This module accepts two formats for conversion; one is an HTML::FromArrayref
style arrayref, one is a variation. Differences are noted below.

=back

=head2 Usage

    set_opt('opt-name','value');
    set_dictionary(\%dictionary);
    add_dictionary_items(\%dictionary_items);
    set_snippet('snippet-name', \@Obj2HTMLItems);
    register_extension('element-name', \%definition);

    $result_html = gen(\@Obj2HTMLItems);

An Obj2HTML arrayref is a structure that when processed is turned into HTML.
Without HTML::FromArrayref format eanbled, it looks like this:

    [
       doctype => "HTML",
       html => [
         head => [
           script => { ... },
         ],
         body => { class => 'someclass', _ => [
           h1 => "Test page",
           p => "This is my test page!"
         ]}
       ]
    ];

=head2 Builtin Features

=over 4

=item Add a snippet with _snippet-name syntax

    [
      div => _snippet
    ]

=item Execute a subroutine at generate time

    [
      div => \&generate_something
    ]

=item Ignore things that don't look like elements at all; treat them like content

    [
      p => [
        "I really ",



( run in 1.063 second using v1.01-cache-2.11-cpan-119454b85a5 )