Skip to content

Instantly share code, notes, and snippets.

/* createTOC */
// This script updates a table of contents for your document. It assumes your document is using
// sections, as each section will be an entry in the TOC
// Please view the "sample" page for this script in the file
// This script also adds section numbers to section and page headers and names the docPage's frame
// Along the way it sorts the docPages and page-numbers them, using other scripts in this file.
// See the other scripts for code comments on them
const {toArray} = require('util');
// returns a timestamp
const timeStamp = () => {
const now = new Date();
return `${'0'.concat(now.getHours()).slice(-2)}:${'0'.concat(now.getMinutes()).slice(-2)}:${'0'.concat(now.getSeconds()).slice(-2)}.${now.getMilliseconds().toString().concat('000').slice(0,3)}`;
}
// Assumes an existing text layer called 'debug_output' on the current page that's NOT in a group or artboard
// parameters: the Sketch page object, the thing (or an array of things) to log, whether or not to clear previous logs
@josephxbrick
josephxbrick / gist:fa6286c86a28889489c84b9093a1b2d5
Created May 17, 2018 21:46
iterating an object using a lodash function
artworks =
card1:
title: "Beach"
x: 40
card2:
title: "Turtle"
x: 50
_.forEach artworks, (value, key) ->
print value.title, value.x, key
@josephxbrick
josephxbrick / symbol_example.coffee
Last active April 6, 2018 17:07
Using Symbols component to take a "card" in Design mode, turn that into a class definition (using Symbols), and fill instances with json data
# in design mode there is a Frame called "template" (targeted for code). In template there is a text layer
# called "title" (not targeted for code) and a layer called "thumbnail" (also not targeted). You can see how
# much using Symbols simplifies the code, and to change the layout, you just change it in design.
{Symbol} = require "symbols/Symbol"
Template = Symbol template # create Template class out of the frame "template" defined in Design
# Handles the JSON
getData = "https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Furbansharp.com%2Frss%2F"