Basic stuff
Add an element to an indexed object, mutating it. Returns object.
add = (indexed, item) ->
Array.prototype.push.call(indexed, item)
indexed
Generic reduction over anything. This will come in handy for iterating
/* | |
This document has been created with Marked.app <http://markedapp.com>, Copyright 2011 Brett Terpstra | |
Please leave this notice in place, along with any additional credits below. | |
--------------------------------------------------------------- | |
Title: Highlighter | |
Author: Gordon Brander http://gordonbrander.com | |
Description: Minimal theme with careful typographic scale and highlighed bold. | |
*/ | |
/* http://retinart.net/typography/typographicscale/ */ | |
html { |
function id(x) { | |
return x; | |
} | |
// Memoize a function -- creates a new function that will cache the results of | |
// the first return by serializing inputs as a key. | |
// | |
// * `fn`: the function to be memoized. | |
// * `hash`: a function to create the cache key. | |
// * `out`: a function to process memoized data on the way out. Useful if you need |
// KV.js | |
// Hash iteration functions | |
// Set a value on an object at field, returning object. | |
function set(object, key, value) { | |
// Set value on object at key. | |
object[key] = value; | |
// Return object. | |
return object; | |
} |
Add an element to an indexed object, mutating it. Returns object.
add = (indexed, item) ->
Array.prototype.push.call(indexed, item)
indexed
Generic reduction over anything. This will come in handy for iterating
// Foldable.js | |
// ============================================================================= | |
// | |
// Fold DOM elements based on whether they match a query string. | |
// | |
// How: | |
// | |
// var foldableParagraphs = document.querySelectorAll('p.foldable'); | |
// foldable(foldableParagraphs) | |
// |
// Returns an array of all indexes at which `pattern` can be found in `string`. | |
function indexesOf(string, pattern) { | |
var i = -1; | |
var indexes = []; | |
// We mutate `i` in place with the result of `indexOf`. We also use the last | |
// value of `i + 1` to continue seeking from. Any index found is pushed into | |
// the `indexes` array. If we ever get `-1` as the result of `indexOf`, we | |
// stop looping. | |
while((i = string.indexOf(pattern, i + 1)) !== -1) indexes.push(i); | |
return indexes; |
// Hashtext: the no-markup markup language. | |
// Quick-and-dirty Twitter-style text rendering. | |
// | |
// * Auto-paragraphatize and linebreak newlines. | |
// * Auto-link URLs (and prettify them, too). | |
// * Expand #hashtags into something useful (your choice). | |
// | |
// Copyright (c) 2014 Gordon Brander. | |
// Released under the MIT license http://opensource.org/licenses/MIT. | |
// |
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
/* | |
Pull structured content out of the DOM. | |
- Hero images | |
- Title | |
- Summary |
// Create a finite state switching function. | |
// Given a list of states, returns a function that will take a `prev` state | |
// and `next` state and will only advance state to `next` if it is one of | |
// the defined states. | |
const states = (...states) => (prev, next) => | |
states.indexOf(next) !== -1 ? next : prev; |
/* | |
Automatically namespace all CSS selectors. | |
Eliminates most problems with style leak | |
.active {} | |
...becomes | |
.button-active {} | |
*/ |