Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
add tags support
Browse files Browse the repository at this point in the history
  • Loading branch information
zag committed Jan 14, 2013
1 parent 73fed1b commit a355966
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Build.PL
Expand Up @@ -4,9 +4,9 @@ Module::Build->new
( module_name => 'WriteAt',
license => 'perl',
prereq => {
'Regexp::Grammars'=>1.015,
'Regexp::Grammars'=>1.021,
'Perl6::Pod::Lib'=>0.11,
'Perl6::Pod'=>0.55,
'Perl6::Pod'=>0.57,
'DateTime::Format::W3CDTF'=>0
},
script_files=>[qw!
Expand Down
5 changes: 4 additions & 1 deletion Changes
@@ -1,6 +1,9 @@
Revision history for Perl extension WriteAt.


0.03
+ convert books to atom feed
+ add latex support
+ util atom2file
+ track path for =Include
0.02
+ rename to WriteAt,
Expand Down
2 changes: 1 addition & 1 deletion lib/WriteAt.pm
Expand Up @@ -71,7 +71,7 @@ Point your web brouser to C<index.html> file in C<work> directory.
use strict;
use warnings;
use v5.10;
our $VERSION = '0.02';
our $VERSION = '0.03';
use WriteAt::CHANGES;
use WriteAt::AUTHOR;
use WriteAt::To::DocBook;
Expand Down
24 changes: 23 additions & 1 deletion lib/WriteAt/To/Atom.pm
Expand Up @@ -127,6 +127,18 @@ sub start_write {
<uri>$base_url</uri>
</author>
TXT
# add category if tag exists
if ( my $desc_node = $tags{DESCRIPTION}->[0] ) {
if ( my $tags = $desc_node->get_attr()->{tag} ) {
# save TAGS as ref to array
$self->{TAGS} = ref($tags) ? $tags : [$tags];
#fill categoty tags
foreach my $tag ( @{$self->{TAGS}} ) {
$w->raw("<category>$tag</category>\n")

}
}
}
}

sub write {
Expand Down Expand Up @@ -191,8 +203,17 @@ sub write {
<link rel="alternate" href="$url" title="$title" type="text/html"/>
<published>$published</published>
<updated>$updated</updated>
<content type="html">%
%
);
if ( my $tags = $entry->{node}->get_attr->{tag} ) {
# save TAGS as ref to array
my $local_tags = ref($tags) ? $tags : [$tags];
#union tags fill categoty tags
foreach my $tag ( @{$local_tags}, @{ $self->{TAGS}|| [] } ) {
$w->raw("<category>$tag</category>\n")
}
}

my $out = '';
open( my $fd, ">", \$out );
my $renderer = new Perl6::Pod::To::XHTML::
Expand All @@ -211,6 +232,7 @@ sub write {
}
close $fd;
my $safe_text = &Perl6::Pod::Writer::_html_escape($out);
$w->raw('<content type="html">');
$w->raw($safe_text);
$w->raw(
'</content>
Expand Down
2 changes: 1 addition & 1 deletion scripts/atom2file
Expand Up @@ -180,7 +180,7 @@ Zahatski Aliaksandr, E<lt>zahatski@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2012 by Zahatski Aliaksandr
Copyright 2013 by Zahatski Aliaksandr
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Expand Down
13 changes: 5 additions & 8 deletions t/01.bookinfo.t
Expand Up @@ -9,7 +9,7 @@ package main;
use strict;
use warnings;
use v5.10;
use Test::More tests => 1; # last test to print
use Test::More tests => 13; # last test to print
use Perl6::Pod::Utl;
use Data::Dumper;
use WriteAt;
Expand All @@ -32,7 +32,7 @@ Jan 08th 2011(v0.5)[zag] Подпрограммы и сигнатуры
=end CHANGES
=AUTHOR Александр Загацкий
=for CHAPTER :published<'2012-11-27T09:39:19Z'>
=for CHAPTER :published<'2012-11-27T09:39:19Z'> :tag<intro>
Test chapter
Ok
Expand Down Expand Up @@ -78,7 +78,6 @@ my %res2 = ();
my $tree2 = Perl6::Pod::Utl::parse_pod( $t, default_pod => 1 )
|| die "Can't parse ";
$tree2 = &WriteAt::get_book_info_blocks( $tree2, \%res2 );

use_ok "WriteAt::To::Atom";

my $out = '';
Expand Down Expand Up @@ -109,9 +108,7 @@ $atom->write($tree2);
$atom->end_write();
close $fd;
is scalar( @{ [ $out =~ /(<\/entry>)/gs ] } ), 1, 'default_published';

#$atom
#print Dumper \%res; exit;
#print Dumper $tree;
#warn $str;
#test DESCRIPTION :tag
ok $out =~ m%<category>pod6</category>%, '=for DESCRITION :tag<pod6>';
ok $out =~ m%<category>intro</category>%, '=for CHAPTER :tag<intro>';

0 comments on commit a355966

Please sign in to comment.