lib/nanoc/helpers/capturing.rb in nanoc-4.5.2 vs lib/nanoc/helpers/capturing.rb in nanoc-4.5.3
- old
+ new
@@ -28,21 +28,23 @@
# Capture
content_string = capture(&block)
# Get existing contents and prep for store
- snapshot_contents = @item.reps[:default].unwrap.snapshot_contents
+ snapshot_repo = @item._context.snapshot_repo
+ rep = @item.reps[:default].unwrap
capture_name = "__capture_#{name}".to_sym
old_content_string =
case existing_behavior
when :overwrite
''
when :append
- c = snapshot_contents[capture_name]
+ c = snapshot_repo.get(rep, capture_name)
c ? c.string : ''
when :error
- if snapshot_contents[capture_name] && snapshot_contents[capture_name].string != content_string
+ contents = snapshot_repo.get(rep, capture_name)
+ if contents && contents.string != content_string
# FIXME: get proper exception
raise "a capture named #{name.inspect} for #{@item.identifier} already exists"
else
''
end
@@ -50,11 +52,12 @@
raise ArgumentError, 'expected :existing_behavior param to #content_for to be one of ' \
":overwrite, :append, or :error, but #{existing_behavior.inspect} was given"
end
# Store
- snapshot_contents[capture_name] = Nanoc::Int::TextualContent.new(old_content_string + content_string)
+ new_content = Nanoc::Int::TextualContent.new(old_content_string + content_string)
+ snapshot_repo.set(rep, capture_name, new_content)
else # Get content
if args.size != 2
raise ArgumentError, 'expected 2 arguments (the item ' \
"and the name of the capture) but got #{args.size} instead"
end
@@ -72,10 +75,11 @@
Fiber.yield(Nanoc::Int::Errors::UnmetDependency.new(rep))
return content_for(*args, &block)
end
end
- content = rep.snapshot_contents["__capture_#{name}".to_sym]
+ snapshot_repo = @config._context.snapshot_repo
+ content = snapshot_repo.get(rep, "__capture_#{name}".to_sym)
content ? content.string : nil
end
end
# @return [String]