Middleman动态页面问题

时间:2012-02-13 03:07:53

标签: ruby middleman static-site

所以我有一个名为development.sqlite3的数据库,它和我的config.rb在同一个目录中。

当我进入IRB并输入以下内容时:

require 'data_mapper'
DataMapper.setup :default, "sqlite://#{Dir.pwd}/development.sqlite3"

class Post
      include DataMapper::Resource
      property :title,      String
      property :slug_url,   String, :key => true
      property :desc,       String
      property :content,    Text
      property :project,    String
      property :target_url, Text
      property :trackback,  Integer
      property :updated_at, String
      property :created_at, DateTime  # A DateTime, for any date you might like.
end


DataMapper.finalize
DataMapper.auto_upgrade!
posts = Post.all 
puts post.slug_url

这就像我期望的那样踢出所有的slug_urls。这是我在config.rb文件开头的内容。

require 'data_mapper'
require 'builder'
require 'maruku'

DataMapper.setup :default, "sqlite://#{Dir.pwd}/development.sqlite3"

class Post
  include DataMapper::Resource
  property :title,      String
  property :slug_url,   String, :key => true
  property :desc,       String
  property :content,    Text
  property :project,    String
  property :target_url, Text
  property :trackback,  Integer
  property :updated_at, String
  property :created_at, DateTime  # A DateTime, for any date you might like.
end

DataMapper.finalize
DataMapper.auto_upgrade!

posts = Post.all 

posts.each do |post|
  page "/kw/#{post.slug_url}.haml", :proxy => "/kw/template.haml" do
    @slug_url = post.slug_url
  end
end

我的template.haml中只包含以下内容:= @slug_url

当我运行middleman build时,我没有错误,它似乎工作正常,但它不会创建kw目录或它应该的任何文件。关于我在这里做错了什么想法?

1 个答案:

答案 0 :(得分:2)

首先,“page”采用输出路径,而不是当前版本的模板路径(3.0 beta支持两种格式)。

所以你想做类似的事情:

page "/kw/#{post.slug_url}.html", :proxy => "/kw/template.html" do
  @slug_url = post.slug_url
end

您有一个/source/kw/template.html.haml文件来处理数据。