Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Add support for module configuration via requirejs_include_tag #174

Closed
ismell opened this issue Jul 12, 2014 · 5 comments
Closed

Add support for module configuration via requirejs_include_tag #174

ismell opened this issue Jul 12, 2014 · 5 comments

Comments

@ismell
Copy link

ismell commented Jul 12, 2014

I would like to be able to specify a module config via requirejs_include_tag. This will help in scenarios where you want to bootstrap some data as a requirejs module. i.e http://stackoverflow.com/questions/9916073/how-to-load-bootstrapped-models-in-backbone-js-while-using-amd-require-js

Because the block requirejs_include_tag takes in is used to append data- attributes maybe we can create two other helpers for this purpose?

requirejs_config_tag do |config|
    config['config'] = {'A' => {'hello' => 'world'}}
requirejs_script_tag do |controller|
    {:foo => :bar}

Would render something like

<script>var require = {...., config: {'A': {'hello': 'world'}}</script>
<script data-foo="bar" src="requirejs.js"></script>
@carsomyr
Copy link
Collaborator

carsomyr commented Sep 8, 2014

@ismell I'm hesitant to add another helper, since someone is going to come along after you and ask for yet another. How about a simple helper that just returns the digestified module paths as JSON? That would be information that only Rails knows.

@ismell
Copy link
Author

ismell commented Sep 8, 2014

Are you suggesting that we no longer use requirejs_script_tag but instead write it out manually using the path information?

@carsomyr
Copy link
Collaborator

carsomyr commented Sep 8, 2014

@ismell Yeah, I mean, requirejs_include_tag accounts for the vast majority of use cases. The one thing that Rails can help you with are the fingerprinted module paths.

@ismell
Copy link
Author

ismell commented Sep 8, 2014

Is this what you were thinking?

- config = requirejs_config.tap{|config| config['config'] = {'A' => {'hello' => 'world'}}}
:javascript
  var require = #{config.to_json}

= javascript_include_tag 'requirejs'

I think it allows for a lot of flexibility and still allows you to use the requirejs.yml to setup all the static configuration.

@carsomyr
Copy link
Collaborator

carsomyr commented Sep 8, 2014

Still too opinionated. How does a merge work among your configuration and the transformed configuration derived from requirejs.yml? I'd recommend filing an issue for just the module paths helper. Basically, I'm for exposing any information that Rails has that the user doesn't, and doing no more. If you look at that Backbone example, it's a rendered template. I'd imagine that a power user would do the same, with requirejs-rails playing the role of an asset pipeline compiler and manager of a special modules manifest.

@carsomyr carsomyr closed this as completed Sep 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants