<commit_before>PartnerCategories = require '../../collections/partner_categories'
Backbone = require 'backbone'
Q = require 'bluebird-q'
PrimaryCarousel = require './components/primary_carousel/fetch'
CategoryCarousel = require './components/partner_cell_carousel/fetch'
_ = require 'underscore'

fetchCategories = (type) ->
  categories = new PartnerCategories()
  categories.fetchUntilEnd cache: true, data: category_type: type
    .then ->
      Q.all categories.map (category) ->
        carousel = new CategoryCarousel(category: category)
        carousel.fetch()

    .then (carousels) ->
      _.select carousels, (carousel) ->
        carousel.partners.length > 0

@galleries = (req, res, next) ->
  carousel = new PrimaryCarousel

  Q.all([
    carousel.fetch()
    fetchCategories('Gallery')
  ])

  .spread (shows, carousels) ->
    res.render 'index',
      type: 'gallery'
      shows: shows
      carousels: carousels

    .catch next
    .done()

@institutions = (req, res, next) ->
  carousel = new PrimaryCarousel

  Q.all([
    carousel.fetch()
    fetchCategories('Institution')
  ])

  .spread (shows, carousels) ->

    res.render 'index',
      type: 'institution'
      shows: shows
      carousels: carousels

    .catch next
    .done()<commit_msg>Fix indentation; bootstrap carousels data<commit_after>_ = require 'underscore'
Q = require 'bluebird-q'
Backbone = require 'backbone'
PartnerCategories = require '../../collections/partner_categories'
PrimaryCarousel = require './components/primary_carousel/fetch'
CategoryCarousel = require './components/partner_cell_carousel/fetch'

fetchCategories = (type) ->
  categories = new PartnerCategories
  categories.fetchUntilEnd cache: true, data: category_type: type
    .then ->
      Q.all categories.map (category) ->
        carousel = new CategoryCarousel category: category
        carousel.fetch()

    .then (carousels) ->
      _.select carousels, (carousel) ->
        carousel.partners.length > 0

@galleries = (req, res, next) ->
  carousel = new PrimaryCarousel

  Q.all [
    carousel.fetch()
    fetchCategories 'Gallery'
  ]
    .spread (shows, carousels) ->

      res.locals.sd.CAROUSELS = carousels

      res.render 'index',
        type: 'gallery'
        shows: shows
        carousels: carousels

    .catch next
    .done()

@institutions = (req, res, next) ->
  carousel = new PrimaryCarousel

  Q.all([
    carousel.fetch()
    fetchCategories('Institution')
  ])

  .spread (shows, carousels) ->

    res.render 'index',
      type: 'institution'
      shows: shows
      carousels: carousels

    .catch next
    .done()
{'fraction_non_alphanumeric': 0.12090007627765065, 'fraction_numerical': 0.0007627765064836003, 'mean_word_length': 2.9802731411229133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5925110', 'n_tokens_mistral': 846, 'n_tokens_neox': 810, 'n_words': 192}