Skip to content

Instantly share code, notes, and snippets.

@digilord
Created December 24, 2013 21:41
Show Gist options
  • Save digilord/8118043 to your computer and use it in GitHub Desktop.
Save digilord/8118043 to your computer and use it in GitHub Desktop.
Meteor.startup () ->
# Countries collection initialization.
countries_csv = Assets.getText('country.csv')
csv = Meteor.require('csv')
countries_count = Countries.find().count()
if countries_count is 0
Future = Npm.require('fibers/future')
future = new Future()
csv()
.from.string(countries_csv, {comment: '#'})
.to.array (data) ->
return future.return(data)
results = future.wait()
for country in results
iso = country[0]
name = country[1]
selected = false
# Setup the default country. Do this so there is no
# flashing in the interface when the country list is
# populated then changed when there is no user selected
# country.
if name is 'United States'
selected = true
Countries.insert {iso: iso, name: name, selected: selected}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment