从 Rakefile 访问 Nanoc 变量
Accessing Nanoc variables from Rakefile
我想知道如何从 Rakefile 访问 Nanoc 的变量(例如 @items
、@config
等)。
我有一个名为 nanoc.yaml
的文件,其中包含如下数据:
products:
ce:
name: 'Community Edition'
ee:
name: 'Enterprise Edition'
我希望能够在 Rakefile 中访问它,所以我有一个 "single source of truth" 可以从 Nanoc 站点以及拉下一些文档的 Rakefile 中访问。例如,在 Nanoc 站点中,您可以使用 @config[:products]
访问这些内容,但不能在 Rakefile 中访问。
我需要 include
Rakefile 中来自 Nanoc 的东西吗?
注意:此答案涉及私人 API!
您可以使用 SiteLoader
创建站点:
site = Nanoc::Int::SiteLoader.new.new_from_cwd
站点有一个配置:
site.config[:products][:ce][:name]
# => Community Edition
同样,这是私有 API 的一部分(至少目前是这样),因此上面的代码可能会在未来的版本中中断。
我想知道如何从 Rakefile 访问 Nanoc 的变量(例如 @items
、@config
等)。
我有一个名为 nanoc.yaml
的文件,其中包含如下数据:
products:
ce:
name: 'Community Edition'
ee:
name: 'Enterprise Edition'
我希望能够在 Rakefile 中访问它,所以我有一个 "single source of truth" 可以从 Nanoc 站点以及拉下一些文档的 Rakefile 中访问。例如,在 Nanoc 站点中,您可以使用 @config[:products]
访问这些内容,但不能在 Rakefile 中访问。
我需要 include
Rakefile 中来自 Nanoc 的东西吗?
注意:此答案涉及私人 API!
您可以使用 SiteLoader
创建站点:
site = Nanoc::Int::SiteLoader.new.new_from_cwd
站点有一个配置:
site.config[:products][:ce][:name]
# => Community Edition
同样,这是私有 API 的一部分(至少目前是这样),因此上面的代码可能会在未来的版本中中断。