Permalink
Browse files

beginning attempt at writing a new inspector

  • Loading branch information...
1 parent 4fdfd7b commit 816f4e414f3cf8bffa9d141cb796a032cdeb0d49 @johnbintz committed May 13, 2011
Showing with 183 additions and 10 deletions.
  1. +4 −9 coffee.watchr
  2. +58 −0 jasmine/console.coffee
  3. +120 −0 jasmine/console.js
  4. +1 −1 lib/jasmine/cli.rb
View
@@ -1,18 +1,13 @@
require 'coffee-script'
-FILE = 'jasmine/jasmine.headless-reporter.coffee' if !self.class.const_defined?(:FILE)
-TARGET = FILE.gsub('.coffee', '.js') if !self.class.const_defined?(:TARGET)
+watch('(jasmine/.*)\.coffee') { |m| coffee(m[1]) }
-watch(FILE) { coffee }
-
-def coffee
+def coffee(file)
begin
- File.open(TARGET, 'w') { |fh| fh.print CoffeeScript.compile File.open(FILE) }
- puts "Wrote #{TARGET}"
+ File.open(file + '.js', 'w') { |fh| fh.print CoffeeScript.compile File.open(file + '.coffee') }
+ puts "Wrote #{file}"
rescue Exception => e
puts e.message
end
end
-coffee
-
View
@@ -0,0 +1,58 @@
+class window.Inspector
+ constructor: (data) ->
+ @data = data
+ @examinedObjects = []
+ run: ->
+ for property in this.inspect([], @data)
+ do (property) =>
+ JHW.log(property.report())
+ inspect: (output, data, indent = 0, key = null) ->
+ for obj in @examinedObjects
+ if obj == data
+ JHW.log("loop")
+ output.push(new InspectedProperty("<< LOOP >>", key, indent))
+ return output
+ @examinedObjects.push(data)
+
+ switch typeof(data)
+ when 'undefined'
+ output.push(new InspectedProperty('undefined', key, indent))
+ when 'string', 'number', 'boolean'
+ output.push(new InspectedProperty(data, key, indent))
+ else
+ output.push(new DefinedObject(key, indent))
+ for newKey, value of data
+ JHW.log("trying #{newKey}")
+ if data.hasOwnProperty(newKey)
+ this.inspect(output, value, indent + 1, newKey)
+ output
+
+class window.IntendableProperty
+ indentString: (output) ->
+ if @key?
+ output = "#{@key}: #{output}"
+ if @indent > 0
+ for i in [1..@indent]
+ do (i) =>
+ output = " " + output
+ output
+
+class window.DefinedObject extends window.IntendableProperty
+ constructor: (key, indent) ->
+ @key = key
+ @indent = indent
+ report: ->
+ this.indentString("Object")
+
+class window.InspectedProperty extends window.IntendableProperty
+ constructor: (data, key, indent) ->
+ @data = data
+ @key = key
+ @indent = indent
+ report: ->
+ output = switch typeof(@data)
+ when 'string'
+ "\"#{@data}\""
+ else
+ @data
+ this.indentString(output)
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -35,7 +35,7 @@ def jasmine_html_template(files)
<head>
<title>Jasmine Test Runner</title>
<script type="text/javascript">
- window.console = { log: function(data) { JHW.log(JSON.stringify(data)); } };
+ window.console = { log: function(data) { JHW.log(JSON.stringify(data)) } }
</script>
#{files.join("\n")}
</head>

0 comments on commit 816f4e4

Please sign in to comment.