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
70
71
72
|
# File 'lib/hx/backend/hobix.rb', line 43
def edit_entry(path, prototype=nil)
if prototype
prototype = prototype.dup
prototype['content'] = (prototype['content'] || "").dup
content = prototype['content']
def content.to_yaml_style ; :literal ; end
native = YAML::DomainType.new('hobix.com,2004', 'entry', prototype)
prototype = { 'content' => YAML.dump(native) }
end
@source.edit_entry(path, prototype) do |text|
begin
previous_mtime = @source.get_entry(path)['updated']
rescue Hx::NoSuchEntryError
previous_mtime = nil
end
text = yield text
repr = YAML.parse(text)
keys = {}
repr.value.each_key { |key| keys[key.value] = key }
%w(created updated).each { |name| keys[name] ||= yaml_repr(name) }
update_time = Time.now
update_time_repr = yaml_repr(update_time)
previous_mtime ||= update_time
previous_mtime_repr = yaml_repr(previous_mtime)
repr.add(keys['created'], previous_mtime_repr) unless repr['created']
repr.add(keys['updated'], update_time_repr)
repr.emit
end
self
end
|