lib/sifttter-redux/sifttter.rb in sifttter-redux-1.0.2 vs lib/sifttter-redux/sifttter.rb in sifttter-redux-1.0.4
- old
+ new
@@ -1,5 +1,7 @@
+require 'htmlentities'
+
module SifttterRedux
# Sifttter Module
# Used to examine Sifttter data and create
# Day One entries as necessary.
module Sifttter
@@ -47,11 +49,11 @@
def parse_sifttter_file(filepath, date)
title = File.basename(filepath).gsub(/^.*?\/([^\/]+)$/, "\\1") + "\n"
date_regex = "(?:#{ date.strftime("%B") } 0?#{ date.strftime("%-d") }, #{ date.strftime("%Y") })"
time_regex = "(?:\d{1,2}:\d{1,2}\s?[AaPpMm]{2})"
- entry_regex = /@begin\n@date\s#{ date_regex }(?: at (.*?)\n)?(.*?)@end/m
+ entry_regex = /@begin\n@date\s#{ date_regex }(?: at (#{ time_regex }?)\n)?(.*?)@end/m
contents = File.read(filepath)
cur_entries = contents.scan(entry_regex)
unless cur_entries.empty?
@entries.merge!(title => []) unless @entries.key?(title)
@@ -87,13 +89,15 @@
parse_sifttter_file(file, date)
end
end
if @entries.length > 0
+
entrytext = "# Things done on #{ date_for_title }\n"
@entries.each do |key, value|
+ coder = HTMLEntities.new
entrytext += '### ' + key.gsub(/.txt/, '').gsub(/_/, ' ').upcase + "\n\n"
- value.each { |v| entrytext += "#{ v[1] }\n" }
+ value.each { |v| entrytext += "#{ coder.encode(v[1]) }\n" }
entrytext += "\n"
end
template = generate_template(datestamp, entrytext, starred, uuid)
fh = File.new(File.expand_path("#{ output_dir }/#{ uuid }.doentry"), 'w+')