Class: Zwite::Blog::Post

Inherits:
Object show all
Defined in:
lib/zwite/plugins/blog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blog, path) ⇒ Post

Initialization



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/zwite/plugins/blog.rb', line 158

def initialize(blog, path)
  self.blog = blog
  self.path = path

  Zwite::Utils.parse_date_and_slug(self.path.basename.to_s) do |date, slug|
    self.date = date
    self.slug = slug
  end

  self.archive = Archive.new(blog, date.year, date.month)
  self.url = "#{self.blog.app.url}blog/#{self.date.strftime("%Y/%m/%d")}/#{self.slug}/"

  Zwite::Utils.((self.path + "post.md").read) do |, markdown|
    self. = 
    self.content = markdown
  end

  self.name = self.["name"]

  self.topics = []
  self.["topics"].each do |topic|
    self.topics << Topic.new(blog, topic)
  end
  self.topics.sort!

end

Instance Attribute Details

#archiveObject

Returns the value of attribute archive.



120
121
122
# File 'lib/zwite/plugins/blog.rb', line 120

def archive
  @archive
end

#blogObject

Properties



116
117
118
# File 'lib/zwite/plugins/blog.rb', line 116

def blog
  @blog
end

#contentObject

Returns the value of attribute content.



125
126
127
# File 'lib/zwite/plugins/blog.rb', line 125

def content
  @content
end

#dateObject

Returns the value of attribute date.



119
120
121
# File 'lib/zwite/plugins/blog.rb', line 119

def date
  @date
end

#metadataObject

Returns the value of attribute metadata.



124
125
126
# File 'lib/zwite/plugins/blog.rb', line 124

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



127
128
129
# File 'lib/zwite/plugins/blog.rb', line 127

def name
  @name
end

#pathObject

Returns the value of attribute path.



117
118
119
# File 'lib/zwite/plugins/blog.rb', line 117

def path
  @path
end

#slugObject

Returns the value of attribute slug.



121
122
123
# File 'lib/zwite/plugins/blog.rb', line 121

def slug
  @slug
end

#topicsObject

Returns the value of attribute topics.



128
129
130
# File 'lib/zwite/plugins/blog.rb', line 128

def topics
  @topics
end

#urlObject

Returns the value of attribute url.



122
123
124
# File 'lib/zwite/plugins/blog.rb', line 122

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object

Actions



189
190
191
192
193
194
# File 'lib/zwite/plugins/blog.rb', line 189

def <=>(other)
  if other.class == self.class
    return other.date <=> self.date
  end
  return nil
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
133
134
135
# File 'lib/zwite/plugins/blog.rb', line 130

def eql?(other)
  if other.class == self.class
    return other.path == self.path
  end
  return false
end

#hashObject



137
138
139
# File 'lib/zwite/plugins/blog.rb', line 137

def hash
  return self.to_liquid.hash
end

#to_liquidObject



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/zwite/plugins/blog.rb', line 141

def to_liquid
  return {
    "date" => self.date,
    "archive" => self.archive,
    "slug" => self.slug,
    "url" => self.url,
    "metadata" => self.,
    "content" => self.content,
    "name" => self.name,
    "topics" => self.topics,
  }
end