【问题标题】:Ruby/Jekyll Plugin - How to render liquid variables inside pluginRuby/Jekyll 插件 - 如何在插件中渲染液体变量
【发布时间】: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


【解决方案1】:

没有在代码中检查这一点,只是开始玩 Jekyll,所以也许我错了。但是试试{% shellcmd image-responsive include.asset %}(你的行没有花括号)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2020-05-15
    • 2017-01-15
    • 2013-07-31
    • 1970-01-01
    • 2014-02-04
    相关资源
    最近更新 更多