Module: Entity::REST
- Defined in:
- lib/rbbt/workflow/rest/entity.rb
Constant Summary collapse
- LIST_REPO =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #action_link(action, text = nil, inputs = {}) ⇒ Object
- #link(text = nil, url = nil, options = {}) ⇒ Object
- #list_action_link(action, text = nil, id = nil, options = {}) ⇒ Object
- #list_link(text = nil, id = nil, options = {}) ⇒ Object
Class Method Details
Instance Method Details
#action_link(action, text = nil, inputs = {}) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/rbbt/workflow/rest/entity.rb', line 72 def action_link(action, text = nil, inputs = {}) = inputs.delete(:link_options) || {} clean_inputs = {} inputs.each do |k, v| clean_inputs[k] = Array === v ? v * "," : v end link(text, nil, .merge(:extra_params => clean_inputs, :action => action)) end |
#link(text = nil, url = nil, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rbbt/workflow/rest/entity.rb', line 6 def link(text = nil, url = nil, = {}) return nil if self.nil? if Array === self text ||= self.name if self.respond_to? :name if Array === text translations = Misc.zip2hash(self, text) self.collect{|e| e.link(translations[e], url, )} else self.collect{|e| e.link(text, url, )} end else text ||= self.name if self.respond_to? :name text = self if text.nil? or text == :literal or text.to_s.strip.empty? klass = [:class] klass ||= "entity " + (self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " ") klass += " " << [:extra_classes] || "" if .include? :extra_classes klass += " " << html_class if self.respond_to? :html_class type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + (self.format || "") : annotation_types.last.to_s params = [:params] || self.info.reject{|k,v| [:annotation_types, :format].include?(k)} params.merge! [:extra_params] if .include? :extra_params url ||= if .include? :action File.join("/entity_action", type, [:action].to_s, self) else File.join("/entity", type, self) end annotations_str = params.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&" "<a class='#{klass}' href='#{url + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>" end end |
#list_action_link(action, text = nil, id = nil, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rbbt/workflow/rest/entity.rb', line 81 def list_action_link(action, text = nil, id = nil, = {}) text = self.length if text.nil? or (String === text and text.strip.empty?) id ||= [:id] || Misc.digest((self * "|").inspect) text = id if text == :id Entity::REST.save_list(id, self) klass = self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " " klass += " " << [:extra_classes] if .include? :extra_classes klass += " " << html_class if self.respond_to? :html_class type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + self.format : annotation_types.last.to_s annotations_str = self.info.reject{|k,v| [:annotation_types, :format].include?(k)}.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&" "<a class='entity_list_action #{klass}' href='#{File.join("/entity_list_action", type, action, id) + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>" end |
#list_link(text = nil, id = nil, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rbbt/workflow/rest/entity.rb', line 53 def list_link(text = nil, id = nil, = {}) text = self.length if text.nil? or (String === text and text.strip.empty?) id ||= [:id] || Misc.digest((self * "|").inspect) Entity::REST.save_list(id, self) klass = self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " " klass += " " << [:extra_classes] if .include? :extra_classes klass += " " << html_class if self.respond_to? :html_class type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + self.format : annotation_types.last.to_s annotations_str = self.info.reject{|k,v| [:annotation_types, :format].include?(k)}.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&" "<a class='entity_list #{klass}' href='#{File.join("/entity_list", type, id) + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>" end |