Adobe 65007312 Programming Guide - Page 203

Define the tags, Lua template using the prefix with which the tagset is imported

Page 203 highlights

CHAPTER 11: Web Gallery Plug-ins: A Tutorial Example Adding a customized tagset 203 Define the tags 1. Create a file in the plug-in folder named myExampleTags.lrweb, and edit it to define this list of sayings: local sayings = { "A dish fit for the gods - Julius Caesar, Shakespeare", "Oh, that way madness lies - King Lear, Shakespeare", "A multitude of sins - James 5:20", "A knight in shining armour - The Ancient Ballad of Prince Baldwin", "Blood is thicker than water - Guy Mannering; or the astrologer, Sir Walter Scott" } 2. Add a local counter variable to keep track of which member is chosen: local randomSayingCount = 0 3. Define a function that selects one of the sayings. Make it a global variable that can be referenced from LuaPage templates: globals = { randomSaying = function () randomSayingCount = math.mod( randomSayingCount + 1, #sayings ) return sayings[ randomSayingCount ] end, } 4. Add the tag definitions: tags = { saying = { startTag = "write( 'Here is a saying: ' ) write( randomSaying() )", endTag = "write( [[And that's all.]] ) ", }, aQuote = { startTag = 'write( [[]] )', endTag = 'write( [[]] )', } } This defines two dynamic tags with the names saying and aQuote. The tags can be referenced from a LuaPage template using the prefix with which the tagset is imported, and the tag name in an opening and closing tag: ... The inner tag uses the global function we defined to construct some strings containing both static and dynamic text. These strings are output before and after the text content of the tag. The outer tag provides some style information for the text. Add the tagset to the gallery 5. Edit the manifest.lrweb file to include the tags defined in the new tagset definition file. Add this line: importTags( "xmpl", "myExampleTags.lrweb" )

  • 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
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204

C
HAPTER
11: Web Gallery Plug-ins: A Tutorial Example
Adding a customized tagset
203
Define the tags
1.
Create a file in the plug-in folder named
myExampleTags.lrweb
, and edit it to define this list of
sayings:
local sayings = {
"A dish fit for the gods - Julius Caesar, Shakespeare",
"Oh, that way madness lies - King Lear, Shakespeare",
"A multitude of sins - James 5:20",
"A knight in shining armour - The Ancient Ballad of Prince Baldwin",
"Blood is thicker than water - Guy Mannering; or the astrologer, Sir Walter
Scott"
}
2.
Add a local counter variable to keep track of which member is chosen:
local randomSayingCount = 0
3.
Define a function that selects one of the sayings. Make it a global variable that can be referenced from
LuaPage templates:
globals = {
randomSaying = function ()
randomSayingCount = math.mod( randomSayingCount + 1, #sayings )
return sayings[ randomSayingCount ]
end,
}
4.
Add the tag definitions:
tags = {
saying = {
startTag = "write( 'Here is a saying: ' ) write( randomSaying() )",
endTag = "write( [[And that's all.]] ) ",
},
aQuote = {
startTag = 'write( [[<blockquote style="
margin: 0 0 0 30px;
padding: 10px 0 0 20px; font-size: 88%; line-height: 1.5em;
color: #666;">]] )',
endTag = 'write( [[</blockquote>]] )',
}
}
This defines two dynamic tags with the names
saying
and
aQuote
. The tags can be referenced from a
LuaPage template using the prefix with which the tagset is imported, and the tag name in an opening
and closing tag:
<
prefix
:
tagname
>...</
prefix
:
tagname
>
The inner tag uses the global function we defined to construct some strings containing both static
and dynamic text. These strings are output before and after the text content of the tag. The outer tag
provides some style information for the text.
Add the tagset to the gallery
5.
Edit the
manifest.lrweb
file to include the tags defined in the new tagset definition file. Add this line:
importTags( "xmpl", "myExampleTags.lrweb" )