File: mason

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (195 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<%doc>
    This is a mason component. 
    # This is a comment
</%doc>

<%args>
    $color         # this argument is required!
    $size => 20    # default size
    $country => undef   # this argument is optional, default value is 'undef'
    @items => (1, 2, 'something else')
    %pairs => (name => "John", age => 29)
    $x => "</%args>"
</%argS>

<%flags>
    inherit => "page-framework.mi"
    inherit => "</%flags>"
</%flags>

<%attr>
author => 'maria ines parnisari'
</%attr>

<%once>
    $Schema = Apprentice::Data->$schema;
</%once>

<%shared>
    my $shared_var = 25;
</%shared>

<%init>
    my $cookies = Apache::Cookie->fetch;
</%init>

% # A random block of Perl code
<%perl>
#testing a comment '<%args>..</%args>>'
    my @people = ('mary' 'john' 'pete' 'david');
    my $moduloOperation = $totalNumber % $numColumns ? 1 : 0;
</%perl>

% # Note how each line of code begins with the mandatory %
% foreach my $person (@people) {
    Name: <% $person %> age: <& 'path/to/component' &> location: (unkown!)
% }

%# this is a comment :)

            % this is not perl code. the % is not the first character of the line!

<h1>Here at wally world you will find all the finest accoutrements.</h1>

% my @array = qw(zero one two);

<table>
%       foreach my $row (0..$#array) {
            <tr>
                <td><% $row          %></td>
                <td><% $array[$row]  %></td>
            </tr>
%        }
</table>

%# These are all component calls
<& 'path/to/component' &>
<& $component &>
<& menu, width => 100, height => 200 &>

%# Special globals $m and $r
%   my $result = $m->base_comp;
%   my $apache = $r->name;

%# a PRIVATE subcomponent that renders a hyperlink
<%def .make_a_link>
    <a href="<% $url %>"> <% $text %></a>
<%args>
    $path
    %query => ()
    $text
</%args>
<%init>
    my $url = $path;
    if (scalar (keys %query) > 0) {
        $url = $url . "?"
    }
    foreach my $queryParam (keys %query) {
        $url = $url . $queryParam . "=" . $query{$queryParam} . "&";
    }
</%init>
<%perl>
    my $someothervar = 42;
</%perl>
</%def>

<%method getPublic>
    <%perl>
        print "<font color=\"red\">some text!</font>";
        return 42;
    </%perl>
    %    my $text = "hello world";
<b><% $text %></b>
</%method>

<%text>
# This is not interpreted and is printed as is
%   my $variable = "hello";
</%text>

<%filter>
    s/(\w+)/\U$1/g #uppercase the entire thing
</%filter>

<%cleanup>
# This runs at the end.
    $db->disconnect();
</%cleanup>

<!-- BEGIN HTML -->
<style>
%   my $wow = "master";
    .normal {
        background: url("http://img.url/");
    }

% # TODO this should work but it doesn't 
% #   .dashed {
% #        background: url("<% $someUrl %>");
% #   }

    .<% $wow %> .normal {
        background: url("http://img.url/");
    }

</style>

<script type="text/javascript">
    alert('hello world');
%   my $superVar = 2;
</script>

<!-- END HTML -->

% # Random Perl blocks
<%perl>my $hello = "world";</%perl>
<%perl> } </%perl>

% # Components with content (https://masonbook.houseabsolute.com/book/chapter-5.html)
<&| .top_menu_filter &>
   <& SELF:top_menu, %ARGS &>
</&>

<&| .uc &>
  I am in <% $m->current_comp->name %>
</&>

<&| .ucfirst &>
  <&| .reverse &>
I am in <% $m->current_comp->name %>
  </&>
</&>

<table>
  <tr>
  <th>Name</th>
  <th>Age</th>
  </tr>
<&| 'query', query => 'SELECT name, age FROM User' &>
  <tr>
  <td>%name</td>
  <td>%age</td>
  </tr>
</&>
</table>


<&| /loop, items => ['one', 'two', 'three'] &>
<% $item %>
</&>

  <&| /loop, items => ['one', 'two', 'three'] &>
<% $item %>
</&>

<table>
<tr><th>Part Number</th><th>Quantity</th><th>Price</th><th>Total</th></tr>
<&| /query/order_items:exec, bind => [$OrderID] &>
    <tr>
        <td><% $_->{PARTNUM} %></td>
        <td><% $_->{QUANTITY} %></td>
        <td><% $_->{PRICE} %></td>
        <td><% $_->{QUANTITY} * $_->{PRICE} %></td>
    </tr>
</&>
</table>