Class: WriteDown::Template
- Inherits:
-
Object
- Object
- WriteDown::Template
- Defined in:
- lib/write_down/template.rb
Class Method Summary collapse
-
.render(dist, articles) ⇒ Object
替换模板变量.
Class Method Details
.render(dist, articles) ⇒ Object
替换模板变量
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/write_down/template.rb', line 4 def self.render dist, articles #套入模板 index_file_content = File.open(File.(dist+"/index.html")).read post_file_content = File.open(File.(dist+"/post.html")).read index_html = Mustache.render(index_file_content, :articles => articles, :site => $site) #TODO should sort by some column? ret_fs = File.open(dist+"/index.html", "w") ret_fs.puts index_html ret_fs.close articles.each do |article| article_html = Mustache.render(post_file_content, :site => $site, :articles => articles) article_fs = File.open(dist+"/"+article.link, "w") article_fs.puts article_html article_fs.close end end |