Class: Docwu::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/docwu/topic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Topic

Returns a new instance of Topic.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/docwu/topic.rb', line 6

def initialize attrs={}
  @worker = attrs[:worker]

  @path = attrs[:path]
  @src = attrs[:src]

  _parse_content = self.parse_content

  # 将合并来自worker的数据
  @content_data = ::Docwu::Utils.hash_deep_merge(self.worker.data, 'page' => _parse_content[:data])  # 来自页面的数据

  # URL ---------------------------------
  _filename_extless = ::Docwu::Utils.filename_extless(self.path)

  @url  = "/#{@path}"
  @dest = "#{self.worker.tmp_deploy_path}/#{self.path}"

  @file_name = ::Docwu::Utils.filename(_filename_extless)

  @name = self.content_data['page']['name'] || self.file_name

  # -------------------------------------
end

Instance Attribute Details

#content_dataObject (readonly)

Returns the value of attribute content_data.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def content_data
  @content_data
end

#destObject (readonly)

Returns the value of attribute dest.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def dest
  @dest
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def file_name
  @file_name
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def path
  @path
end

#srcObject (readonly)

Returns the value of attribute src.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def src
  @src
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def url
  @url
end

#workerObject (readonly)

Returns the value of attribute worker.



4
5
6
# File 'lib/docwu/topic.rb', line 4

def worker
  @worker
end

Instance Method Details

#generateObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/docwu/topic.rb', line 51

def generate
  _prepare_data

  _parse_content = self.parse_content

  _content_text = _parse_content[:text]

  ::Docwu::Render.generate(
    :content_text => _content_text,
    :content_data => self.content_data,
    :dest         => self.dest,
    :template     => self.template
  )
end

#layoutObject



66
67
68
# File 'lib/docwu/topic.rb', line 66

def layout
  self.page_data['layout']
end

#page_dataObject

页面数据



31
32
33
# File 'lib/docwu/topic.rb', line 31

def page_data
  self.content_data['page'] ||= {}
end

#parse_contentObject

解析正文



75
76
77
78
79
# File 'lib/docwu/topic.rb', line 75

def parse_content
  _content = ::File.read(self.src)

  ::Docwu::Utils.parse_marked_content(_content)
end

#templateObject



70
71
72
# File 'lib/docwu/topic.rb', line 70

def template
  self.worker.layouts[self.layout] || self.worker.layouts['topic'] || self.worker.layouts['application']
end

#to_dataObject



43
44
45
46
47
48
49
# File 'lib/docwu/topic.rb', line 43

def to_data
  {
    'name'  => self.name,
    'url'   => self.url,
    'title' => self.title
  }
end