Module: Antwort::ApplicationHelpers

Defined in:
lib/antwort/helpers/server_helper.rb

Instance Method Summary collapse

Instance Method Details

#hash_to_instance_vars(data) ⇒ Object



15
16
17
# File 'lib/antwort/helpers/server_helper.rb', line 15

def hash_to_instance_vars(data)
  data.each { |k, v| instance_variable_set("@#{k}", v) } if data
end

#image_url_from_path(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/antwort/helpers/server_helper.rb', line 19

def image_url_from_path(path)
  p = path.split(':')[0]
  if p == 'http' || p == 'https'
    url = path
  else
    a = [path]
    a.unshift(template_from_path) unless path[0] == '/'
    a.unshift('/assets')
    url = File.join(a)
  end
  url
end

#sanitize_param(string) ⇒ Object



3
4
5
# File 'lib/antwort/helpers/server_helper.rb', line 3

def sanitize_param(string)
  string.nil? ? '' : string.gsub(%r{([^A-Za-z0-9_/-]+)|(--)}, '_')
end

#template_exists?(template_name) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/antwort/helpers/server_helper.rb', line 7

def template_exists?(template_name)
  File.file? settings.templates_dir + '/' + template_name + '/index.html.erb'
end

#template_from_pathObject



11
12
13
# File 'lib/antwort/helpers/server_helper.rb', line 11

def template_from_path
  request.path_info.gsub(%r{/template/}i, '')
end