我希望能够让用户完全控制和编辑布局。我还希望他们能够包含他们想要的 javascript 插件。因此,我必须制作一个界面来允许他们这样做。
例如,默认的 html 看起来像一个更复杂的版本:
<head>
<title>{{site.name}}</title>
...
{{js_plugins.colorbox}} # this should return the necessary javascript and/or stylesheet tags
</head>
我的 Liquid JsPlugins drop 是这样的:
class JsPluginsDrop < Liquid::Drop
include ActionView::Helpers::AssetTagHelper
...
def colorbox
javascript_include_tag "/path/to/js"
end
end
但是,当我运行我的规范时,我收到了这个错误(请注意,您会看到@drop["colorbox-1.3.15"]
我上面提供的代码的行为不同。但是,我想简化我的代码,因为这不是问题,而是问题的使用TagHelper
):
Failures:
1) JsPluginsDrop colorbox-1.3.15 should return the correct script tags
Failure/Error: @drop["colorbox-1.3.15"].stylesheets.should include("/jquery-plugins/colorbox-1.3.15/example1/colorbox.css")
undefined local variable or method `config' for #<JsPluginsDrop:0xcbfab38>
# ./app/drops/js_plugins_drop.rb:22:in `stylesheets'
# ./spec/models/js_plugins_drop_spec.rb:11
如果问题是由于它与我的 Rails 环境是分开的,并且 drop 无法访问 Rails 的这一事实引起的,我不会感到惊讶config
。由于我仍然希望能够使用这些方便的方法并且:cache => true
它们提供了,如果可能的话,我如何在 drop 中使用 stylesheet_link_tag 和 javascript_include_tag?