Module: SinatraMore::OutputHelpers

Defined in:
lib/sinatra_more/markup_plugin/output_helpers.rb

Instance Method Summary collapse

Instance Method Details

#block_is_template?(block) ⇒ Boolean

Returns true if the block is from an ERB or HAML template; false otherwise. Used to determine if html should be returned or concatted to view block_is_template?(block)

Returns:

  • (Boolean)


27
28
29
# File 'lib/sinatra_more/markup_plugin/output_helpers.rb', line 27

def block_is_template?(block)
   block && (block_is_erb?(block) || (self.respond_to?(:block_is_haml?) && block_is_haml?(block)))
end

#capture_html(*args, &block) ⇒ Object

Captures the html from a block of template code for erb or haml capture_html(&block) => “…html…”



5
6
7
8
9
10
11
12
# File 'lib/sinatra_more/markup_plugin/output_helpers.rb', line 5

def capture_html(*args, &block)
  if self.respond_to?(:is_haml?) && is_haml?
     block_is_haml?(block) ? capture_haml(*args, &block) : block.call
  else
    result_text = capture_erb(*args, &block)
    result_text.present? ? result_text : block.call
  end
end

#concat_content(text = "") ⇒ Object

Outputs the given text to the templates buffer directly concat_content(“This will be output to the template buffer in erb or haml”)



16
17
18
19
20
21
22
# File 'lib/sinatra_more/markup_plugin/output_helpers.rb', line 16

def concat_content(text="")
  if self.respond_to?(:is_haml?) && is_haml?
    haml_concat(text)
  else
    @_out_buf << text
  end
end