lib/rack/blogengine/doc_parser.rb in rack-blogengine-0.1.6 vs lib/rack/blogengine/doc_parser.rb in rack-blogengine-0.1.7
- old
+ new
@@ -20,14 +20,17 @@
@document = Document.new
@document.path = @path
@document.html = @html
@document.title = @title
+ @document.date = @date
documents << @document
end
+ sort documents
+
# Has to exec operator after all docs were read, so documents are available for operators (list all docs, etc...)
documents.each do |document|
document.exec_content_operator(documents, @target)
end
@@ -37,19 +40,20 @@
return documentshashed
end
# Get File Contents (path, title, content)
- # @param file
+ # @param [String] file
def self.getFileContents(file)
content_file = ::File.open("#{@target}/#{file}");
content = content_file.read
# Replace Closing tags
content["/path"] = "/close"
content["/title"] = "/close"
content["/content"] = "/close"
+ content["/date"] = "/close"
contentarray = content.split("[/close]")
contentarray.each do |contentblock|
if contentblock.include? "[path]:"
@@ -57,29 +61,49 @@
@path = "/#{contentblock}"
end
if contentblock.include? "[title]:"
contentblock["[title]:"] = ""
- @title = contentblock
+ @title = contentblock.strip
end
if contentblock.include? "[content]:"
contentblock["[content]:"] = ""
- @content = contentblock
+ @content = contentblock.strip
end
+
+ if contentblock.include? "[date]:"
+ contentblock["[date]:"] = ""
+ #TODO: Generate Date out of [date] string
+ #@date = Date.new(..splitted date string..)
+ @date = contentblock.strip
+ end
end
end
# Replace layout placeholder with content from .content file
- # @param layout
+ # @param [String] layout
# return [String] html placeholder replaced with content
def self.fillFileContents(layout)
html = layout.dup
html.gsub! "{title}", @title
html["{content}"] = @content
+ html.gsub! "{date}", @date
return html
+ end
+
+ # Sort documents array by date of each documenthash
+ # @param [Array] documents
+ # return [Array] documents (sorted)
+ # Should it be sorted in Core or in the operator??
+ def self.sort(documents)
+ documents.sort! do | a, b |
+ a.date.to_time.to_i <=> b.date.to_time.to_i
+ end
+
+ return documents
end
end
end
end
\ No newline at end of file