Module: Sinatra::Settings::Helpers

Includes:
Rack::Utils
Defined in:
lib/sinatra/settings.rb

Instance Method Summary collapse

Instance Method Details

#nl2br(txt) ⇒ Object

Convert new lines (n) into
tags in the given text

Examples



163
164
165
# File 'lib/sinatra/settings.rb', line 163

def nl2br(txt) 
  txt.gsub("\n", '<br>')
end

#settings_inspectObject

Convenience helper method that returns a Hash, nicely formatted with all ‘registered’ settings in the app.

Mainly used in the HTML output of :show_settings_output? method, but can be used for other debug purposes.

Examples

settings_inspect => {...} # a Hash with settings.


182
183
184
185
186
187
188
# File 'lib/sinatra/settings.rb', line 182

def settings_inspect 
  out = {}
  settings.sinatra_settings_for_inspection.uniq.each do |s|
    out[s.to_sym] = self.class.respond_to?(s.to_sym) ? self.class.send(s) : nil
  end
  out
end

#show_settings_output?Boolean

Add settings debug output to the page. Controlled by the following configurations:

  • set :show_settings_output, (boolean) => turns output On / Off

  • set :show_settings_environment, (symbol) :development/:production => turns output On in the given environment

Examples

<%= show_settings_output? %>  => will output the settings debug if enabled.

Returns:

  • (Boolean)


203
204
205
206
207
208
209
# File 'lib/sinatra/settings.rb', line 203

def show_settings_output?
  if _show_settings_output?
    erb(TEMPLATE, :layout => false)
  else
    "<!-- :show_settings is [#{settings.show_settings ? 'ON' : 'OFF'}]  -->"
  end
end