Method: Arrow::HTMLUtilities.make_object_html_wrapper
- Defined in:
- lib/arrow/mixins.rb
.make_object_html_wrapper(object) ⇒ Object
Wrap up the various parts of a complex object in an HTML fragment. If the object has already been wrapped, returns a link to the previous rendering instead.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/arrow/mixins.rb', line 234 def make_object_html_wrapper( object ) # If the object has been rendered already, just return a link to the previous # HTML fragment Thread.current[ THREAD_DUMP_KEY ] ||= {} if Thread.current[ THREAD_DUMP_KEY ].key?( object.object_id ) return %Q{<a href="#object-%d" class="cache-link" title="jump to previous details">%s</a>} % [ object.object_id, %{→ %s #%d} % [ object.class.name, object.object_id ] ] else Thread.current[ THREAD_DUMP_KEY ][ object.object_id ] = true end # Assemble the innards as an array of parts parts = [ %{<div class="object-header">}, %{<span class="object-class">#{object.class.name}</span>}, %{<span class="object-id">##{object.object_id}</span>}, %{</div>}, %{<div class="object-body">}, ] object.instance_variables.sort.each do |ivar| value = object.instance_variable_get( ivar ) html = make_html_for_object( value ) classes = %w[instance-variable] if value.instance_variables.empty? && !value.respond_to?( :values_at ) classes << 'simple' else classes << 'complex' end parts << IVAR_HTML_FRAGMENT % [ classes.join(' '), ivar, html ] end parts << %{</div>} # Make HTML class names out of the object's namespaces namespaces = object.class.name.downcase.split(/::/) classes = [] namespaces.each_index do |i| classes << namespaces[0..i].join('-') + '-object' end # Glue the whole thing together and return it return OBJECT_HTML_CONTAINER % [ object.object_id, classes.join(" "), parts.join("\n") ] end |