Class: Hx::Backend::HobixFilter
- Inherits:
-
Object
- Object
- Hx::Backend::HobixFilter
- Includes:
- Filter
- Defined in:
- lib/hx/backend/hobix.rb
Direct Known Subclasses
Instance Method Summary collapse
- #each_entry_path(selector) ⇒ Object
- #edit_entry(path, prototype = nil) ⇒ Object
- #get_entry(path) ⇒ Object
-
#initialize(input, options) ⇒ HobixFilter
constructor
A new instance of HobixFilter.
Methods included from Filter
Methods included from View
Constructor Details
#initialize(input, options) ⇒ HobixFilter
Returns a new instance of HobixFilter.
34 35 36 |
# File 'lib/hx/backend/hobix.rb', line 34 def initialize(input, ) @source = Hx::StripPath.new(input, :suffix => ".yaml") end |
Instance Method Details
#each_entry_path(selector) ⇒ Object
74 75 76 77 |
# File 'lib/hx/backend/hobix.rb', line 74 def each_entry_path(selector) @source.each_entry_path(selector) { |path| yield path } self end |
#edit_entry(path, prototype = nil) ⇒ Object
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 |
#get_entry(path) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/hx/backend/hobix.rb', line 79 def get_entry(path) raw_entry = @source.get_entry(path) entry = YAML.load(raw_entry['content'].to_s).value entry['updated'] ||= raw_entry['updated'] entry['created'] ||= raw_entry['created'] || raw_entry['updated'] entry end |