【发布时间】:2020-02-19 13:10:45
【问题描述】:
我正在创建一个 Jekyll 插件,它执行带有一些(液体或非液体)参数的 shell 脚本。
我在提取一些液体变量的值时遇到问题。
例如,如果我这样使用这个插件:
{% shellcmd image-responsive "{{ include.asset }}" %}
它没有渲染{{ include.asset }} 部分。我需要帮助,尤其是这部分。
到目前为止,插件是这样的:
module Jekyll
class ShellCommand < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render_variable(context)
Liquid::Template.parse(@text).render(context)
end
def render(context)
text = render_variable(@text)
`#{text}`.strip
end
end
end
Liquid::Template.register_tag('shellcmd', Jekyll::ShellCommand)
应该怎么样?
【问题讨论】:
-
我正在寻找相同的答案。你想好如何解决了吗?
-
目前我对为 Jekyll 做贡献不感兴趣。我还没有尝试过 Stefan 下面的答案
-
奇怪的评论@alexandre1985。你先问比你不感兴趣?也许我误解了你的评论。
-
@Stefan 如果这澄清了,我已经从制作插件转向 Jekyll 和 Ruby 语言。不是我需要证明,但有些人认为将判断归因于人非常适合 StackOverFlow.com 技术答案
标签: ruby jekyll liquid jekyll-extensions