lib/card/content.rb in card-1.97.0.1 vs lib/card/content.rb in card-1.98.0
- old
+ new
@@ -7,11 +7,11 @@
class Card
# Content objects support the parsing of content strings into arrays that
# contain semantically meaningful "chunks" like nests, links, urls, etc.
#
- # Each chunk has an object whose class inherits from {Card::Chunk::Abstract}
+ # Each chunk has an object whose class inherits from {Card::Content::Chunk::Abstract}
#
class Content < SimpleDelegator
extend Card::Content::Clean
extend Card::Content::Truncate
@@ -44,14 +44,22 @@
def find_chunks chunk_type
each_chunk.select { |chunk| chunk.is_a?(chunk_type) }
end
# sends &block to #process_chunk on each Chunk object
- def process_each_chunk &block
- each_chunk { |chunk| chunk.process_chunk(&block) }
+ def process_chunks &block
+ return custom_process_chunks(&block) if block_given?
+
+ each_chunk(&:process_chunk)
end
+ def custom_process_chunks
+ each_chunk do |chunk|
+ chunk.burn_after_reading yield(chunk)
+ end
+ end
+
def pieces
Array.wrap(__getobj__)
end
def each_chunk
@@ -85,9 +93,22 @@
end
end
def inspect
"<#{__getobj__.class}:#{card}:#{self}>"
+ end
+
+ def without_nests
+ nests = []
+ find_chunks(Card::Content::Chunk::Nest).each_with_index do |chunk, i|
+ nests << chunk.text
+ chunk.burn_after_reading "{{#{i}}}"
+ end
+
+ result = yield to_s
+ Chunk::Nest.gsub result do |nest_content|
+ nests[nest_content.to_i]
+ end
end
private
def resolve_format format_or_card