Module: Haml::Filters::Example

Includes:
Base
Defined in:
lib/polleverywhere/haml.rb

Overview

Renders various formats of code for a given piece of Ruby API code.

Instance Method Summary collapse

Instance Method Details

#render(text) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/polleverywhere/haml.rb', line 5

def render(text)
  # TODO move this into a klass so that different formats are supported 'n' such
  formats = {}
  formats[:ruby] = text
  eval(text, self.send(:binding)) # Run the ruby code so we can get at the curl formats, etc
  formats[:curl] = PollEverywhere.config.http_adapter.last_requests.map(&:to_curl).join("\n\n")
  formats.map{ |format, example| %(<pre class="#{format}">#{example}</pre>) }.join
end