Skip to content

Commit 9e3427d

Browse files
authored
Merge pull request #185 from tolmasky/runkit-try-example
Inline runnable examples with RunKit
2 parents 586b423 + bd277db commit 9e3427d

16 files changed

Lines changed: 938 additions & 520 deletions

0.24.1/docs/dist/ramda.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Ramda v0.24.0
1+
// Ramda v0.24.1
22
// https://github.com/ramda/ramda
33
// (c) 2013-2017 Scott Sauyet, Michael Hurley, and David Chambers
44
// Ramda may be freely distributed under the MIT license.
@@ -559,6 +559,23 @@
559559
};
560560
};
561561

562+
/**
563+
* Tests whether or not an object is similar to an array.
564+
*
565+
* @private
566+
* @category Type
567+
* @category List
568+
* @sig * -> Boolean
569+
* @param {*} x The object to test.
570+
* @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
571+
* @example
572+
*
573+
* _isArrayLike([]); //=> true
574+
* _isArrayLike(true); //=> false
575+
* _isArrayLike({}); //=> false
576+
* _isArrayLike({length: 10}); //=> false
577+
* _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
578+
*/
562579
var _isArrayLike = _curry1(function isArrayLike(x) {
563580
if (_isArray(x)) {
564581
return true;
@@ -6801,7 +6818,7 @@
68016818
* @memberOf R
68026819
* @since v0.12.0
68036820
* @category List
6804-
* @sig (c -> c) -> (a,b -> a) -> a -> [b] -> a
6821+
* @sig (c -> c) -> ((a, b) -> a) -> a -> [b] -> a
68056822
* @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
68066823
* @param {Function} fn The iterator function. Receives two values, the accumulator and the
68076824
* current element from the array. Wrapped as transformer, if necessary, and used to
@@ -6814,8 +6831,11 @@
68146831
*
68156832
* var numbers = [1, 2, 3, 4];
68166833
* var transducer = R.compose(R.map(R.add(1)), R.take(2));
6817-
*
68186834
* R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3]
6835+
*
6836+
* var isOdd = (x) => x % 2 === 1;
6837+
* var firstOddTransducer = R.compose(R.filter(isOdd), R.take(1));
6838+
* R.transduce(firstOddTransducer, R.flip(R.append), [], R.range(0, 100)); //=> [1]
68196839
*/
68206840
var transduce = curryN(4, function transduce(xf, fn, acc, list) {
68216841
return _reduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list);
@@ -8882,7 +8902,9 @@
88828902
* factorial(5); //=> 120
88838903
* count; //=> 1
88848904
*/
8885-
var memoize = memoizeWith(toString);
8905+
var memoize = memoizeWith(function () {
8906+
return toString(arguments);
8907+
});
88868908

88878909
/**
88888910
* Splits a string into an array of strings based on the given

0.24.1/docs/index.html

Lines changed: 252 additions & 248 deletions
Large diffs are not rendered by default.

0.24.1/docs/index.html.handlebars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@
153153
{{/if}}
154154

155155
{{#if example}}
156-
<pre><button class="try-repl" data-ramda-version="{{@root.version}}">Try in REPL</button><code class="hljs javascript">{{{example}}}</code></pre>
156+
<pre><div class = "try-repl" ><button class = "send-repl" data-ramda-version="{{@root.version}}">Open in REPL</button><button class = "run-here" data-ramda-version="{{@root.version}}">Run it here</button></div><code class="hljs javascript">{{{example}}}</code></pre>
157157
{{/if}}
158158
</section>
159159
{{/each}}
160160
</main>
161161
<script src="dist/ramda.js"></script>
162162
<script src="main.js"></script>
163+
<script src = "https://embed.runkit.com"></script>
163164
</body>
164165
</html>

0.24.1/docs/main.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,58 @@
9898
}
9999

100100
function tryInREPL(event) {
101-
if (!event.target.matches('.try-repl')) {
101+
var target = event.target;
102+
var isREPL = target.matches('.send-repl');
103+
var isRun = target.matches('.run-here');
104+
105+
if (!isREPL && !isRun) {
102106
return;
103107
}
104-
var version = event.target.dataset && event.target.dataset.ramdaVersion;
105-
var versionParam = version ? '?v=' + version : '';
106-
var code = event.target.nextElementSibling.textContent;
107-
var encoded = fixedEncodeURIComponent(code);
108-
location.assign(location.origin + '/repl/' +
109-
versionParam + '#;' + encoded);
108+
109+
var codeElement = target.parentNode.nextElementSibling;
110+
111+
if (isREPL || !window.RunKit) {
112+
var version = event.target.dataset && event.target.dataset.ramdaVersion;
113+
var versionParam = version ? '?v=' + version : '';
114+
var code = codeElement.textContent;
115+
var encoded = fixedEncodeURIComponent(code);
116+
117+
return window.open(location.origin + '/repl/' +
118+
versionParam + '#;' + encoded);
119+
}
120+
121+
var parent = target.parentNode.parentNode;
122+
var ramdaVersion = target.dataset && "@" + target.dataset.ramdaVersion || "";
123+
124+
parent.style.background = "transparent";
125+
parent.style.overflow = "hidden";
126+
127+
var container = document.createElement("div");
128+
129+
container.style.width = "1px";
130+
container.style.height = "1px";
131+
132+
parent.appendChild(container);
133+
134+
RunKit.createNotebook({
135+
element: container,
136+
nodeVersion: '*',
137+
preamble: 'var R = require("ramda' + ramdaVersion + '")',
138+
source: codeElement.textContent,
139+
syntaxTheme: 'atom-dark-syntax',
140+
minHeight: "52px",
141+
onLoad: function(notebook) {
142+
parent.removeChild(codeElement);
143+
parent.removeChild(target.parentNode);
144+
145+
container.style.cssText = "";
146+
147+
var iframe = container.lastElementChild;
148+
iframe.style.cssText = 'height:' + iframe.style.height;
149+
iframe.classList.add('repl');
150+
notebook.evaluate()
151+
}
152+
});
110153
}
111154

112155

19.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)