Commits

Shlomi Fish committed 54610b9

Passing html_with_title the examples.

TODO: pass it also the id_base and the title.

Comments (0)

Files changed (2)

lib/PerlBegin/TopicsExamples.pm

 
 has 'title' => (isa => 'Str', is => 'ro');
 has 'id_base' => (isa => 'Str', is => 'ro');
-has 'examples' => (isa => 'ArrayRef[HashRef]', is => 'ro');
 
 sub _calc_post_code
 {
 
 sub render
 {
-    my $self = shift;
+    my ($self, $args) = @_;
+
+    my $examples = $args->{'examples'};
 
     my $ret_string = '';
 
     my @lis;
     my @codes;
 
-    foreach my $ex_spec (@{$self->examples})
+    foreach my $ex_spec (@$examples)
     {
         my $id = $self->id_base . '__' . $ex_spec->{id};
         my $label = $ex_spec->{label};
 
 sub html_with_title
 {
-    my $self = shift;
+    my ($self, $args) = @_;
 
     return
         qq[<h3 id="] . CGI::escapeHTML($self->id_base())
         . qq[">] . CGI::escapeHTML($self->title()) . qq[</h3>\n\n]
-        . $self->render()
+        . $self->render($args)
         ;
 }
 

src/topics/files-and-directories/index.html.wml

         {
             title => "Copying a file",
             id_base => "copying_a_file",
+        }
+    )->html_with_title({
+        {
             examples =>
             [
                 {
                 },
             ],
         }
-    )->html_with_title();
+    });
 }:>
 
 
         {
             title => "Overwriting a file with text",
             id_base => "overwrite_a_file",
+        }
+    )->html_with_title(
+        {
             examples =>
             [
                 {
                 },
             ],
         }
-    )->html_with_title();
+    );
 }:>
 
 <:{
         {
             title => "Processing the Lines of a File",
             id_base => "processing_lines_of_a_file",
+        }
+    )->html_with_title(
+        {
             examples =>
             [
                 {
                 },
             ],
         }
-    )->html_with_title();
+    );
 }:>
 
 <:{
         {
             title => "Reading an entire UTF-8 file into a big variable",
             id_base => "string_slurp_utf8",
+        }
+    )->html_with_title(
+        {
             examples =>
             [
                 {
                 },
             ],
         }
-    )->html_with_title();
-
+    );
 }:>
 
 <:{
         {
             title => "Appending to a File",
             id_base => "append_to_file",
+        }
+    )->html_with_title(
+        {
             examples =>
             [
                 {
 EOF
                 },
             ],
-        }
-    )->html_with_title();
-
+    });
 }:>