lib/prawn/icon.rb in prawn-icon-1.1.0 vs lib/prawn/icon.rb in prawn-icon-1.1.1
- old
+ new
@@ -117,14 +117,18 @@
# opts::
# A hash of options that may be supplied to the
# underlying text call.
#
def inline_icon(text, opts = {})
- parsed = Icon::Parser.format(self, text)
- content = Text::Formatted::Parser.format(parsed)
- opts.merge!(inline_format: true, document: self)
- Text::Formatted::Box.new(content, opts)
+ parsed = Icon::Parser.format(self, text)
+ content = Text::Formatted::Parser.format(parsed)
+ box_options = opts.merge(
+ inline_format: true,
+ document: self,
+ at: [bounds.left, cursor]
+ )
+ icon_box(content, box_options)
end
# Initialize a new Prawn::Icon, but don't render
# the icon to a document. Intended to be used as
# an entry of a data array when combined with
@@ -168,10 +172,22 @@
opts.merge(content: content)
else
make_icon(key, opts).format_hash
end
end
+
+ private
+
+ def icon_box(content, opts = {}) # :nodoc:
+ Text::Formatted::Box.new(content, opts).tap do |box|
+ box.render(dry_run: true)
+ self.y -= box.height
+ unless opts.fetch(:final_gap, true)
+ self.y -= box.line_gap + box.leading
+ end
+ end
+ end
end
attr_reader :set, :unicode
def initialize(key, document, opts = {})
@@ -198,10 +214,10 @@
end
end
private
- def strip_specifier_from_key(key) #:nodoc:
+ def strip_specifier_from_key(key) # :nodoc:
reg = Regexp.new "#{@data.specifier}-"
key.sub(reg, '') # Only one specifier
end
end
end