-
Notifications
You must be signed in to change notification settings - Fork 983
/
AssetSettingTagLib.groovy
62 lines (48 loc) · 1.68 KB
/
AssetSettingTagLib.groovy
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
package streama
class AssetSettingTagLib {
def getAssetFromSetting(setting){
if(setting.startsWith("upload:")){
def id = setting.split(":")[1]
def file = File.get(id)
return file.getSrc()
}else{
return setting
}
}
def linkRelIconSetting = { attribs ->
def setting = attribs['setting']
out << '<link rel="icon" href="'+getAssetFromSetting(setting)+'" type="image/x-icon">'
}
def imgSetting = { attribs ->
def setting = attribs['setting']
def alt = attribs['alt']
def classNames = attribs['class']
def altText = ""
if(alt) altText = 'alt="'+alt+'"'
out << '<img class="'+classNames+'" src="'+getAssetFromSetting(setting)+'" '+altText+'>'
}
def cssBackgroundSetting = { attribs ->
def setting = attribs['setting']
def selector = attribs['selector']
out << '<style>'
out << selector
out << '{ background-image: url('
out << getAssetFromSetting(setting)
out << ');}</style>'
}
def googleAnalytics = { attribs ->
def enabled = grailsApplication.config.streama.googleAnalytics?.enabled
def id = grailsApplication.config.streama.googleAnalytics?.id
if(!enabled){
return
}
out << '<!-- Global site tag (gtag.js) - Google Analytics -->'
out << '<script async src="https://www.googletagmanager.com/gtag/js?id='+ id +'"></script>'
out << '<script>'
out << 'window.dataLayer = window.dataLayer || [];'
out << 'function gtag(){dataLayer.push(arguments);}'
out << 'gtag(\'js\', new Date());'
out << 'gtag(\'config\', \'UA-124224387-2\');'
out << '</script>'
}
}