Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions lib/google_apps_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,33 @@ def self.clean_key(key)
class DocumentMacros
def self.get_doc(obj, args)
doc_key = args[0]
action = false
domain = false
if args.length == 2
edit = (args[1].strip == "edit")
else
edit = false
case args[1].strip
when "edit"
action = "edit"
when "view"
action = "view"
else /^[\w]+(\.+[\w-])+/
domain = args[1].strip
end
end
if args.length == 3
domain = args[1].strip if /^[\w]+(\.+[\w-])+/.match(args[1].strip)
action = "edit" if args[2].strip == "edit"
action = "view" if args[2].strip == "view"
end
if /^[\w-]+$/.match(doc_key)
if edit
url = "https://docs.google.com/document/d/#{doc_key}/edit"
if domain
url = "https://docs.google.com/a/#{domain}/document/"
else
url = "https://docs.google.com/document/"
end
if action
url += "d/#{doc_key}/#{action}"
else
url = "https://docs.google.com/document/d/#{doc_key}"
url += "pub?id=#{doc_key}"
end
out = "<iframe src='#{url}' width='800' height='400'></iframe>"
else
Expand Down