【发布时间】:2012-04-19 00:04:58
【问题描述】:
所以在 Octopress 中,我希望有一个充满部分的文件夹,我可以轻松地在网站上以不同的方式显示。我想要一个链接到包含所有部分的文档中的部分标题列表。
这是我想使用的逻辑,但我不知道如何在 Octopress 中实际实现它。
class Collection
attr_accessor :directory, :files
def new(dir)
self.files = []
self.directory = dir
load_files
end
def list(options={})
# Handle options here
files
end
private
def load_files
files_in(@directory).each do |file| # Psuedo-code
f = Jekyll::FileObject.new(file.read) # Also fictional, but I imagine something similar exists
f.text # Would return the actual content
f.yaml # Would return a hash of options from the YAML front matter
files << f
end
end
end
然后我想加载partials的集合:
api_methods = Collection.new("api_methods").list(:alphabetical => true, :method_type => "public")
在液体中,列出目录:
<ul>
{% for partial in api_methods %}
<li><a href="{% partial.yaml.url %}">{% partial.yaml.name %}</a></li>
{% endfor %}
</ul>
在液体中,列出全文:
{% for partial in api_methods %}
<h2>{% partial.yaml.name %}</h2>
{% partial.text %}
{% endfor %}
所以这应该可以让您对我正在尝试做的事情有一个基本的了解,但是我不知道如何实际实现它。
【问题讨论】: