From b298aa0a647829b2c92cedbec75be2e2f0306f4c Mon Sep 17 00:00:00 2001 From: Evgeny Sinelnikov Date: Fri, 10 Feb 2012 04:13:02 +0400 Subject: [PATCH] Update googledoc macro for view, edit and default public options with domain for google apps --- lib/google_apps_macros.rb | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/google_apps_macros.rb b/lib/google_apps_macros.rb index 664215e..91ad9e1 100644 --- a/lib/google_apps_macros.rb +++ b/lib/google_apps_macros.rb @@ -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 = "" else