【发布时间】:2011-03-12 10:04:18
【问题描述】:
我希望能够让用户完全控制和编辑布局。我还希望他们能够包含他们想要的 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,如果可能的话,我该如何使用下拉列表中的 stylesheet_link_tag 和 javascript_include_tag?
【问题讨论】:
标签: ruby-on-rails liquid