diff --git a/docs/documentation.md b/docs/documentation.md index 88a39d7a95..e378329f47 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -95,7 +95,7 @@ If you already have a JavaScript build system, you can use **instantsearch.js** ### Initialization
-
+
{% highlight javascript %} var search = instantsearch({ appId: '$appId', @@ -171,7 +171,7 @@ Most widgets requires you to configure the DOM element they will use to display ### Start
-
+
{% highlight javascript %} search.start(); {% endhighlight %} diff --git a/docs/js/doc.js b/docs/js/doc.js index 8bf4c4e973..71e4522b65 100644 --- a/docs/js/doc.js +++ b/docs/js/doc.js @@ -6,7 +6,7 @@ function search() { function t(tmpl, vars) { Object.keys(vars).forEach(function(k) { - tmpl = tmpl.replace('$' + k, vars[k]); + tmpl = tmpl.replace(new RegExp('\\$' + k, 'g'), vars[k]); }); return tmpl; } @@ -15,11 +15,17 @@ apiKey: '6be0576ff61c053d5f9a3225e2a90f76', indexName: 'instant_search' }; - var codeSnippets = q('.code-sample-snippet:not(.last):not(.ignore)'); - var lastSnippets = q('.code-sample-snippet.last'); - var source = codeSnippets - .concat(lastSnippets) - .map(function(d) {return d.textContent;}); + var codeSnippets = q('.code-sample-snippet:not(.start):not(.config):not(.ignore)'); + var configSnippet = q('.code-sample-snippet.config')[0]; + var startSnippet = q('.code-sample-snippet.start')[0]; + + var source = codeSnippets.map(function(snippet) { + var functionBody = [configSnippet, snippet, startSnippet] + .map(function(e) { return e.textContent; }) + .join(';'); + return "(function() {" + functionBody + "})();"; + }); + source = t(source.join('\n'), constants); eval(source); }