Class: Docwu::Topic
- Inherits:
-
Object
- Object
- Docwu::Topic
- Defined in:
- lib/docwu/topic.rb
Instance Attribute Summary collapse
-
#content_data ⇒ Object
readonly
Returns the value of attribute content_data.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(attrs = {}) ⇒ Topic
constructor
A new instance of Topic.
- #layout ⇒ Object
-
#page_data ⇒ Object
页面数据.
-
#parse_content ⇒ Object
解析正文.
- #template ⇒ Object
- #to_data ⇒ Object
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_data ⇒ Object (readonly)
Returns the value of attribute content_data.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def content_data @content_data end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def dest @dest end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def file_name @file_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def path @path end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def src @src end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def url @url end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
4 5 6 |
# File 'lib/docwu/topic.rb', line 4 def worker @worker end |
Instance Method Details
#generate ⇒ Object
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 |
#layout ⇒ Object
66 67 68 |
# File 'lib/docwu/topic.rb', line 66 def layout self.page_data['layout'] end |
#page_data ⇒ Object
页面数据
31 32 33 |
# File 'lib/docwu/topic.rb', line 31 def page_data self.content_data['page'] ||= {} end |
#parse_content ⇒ Object
解析正文
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 |
#template ⇒ Object
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_data ⇒ Object
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 |