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_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.
- #rel(fragment) ⇒ Object
-
#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 { "links" => links( resource ), resource => object }.to_json 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}", rel('#process') ), link( "/_ruote/expressions/#{expression.fei.wfid}", rel('#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}", rel('#process') ), link( "/_ruote/expressions/#{process.wfid}", rel('#expressions') ), link( "/_ruote/workitems/#{process.wfid}", rel('#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 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 52 def json_workitem( workitem ) links = [ link( "/_ruote/processes/#{workitem.fei.wfid}", rel('#process') ), link( "/_ruote/expressions/#{workitem.fei.wfid}", rel('#expressions') ) ] 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
77 78 79 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 77 def link( href, rel ) { 'href' => href, 'rel' => rel } end |
#links(resource) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 65 def links( resource ) links = [ link( '/_ruote', rel('#root') ), link( '/_ruote/processes', rel('#processes') ), link( '/_ruote/workitems', rel('#workitems') ), link( '/_ruote/history', rel("#history") ), link( request.fullpath, 'self' ) ] links end |
#process_tree(object) ⇒ Object
Extract the process tree
100 101 102 103 104 105 106 107 108 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 100 def process_tree( object ) case object when Ruote::Workitem process = engine.process( object.fei.wfid ) process.current_tree.to_json when Ruote::ProcessStatus object.current_tree.to_json end end |
#rel(fragment) ⇒ Object
61 62 63 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 61 def rel( fragment ) "http://ruote.rubyforge.org/rels.html#{ fragment }" end |
#resource_not_found ⇒ Object
Easy 404
82 83 84 85 86 87 88 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 82 def resource_not_found status 404 respond_to do |format| format.html { haml :resource_not_found } format.json { { "error" => { "code" => 404, "message" => "Resource not found" } }.to_json } end end |
#workitems_not_available ⇒ Object
Easy 503
91 92 93 94 95 96 97 |
# File 'lib/ruote-kit/helpers/render_helpers.rb', line 91 def workitems_not_available status 503 respond_to do |format| format.html { haml :workitems_not_available } format.json { { "error" => { "code" => 503, "messages" => "Workitems not available" } }.to_json } end end |