|
Lines 17-22
package Koha::Template::Plugin::Asset;
Link Here
|
| 17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
|
|
20 |
=head1 NAME |
| 21 |
|
| 22 |
Koha::Template::Plugin::Asset |
| 23 |
|
| 24 |
=head1 DESCRIPTION |
| 25 |
|
| 26 |
The Asset plugin is a helper that generates HTML tags for JS and CSS files |
| 27 |
|
| 28 |
=head1 SYNOPSYS |
| 29 |
|
| 30 |
[% USE Asset %] |
| 31 |
|
| 32 |
[% Asset.css("css/datatables.css") %] |
| 33 |
[% Asset.js("js/datatables.js") %] |
| 34 |
|
| 35 |
[%# With attributes %] |
| 36 |
[% Asset.css("css/print.css", { media = "print" }) %] |
| 37 |
|
| 38 |
[%# If you only want the url and not the HTML tag %] |
| 39 |
[% url = Asset.url("css/datatables.css") %] |
| 40 |
|
| 41 |
=cut |
| 42 |
|
| 20 |
use Modern::Perl; |
43 |
use Modern::Perl; |
| 21 |
|
44 |
|
| 22 |
use Template::Plugin; |
45 |
use Template::Plugin; |
|
Lines 26-31
use File::Basename;
Link Here
|
| 26 |
use File::Spec; |
49 |
use File::Spec; |
| 27 |
use C4::Context; |
50 |
use C4::Context; |
| 28 |
|
51 |
|
|
|
52 |
=head1 FUNCTIONS |
| 53 |
|
| 54 |
=head2 new |
| 55 |
|
| 56 |
Constructor. Do not use this directly. |
| 57 |
|
| 58 |
=cut |
| 59 |
|
| 29 |
sub new { |
60 |
sub new { |
| 30 |
my ($class, $context) = @_; |
61 |
my ($class, $context) = @_; |
| 31 |
|
62 |
|
|
Lines 36-41
sub new {
Link Here
|
| 36 |
return bless $self, $class; |
67 |
return bless $self, $class; |
| 37 |
} |
68 |
} |
| 38 |
|
69 |
|
|
|
70 |
=head2 js |
| 71 |
|
| 72 |
Returns a <script> tag for the given JS file |
| 73 |
|
| 74 |
[% Asset.js('js/datatables.js') %] |
| 75 |
|
| 76 |
=cut |
| 77 |
|
| 39 |
sub js { |
78 |
sub js { |
| 40 |
my ( $self, $filename, $attributes ) = @_; |
79 |
my ( $self, $filename, $attributes ) = @_; |
| 41 |
|
80 |
|
|
Lines 50-55
sub js {
Link Here
|
| 50 |
return $self->tag('script', $attributes) . '</script>'; |
89 |
return $self->tag('script', $attributes) . '</script>'; |
| 51 |
} |
90 |
} |
| 52 |
|
91 |
|
|
|
92 |
=head2 css |
| 93 |
|
| 94 |
Returns a <link> tag for the given CSS file |
| 95 |
|
| 96 |
[% Asset.css('css/datatables.css') %] |
| 97 |
[% Asset.css('css/print.css', { media = "print" }) %] |
| 98 |
|
| 99 |
=cut |
| 100 |
|
| 53 |
sub css { |
101 |
sub css { |
| 54 |
my ( $self, $filename, $attributes ) = @_; |
102 |
my ( $self, $filename, $attributes ) = @_; |
| 55 |
|
103 |
|
|
Lines 66-71
sub css {
Link Here
|
| 66 |
return $self->tag('link', $attributes); |
114 |
return $self->tag('link', $attributes); |
| 67 |
} |
115 |
} |
| 68 |
|
116 |
|
|
|
117 |
=head2 url |
| 118 |
|
| 119 |
Returns the URL for the given file |
| 120 |
|
| 121 |
[% Asset.url('css/datatables.css') %] |
| 122 |
|
| 123 |
=cut |
| 124 |
|
| 69 |
sub url { |
125 |
sub url { |
| 70 |
my ( $self, $filename ) = @_; |
126 |
my ( $self, $filename ) = @_; |
| 71 |
|
127 |
|
|
Lines 93-98
sub url {
Link Here
|
| 93 |
} |
149 |
} |
| 94 |
} |
150 |
} |
| 95 |
|
151 |
|
|
|
152 |
=head2 tag |
| 153 |
|
| 154 |
Returns an HTML tag with given name and attributes. |
| 155 |
This shouldn't be used directly. |
| 156 |
|
| 157 |
[% Asset.tag("script", { src = "/koha-tmpl/intranet-tmpl/prog/css/datatables.css" }) %] |
| 158 |
|
| 159 |
=cut |
| 160 |
|
| 96 |
sub tag { |
161 |
sub tag { |
| 97 |
my ($self, $name, $attributes) = @_; |
162 |
my ($self, $name, $attributes) = @_; |
| 98 |
|
163 |
|
| 99 |
- |
|
|