From c7a25244b4cf0ee7a26ea0e4f1250ac7e5e64eaf Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Mon, 7 Mar 2011 10:49:51 +0100 Subject: [PATCH] URL generatiion logic, moved D7 branch --- recipe.js | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 recipe.js diff --git a/recipe.js b/recipe.js new file mode 100644 index 0000000..5f380e9 --- /dev/null +++ b/recipe.js @@ -0,0 +1,119 @@ + +function choose_url (data, proxyPattern) { + //first try to prepare local_url from recipe + var local_url = data["md-url_recipe"] !== undefined + ? prepare_url(data["md-url_recipe"][0], data) : null; + + var use_url_proxy = data["md-use_url_proxy"] !== undefined + ? data["md-use_url_proxy"] : "0"; + + //use the proxyPattern + if (proxyPattern && use_url_proxy == "1") { + if (local_url) { + data["md-local-url"] = []; + data["md-local-url"].push(local_url); + } + var ref_local_url = prepare_url(proxyPattern, data); + if (ref_local_url) return ref_local_url; + } + + // proxyPattern failed, go for local + if (local_url) + return local_url; + + //local failed, go for resource + return data["md-electronic-url"] !== undefined + ? data["md-electronic-url"][0] : null; +} + +var XRef = function (url, text) { + this.url = url; + this.text = text; +}; + +function has_recipe (data) { + var has = false; + if (data["md-url_recipe"] !== undefined) { + var recipe = data["md-url_recipe"][0]; + if (typeof recipe == "string" && recipe.length>0) { + has = true; + } + } + return has; +} + +function getUrlFromRecipe (data) { + if (has_recipe(data)) { + return prepare_url(data["md-url_recipe"][0],data); + } else { + return null; + } +} + +function getElectronicUrls (data) { + var urls = []; + if (data["md-electronic-url"] !== undefined) { + for (var i=0; i0 && regex_str.charAt(j) == '/' && regex_str.charAt(j-1) != '\\') + i++; + else + regex_parts[i] += regex_str.charAt(j); + } + var regex_obj = new RegExp(regex_parts[0], regex_parts[2]); + return input_str.replace(regex_obj, regex_parts[1]); +} + +function test_url_recipe() { + var url_recipe = "http://www.indexdata.com/?title=${md-title[\\s+/+/g]}&author=${md-author}"; + var meta_data = { "md-title" : ["Art of Computer Programming"], "md-author" : ["Knuth"]} + var final_url = prepare_url(url_recipe, meta_data); + alert(final_url); +} \ No newline at end of file -- 1.7.10.4