Class: PostRunner::ViewFrame
- Inherits:
-
Object
- Object
- PostRunner::ViewFrame
- Defined in:
- lib/postrunner/ViewFrame.rb
Overview
Creates an HTML frame around the passed object or HTML block.
Instance Method Summary collapse
-
#initialize(title, width = 600, content = nil, &block) ⇒ ViewFrame
constructor
Create a ViewFrame object.
-
#to_html(doc) ⇒ Object
Generate the HTML code for the frame and the enclosing content.
Constructor Details
#initialize(title, width = 600, content = nil, &block) ⇒ ViewFrame
Create a ViewFrame object.
24 25 26 27 28 29 |
# File 'lib/postrunner/ViewFrame.rb', line 24 def initialize(title, width = 600, content = nil, &block) @title = title @content = content @block = block @width = width end |
Instance Method Details
#to_html(doc) ⇒ Object
Generate the HTML code for the frame and the enclosing content.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/postrunner/ViewFrame.rb', line 33 def to_html(doc) doc.unique(:viewframe_style) { # Add the necessary style sheet snippets to the document head. doc.head { doc.style(style) } } attr = { 'class' => 'widget_frame' } attr['style'] = "width: #{@width}px" if @width doc.div(attr) { doc.div({ 'class' => 'widget_frame_title' }) { doc.b(@title) } doc.div { # The @content holds an object that must respond to to_html to # generate the HTML code. if @content if @content.is_a?(Array) @content.each { |c| c.to_html(doc) } else @content.to_html(doc) end end # The block generates HTML code directly @block.yield if @block } } end |