Class: Bread::Basket::Poster::HeaderCallback
- Inherits:
-
Object
- Object
- Bread::Basket::Poster::HeaderCallback
- Defined in:
- lib/bread/basket/poster/header_callback.rb
Instance Method Summary collapse
-
#initialize(document, options) ⇒ HeaderCallback
constructor
A new instance of HeaderCallback.
- #render_behind(fragment) ⇒ Object
Constructor Details
#initialize(document, options) ⇒ HeaderCallback
Returns a new instance of HeaderCallback.
5 6 7 8 9 10 11 |
# File 'lib/bread/basket/poster/header_callback.rb', line 5 def initialize(document, ) @color = ['background-color'] @document = document @radius = ['radius'] @height = ['height'] @width = ['width'] end |
Instance Method Details
#render_behind(fragment) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bread/basket/poster/header_callback.rb', line 13 def render_behind(fragment) original_color = @document.fill_color vert_dist = (@height - fragment.height) / 2 # TODO: If you want to get real picky, the vertical centering should # be aware of whether the text has ascenders or descenders, there's # a prawn method for calculating that sort of thing precisely. left_top = [@document.bounds.left, fragment.top + vert_dist] @document.fill_color = @color.sub('#', '') @document.fill_rounded_rectangle(left_top, @width, @height, @radius) @document.fill_color = original_color end |