Class: WriteDown::Model::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/write_down/model/container.rb

Overview

基类, 定义了一些接口

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_file, options = {}) ⇒ Container



12
13
14
15
16
# File 'lib/write_down/model/container.rb', line 12

def initialize(target_file, options = {})
  @target_file = target_file
  @items = []
  @options = options
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



10
11
12
# File 'lib/write_down/model/container.rb', line 10

def items
  @items
end

Instance Method Details

#append(item) ⇒ Object



29
30
31
32
# File 'lib/write_down/model/container.rb', line 29

def append(item)
  @items << item
  self
end

#buildObject



24
25
26
27
# File 'lib/write_down/model/container.rb', line 24

def build
  Layout.new(self, @target_file, @options).render
  self
end

#renderObject



18
19
20
21
22
# File 'lib/write_down/model/container.rb', line 18

def render
  template_file = File.expand_path('../../erb/container.erb', __FILE__)
  template = File.read(template_file)
  html_string = ERB.new(template).result(binding)
end