7 use CMS::Simple::Filter::Markup ;
14 my $cont_file = shift @ARGV || 'compshare.cont' ;
19 # name => 'html_escape',
20 # tags => [ qw( code ) ],
21 # code => \&html_escape,
25 tags => [ qw( text email image ) ],
26 code => \&CMS::Simple::Filter::Markup::filter_markup,
33 output_suffix => '.html',
37 # page_header => 'header.cont',
38 # page_footer => 'footer.cont',
39 # book => 'compshare.cont',
44 default_template => 'base_page',
46 # this maps loaded contents to location in this page's data tree.
47 # the location will be multilevel later on
49 # the page key name is the base name for the output file
54 template => 'chapters',
65 load_book_content( $conf, $cont_file ) ;
68 #print Dumper $conf->{pages} ;
70 my $cms = CMS::Simple->new( $conf ) ;
72 $cms->build_all_pages() ;
77 sub load_book_content {
79 my( $conf, $cont_file ) = @_ ;
81 my $cont_text = read_file( "contents/$cont_file" ) ;
82 my $content = CMS::Simple::Parse::parse_content( $cont_text ) ;
84 process_book_content( $conf, $content ) ;
86 #print Dumper $content ;
90 sub process_book_content {
92 my( $conf, $book_cont ) = @_ ;
94 my $book_title = $book_cont->{book}{title} ;
96 my $chap_conts = $book_cont->{chapter} ;
97 $chap_conts = [ $chap_conts ] unless ref $chap_conts eq 'ARRAY' ;
101 foreach my $chap_cont ( @{$chap_conts} ) {
103 $chap_cont->{number} = $chap_num++ ;
104 $chap_cont->{book_title} = $book_title ;
106 process_chap_content( $conf, $chap_cont ) ;
109 process_index_page( $conf, $chap_conts ) ;
111 #print Dumper $conf ;
115 sub process_index_page {
117 my( $conf, $chap_conts ) = @_ ;
119 my $index_cont = $conf->{pages}{index}{contents} ||= {} ;
121 foreach my $chap_cont ( @{$chap_conts} ) {
123 my $page_titles = $chap_cont->{page_title} ;
125 push( @{$index_cont->{chapter}}, {
127 chap_title => $chap_cont->{title},
128 chap_num => $chap_cont->{number},
129 page => $page_titles,
133 print Dumper $index_cont ;
139 sub process_chap_content {
141 my( $conf, $chap_data ) = @_ ;
143 my $chap_title = $chap_data->{title} ;
145 my $chap_page_cont = $conf->{pages}{chapters}{contents} ||= {} ;
147 push( @{$chap_page_cont->{chap_title}}, {
148 number => $chap_data->{number},
152 my $page_conts = $chap_data->{page} ;
153 $page_conts = [ $page_conts ] unless ref $page_conts eq 'ARRAY' ;
155 my $page_num = '01' ;
157 foreach my $page_cont ( @{$page_conts} ) {
159 $page_cont->{number} = $page_num++ ;
161 #print Dumper $page_cont ;
163 process_page_content( $conf, $chap_data, $page_cont ) ;
168 sub process_page_content {
170 my( $conf, $chap_data, $page_data ) = @_ ;
172 my $chap_title = $chap_data->{title} ;
173 my $page_title = $page_data->{title} ;
176 #print "TITLE $page_title\n" ;
178 my $chap_num = $chap_data->{number} ;
179 my $page_num = $page_data->{number} ;
181 my $page_name = "page-$chap_num$page_num" ;
182 my $page_url = "$page_name.html" ;
184 push( @{$chap_data->{page_title}}, {
186 title => $page_title,
187 page_link => $page_url,
202 book_title => $chap_data->{book_title} || 'FOO',
204 text => 'index.html',
206 chap_link => 'chapters.html',
209 if ( $page_num > 1 ) {
211 my $prev_page_num = sprintf "%02d", $page_num - 1 ;
212 $header_cont->{prev_link} = {
213 prev_page => "page-$chap_num$prev_page_num.html",
217 if ( $page_num < 50 ) {
219 my $next_page_num = sprintf "%02d", $page_num + 1 ;
220 $header_cont->{next_link} = {
221 next_page => "page-$chap_num$next_page_num.html",
226 #print Dumper $page_data ;
228 my $items = process_page_items( $page_data ) ;
236 set_page_header_data( $page_cont, $header_cont ) ;
238 $page->{contents} = $page_cont ;
239 #print Dumper $page_cont ;
241 $conf->{pages}{$page_name} = $page ;
245 sub process_page_items {
247 my( $page_data ) = @_ ;
249 my $items = $page_data->{item} ;
250 $items = [ $items ] unless ref $items eq 'ARRAY' ;
252 foreach my $item ( @{$items} ) {
258 text => $item->{title},
270 process_subitems( $item ) ;
271 process_code( $item ) ;
274 #print Dumper $items ;
279 sub process_subitems {
283 my $subitems = $item->{subitem} ;
285 return unless $subitems ;
287 $subitems = [ $subitems ] unless ref $subitems eq 'ARRAY' ;
289 $item->{subitems} = [
303 my $code = $item->{code} ;
305 return unless $code ;
307 # append a newline if needed - scalar content loses a trailing newline
309 #print "CODE: [$code]\n" ;
311 $code =~ s/(?<!\n)\z/\n/ ;
314 $code = encode_entities( $code, '<>&"') ;
323 sub set_page_header_data {
325 my( $page_cont, $data ) = @_ ;
327 for my $header ( qw( html_header page_header page_footer ) ) {
329 @{$page_cont->{$header}}{keys %{$data}} = values %{$data} ;