requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Allow defining functions in requirejs.yml

Open wuservices opened this issue 11 years ago • 5 comments

Some RequireJS config options such as init need a function, however YAML and JSON can only store data - not JavaScript. As a workaround this detects a function and unescapes it when the config is added to the page in the helper.

Fixes #177

wuservices avatar Jul 23 '14 17:07 wuservices

@wuservices Could you provide an example?

carsomyr avatar Jul 28 '14 05:07 carsomyr

See #177.

carsomyr avatar Jul 28 '14 05:07 carsomyr

Example:

shim:
  underscore:
    exports: _
    init: |
      function() {
        this._.templateSettings.interpolate = /\{\{(.+?)\}\}/g;
      }
  twitter/bootstrap/button:
    deps: [jquery]
    # Reverts $.fn.button to jQuery UI btn and
    # assigns Bootstrap button functionality to $.fn.btn
    init: |
      function($) {
        var btn = $.fn.button.noConflict();
        $.fn.btn = btn;
      }

wuservices avatar Jul 28 '14 18:07 wuservices

+1

steveklebanoff avatar Oct 21 '14 23:10 steveklebanoff

+1 @carsomyr any reason why this can't be merged in? Would be nice to have!

garbles avatar May 21 '15 03:05 garbles