Skip to content

Instantly share code, notes, and snippets.

@amalex5
Last active October 4, 2017 15:00
Show Gist options
  • Save amalex5/0f0075b464444261b0d5572504acd241 to your computer and use it in GitHub Desktop.
Save amalex5/0f0075b464444261b0d5572504acd241 to your computer and use it in GitHub Desktop.
$.getJSON( sheetURL, function( data ) {
data.feed.entry
.filter(function(e){if (e['gsx$render']['$t'] !== 'n'){return e} }) // labels we don't want to render
.reduce(function(acc,e,i){
return (
acc
.append(
(i % 30 == 0) ? $('<div class="half-inch-padding"></div>') : '' // 30 labels per page
)
.append(
$("<div/>",{
'class': 'label',
html:
[ // this first part is a bit hacky:
(e['gsx$first']['$t'] + ' ' + e['gsx$last']['$t'])
+ ( e['gsx$other']['$t'] // a person with diff last name at same address
? ' & ' + e['gsx$other']['$t'] // sometimes they exist!
: '' // usually they don't!
), // my DREAM would be to be able to doodle a picture of a finite automata
// and have that be valid code
e['gsx$secondline']['$t'],
e['gsx$street']['$t'],
e['gsx$city']['$t'] + ', ' + e['gsx$state']['$t'] + ' ' + e['gsx$zip']['$t'],
e['gsx$country']['$t']
]
.filter(function(d){ if (d !== ''){return d}}) // filter out any blank lines
.join("<br>") // concat it into a single string
})
)
.append(
( (i+1) % 30 == 0) ? $('<div class="page-break"></div>') : '' // 30 labels per page
)
);
},
$("<div class='everything'/>") // the initial value of the accumulator
// (in this case, the parent DOM element)
// unhelpfully forced by syntax to be way at the bottom
)
.appendTo("body")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment