For example: I want to create a new kind of tag (fancy_input_tag
) for use from any view as a plugin. No problem, I can do this. The trick is my tag requires the use of stylesheets and javascripts. As usual, my rake task copies these assets into their appropriate public folders.
Having built this plugin myself, there’s no real issue for me. I can have the plugin communicate which stylesheets and javascripts to use in light of how my app expects to be told about them. But that’s the rub. This communication is dependent on the handshake between my plugin any my app, and my app is responsible for how we shake hands. When I want to distribute this plugin, there's no guarantee about how that handshake is to occur.
In one Rails app, for example, I call include_stylesheet
or include_javascript
and this registers the asset so that it will included automatically in the page head. I can’t very well distribute a plugin that relies on these include methods because other people’s apps may not support this. I can’t rely on using content_for :head
on the same premise. Sure, I can provide some instructions to the developer along the lines of “make sure to include this javascript and that stylesheet”, but this is an extra configuration. In a community that is all about “convention over configuration” doesn’t it seem to make sense that there would be a standard way of communicating these kinds of dependencies? Wouldn't this improve modularity so that a plugin could just be dropped in?
Am I missing something? I feel like I am and this will end up being just another dumb question. I was curious enough to ask anyway.
EDIT: It's also important to note: I want these assets to be included up in the page head. I don't want to use stylesheet_tag
, etc. in the view and have the markup just inserted willy-nilly at any point in the page. (Maybe this is a bit fussy, but I like all my assets up in the head as much as possible.)