<commit_before>AssetsManager = require './assets_manager'
Js = require './js'
Css = require './css'
OnTheFlyCompiler = require './otf_compiler'
compilers = require './default_compilers'

class BundleUp
  constructor: (app, asset, options = {bundle:false}) ->
    unless options.compilers?
      options.compilers = compilers
    else
      options.compilers.stylus = options.compilers.stylus || compilers.stylus
      options.compilers.coffee = options.compilers.coffee || compilers.coffee
      options.compilers.js = options.compilers.js || compilers.js
      options.compilers.css = options.compilers.css || compilers.css

    options.minifyCss = options.minifyCss || false
    options.minifyJs = options.minifyJs || false

    @app = app
    @js = new Js(options)
    @css = new Css(options)

    if typeof asset == "string"
      require(asset)(new AssetsManager(@css, @js))
    else if typeof asset == 'function'
      asset(new AssetsManager(@css, @js))
    else
      throw new Error("Unsupported asset type")

    if options.bundle
      @js.toBundles()
      @css.toBundles()
    else
      # Compile files on-the-fly when not bundled
      @app.use (new OnTheFlyCompiler(@js, @css, options.compilers)).middleware


    if(@app.dynamicHelpers)
      # Support for Express 2
      @app.dynamicHelpers(
          renderStyles: @css.render.bind(@css)
          renderJs: @js.render.bind(@js)
      )

    else if(@app.locals)
      # Support for Express 3
      @app.locals(
        renderStyles: (namespace=@css.defaultNamespace) =>
          return @css.render(namespace)
        renderJs: (namespace=@js.defaultNamespace) =>
          return @js.render(namespace)
      )

module.exports = (app, assetPath, options)->
  new BundleUp(app, assetPath, options)<commit_msg>Fix dynamic helpers for Express 3 & 2<commit_after>AssetsManager = require './assets_manager'
Js = require './js'
Css = require './css'
OnTheFlyCompiler = require './otf_compiler'
compilers = require './default_compilers'

class BundleUp
  constructor: (app, asset, options = {bundle:false}) ->
    unless options.compilers?
      options.compilers = compilers
    else
      options.compilers.stylus = options.compilers.stylus || compilers.stylus
      options.compilers.coffee = options.compilers.coffee || compilers.coffee
      options.compilers.js = options.compilers.js || compilers.js
      options.compilers.css = options.compilers.css || compilers.css

    options.minifyCss = options.minifyCss || false
    options.minifyJs = options.minifyJs || false

    @app = app
    @js = new Js(options)
    @css = new Css(options)

    if typeof asset == "string"
      require(asset)(new AssetsManager(@css, @js))
    else if typeof asset == 'function'
      asset(new AssetsManager(@css, @js))
    else
      throw new Error("Unsupported asset type")

    if options.bundle
      @js.toBundles()
      @css.toBundles()
    else
      # Compile files on-the-fly when not bundled
      @app.use (new OnTheFlyCompiler(@js, @css, options.compilers)).middleware


    if(@app.locals)
      # Support for Express 3
      @app.locals(
        renderStyles: (namespace=@css.defaultNamespace) =>
          return @css.render(namespace)
        renderJs: (namespace=@js.defaultNamespace) =>
          return @js.render(namespace)
      )

    else if(@app.dynamicHelpers)
      # Support for Express 2
      @app.dynamicHelpers(
          renderStyles: @css.render.bind(@css)
          renderJs: @js.render.bind(@js)
      )


module.exports = (app, assetPath, options)->
  new BundleUp(app, assetPath, options)
{'fraction_non_alphanumeric': 0.12029025955902875, 'fraction_numerical': 0.0016745743790120011, 'mean_word_length': 2.9689922480620154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7516933', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1101, 'n_words': 251}