lib/hx.rb in hx-0.16.0 vs lib/hx.rb in hx-0.17.0
- old
+ new
@@ -1,8 +1,8 @@
# hx - A very small website generator.
#
-# Copyright (c) 2009-2010 MenTaLguY <mental@rydia.net>
+# Copyright (c) 2009-2011 MenTaLguY <mental@rydia.net>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@@ -330,10 +330,46 @@
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
@@ -433,9 +469,14 @@
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