Class: WriteDown::Model::Layout
- Inherits:
-
Object
- Object
- WriteDown::Model::Layout
- Defined in:
- lib/write_down/model/layout.rb
Instance Method Summary collapse
-
#assets_version ⇒ Object
css 的版本号.
-
#friend_links ⇒ Object
友情链接集合.
-
#initialize(page, target_file, option = {}) ⇒ Layout
constructor
A new instance of Layout.
-
#menus ⇒ Object
菜单.
-
#render ⇒ Object
实际写入硬盘的是这个地方.
-
#render_all_content(page) ⇒ Object
page 相当于一个接口, 需要实现 render 方法.
-
#render_layout ⇒ Object
可以调用到 erb 中的 yield.
-
#tagline ⇒ Object
副标题.
-
#title ⇒ Object
网站 title.
Constructor Details
#initialize(page, target_file, option = {}) ⇒ Layout
Returns a new instance of Layout.
13 14 15 16 17 |
# File 'lib/write_down/model/layout.rb', line 13 def initialize(page, target_file, option = {}) @page = page @target_file = target_file @option = option end |
Instance Method Details
#assets_version ⇒ Object
css 的版本号
41 42 43 |
# File 'lib/write_down/model/layout.rb', line 41 def assets_version "" #"?v=1" end |
#friend_links ⇒ Object
友情链接集合
69 70 71 |
# File 'lib/write_down/model/layout.rb', line 69 def friend_links { "苏州八零年代": 'http://niandai80.com/' } end |
#menus ⇒ Object
菜单
58 59 60 61 62 63 64 65 66 |
# File 'lib/write_down/model/layout.rb', line 58 def { "home": '/', "about": '/about/', "essays": '/essays/', "reading": '/reading/', "github": 'https://github.com/teddy-ma/' } end |
#render ⇒ Object
实际写入硬盘的是这个地方
20 21 22 23 24 25 |
# File 'lib/write_down/model/layout.rb', line 20 def render output = Pathname.new(@target_file) output.dirname.mkpath final_content = render_all_content(@page) output.write(final_content) end |
#render_all_content(page) ⇒ Object
page 相当于一个接口, 需要实现 render 方法
29 30 31 32 |
# File 'lib/write_down/model/layout.rb', line 29 def render_all_content(page) page_html = page.render # 先渲染 page, 这里使用了代理模式把职责分配给当前的 page render_layout { page_html } # 再渲染 layout end |
#render_layout ⇒ Object
可以调用到 erb 中的 yield
35 36 37 38 |
# File 'lib/write_down/model/layout.rb', line 35 def render_layout layout_path = @option['layout'] || File.('../../erb/layout.erb', __FILE__) ERB.new(File.read(layout_path)).result(binding) end |
#tagline ⇒ Object
副标题
53 54 55 |
# File 'lib/write_down/model/layout.rb', line 53 def tagline '没有银弹' end |
#title ⇒ Object
网站 title
48 49 50 |
# File 'lib/write_down/model/layout.rb', line 48 def title '编程青年' end |