Module: RuoteKit::Helpers::RenderHelpers
- Defined in:
- lib/ruote-kit/helpers/render_helpers.rb
Overview
Helpers for rendering stuff
Instance Method Summary collapse
- #json(resource, object) ⇒ Object
- #json_error(error) ⇒ Object
- #json_errors(errors) ⇒ Object
- #json_expression(expression) ⇒ Object
- #json_expressions(expressions) ⇒ Object
- #json_process(process) ⇒ Object
- #json_processes(processes) ⇒ Object
- #json_workitem(workitem) ⇒ Object
- #json_workitems(workitems) ⇒ Object
- #link(href, rel) ⇒ Object
- #links(resource) ⇒ Object
-
#process_tree(object) ⇒ Object
Extract the process tree.
-
#resource_not_found ⇒ Object
Easy 404.
-
#workitems_not_available ⇒ Object
Easy 503.
Instance Method Details
#json(resource, object) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 6 def json( resource, object ) if respond_to?( "json_#{resource}" ) object = send( "json_#{resource}", object ) end Rufus::Json.encode( { "links" => links( resource ), resource.to_s => object } ) end |
#json_error(error) ⇒ Object
67 68 69 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 67 def json_error( error ) error.to_h.merge( 'links' => links ) end |
#json_errors(errors) ⇒ Object
63 64 65 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 63 def json_errors( errors ) errors.collect { |e| json_error( e, false ) } end |
#json_expression(expression) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 31 def json_expression( expression ) links = [ link( "/_ruote/processes/#{expression.fei.wfid}", '#process' ), link( "/_ruote/expressions/#{expression.fei.wfid}", '#expressions' ) ] if expression.parent links << link( "/_ruote/expressions/#{expression.fei.wfid}/#{expression.parent.fei.expid}", 'parent' ) end expression.to_h.merge( 'links' => links ) end |
#json_expressions(expressions) ⇒ Object
44 45 46 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 44 def json_expressions( expressions ) expressions.map { |e| json_expression( e ) } end |
#json_process(process) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 21 def json_process( process ) links = [ link( "/_ruote/processes/#{process.wfid}", '#process' ), link( "/_ruote/expressions/#{process.wfid}", '#expressions' ), link( "/_ruote/workitems/#{process.wfid}", '#workitems' ) ] process.to_h.merge( 'links' => links ) end |
#json_processes(processes) ⇒ Object
17 18 19 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 17 def json_processes( processes ) processes.map { |p| json_process( p ) } end |
#json_workitem(workitem) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 52 def json_workitem( workitem ) links = [ link( "/_ruote/processes/#{workitem.fei.wfid}", '#process' ), link( "/_ruote/expressions/#{workitem.fei.wfid}", '#expressions' ), link( "/_ruote/errors/#{workitem.fei.wfid}", '#errors' ) ] workitem.to_h.merge( 'links' => links ) end |
#json_workitems(workitems) ⇒ Object
48 49 50 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 48 def json_workitems( workitems ) workitems.map { |w| json_workitem( w ) } end |
#link(href, rel) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 82 def link( href, rel ) { 'href' => href, 'rel' => rel.match(/^#/) ? "http://ruote.rubyforge.org/rels.html#{rel}" : rel } end |
#links(resource) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 71 def links( resource ) [ link( '/_ruote', '#root' ), link( '/_ruote/processes', '#processes' ), link( '/_ruote/workitems', '#workitems' ), link( '/_ruote/errors', '#errors' ), link( '/_ruote/history', '#history' ), link( request.fullpath, 'self' ) ] end |
#process_tree(object) ⇒ Object
Extract the process tree
118 119 120 121 122 123 124 125 126 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 118 def process_tree( object ) case object when Ruote::Workitem process = engine.process( object.fei.wfid ) Rufus::Json.encode( process.current_tree ) when Ruote::ProcessStatus Rufus::Json.encode( object.current_tree ) end end |
#resource_not_found ⇒ Object
Easy 404
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 91 def resource_not_found status 404 @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 ?) respond_to do |format| format.html { haml :resource_not_found } format.json { Rufus::Json.encode( { "error" => { "code" => 404, "message" => "Resource not found" } } ) } end end |
#workitems_not_available ⇒ Object
Easy 503
109 110 111 112 113 114 115 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 109 def workitems_not_available status 503 respond_to do |format| format.html { haml :workitems_not_available } format.json { Rufus::Json.encode( { "error" => { "code" => 503, "messages" => "Workitems not available" } } ) } end end |