Class: Docwu::Post
- Inherits:
-
Object
- Object
- Docwu::Post
- Defined in:
- lib/docwu/post.rb
Instance Attribute Summary collapse
-
#content_data ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#content_type ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#datetime ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#dest ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#file_name ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#name ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#parent ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#path ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#ranking ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#src ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#url ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
-
#worker ⇒ Object
readonly
一个文件夹下面可能会有很多文件或文件夹的.
Instance Method Summary collapse
- #folder? ⇒ Boolean
-
#generate ⇒ Object
渲染.
- #has_folder? ⇒ Boolean
-
#index? ⇒ Boolean
是否是首页?.
-
#initialize(attrs = {}) ⇒ Post
constructor
A new instance of Post.
- #layout ⇒ Object
- #outline ⇒ Object
-
#page_data ⇒ Object
页面数据.
- #parent_datas ⇒ Object
- #parents ⇒ Object
-
#parse_content ⇒ Object
解析正文.
- #post? ⇒ Boolean
- #template ⇒ Object
- #title ⇒ Object
- #to_data ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Post
Returns a new instance of Post.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docwu/post.rb', line 30 def initialize attrs={} @parent = attrs[:parent] @worker = attrs[:worker] @src = attrs[:src] _parse_content = self.parse_content # 将合并来自worker的数据 @content_data = ::Docwu::Utils.hash_deep_merge(self.worker.data, 'page' => _parse_content[:data]) # 来自页面的数据 @content_type = @content_data['content_type'] || 'html' _extend_name = case self.content_type when 'html' 'html' else 'html' end # URL --------------------------------- _filename_extless = ::Docwu::Utils.filename_extless(attrs[:path]) @path = "#{_filename_extless}.#{_extend_name}" @url = "/#{@path}" @dest = "#{self.worker.tmp_deploy_path}/#{self.path}" @file_name = ::Docwu::Utils.filename(_filename_extless) @name = self.file_name @datetime = self.page_data['datetime'] # 创建时间 @ranking = self.page_data['ranking'].to_i # 创建时间 # puts "post to: -----------------> desc: #{self.dest}" # puts " src: #{self.src}" # puts " path: #{self.path}" # puts " url: #{self.url}" # ------------------------------------- end |
Instance Attribute Details
#content_data ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def content_data @content_data end |
#content_type ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def content_type @content_type end |
#datetime ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def datetime @datetime end |
#dest ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def dest @dest end |
#file_name ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def file_name @file_name end |
#name ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def parent @parent end |
#path ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def path @path end |
#ranking ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def ranking @ranking end |
#src ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def src @src end |
#url ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def url @url end |
#worker ⇒ Object (readonly)
一个文件夹下面可能会有很多文件或文件夹的
5 6 7 |
# File 'lib/docwu/post.rb', line 5 def worker @worker end |
Instance Method Details
#folder? ⇒ Boolean
130 131 132 |
# File 'lib/docwu/post.rb', line 130 def folder? false end |
#generate ⇒ Object
渲染
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/docwu/post.rb', line 112 def generate _prepare_data _parse_content = self.parse_content _content_text = _parse_content[:text] _path = self.path _dest = self.dest ::Docwu::Render.generate( :content_text => _content_text, :content_data => self.content_data, :dest => _dest, :template => self.template ) end |
#has_folder? ⇒ Boolean
145 146 147 |
# File 'lib/docwu/post.rb', line 145 def has_folder? self.parent.is_a?(::Docwu::Folder) end |
#index? ⇒ Boolean
是否是首页?
76 77 78 |
# File 'lib/docwu/post.rb', line 76 def index? self.file_name == 'index' end |
#layout ⇒ Object
80 81 82 |
# File 'lib/docwu/post.rb', line 80 def layout self.page_data['layout'] end |
#outline ⇒ Object
84 85 86 |
# File 'lib/docwu/post.rb', line 84 def outline @outline ||= self.page_data['outline'].to_s end |
#page_data ⇒ Object
页面数据
103 104 105 |
# File 'lib/docwu/post.rb', line 103 def page_data self.content_data['page'] ||= {} end |
#parent_datas ⇒ Object
26 27 28 |
# File 'lib/docwu/post.rb', line 26 def parent_datas self.parents.map(&:to_data) end |
#parents ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/docwu/post.rb', line 18 def parents if self.parent.nil? [] else self.parent.parents.dup << self.parent end end |
#parse_content ⇒ Object
解析正文
139 140 141 142 143 |
# File 'lib/docwu/post.rb', line 139 def parse_content _content = ::File.read(self.src) ::Docwu::Utils.parse_marked_content(_content) end |
#post? ⇒ Boolean
134 135 136 |
# File 'lib/docwu/post.rb', line 134 def post? true end |
#template ⇒ Object
71 72 73 |
# File 'lib/docwu/post.rb', line 71 def template self.worker.layouts[self.layout] || self.worker.layouts['post'] || self.worker.layouts['application'] end |
#title ⇒ Object
107 108 109 |
# File 'lib/docwu/post.rb', line 107 def title self.page_data['title'] || self.name end |
#to_data ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/docwu/post.rb', line 88 def to_data introduction_size = 32 introduction = "#{self.outline[0, introduction_size]}#{' ...' if self.outline.size > introduction_size}" { 'name' => self.name, 'url' => self.url, 'title' => self.title, 'outline' => self.outline, 'introduction' => introduction } end |