Module: RuoteKit::Helpers::RenderHelpers
- Defined in:
- lib/ruote-kit/helpers/render_helpers.rb
Overview
Helpers for rendering stuff
Constant Summary collapse
- HTTP_CODES =
Used by #http_error
{ 400 => 'bad request', 404 => 'resource not found', 412 => 'precondition failed' }
Instance Method Summary collapse
-
#check_if_match_etag(value) ⇒ Object
http error 412 if if-match header is set to an etag different to the value given.
-
#h(s) ⇒ Object
Escaping HTML, rack style.
-
#http_error(code, cause = nil) ⇒ Object
HTTP errors.
- #pluralize(number, word) ⇒ Object
-
#process_tree(object) ⇒ Object
Extract the process tree.
Instance Method Details
#check_if_match_etag(value) ⇒ Object
http error 412 if if-match header is set to an etag different to the value given
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 65 def check_if_match_etag(value) value = '"%s"' % value if = request.env['HTTP_IF_MATCH'] = .split(/\s*,\s*/) unless .include?(value) || .include?('*') http_error(412) halt end end end |
#h(s) ⇒ Object
Escaping HTML, rack style.
20 21 22 23 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 20 def h(s) Rack::Utils.escape_html(s) end |
#http_error(code, cause = nil) ⇒ Object
HTTP errors
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 35 def http_error(code, cause=nil) @code = code @message = HTTP_CODES[code] @cause = cause @trace = if cause [ cause. ] + cause.backtrace else nil end @format = if m = @format.to_s.match(/^[^\/]+\/([^;]+)/) m[1].to_sym else @format end # freaking sinata-respond_to 0.4.0... (or is that it ?) status(@code) respond_to do |format| format.html { haml :http_error } format.json { json(:http_error, [ @code, @message, @cause ]) } end end |
#pluralize(number, word) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 11 def pluralize(number, word) word << 's' if number > 1 return [ number, word ].join(' ') end |
#process_tree(object) ⇒ Object
Extract the process tree
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 80 def process_tree(object) case object when Ruote::Workitem process = RuoteKit.engine.process(object.fei.wfid) Rufus::Json.encode(process.current_tree) when Ruote::ProcessStatus Rufus::Json.encode(object.current_tree) end end |