Commits

Shlomi Fish  committed d7385cf

Move id_base and title to html_with_title / render.

  • Participants
  • Parent commits 54610b9

Comments (0)

Files changed (2)

File lib/PerlBegin/TopicsExamples.pm

 use CGI ();
 use Text::VimColor;
 
-has 'title' => (isa => 'Str', is => 'ro');
-has 'id_base' => (isa => 'Str', is => 'ro');
+use Carp ();
 
 sub _calc_post_code
 {
     my ($self, $args) = @_;
 
     my $examples = $args->{'examples'};
+    my $title = $args->{'title'};
+    my $id_base = $args->{'id_base'};
 
     my $ret_string = '';
 
 
     foreach my $ex_spec (@$examples)
     {
-        my $id = $self->id_base . '__' . $ex_spec->{id};
+        my $id = $id_base . '__' . $ex_spec->{id};
         my $label = $ex_spec->{label};
 
         my $esc_id = CGI::escapeHTML($id);
 {
     my ($self, $args) = @_;
 
+    my $id_base = $args->{'id_base'}
+        or Carp::confess("id_base not specified.");
+    my $title = $args->{'title'}
+        or Carp::confess("title not specified.");
+
     return
-        qq[<h3 id="] . CGI::escapeHTML($self->id_base())
-        . qq[">] . CGI::escapeHTML($self->title()) . qq[</h3>\n\n]
+        qq[<h3 id="] . CGI::escapeHTML($id_base)
+        . qq[">] . CGI::escapeHTML($title) . qq[</h3>\n\n]
         . $self->render($args)
         ;
 }

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

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