luca 0.8.599 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/CHANGELOG +51 -2
- data/README.md +10 -247
- data/ROADMAP +6 -2
- data/app.rb +16 -2
- data/assets/javascripts/dependencies/bootstrap.min.js +7 -1
- data/assets/javascripts/dependencies/codemirror-coffeescript.js +347 -0
- data/assets/javascripts/dependencies/codemirror-css.js +124 -0
- data/assets/javascripts/dependencies/codemirror-html.js +410 -0
- data/assets/javascripts/dependencies/codemirror-javascript.js +361 -0
- data/assets/javascripts/dependencies/codemirror-less.js +232 -0
- data/assets/javascripts/dependencies/codemirror-vim.js +500 -0
- data/assets/javascripts/dependencies/codemirror.js +3076 -0
- data/assets/javascripts/dependencies.coffee +0 -1
- data/assets/javascripts/luca-ui-base.coffee +10 -3
- data/assets/javascripts/luca-ui-bootstrap.js +1 -0
- data/assets/javascripts/luca-ui-development-tools.coffee +9 -0
- data/assets/javascripts/luca-ui.coffee +6 -1
- data/assets/javascripts/sandbox/application.coffee +51 -0
- data/assets/javascripts/sandbox/router.coffee +14 -0
- data/assets/javascripts/sandbox/templates/main.luca +33 -0
- data/assets/javascripts/sandbox/templates/sandbox/navigation.luca +1 -0
- data/assets/javascripts/sandbox/templates/sandbox.luca +1 -0
- data/assets/javascripts/sandbox/views/top_navigation.coffee +4 -0
- data/assets/javascripts/sandbox.coffee +2 -2
- data/assets/stylesheets/bootstrap.min.css +395 -297
- data/assets/stylesheets/codemirror-blackboard.css +25 -0
- data/assets/stylesheets/codemirror-monokai.css +33 -0
- data/assets/stylesheets/codemirror.css +126 -0
- data/assets/stylesheets/luca-ui-bootstrap.css +0 -1
- data/assets/stylesheets/luca-ui-development-tools.css +5 -0
- data/assets/stylesheets/sandbox/sandbox.scss +1 -3
- data/assets/stylesheets/themes/amelia-bootstrap.css +826 -0
- data/assets/stylesheets/themes/slate-bootstrap.css +797 -0
- data/assets/stylesheets/themes/superhero-bootstrap.css +830 -0
- data/lib/luca/code_browser.rb +55 -0
- data/lib/luca/rails/version.rb +1 -1
- data/lib/luca/rails.rb +1 -0
- data/spec/components/fields/checkbox_array_spec.coffee +46 -0
- data/spec/components/form_view_spec.coffee +10 -4
- data/spec/containers/card_view_spec.coffee +7 -0
- data/spec/core/collection_spec.coffee +58 -4
- data/spec/core/container_spec.coffee +6 -6
- data/spec/core/view_spec.coffee +93 -7
- data/spec/framework_spec.coffee +15 -12
- data/src/components/application.coffee +126 -18
- data/src/components/base_toolbar.coffee +2 -2
- data/src/components/collection_loader_view.coffee +1 -2
- data/src/components/collection_view.coffee +77 -0
- data/src/components/controller.coffee +1 -4
- data/src/components/fields/button_field.coffee +1 -1
- data/src/components/fields/checkbox_array.coffee +2 -2
- data/src/components/fields/checkbox_field.coffee +3 -1
- data/src/components/fields/file_upload_field.coffee +1 -1
- data/src/components/fields/hidden_field.coffee +1 -1
- data/src/components/fields/select_field.coffee +1 -1
- data/src/components/fields/text_area_field.coffee +1 -1
- data/src/components/fields/text_field.coffee +10 -6
- data/src/components/fields/type_ahead_field.coffee +18 -5
- data/src/components/form_button_toolbar.coffee +1 -2
- data/src/components/form_view.coffee +44 -62
- data/src/components/grid_view.coffee +27 -20
- data/src/components/load_mask.coffee +3 -0
- data/src/components/nav_bar.coffee +26 -0
- data/src/components/record_manager.coffee +1 -3
- data/src/components/router.coffee +1 -1
- data/src/components/template.coffee +3 -15
- data/src/components/toolbar_dialog.coffee +25 -0
- data/src/containers/card_view.coffee +22 -23
- data/src/containers/column_view.coffee +1 -6
- data/src/containers/modal_view.coffee +20 -71
- data/src/containers/panel_toolbar.coffee +156 -0
- data/src/containers/panel_view.coffee +1 -1
- data/src/containers/split_view.coffee +1 -3
- data/src/containers/tab_view.coffee +29 -29
- data/src/containers/viewport.coffee +38 -3
- data/src/core/collection.coffee +80 -48
- data/src/core/container.coffee +153 -72
- data/src/core/core.coffee +181 -0
- data/src/core/field.coffee +4 -2
- data/src/core/model.coffee +1 -1
- data/src/core/observer.coffee +3 -3
- data/src/core/panel.coffee +143 -0
- data/src/core/registry.coffee +104 -0
- data/src/core/util.coffee +82 -0
- data/src/core/view.coffee +158 -85
- data/src/framework.coffee +112 -178
- data/src/index.coffee +0 -255
- data/src/managers/collection_manager.coffee +1 -0
- data/src/samples/definition.coffee +49 -0
- data/src/stylesheets/base.scss +0 -78
- data/src/stylesheets/components/form_view.scss +8 -3
- data/src/stylesheets/components/grid_view.scss +3 -7
- data/src/stylesheets/components/load_mask.scss +14 -0
- data/src/stylesheets/components/toolbar.scss +0 -15
- data/src/stylesheets/containers/container.scss +14 -2
- data/src/stylesheets/containers/panels.scss +23 -0
- data/src/stylesheets/tools/class_browser.scss +32 -0
- data/src/stylesheets/tools/code_editor.scss +24 -0
- data/src/stylesheets/tools/component_tester.scss +8 -0
- data/src/stylesheets/tools/console.scss +26 -0
- data/src/templates/components/collection_loader_view.luca +1 -1
- data/src/templates/components/form_view.luca +2 -13
- data/src/templates/components/grid_view.luca +0 -2
- data/src/templates/components/load_mask.luca +3 -0
- data/src/templates/components/nav_bar.luca +2 -0
- data/src/templates/containers/tab_view.luca +1 -0
- data/src/templates/fields/text_field.luca +4 -1
- data/src/tools/class_browser.coffee +39 -0
- data/src/tools/code_editor.coffee +258 -0
- data/src/tools/code_mirror_field.coffee +57 -0
- data/src/tools/coffee_script_editor.coffee +60 -0
- data/src/tools/collection_inspector.coffee +4 -0
- data/src/tools/component_tester.coffee +472 -0
- data/src/tools/components/class_browser_detail.coffee +10 -0
- data/src/tools/components/class_browser_list.coffee +74 -0
- data/src/tools/console.coffee +147 -0
- data/src/tools/development_console.coffee +147 -0
- data/src/tools/models/components.coffee +63 -0
- data/src/tools/templates/component_tester/help.luca +14 -0
- data/vendor/assets/javascripts/luca-ui-base.js +1389 -611
- data/vendor/assets/javascripts/luca-ui-bootstrap.js +9 -0
- data/vendor/assets/javascripts/luca-ui-development-tools.js +18719 -0
- data/vendor/assets/javascripts/luca-ui-spec.js +2065 -878
- data/vendor/assets/javascripts/luca-ui.js +1759 -852
- data/vendor/assets/javascripts/luca-ui.min.js +3 -3
- data/vendor/assets/stylesheets/luca-ui-bootstrap.css +494 -440
- data/vendor/assets/stylesheets/luca-ui-development-tools.css +224 -0
- data/vendor/assets/stylesheets/luca-ui-spec.css +99 -140
- data/vendor/assets/stylesheets/luca-ui.css +99 -140
- data/views/index.erb +6 -3
- metadata +60 -18
- data/assets/javascripts/dependencies/jquery-console.js +0 -649
- data/assets/javascripts/development-console.coffee +0 -2
- data/assets/javascripts/sandbox/sandbox.coffee +0 -16
- data/assets/javascripts/sandbox/templates/features/collection_helpers.luca +0 -33
- data/assets/javascripts/sandbox/templates/features/form_demo_code.luca +0 -48
- data/assets/javascripts/sandbox/templates/features/grid_demo_code.luca +0 -24
- data/assets/javascripts/sandbox/templates/features/introduction.luca +0 -11
- data/assets/javascripts/sandbox/templates/features/view_helpers.luca +0 -43
- data/assets/javascripts/sandbox/templates/navigation.luca +0 -8
- data/assets/javascripts/sandbox/views/form_demo.coffee +0 -47
- data/assets/javascripts/sandbox/views/grid_demo.coffee +0 -23
- data/assets/javascripts/sandbox/views/pages/collection_events_sample.coffee +0 -1
- data/assets/javascripts/sandbox/views/pages/pages_controller.coffee +0 -38
- data/src/components/collection_inspector.coffee +0 -2
- data/src/components/development_console.coffee +0 -59
- data/src/stylesheets/components/development_console.scss +0 -47
@@ -0,0 +1,472 @@
|
|
1
|
+
# TODO
|
2
|
+
#
|
3
|
+
# Developed this component for use with the component tester.
|
4
|
+
#
|
5
|
+
# The editor which compiles coffeescript code should be extracted into a separate component
|
6
|
+
# and all of the buffers / specifics etc should be moved into a more specific component for
|
7
|
+
# this purpose
|
8
|
+
|
9
|
+
defaults = {}
|
10
|
+
|
11
|
+
defaults.setup = """
|
12
|
+
# the setup tab contains code which is run every time
|
13
|
+
# prior to the 'implementation' run
|
14
|
+
"""
|
15
|
+
|
16
|
+
defaults.component = """
|
17
|
+
# the component tab is where you handle the definition of the component
|
18
|
+
# that you are trying to test. it will render its output into the
|
19
|
+
# output panel of the code tester
|
20
|
+
#
|
21
|
+
# example definition:
|
22
|
+
#
|
23
|
+
# _.def('MyComponent').extends('Luca.View').with
|
24
|
+
# bodyTemplate: 'sample/welcome'
|
25
|
+
"""
|
26
|
+
|
27
|
+
defaults.teardown = """
|
28
|
+
# the teardown tab is where you undo / cleanup any of the operations
|
29
|
+
# from setup / implementation
|
30
|
+
"""
|
31
|
+
|
32
|
+
defaults.implementation = """
|
33
|
+
# the implementation tab is where you specify options for your component.
|
34
|
+
#
|
35
|
+
# NOTE: the component tester uses whatever is returned from evalulating
|
36
|
+
# the code in this tab. if it responds to render(), it will append
|
37
|
+
# render().el to the output panel. if it is an object, then we will attempt
|
38
|
+
# to create an instance of the component you defined with the object as
|
39
|
+
"""
|
40
|
+
|
41
|
+
defaults.style = """
|
42
|
+
/*
|
43
|
+
* customize the styles that effect this component
|
44
|
+
* note, all styles here will be scoped to only effect
|
45
|
+
* the output panel :)
|
46
|
+
*/
|
47
|
+
"""
|
48
|
+
|
49
|
+
defaults.html = ""
|
50
|
+
|
51
|
+
bufferNames = ["setup","implementation","component","style","html"]
|
52
|
+
compiledBuffers = ["setup","implementation","component"]
|
53
|
+
|
54
|
+
ComponentPicker = Luca.fields.TypeAheadField.extend
|
55
|
+
name: "component_picker"
|
56
|
+
|
57
|
+
label: "Choose a component to edit"
|
58
|
+
|
59
|
+
initialize: ()->
|
60
|
+
@collection = new Luca.collections.Components()
|
61
|
+
@collection.fetch()
|
62
|
+
|
63
|
+
@_super("initialize", @, arguments)
|
64
|
+
|
65
|
+
getSource: ()->
|
66
|
+
@collection.classes()
|
67
|
+
|
68
|
+
change_handler: ()->
|
69
|
+
componentDefinition = @getValue()
|
70
|
+
|
71
|
+
component = @collection.find (model)->
|
72
|
+
model.get("className") is componentDefinition
|
73
|
+
|
74
|
+
component.fetch success: (model, response)=>
|
75
|
+
if response?.source.length > 0
|
76
|
+
@trigger "component:fetched", response.source, response.className
|
77
|
+
|
78
|
+
@hide()
|
79
|
+
|
80
|
+
createWrapper: ()->
|
81
|
+
@make "div",
|
82
|
+
class: "component-picker span4 well"
|
83
|
+
style:
|
84
|
+
"position: absolute; z-index:12000"
|
85
|
+
|
86
|
+
show: ()->
|
87
|
+
@$el.parent().show()
|
88
|
+
|
89
|
+
hide: ()->
|
90
|
+
@$el.parent().hide()
|
91
|
+
|
92
|
+
toggle: ()->
|
93
|
+
@$el.parent().toggle()
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
_.def("Luca.tools.ComponentTester").extends("Luca.core.Container").with
|
98
|
+
name: "component_tester"
|
99
|
+
|
100
|
+
className:"span11"
|
101
|
+
|
102
|
+
autoEvaluateCode: true
|
103
|
+
|
104
|
+
components:[
|
105
|
+
ctype: 'card_view'
|
106
|
+
name: "component_detail"
|
107
|
+
activeCard: 0
|
108
|
+
components:[
|
109
|
+
ctype: 'panel'
|
110
|
+
name: "component_tester_output"
|
111
|
+
bodyTemplate: "component_tester/help"
|
112
|
+
]
|
113
|
+
,
|
114
|
+
ctype: "code_editor"
|
115
|
+
name: "ctester_edit"
|
116
|
+
className: 'font-large fixed-height'
|
117
|
+
minHeight:'350px'
|
118
|
+
|
119
|
+
styles:
|
120
|
+
"position" : "absolute"
|
121
|
+
"bottom" : "0px"
|
122
|
+
"width" : "96%"
|
123
|
+
|
124
|
+
currentBuffers: defaults
|
125
|
+
|
126
|
+
compiledBuffers:["component","setup","implementation"]
|
127
|
+
|
128
|
+
topToolbar:
|
129
|
+
buttons:[
|
130
|
+
icon: "resize-full"
|
131
|
+
align: "right"
|
132
|
+
description: "change the size of the component tester editor"
|
133
|
+
eventId: "toggle:size"
|
134
|
+
,
|
135
|
+
icon: "pause"
|
136
|
+
align: "right"
|
137
|
+
description: "Toggle auto-evaluation of test script on code change"
|
138
|
+
eventId: "click:autoeval"
|
139
|
+
,
|
140
|
+
icon: "plus"
|
141
|
+
description: "add a new component to test"
|
142
|
+
eventId: "click:add"
|
143
|
+
,
|
144
|
+
icon: "folder-open"
|
145
|
+
description: "open an existing component's definition"
|
146
|
+
eventId: "click:open"
|
147
|
+
]
|
148
|
+
|
149
|
+
bottomToolbar:
|
150
|
+
buttons:[
|
151
|
+
group: true
|
152
|
+
wrapper: "span4"
|
153
|
+
buttons:[
|
154
|
+
label: "View Javascript"
|
155
|
+
description: "Switch between compiled JS and Coffeescript"
|
156
|
+
eventId: "toggle:mode"
|
157
|
+
]
|
158
|
+
,
|
159
|
+
group: true
|
160
|
+
wrapper: "span6 offset4"
|
161
|
+
buttons:[
|
162
|
+
label: "Component"
|
163
|
+
eventId: "edit:component"
|
164
|
+
description: "Edit the component itself"
|
165
|
+
,
|
166
|
+
label: "Setup"
|
167
|
+
eventId: "edit:setup"
|
168
|
+
description: "Edit the setup for your component test"
|
169
|
+
,
|
170
|
+
label: "Implementation"
|
171
|
+
eventId: "edit:implementation"
|
172
|
+
description: "Implement your component"
|
173
|
+
,
|
174
|
+
label: "Markup",
|
175
|
+
eventId: "edit:markup"
|
176
|
+
description: "Edit the HTML produced by the component"
|
177
|
+
,
|
178
|
+
label: "CSS"
|
179
|
+
eventId: "edit:style"
|
180
|
+
description: "Edit CSS"
|
181
|
+
]
|
182
|
+
,
|
183
|
+
group: true
|
184
|
+
align: "right"
|
185
|
+
buttons:[
|
186
|
+
icon:"question-sign"
|
187
|
+
align: "right"
|
188
|
+
eventId: "click:help"
|
189
|
+
description: "Help"
|
190
|
+
,
|
191
|
+
icon: "cog"
|
192
|
+
align: 'right'
|
193
|
+
eventId: "click:settings"
|
194
|
+
description : "component tester settings"
|
195
|
+
,
|
196
|
+
icon: "eye-close"
|
197
|
+
align: "right"
|
198
|
+
eventId: "click:hide"
|
199
|
+
description: "hide the tester controls"
|
200
|
+
,
|
201
|
+
icon: "heart"
|
202
|
+
eventId: "click:console"
|
203
|
+
description: "Coffeescript Console"
|
204
|
+
align: "right"
|
205
|
+
]
|
206
|
+
]
|
207
|
+
]
|
208
|
+
|
209
|
+
debugMode: true
|
210
|
+
|
211
|
+
componentEvents:
|
212
|
+
"ctester_edit click:autoeval" : "toggleAutoeval"
|
213
|
+
"ctester_edit click:refresh" : "refreshCode"
|
214
|
+
"ctester_edit click:hide" : "toggleControls"
|
215
|
+
"ctester_edit click:settings" : "toggleSettings"
|
216
|
+
"ctester_edit click:add" : "addComponent"
|
217
|
+
"ctester_edit click:open" : "openComponent"
|
218
|
+
"ctester_edit click:help" : "showHelp"
|
219
|
+
"ctester_edit click:console" : "toggleConsole"
|
220
|
+
"ctester_edit eval:error" : "onError"
|
221
|
+
"ctester_edit eval:success" : "onSuccess"
|
222
|
+
"ctester_edit edit:setup" : "editSetup"
|
223
|
+
"ctester_edit edit:teardown" : "editTeardown"
|
224
|
+
"ctester_edit edit:component" : "editComponent"
|
225
|
+
"ctester_edit edit:style" : "editStyle"
|
226
|
+
"ctester_edit edit:markup" : "editMarkup"
|
227
|
+
"ctester_edit edit:implementation" : "editImplementation"
|
228
|
+
"ctester_edit toggle:keymap" : "toggleKeymap"
|
229
|
+
"ctester_edit toggle:mode" : "toggleMode"
|
230
|
+
"ctester_edit code:change:html" : "onMarkupChange"
|
231
|
+
"ctester_edit code:change:style" : "onStyleChange"
|
232
|
+
"ctester_edit toggle:size" : "toggleSize"
|
233
|
+
|
234
|
+
|
235
|
+
initialize: ()->
|
236
|
+
Luca.core.Container::initialize.apply(@, arguments)
|
237
|
+
|
238
|
+
for key, value of @componentEvents
|
239
|
+
@[ value ] = _.bind(@[value], @)
|
240
|
+
|
241
|
+
@defer("editComponent").until("after:render")
|
242
|
+
|
243
|
+
afterRender: ()->
|
244
|
+
@getOutput().applyStyles('min-height':'400px')
|
245
|
+
|
246
|
+
# TEMP
|
247
|
+
# Visual hacks
|
248
|
+
@$('.toolbar-container').css('padding-right','12px')
|
249
|
+
@$('.luca-ui-toolbar.toolbar-bottom').css('margin','0px')
|
250
|
+
|
251
|
+
changeHandler = _.idleMedium ()=>
|
252
|
+
if @autoEvaluateCode is true
|
253
|
+
@applyTestRun()
|
254
|
+
, 500
|
255
|
+
|
256
|
+
@getEditor().bind "code:change", changeHandler
|
257
|
+
|
258
|
+
getEditor: ()->
|
259
|
+
Luca("ctester_edit")
|
260
|
+
|
261
|
+
getDetail: ()->
|
262
|
+
Luca("component_detail")
|
263
|
+
|
264
|
+
getOutput: ()->
|
265
|
+
@getDetail().findComponentByName("component_tester_output")
|
266
|
+
|
267
|
+
onError: (error, bufferId)->
|
268
|
+
console.log "Error in #{ bufferId }", error, error.message, error.stack
|
269
|
+
|
270
|
+
onSuccess: (result, bufferId)->
|
271
|
+
if bufferId is "component"
|
272
|
+
@componentDefinition = result
|
273
|
+
|
274
|
+
if bufferId is "implementation"
|
275
|
+
if Luca.isBackboneView(result)
|
276
|
+
object = result
|
277
|
+
else if _.isObject(result) and result.ctype?
|
278
|
+
object = Luca(result)
|
279
|
+
else if _.isObject(result) and _.isFunction(@componentDefinition)
|
280
|
+
object = ( new @componentDefinition(result) )
|
281
|
+
|
282
|
+
if Luca.isBackboneView(object)
|
283
|
+
@getOutput().$html( object.render().el )
|
284
|
+
|
285
|
+
applyTestRun: ()->
|
286
|
+
@getOutput().$html('')
|
287
|
+
|
288
|
+
for bufferId, code of @getTestRun()
|
289
|
+
@evaluateCode(code, bufferId)
|
290
|
+
|
291
|
+
toggleConsole: (button)->
|
292
|
+
@developmentConsole = Luca "coffeescript-console", ()-> new Luca.tools.DevelopmentConsole(name:"coffeescript-console")
|
293
|
+
|
294
|
+
unless @consoleContainerAppended
|
295
|
+
container = @make("div",{id:"devtools-console-wrapper",class:"devtools-console-container modal",style:"width:900px;height:650px;"}, @developmentConsole.el)
|
296
|
+
$('body').append( container )
|
297
|
+
@consoleContainerAppended = true
|
298
|
+
@developmentConsole.render()
|
299
|
+
|
300
|
+
$('#devtools-console-wrapper').modal(backdrop:false,show:true)
|
301
|
+
|
302
|
+
toggleAutoeval: (button)->
|
303
|
+
@autoEvaluateCode = !(@autoEvaluateCode is true)
|
304
|
+
|
305
|
+
if not @started and @autoEvaluateCode is true
|
306
|
+
@started = true
|
307
|
+
@applyTestRun()
|
308
|
+
|
309
|
+
iconHolder = button.children('i').eq(0)
|
310
|
+
buttonClass = if @autoEvaluateCode then "icon-pause" else "icon-play"
|
311
|
+
iconHolder.removeClass()
|
312
|
+
iconHolder.addClass(buttonClass)
|
313
|
+
|
314
|
+
@
|
315
|
+
|
316
|
+
showEditor: (options)->
|
317
|
+
@getEditor().$('.toolbar-container.top').toggle(options)
|
318
|
+
@getEditor().$('.codemirror-wrapper').toggle(options)
|
319
|
+
@trigger "controls:toggled"
|
320
|
+
|
321
|
+
toggleKeymap: (button)->
|
322
|
+
newMode = if @getEditor().keyMap is "vim" then "basic" else "vim"
|
323
|
+
@getEditor().setKeyMap(newMode)
|
324
|
+
button.html( _.string.capitalize(newMode) )
|
325
|
+
|
326
|
+
toggleMode: (button)->
|
327
|
+
newMode = if @getEditor().mode is "coffeescript" then "javascript" else "coffeescript"
|
328
|
+
@getEditor().setMode(newMode)
|
329
|
+
button.html _.string.capitalize((if newMode is "coffeescript" then "View Javascript" else "View Coffeescript"))
|
330
|
+
@editBuffer @currentBufferName, (newMode is "javascript")
|
331
|
+
|
332
|
+
|
333
|
+
currentSize: 1
|
334
|
+
sizes:[
|
335
|
+
icon: "resize-full"
|
336
|
+
value: ()-> $(window).height() * 0.3
|
337
|
+
,
|
338
|
+
icon: "resize-small"
|
339
|
+
value: ()-> $(window).height() * 0.6
|
340
|
+
]
|
341
|
+
|
342
|
+
toggleSize: (button)->
|
343
|
+
index = @currentSize++ % @sizes.length
|
344
|
+
newSize = @sizes[ index ].value()
|
345
|
+
newIcon = @sizes[ index ].icon
|
346
|
+
|
347
|
+
if button?
|
348
|
+
iconHolder = button.children('i').eq(0)
|
349
|
+
iconHolder.removeClass().addClass("icon-#{ newIcon }")
|
350
|
+
|
351
|
+
@$('.codemirror-wrapper').css('height', "#{ parseInt(newSize) }px")
|
352
|
+
@getEditor().refresh()
|
353
|
+
|
354
|
+
toggleControls: (button)->
|
355
|
+
@bind "controls:toggled", ()=>
|
356
|
+
iconHolder = button.children('i').eq(0)
|
357
|
+
iconHolder.removeClass()
|
358
|
+
|
359
|
+
buttonClass = if @getEditor().$('.toolbar-container.top').is(":visible") then "icon-eye-close" else "icon-eye-open"
|
360
|
+
iconHolder.addClass(buttonClass)
|
361
|
+
|
362
|
+
@showEditor()
|
363
|
+
|
364
|
+
@
|
365
|
+
|
366
|
+
toggleSettings: ()->
|
367
|
+
@
|
368
|
+
|
369
|
+
setValue: (value, buffer="component")->
|
370
|
+
compiled = @getEditor().editor.getOption('mode') is "javascript"
|
371
|
+
@editBuffer(buffer, compiled, false).getEditor().setValue( value )
|
372
|
+
|
373
|
+
editBuffer: (@currentBufferName, compiled=false, autoSave=true)->
|
374
|
+
@showEditor(true)
|
375
|
+
@highlight(@currentBufferName)
|
376
|
+
|
377
|
+
buffer = if compiled then "compiled_#{ @currentBufferName }" else @currentBufferName
|
378
|
+
@getEditor().loadBuffer(buffer,autoSave)
|
379
|
+
@
|
380
|
+
|
381
|
+
editMarkup: ()->
|
382
|
+
@getEditor().setMode('htmlmixed')
|
383
|
+
@getEditor().setWrap(true)
|
384
|
+
@editBuffer("html").setValue(@getOutput().$html(), 'html')
|
385
|
+
|
386
|
+
editStyle: ()->
|
387
|
+
@getEditor().setMode('css')
|
388
|
+
@editBuffer("style")
|
389
|
+
|
390
|
+
editComponent: ()->
|
391
|
+
@getEditor().setMode('coffeescript')
|
392
|
+
@editBuffer("component")
|
393
|
+
|
394
|
+
editTeardown: ()->
|
395
|
+
@getEditor().setMode('coffeescript')
|
396
|
+
@editBuffer("teardown")
|
397
|
+
|
398
|
+
editSetup: ()->
|
399
|
+
@getEditor().setMode('coffeescript')
|
400
|
+
@editBuffer("setup")
|
401
|
+
|
402
|
+
editImplementation: ()->
|
403
|
+
@getEditor().setMode('coffeescript')
|
404
|
+
@editBuffer("implementation")
|
405
|
+
|
406
|
+
getTestRun: ()->
|
407
|
+
editor = @getEditor()
|
408
|
+
|
409
|
+
testRun = {}
|
410
|
+
|
411
|
+
for buffer in ["component","setup","implementation"]
|
412
|
+
testRun[buffer] = editor.getBuffer(buffer, true)
|
413
|
+
|
414
|
+
testRun
|
415
|
+
|
416
|
+
getContext: ()->
|
417
|
+
Luca.util.resolve(@context||="window")
|
418
|
+
|
419
|
+
evaluateCode: (code, bufferId, compile=false)->
|
420
|
+
code ||= @getEditor().getValue()
|
421
|
+
compiled = if compile is true then @getEditor().compileCode(code) else code
|
422
|
+
|
423
|
+
evaluator = ()-> eval( compiled )
|
424
|
+
|
425
|
+
try
|
426
|
+
result = evaluator.call( @getContext() )
|
427
|
+
@onSuccess(result, bufferId, code)
|
428
|
+
catch error
|
429
|
+
@onError( error, bufferId, code)
|
430
|
+
|
431
|
+
onMarkupChange: ()->
|
432
|
+
if @autoEvaluateCode is true
|
433
|
+
@getOutput().$html @getEditor().getValue()
|
434
|
+
|
435
|
+
onStyleChange: ()->
|
436
|
+
if @autoEvaluateCode is true
|
437
|
+
$('#component-tester-stylesheet').remove()
|
438
|
+
|
439
|
+
style = @getEditor()?.getValue()
|
440
|
+
|
441
|
+
if style
|
442
|
+
styleTag = @make "style", type:"text/css", id: "component-tester-stylesheet"
|
443
|
+
$('head').append( styleTag )
|
444
|
+
$(styleTag).append(style)
|
445
|
+
|
446
|
+
showHelp: ()->
|
447
|
+
@getOutput().$html( Luca.template("component_tester/help",@) )
|
448
|
+
|
449
|
+
addComponent: (button)->
|
450
|
+
|
451
|
+
openComponent: (button)->
|
452
|
+
@componentPicker ||= new ComponentPicker()
|
453
|
+
|
454
|
+
@componentPicker.bind "component:fetched", (source, component)=>
|
455
|
+
@setEditorNamespace(component).setValue( source, "component")
|
456
|
+
|
457
|
+
if !@getEditor().$('.component-picker').length > 0
|
458
|
+
@getEditor().$('.codemirror-wrapper').before(@componentPicker.createWrapper())
|
459
|
+
@getEditor().$('.component-picker').html( @componentPicker.render().el )
|
460
|
+
@componentPicker.show()
|
461
|
+
return
|
462
|
+
|
463
|
+
@componentPicker.toggle()
|
464
|
+
|
465
|
+
highlight: (section)->
|
466
|
+
@$("a.btn[data-eventid='edit:#{ section }']").siblings().css('font-weight','normal')
|
467
|
+
@$("a.btn[data-eventid='edit:#{ section }']").css('font-weight','bold')
|
468
|
+
|
469
|
+
setEditorNamespace: (namespace)->
|
470
|
+
@getEditor().namespace( namespace )
|
471
|
+
@getEditor().buffers.fetch()
|
472
|
+
@
|
@@ -0,0 +1,74 @@
|
|
1
|
+
_.def("Luca.tools.ClassBrowserList").extends("Luca.View").with
|
2
|
+
tagName: "ul"
|
3
|
+
className: "nav nav-list class-browser-list"
|
4
|
+
|
5
|
+
autoBindEventHandlers: true
|
6
|
+
|
7
|
+
events:
|
8
|
+
"click li.namespace a" : "namespaceClickHandler"
|
9
|
+
"click li.className a" : "classClickHandler"
|
10
|
+
|
11
|
+
initialize: (@options={})->
|
12
|
+
@deferrable = @collection = new Luca.collections.Components()
|
13
|
+
|
14
|
+
collapseAllNamespaceLists: ()->
|
15
|
+
@$('ul.classList').collapse('hide')
|
16
|
+
|
17
|
+
namespaceClickHandler: (e)->
|
18
|
+
me = my = $( e.target )
|
19
|
+
classList = my.siblings('.classList')
|
20
|
+
classList.collapse('toggle')
|
21
|
+
|
22
|
+
classClickHandler: (e)->
|
23
|
+
e.preventDefault()
|
24
|
+
|
25
|
+
me = my = $( e.currentTarget )
|
26
|
+
className = my.data('component')
|
27
|
+
list = @
|
28
|
+
|
29
|
+
model = @collection.detect (component)->
|
30
|
+
component.get("className") is className
|
31
|
+
|
32
|
+
if model and !model.get("contents")
|
33
|
+
# TODO Why is this firing twice?
|
34
|
+
model.fetch success: _.once (model, response)->
|
35
|
+
list.trigger "component:loaded", model, response
|
36
|
+
|
37
|
+
afterRender: ()->
|
38
|
+
@collapseAllNamespaceLists()
|
39
|
+
Luca.View::afterRender?.apply(@, arguments)
|
40
|
+
|
41
|
+
attach: _.once( Luca.View::$attach )
|
42
|
+
|
43
|
+
render: ()->
|
44
|
+
tree = @
|
45
|
+
data = @collection.asTree()
|
46
|
+
|
47
|
+
_( data ).each (namespace, root)->
|
48
|
+
target = tree.make("a",{},root)
|
49
|
+
li = tree.make("li",class:"root", target)
|
50
|
+
namespaceList = _( namespace ).keys()
|
51
|
+
|
52
|
+
namespaceElements = _( namespaceList ).map (namespace)->
|
53
|
+
classId = namespace.toLowerCase().replace(/\./g, '-')
|
54
|
+
target = tree.make("a",{},namespace)
|
55
|
+
nli = tree.make "li", {class:"namespace #{ classId }"}, target
|
56
|
+
|
57
|
+
resolved = Luca.util.resolve(namespace, (window || global))
|
58
|
+
classes = _( resolved ).keys()
|
59
|
+
classElements = _( classes ).map (componentClass)->
|
60
|
+
fullName = "#{ namespace }.#{ componentClass }"
|
61
|
+
link = tree.make("a",{"data-component":fullName}, fullName)
|
62
|
+
classId = fullName.toLowerCase().replace(/\./g, '-')
|
63
|
+
tree.make "li", {class:"className #{ classId }"}, link
|
64
|
+
|
65
|
+
cul = tree.make "ul", {class:"classList"}, classElements
|
66
|
+
$( nli ).append( cul )
|
67
|
+
nli
|
68
|
+
|
69
|
+
ul = tree.make "ul",{class:"namespace"}, namespaceElements
|
70
|
+
|
71
|
+
$( li ).append(ul)
|
72
|
+
tree.$append( li )
|
73
|
+
|
74
|
+
@attach()
|
@@ -0,0 +1,147 @@
|
|
1
|
+
codeMirrorOptions =
|
2
|
+
readOnly: true
|
3
|
+
autoFocus: false
|
4
|
+
theme: "monokai"
|
5
|
+
mode: "javascript"
|
6
|
+
|
7
|
+
Luca.define("Luca.tools.DevelopmentConsole").extends("Luca.core.Container").with
|
8
|
+
className: "luca-ui-console"
|
9
|
+
name: "console"
|
10
|
+
history: []
|
11
|
+
historyIndex: 0
|
12
|
+
|
13
|
+
componentEvents:
|
14
|
+
"code_input key:keyup" : "historyUp"
|
15
|
+
"code_input key:keydown" : "historyDown"
|
16
|
+
"code_input key:enter" : "runCommand"
|
17
|
+
|
18
|
+
compileOptions:
|
19
|
+
bare: true
|
20
|
+
|
21
|
+
components:[
|
22
|
+
ctype: "code_mirror_field"
|
23
|
+
name: "code_output"
|
24
|
+
readOnly: true
|
25
|
+
lineNumbers: false
|
26
|
+
mode: "javascript"
|
27
|
+
height:"621px"
|
28
|
+
maxHeight:"621px"
|
29
|
+
lineWrapping: true
|
30
|
+
gutter: false
|
31
|
+
,
|
32
|
+
ctype: "text_field"
|
33
|
+
name: "code_input"
|
34
|
+
lineNumbers: false
|
35
|
+
height: '30px'
|
36
|
+
maxHeight: '30px'
|
37
|
+
gutter: false
|
38
|
+
autoBindEventHandlers: true
|
39
|
+
hideLabel: true
|
40
|
+
prepend: "Coffee>"
|
41
|
+
events:
|
42
|
+
"keypress input" : "onKeyEvent"
|
43
|
+
"keydown input" : "onKeyEvent"
|
44
|
+
|
45
|
+
onKeyEvent: (keyEvent)->
|
46
|
+
if keyEvent.type is "keypress" and keyEvent.keyCode is Luca.keys.ENTER
|
47
|
+
@trigger("key:enter", @getValue())
|
48
|
+
|
49
|
+
if keyEvent.type is "keydown" and keyEvent.keyCode is Luca.keys.KEYUP
|
50
|
+
@trigger("key:keyup")
|
51
|
+
|
52
|
+
if keyEvent.type is "keydown" and keyEvent.keyCode is Luca.keys.KEYDOWN
|
53
|
+
@trigger("key:keydown")
|
54
|
+
|
55
|
+
afterRender: ()->
|
56
|
+
@$('input').focus()
|
57
|
+
]
|
58
|
+
|
59
|
+
getContext: ()->
|
60
|
+
window
|
61
|
+
|
62
|
+
initialize: ()->
|
63
|
+
@_super("initialize", @, arguments)
|
64
|
+
_.bindAll @, "historyUp", "historyDown", "onSuccess", "onError", "runCommand"
|
65
|
+
|
66
|
+
saveHistory: (command)->
|
67
|
+
@history.push( command ) if command?.length > 0
|
68
|
+
@historyIndex = 0
|
69
|
+
|
70
|
+
historyUp: ()->
|
71
|
+
@historyIndex -= 1
|
72
|
+
@historyIndex = 0 if @historyIndex < 0
|
73
|
+
|
74
|
+
currentValue = Luca("code_input").getValue()
|
75
|
+
Luca("code_input").setValue( @history[ @historyIndex ] || currentValue )
|
76
|
+
|
77
|
+
historyDown: ()->
|
78
|
+
@historyIndex += 1
|
79
|
+
@historyIndex = @history.length - 1 if @historyIndex > @history.length - 1
|
80
|
+
|
81
|
+
currentValue = Luca("code_input").getValue()
|
82
|
+
|
83
|
+
Luca("code_input").setValue( @history[ @historyIndex ] || currentValue)
|
84
|
+
|
85
|
+
append: (code, result, skipFormatting=false)->
|
86
|
+
output = Luca("code_output")
|
87
|
+
current = output.getValue()
|
88
|
+
|
89
|
+
source = "// #{ code }" if code?
|
90
|
+
|
91
|
+
payload = if skipFormatting or code.match(/^console\.log/)
|
92
|
+
[current,result]
|
93
|
+
else
|
94
|
+
[current,source, result]
|
95
|
+
|
96
|
+
output.setValue( _.compact(payload).join("\n") )
|
97
|
+
output.getCodeMirror().scrollTo(0,90000)
|
98
|
+
|
99
|
+
onSuccess: (result, js, coffee)->
|
100
|
+
@saveHistory(coffee)
|
101
|
+
dump = JSON.stringify(result, null, "\t")
|
102
|
+
dump ||= result.toString?()
|
103
|
+
|
104
|
+
@append(js, dump || "undefined")
|
105
|
+
|
106
|
+
onError: (error, js, coffee)->
|
107
|
+
@append(js, "// ERROR: #{ error.message }")
|
108
|
+
|
109
|
+
evaluateCode: (code, raw)->
|
110
|
+
return unless code?.length > 0
|
111
|
+
|
112
|
+
raw = _.string.strip(raw)
|
113
|
+
output = Luca("code_output")
|
114
|
+
dev = @
|
115
|
+
|
116
|
+
evaluator = ()->
|
117
|
+
old_console = window.console
|
118
|
+
|
119
|
+
console =
|
120
|
+
log: ()->
|
121
|
+
for arg in arguments
|
122
|
+
dev.append(undefined, arg, true)
|
123
|
+
|
124
|
+
log = console.log
|
125
|
+
|
126
|
+
try
|
127
|
+
result = eval( code )
|
128
|
+
catch error
|
129
|
+
window.console = old_console
|
130
|
+
throw(error)
|
131
|
+
|
132
|
+
window.console = old_console
|
133
|
+
|
134
|
+
result
|
135
|
+
|
136
|
+
try
|
137
|
+
result = evaluator.call( @getContext() )
|
138
|
+
@onSuccess(result, code, raw) unless raw.match(/^console\.log/)
|
139
|
+
catch error
|
140
|
+
@onError(error, code, raw)
|
141
|
+
|
142
|
+
runCommand: ()->
|
143
|
+
dev = @
|
144
|
+
compile = _.bind(Luca.tools.CoffeeEditor::compile, @)
|
145
|
+
raw = Luca("code_input").getValue()
|
146
|
+
compiled = compile raw, (compiled)->
|
147
|
+
dev.evaluateCode(compiled, raw)
|