Files: a738ecf91d844ee886e94857a82177ab446113f1 / tmpl / com.part.js
696 bytesRaw
1 | |
2 | // `examples` is an object, mapping language->example |
3 | module.exports.code = examples => { |
4 | return `<div class="code-examples"> |
5 | <div class="head"> |
6 | ${ Object.keys(examples).sort(langPrioritySort).map(lang => `<div class="tab">${lang}</div>`).join('') } |
7 | </div> |
8 | <div class="body"> |
9 | ${ Object.keys(examples).sort(langPrioritySort).map(lang => `<pre><code class="language-${lang}">${cleanupCode(examples[lang])}</code></pre>`).join('') } |
10 | </div> |
11 | </div>` |
12 | } |
13 | |
14 | // enforce an order to the language tabs |
15 | function langPrioritySort (a, b) { |
16 | if (b == 'js' && a != 'js') |
17 | return 1 |
18 | return -1 |
19 | } |
20 | |
21 | // do some cleanup on the code |
22 | function cleanupCode (str) { |
23 | return str.trim() |
24 | } |
Built with git-ssb-web