lib/hx.rb in hx-0.24.0 vs lib/hx.rb in hx-0.25.0
- old
+ new
@@ -37,16 +37,31 @@
end
class EditingNotSupportedError < RuntimeError
end
-# minimal complete definition: each_entry_path + get_entry, or each_entry
-module Filter
+module View
def edit_entry(path, prototype=nil)
raise EditingNotSupportedError, "Editing not supported for #{path}"
end
+ def each_entry(selector)
+ raise NotImplementedError, "#{self.class}#each_entry not implemented"
+ end
+end
+
+def self.get_entry(view, path)
+ view.each_entry(Path.literal(path)) do |entry_path, entry|
+ return entry
+ end
+ raise NoSuchEntryError, path
+end
+
+# minimal complete definition: each_entry_path + get_entry, or each_entry
+module Filter
+ include View
+
def each_entry_path(selector)
each_entry(selector) { |path, entry| yield path }
end
def each_entry(selector)
@@ -59,14 +74,11 @@
yield path, entry
end
end
def get_entry(path)
- each_entry(Path.literal(path)) do |entry_path, entry|
- return entry
- end
- raise NoSuchEntryError, path
+ Hx.get_entry(self, path)
end
end
class NullInput
include Filter
@@ -330,46 +342,10 @@
def get_entry(path)
@input.get_entry(path)
end
end
-class IncludeFragments
- include Hx::Filter
-
- def initialize(input, options)
- @input = input
- @fragments = options[:fragments] || {}
- @fragment_paths = Set.new(@fragments.values)
- end
-
- def edit_entry(path, prototype)
- raise EditingNotSupported, path if @fragment_paths.include? path
- @input.edit_entry(path, prototype) { |text| yield text }
- self
- end
-
- def each_entry_path(selector)
- @input.each_entry_path(selector) do |path|
- yield path unless @fragment_paths.include? path
- end
- self
- end
-
- def get_entry(path)
- raise NoSuchEntryError, path if @fragment_paths.include? path
- entry = @input.get_entry(path)
- entry = entry.dup
- for field, fragment_path in @fragments
- begin
- entry[field] = @input.get_entry(path)
- rescue NoSuchEntryError
- end
- end
- entry
- end
-end
-
Chain = Object.new
def Chain.new(input, options)
filters = options[:chain] || []
options = options.dup
options.delete(:chain) # prevent inheritance
@@ -469,14 +445,9 @@
source = default_input
when 1
source = input_sources.first
else
source = Overlay.new(*input_sources)
- end
-
- if raw_source.has_key? 'fragments'
- source = IncludeFragments.new(source,
- :fragments => raw_source['fragments'])
end
if raw_source.has_key? 'filter'
if raw_source.has_key? 'options'
filter_options = options.dup