Browse Source

Added base (plaintext) for rendering functions

Alois Mahdal (@azzgoat) 12 years ago
parent
commit
3ab7671763
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      lib/SugarTrail/Template/Slave.pm

+ 38
- 0
lib/SugarTrail/Template/Slave.pm View File

11
     my $args = shift;
11
     my $args = shift;
12
     my $self = {};
12
     my $self = {};
13
     $self->{args} = $args;
13
     $self->{args} = $args;
14
+    $self->{steps} = [];
14
     return bless $self, $class;
15
     return bless $self, $class;
15
 }
16
 }
16
 
17
 
18
+sub source {
19
+    my $self = shift;
20
+    return sprintf "%s\n\n%s%s", $self->head, $self->warnings, $self->body; 
21
+}
22
+
23
+sub head {
24
+    my $self = shift;
25
+    my @head;
26
+    push @head, sprintf "%s: %s", $_, $self->{meta}->{$_} foreach keys %{$self->{meta}};
27
+    return join "\n", @head;
28
+}
29
+
30
+sub body {
31
+    my $self = shift;
32
+    my @source;
33
+    push @source, $_->{line} foreach @{$self->{steps}};
34
+    return join "\n", @source;
35
+}
36
+
37
+sub warnings {
38
+    my $self = shift;
39
+    my @warnings;
40
+    foreach my $step (@{$self->{steps}}) {
41
+        push @warnings, $_ foreach @{$step->{warnings}};
42
+    }
43
+    my $warnings;
44
+    if (@warnings) {
45
+        $warnings .= "---\n# SUGAR-TRAIL WARNINGS #\n\n";
46
+        foreach (@warnings) {
47
+            $warnings .= "> warning: $_\n";
48
+        }
49
+        $warnings .= "---\n\n";
50
+    }
51
+    return $warnings;
52
+}
53
+
54
+
17
 1;
55
 1;