Ram*_*yag 5 ruby-on-rails liquid
我希望能够为用户提供完全控制并编辑布局.我还希望他们能够包含他们想要的javascript插件.因此,我必须创建一个允许他们这样做的界面.
例如,默认的html看起来像这个更复杂的版本:
<head>
<title>{{site.name}}</title>
...
{{js_plugins.colorbox}} # this should return the necessary javascript and/or stylesheet tags
</head>
Run Code Online (Sandbox Code Playgroud)
我的Liquid JsPlugins drop是这样的:
class JsPluginsDrop < Liquid::Drop
include ActionView::Helpers::AssetTagHelper
...
def colorbox
javascript_include_tag "/path/to/js"
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行我的规范时,我得到了这个错误(请注意,你看到@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
Run Code Online (Sandbox Code Playgroud)
如果问题是由于它与我的Rails环境分开,并且drop无法访问Rails,我不会感到惊讶config.由于我仍然希望能够使用这些方便的方法,并且:cache => true如果可能的话,如何在drop中使用stylesheet_link_tag和javascript_include_tag?
看起来现在这样做是可能的:
class MyDrop < Liquid::Drop
...
def my_js_tag
helpers.javascript_include_tag '/some/thing'
end
...
def helpers
@helpers ||= ActionController::Base.helpers
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1073 次 |
| 最近记录: |