src/tools/console.coffee in luca-0.9.4 vs src/tools/console.coffee in luca-0.9.6

- old
+ new

@@ -1,37 +1,38 @@ -codeMirrorOptions = - readOnly: true - autoFocus: false - theme: "monokai" - mode: "javascript" +developmentConsole = Luca.register "Luca.tools.DevelopmentConsole" -Luca.define("Luca.tools.DevelopmentConsole").extends("Luca.core.Container").with +developmentConsole.extends "Luca.core.Container" + +developmentConsole.defines className: "luca-ui-console" name: "console" history: [] historyIndex: 0 + width: 1000 componentEvents: - "code_input key:keyup" : "historyUp" - "code_input key:keydown" : "historyDown" - "code_input key:enter" : "runCommand" + "code_input key:keyup" : "historyUp" + "code_input key:keydown" : "historyDown" + "code_input key:enter" : "runCommand" compileOptions: bare: true components:[ - ctype: "code_mirror_field" + type: "code_mirror_field" + getter: "getCodeMirror" additionalClassNames: "clearfix" name: "code_output" readOnly: true lineNumbers: false mode: "javascript" lineWrapping: true gutter: false , - ctype: "text_field" + type: "text_field" name: "code_input" + getter: "getInput" lineNumbers: false height: '30px' maxHeight: '30px' gutter: false autoBindEventHandlers: true @@ -55,12 +56,15 @@ @$('input').focus() ] afterRender: ()-> @$container().modal(backdrop: false) - @$container.css + if @width? + marginLeft = parseInt(@width) * 0.5 * -1 + @$container().css("width", @width).css('margin-left', parseInt(marginLeft) ) + show: (options={})-> @$container().modal('show') @ getContext: ()-> @@ -76,23 +80,23 @@ historyUp: ()-> @historyIndex -= 1 @historyIndex = 0 if @historyIndex < 0 - currentValue = Luca("code_input").getValue() - Luca("code_input").setValue( @history[ @historyIndex ] || currentValue ) + currentValue = @getInput().getValue() + @getInput().setValue( @history[ @historyIndex ] || currentValue ) historyDown: ()-> @historyIndex += 1 @historyIndex = @history.length - 1 if @historyIndex > @history.length - 1 - currentValue = Luca("code_input").getValue() + currentValue = @getInput().getValue() - Luca("code_input").setValue( @history[ @historyIndex ] || currentValue) + @getInput().setValue( @history[ @historyIndex ] || currentValue) append: (code, result, skipFormatting=false)-> - output = Luca("code_output") + output = @getCodeMirror() current = output.getValue() source = "// #{ code }" if code? payload = if skipFormatting or code.match(/^console\.log/) @@ -103,11 +107,16 @@ output.setValue( _.compact(payload).join("\n") ) output.getCodeMirror().scrollTo(0,90000) onSuccess: (result, js, coffee)-> @saveHistory(coffee) - dump = JSON.stringify(result, null, "\t") + + dump = "" + + if _.isArray( result ) or _.isObject( result ) or _.isString( result ) or _.isNumber(result) + dump = JSON.stringify(result, null, "\t") + dump ||= result.toString?() @append(js, dump || "undefined") onError: (error, js, coffee)-> @@ -115,11 +124,11 @@ evaluateCode: (code, raw)-> return unless code?.length > 0 raw = _.string.strip(raw) - output = Luca("code_output") + output = @getCodeMirror() dev = @ evaluator = ()-> old_console = window.console @@ -140,29 +149,50 @@ result try result = evaluator.call( @getContext() ) + + # capture luca objects for special inspection + if Luca.isComponent( result ) + result = Luca.util.inspectComponent( result ) + else if Luca.isComponentPrototype( result ) + result = Luca.util.inspectComponentPrototype( result ) + @onSuccess(result, code, raw) unless raw.match(/^console\.log/) catch error @onError(error, code, raw) runCommand: ()-> dev = @ compile = _.bind(Luca.tools.CoffeeEditor::compile, @) - raw = Luca("code_input").getValue() + raw = @getInput().getValue() compiled = compile raw, (compiled)-> dev.evaluateCode(compiled, raw) Luca.util.launchers ||= {} +Luca.util.inspectComponentPrototype = (componentPrototype)-> + liveInstances = Luca.registry.findInstancesByClass( componentPrototype ) + +Luca.util.inspectComponent = (component)-> + component = Luca(component) if _.isString(component) + + { + name: component.name + instanceOf: component.displayName + subclassOf: component._superClass()::displayName + inheritsFrom: Luca.parentClasses( component ) + } + Luca.util.launchers.developmentConsole = (name="luca-development-console")-> @_lucaDevConsole = Luca name, ()=> - @$el.append Backbone.View::make("div", id: "#{ name }-wrapper", class: "modal fade") + @$el.append Backbone.View::make("div", id: "#{ name }-wrapper", class: "modal fade large") console = new Luca.tools.DevelopmentConsole name: name container: "##{ name }-wrapper" console.render() + console.getCodeMirror().setHeight(602) @_lucaDevConsole.show() \ No newline at end of file