Sha256: 46288a1193234378b25cf33f168ff48d2ecefba7db37e49bdb338c469d364ba6

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

#= require require/require
#= require build

root = exports ? this

# Little object class to merge component require and requirejs require
loader =
  shim: ->
    # Store loaders functions
    loader.loaders.component = require
    loader.loaders.requirejs = requirejs
    loader.activate.define   = root.define

    # Expand require fuction with requirejs configurations
    # so we can require without great problems
    loader.require.config  = requirejs.config
    loader.require.s       = requirejs.s

  initialize: ->
    extend = require 'segmentio-extend'
    extend loader.require, require

    # Override global require for ower one
    root.require = loader.require
    root.loader = loader

  # Resource loaders compatibility
  loaders:
    requirejs : null
    component : null
    discovered: null

  discover: (params...) ->

    if params[0] instanceof Array
      requirer = 'requirejs'
    else
      requirer = 'component'

    @activate (requirer) and requirer

  activate: (requirer) ->
    switch requirer
      when 'component'
        root.define = null
      when 'requirejs'
        root.define = @activate.define
      else
        false

    @loaders.discovered = @loaders[requirer]

    true

  require: (params...) ->
    using = loader.discover params...

    try

      module = loader.loaders.discovered.apply @, params

    catch e
      console.warn 'Failed to load \'', params[0], "' with #{using}: Error: '", e.message, '\'. Trying with requirejs.'
      loader.activate 'requirejs'
      module = loader.loaders.discovered.apply @, params unless module

    # Always let requirjs active by default
    loader.activate 'requirejs'

    module

loader.shim()
loader.initialize()

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ende-0.1.4 lib/assets/javascripts/config/initializers/load_components.js.coffee
ende-0.1.3 lib/assets/javascripts/config/initializers/load_components.js.coffee
ende-0.1.2 lib/assets/javascripts/config/initializers/load_components.js.coffee
ende-0.1.1 lib/assets/javascripts/config/initializers/load_components.js.coffee
ende-0.0.1 lib/assets/javascripts/config/initializers/load_components.js.coffee