<script>
//required for palette
function filterblocks(a) {
// Show 'say' block only on browsers that support speech synthesis.
if (!window.SpeechSynthesisUtterance || !window.speechSynthesis) {
a = a.filter(function(b) { return !/^@?say\b/.test(b.block); });
}
// Show 'listen' blocks only on browsers that support speech recognition.
if (!window.webkitSpeechRecognition || window.SpeechRecognition) {
a = a.filter(function(b) { return !/\blisten\b/.test(b.block); });
}
return a.map(function(e) {
if (!e.id) {
// As the id (for logging), use the first (non-puncutation) word
e.id = e.block.replace(/^\W*/, '').
replace(/^new /, '').replace(/\W.*$/, '');
// If that doesn't turn into anything, use the whole block text.
if (!e.id) { e.id = e.block; }
}
return e;
});
}
// This is where we customize the blocks palette
PencilCodeGuide.session(
{
palette : [
{
name: 'Snippets',
color: 'deeporange',
blocks: filterblocks([
{
block: "encode = (x)->\n map = new Map\n map.set('a','.-')\n map.get( x )",
title: 'Define an encoding using a map',
id: "encode-definition"
},
{
block: "write encode('a')",
title: 'Encode a letter using the encode function and write it out',
id: "encode"
}
])
}
]
}
);
</script>