-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint-svg.vtl
52 lines (52 loc) · 1.72 KB
/
print-svg.vtl
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
#if( $request.getServerName().contains('stag.') )##
#set( $_domain = 'stag.' )##
#elseif( $request.getServerName().contains('dev.') )##
#set( $_domain = 'dev.' )##
#end##
#set( $knownSvgList = {
'name' : "/path/to/file",
'name2' : "/path/to/file"
} )##
#macro( printSVG $svg $attributesObject )##
#if( $UtilMethods.isSet($svg) )##
## CHECK TO SEE IF $svg IS IN $knownSvgList - if not it must be a path...
#if( $svg.matches("\w+") && $UtilMethods.isSet( $knownSvgList[$svg] ) )##
#set( $svg = $knownSvgList[$svg] )##
#end##
## CREATE FILE PATH
#set( $_filePath = "http://${_domain}" )##
#if( $svg.indexOf('//') > -1 )##
#set( $_filePath = "http:" )##
#end##
#set( $_filePath = "${_filePath}$!{svg}" )##
## GET FILE
#set( $_file = $import.read("$!{_filePath}") )##
## RENDER HTML
#if( $UtilMethods.isSet($_file) )##
#if( $UtilMethods.isSet($attributesObject) )##
#if( $attributesObject.class.name == 'java.lang.String' )##
## STRING VALUE
#elseif( !$!listTool.isArray($attributesObject) )##
## OBJECT
#foreach( $property in $attributesObject.keySet() )##
## remove existing attribute if it is set
#set( $_searchPattern = "${property}=\"[^\"]*" )##
#set( $_file = $_file.replaceAll($_searchPattern , '') )##
## and new attribute value assignment to svg tag
#if( $UtilMethods.isSet( $attributesObject.get($property) ) )##
#set( $_file = $_file.replaceAll('<svg', "<svg ${property}='${attributesObject.get($property)}'") )##
#end##
#end## foreach $property in $attributesObject
## render the html
$_file##
#end## if not array or string
#end## if $attributesObject is set
#end##
## RESET VARS
#set( $svg = '' )##
#set( $attributesObject = '' )##
#set( $_filePath = '' )##
#set( $_file = '' )##
#set( $_searchPattern = '' )##
#end## isset $svg
#end## end printSVG