Class: String

Inherits:
Object show all
Defined in:
lib/goat.rb,
lib/goat/dom.rb,
lib/goat/extn.rb

Direct Known Subclasses

Goat::HTMLString

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.random(len = 10, opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/goat/extn.rb', line 17

def self.random(len=10, opts={})
  opts = {:alpha => false}.merge(opts)

  regexp = opts[:alpha] ? /[^A-Za-z]/ : /[^A-Za-z0-9]/ 

    str = SecureRandom.random_bytes(len * 8).gsub(regexp, '')
  if str.size >= len
    str[0..(len-1)]
  else
    # should basically never happen
    random(len, opts)
  end
end

Instance Method Details

#h!Object



50
51
52
53
# File 'lib/goat.rb', line 50

def h!
  # TODO is this even used any more?
  Goat::HTMLString.new(self)
end

#handle_request(req) ⇒ Object



55
56
57
# File 'lib/goat.rb', line 55

def handle_request(req)
  [200, {}, self]
end

#prefix_ns(ns) ⇒ Object



46
47
48
# File 'lib/goat.rb', line 46

def prefix_ns(ns)
  self.gsub(/^%(.+)$/, "#{ns}_\\1")
end

#to_html(builder) ⇒ Object



212
213
214
# File 'lib/goat/dom.rb', line 212

def to_html(builder)
  Rack::Utils.escape_html(self)
end