Most recent edit on 2008-05-21 10:44:19 by BradEllis
Additions:
%%--
-- Assign this page to "Page Created" trigger
-- Just loading some stuff to get us started
-- Looking to make sure the page is a page and not something else
--
if (string.find(newPage:dataAsAttributedString():string(),
"Calendar")) then
otherPage = document:pageForKey("
DailyLogTemplate")
attributedString = newPage:dataAsAttributedString()
newString = otherPage:dataAsAttributedString():string()
attributedString:objc_mutableString():appendString(newString)
newPage:setDataAsAttributedString(attributedString)
Edited on 2008-05-19 14:22:29 by BradEllis
Additions:
Paste text from a template page based on the title of the newly created page
-- Assign this to the "Page Created" trigger
-- This script requires your document to have a page called PlasmidTemplate. If you have another page as your template, change the appropriate variable.
-- Page variables such as $date$ won't work with this script
-- Making sure the page we're creating is a text page
-- Checking to see if the page title includes the word "plasmid" and if so, pulling the content from the "PlasmidTemplate" and pasting it onto the new page, replacing the content. ie, if you created a new page called "plasmid power" it would pass.
if (string.find(newPage:displayName(), "plasmid")) then
pageTemplate = document:pageForKey("PlasmidTemplate")
pageText = pageTemplate:dataAsAttributedString()
newPage:setDataAsAttributedString(pageText)
end
Edited on 2008-03-09 15:00:06 by GusMueller
Deletions:
return
Oldest known version of this page was edited on 2008-01-25 17:56:08 by BradEllis []
Page view:
Trigger Examples
A trigger that creates a new page based on the current date when a document opens
-- assign this to the "Document did open" event.
pageName = os.date("%Y.%m.%d", os.time())
triggerDictionary.document:openPageWithTitle(pageName)
A simple trigger that you could use to modify the default text on a new page
-- assign this to the "Page created" event
newPage = triggerDictionary.item
-- check and see if we are dealing with a regular page type.
-- if it's not a regular page type, then bail out on this trigger.
if (newPage:type() ~= VPPageType) then
return
end
-- we grab the contents of the page
attributedString = newPage:dataAsAttributedString()
-- using objc_mutableString() insteadof mutableString() will return an objective-c object which we can then
-- call a function on, instead of a lua string.
attributedString:objc_mutableString():appendString("\nThis is an addition to the new page text.")
attributedString:objc_mutableString():appendString("\nThis new page's name is '" .. newPage:displayName() .. "'")
-- and now we set the value in the new page.
newPage:setDataAsAttributedString(attributedString)
A WebServer trigger example:
-- assign this to the "Web server will send page" event
-- check and see if we are dealing with a regular page type.
-- if it's not a regular page type, then return.
if (triggerDictionary.item:type() ~= VPPageType) then
return
end
-- grab what's going to be sent out to the browser (this is the raw html)
output = triggerDictionary.output
-- look for the key $lookingFor$ , and replace it with the string "replaceValue"
-- notice that we assign the value back to the trigger dictionary. This way, VoodooPad
-- gets the updated value.
triggerDictionary.output = output:replace("$lookingFor$", "replaceValue")
A Trigger to update a page listing all the pages in the document:
-- assign this to the "Page Deleted" and "Page Created" events.
-- the index is created in a page named "Page Index"
indexPageName = "Page Index"
document = triggerDictionary.document
list = "All the pages in this document:\n"
for key in objc.values(document:keys()) do
page = document:pageForKey(key)
list = list .. page:displayName() .. "\n"
end
document:createNewPageWithName(indexPageName) -- noop if it's already around.
pageData = document:pageForKey(indexPageName)
attributedString = pageData:dataAsAttributedString()
attributedString:objc_mutableString():setString(list)
pageData:setDataAsAttributedString(attributedString)
Replace the template placeholder $clipboard$ with the text on the clipboard:
-- assign this to the "Page created" event
newPage = triggerDictionary.item
-- check and see if we are dealing with a regular page type.
-- if it's not a regular page type, then bail out on this trigger.
if (newPage:type() ~= VPPageType) then
return
end
-- we grab the contents of the page
attributedString = newPage:dataAsAttributedString()
-- grab the clipboard
p = objc.class("NSPasteboard"):generalPasteboard()
t = p:stringForType("NSStringPboardType")
range = objc.luaToNSRange({location=0, length=attributedString:objc_mutableString():length()})
if (t ~= nil) then
count = attributedString:objc_mutableString():replaceOccurrencesOfString_withString_options_range_("$clipboard$", t, 0, range)
else
-- otherwise just make the $clipboard$ placeholder an empty string
attributedString:objc_mutableString():replaceOccurrencesOfString_withString_options_range_("$clipboard$", "", 0, range)
end
-- and now we set the value in the new page.
newPage:setDataAsAttributedString(attributedString)