mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
boom. errors with scripts and line numbers now show up in web inspector
https://img.skitch.com/20110828-rrfnqet2y2yrxq6witst6mrscx.png fixes #3 atomicity modules that want to export an api must use define(). this mirrors ace's module definition style so it should fit in fine. $, _, and CoffeeScript are now global scripts show up as loaded before: https://img.skitch.com/20110828-japr2cp4ucbr4a1kmp9degs3t.png after: https://img.skitch.com/20110828-txc782k47gn4rb67mhbujsgkw5.png
This commit is contained in:
parent
326f91bbef
commit
003776da8f
@ -1,153 +0,0 @@
|
||||
# nice!
|
||||
|
||||
{Chrome, File, Process, Dir} = require 'osx'
|
||||
|
||||
ace = require 'ace/ace'
|
||||
canon = require 'pilot/canon'
|
||||
|
||||
$ = require 'jquery'
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
|
||||
Chrome.addPane 'main', '<div id="editor"></div>'
|
||||
|
||||
editor = ace.edit "editor"
|
||||
editor.setTheme require "ace/theme/twilight"
|
||||
JavaScriptMode = require("ace/mode/javascript").Mode
|
||||
CoffeeMode = require("ace/mode/coffee").Mode
|
||||
HTMLMode = require("ace/mode/html").Mode
|
||||
editor.getSession().setMode new JavaScriptMode
|
||||
editor.getSession().setUseSoftTabs true
|
||||
editor.getSession().setTabSize 2
|
||||
|
||||
# fuuuuu, ui bug
|
||||
setTimeout ->
|
||||
editor.focus()
|
||||
editor.resize()
|
||||
, 50
|
||||
|
||||
if css = File.read "~/.atomicity/twilight.css"
|
||||
head = $('head')[0]
|
||||
style = document.createElement 'style'
|
||||
rules = document.createTextNode css
|
||||
style.type = 'text/css'
|
||||
style.appendChild rules
|
||||
head.appendChild style
|
||||
|
||||
_.map Dir.list("~/.atomicity/"), (path) ->
|
||||
if /\.js$/.test path
|
||||
$.getScript path
|
||||
else if /\.coffee/.test path
|
||||
eval CoffeeScript.compile File.read path
|
||||
|
||||
filename = null
|
||||
editor.getSession().on 'change', ->
|
||||
Chrome.setDirty true
|
||||
save = ->
|
||||
File.write filename, editor.getSession().getValue()
|
||||
setMode()
|
||||
Chrome.setDirty false
|
||||
open = ->
|
||||
if /png|jpe?g|gif/i.test filename
|
||||
Chrome.openURL filename
|
||||
else
|
||||
Chrome.title _.last filename.split('/')
|
||||
editor.getSession().setValue File.read filename
|
||||
setMode()
|
||||
Chrome.setDirty false
|
||||
setMode = ->
|
||||
if /\.js$/.test filename
|
||||
editor.getSession().setMode new JavaScriptMode
|
||||
else if /\.coffee$/.test filename
|
||||
editor.getSession().setMode new CoffeeMode
|
||||
else if /\.html/.test filename
|
||||
editor.getSession().setMode new HTMLMode
|
||||
saveAs = ->
|
||||
if file = Chrome.savePanel()
|
||||
filename = file
|
||||
Chrome.title _.last filename.split('/')
|
||||
save()
|
||||
bindKey = (name, shortcut, callback) ->
|
||||
canon.addCommand
|
||||
name: name
|
||||
exec: callback
|
||||
bindKey:
|
||||
win: null
|
||||
mac: shortcut
|
||||
sender: 'editor'
|
||||
|
||||
|
||||
bindKey 'open', 'Command-O', (env, args, request) ->
|
||||
if file = Chrome.openPanel()
|
||||
filename = file
|
||||
open()
|
||||
|
||||
bindKey 'openURL', 'Command-Shift-O', (env, args, request) ->
|
||||
if url = prompt "Enter URL:"
|
||||
Chrome.openURL url
|
||||
|
||||
bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
|
||||
saveAs()
|
||||
|
||||
bindKey 'save', 'Command-S', (env, args, request) ->
|
||||
if filename then save() else saveAs()
|
||||
|
||||
bindKey 'new', 'Command-N', (env, args, request) ->
|
||||
Chrome.createWindow()
|
||||
|
||||
bindKey 'copy', 'Command-C', (env, args, request) ->
|
||||
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
|
||||
Chrome.writeToPasteboard text
|
||||
|
||||
bindKey 'cut', 'Command-X', (env, args, request) ->
|
||||
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
|
||||
Chrome.writeToPasteboard text
|
||||
editor.session.remove editor.getSelectionRange()
|
||||
|
||||
bindKey 'eval', 'Command-R', (env, args, request) ->
|
||||
eval env.editor.getSession().getValue()
|
||||
|
||||
# textmate
|
||||
|
||||
bindKey 'togglecomment', 'Command-/', (env) ->
|
||||
env.editor.toggleCommentLines()
|
||||
|
||||
bindKey 'tmoutdent', 'Command-[', (env) ->
|
||||
env.editor.blockOutdent()
|
||||
|
||||
bindKey 'tmindent', 'Command-]', (env) ->
|
||||
env.editor.indent()
|
||||
|
||||
# emacs > you
|
||||
|
||||
bindKey 'moveforward', 'Alt-F', (env) ->
|
||||
env.editor.navigateWordRight()
|
||||
|
||||
bindKey 'moveback', 'Alt-B', (env) ->
|
||||
env.editor.navigateWordLeft()
|
||||
|
||||
bindKey 'deleteword', 'Alt-D', (env) ->
|
||||
env.editor.removeWordRight()
|
||||
|
||||
bindKey 'selectwordright', 'Alt-B', (env) ->
|
||||
env.editor.navigateWordLeft()
|
||||
|
||||
bindKey 'home', 'Alt-Shift-,', (env) ->
|
||||
env.editor.navigateFileStart()
|
||||
|
||||
bindKey 'end', 'Alt-Shift-.', (env) ->
|
||||
env.editor.navigateFileEnd()
|
||||
|
||||
bindKey 'fullscreen', 'Command-Shift-Return', (env) ->
|
||||
Chrome.toggleFullscreen()
|
||||
|
||||
# HAX
|
||||
# this should go in coffee.coffee or something
|
||||
bindKey 'consolelog', 'Ctrl-L', (env) ->
|
||||
env.editor.insert 'console.log ""'
|
||||
env.editor.navigateLeft()
|
||||
|
||||
exports.bindKey = bindKey
|
||||
|
||||
## load plugins
|
||||
plugins = _.map Dir.list(Chrome.appRoot() + "/plugins"), (plugin) ->
|
||||
require plugin
|
@ -16,5 +16,4 @@ console.log require.resolve 'underscore'
|
||||
console.log require.resolve 'osx'
|
||||
console.log require.resolve 'ace/requirejs/text!ace/css/editor.css'
|
||||
console.log require.resolve 'ace/keyboard/keybinding'
|
||||
|
||||
this._ = require 'underscore'
|
||||
console.log '--------------'
|
||||
|
154
src/editor.coffee
Normal file
154
src/editor.coffee
Normal file
@ -0,0 +1,154 @@
|
||||
# nice!
|
||||
|
||||
define (require, exports, module) ->
|
||||
{Chrome, File, Process, Dir} = require 'osx'
|
||||
|
||||
ace = require 'ace/ace'
|
||||
canon = require 'pilot/canon'
|
||||
|
||||
Chrome.addPane 'main', '<div id="editor"></div>'
|
||||
|
||||
editor = ace.edit "editor"
|
||||
editor.setTheme require "ace/theme/twilight"
|
||||
JavaScriptMode = require("ace/mode/javascript").Mode
|
||||
CoffeeMode = require("ace/mode/coffee").Mode
|
||||
HTMLMode = require("ace/mode/html").Mode
|
||||
editor.getSession().setMode new JavaScriptMode
|
||||
editor.getSession().setUseSoftTabs true
|
||||
editor.getSession().setTabSize 2
|
||||
|
||||
# fuuuuu, ui bug
|
||||
setTimeout ->
|
||||
editor.focus()
|
||||
editor.resize()
|
||||
, 50
|
||||
|
||||
if css = File.read "~/.atomicity/twilight.css"
|
||||
head = $('head')[0]
|
||||
style = document.createElement 'style'
|
||||
rules = document.createTextNode css
|
||||
style.type = 'text/css'
|
||||
style.appendChild rules
|
||||
head.appendChild style
|
||||
|
||||
_.map Dir.list("~/.atomicity/"), (path) ->
|
||||
if /\.js$/.test path
|
||||
$.getScript path
|
||||
else if /\.coffee/.test path
|
||||
eval CoffeeScript.compile File.read path
|
||||
|
||||
filename = null
|
||||
editor.getSession().on 'change', ->
|
||||
Chrome.setDirty true
|
||||
save = ->
|
||||
File.write filename, editor.getSession().getValue()
|
||||
setMode()
|
||||
Chrome.setDirty false
|
||||
open = ->
|
||||
if /png|jpe?g|gif/i.test filename
|
||||
Chrome.openURL filename
|
||||
else
|
||||
Chrome.title _.last filename.split('/')
|
||||
editor.getSession().setValue File.read filename
|
||||
setMode()
|
||||
Chrome.setDirty false
|
||||
setMode = ->
|
||||
if /\.js$/.test filename
|
||||
editor.getSession().setMode new JavaScriptMode
|
||||
else if /\.coffee$/.test filename
|
||||
editor.getSession().setMode new CoffeeMode
|
||||
else if /\.html/.test filename
|
||||
editor.getSession().setMode new HTMLMode
|
||||
saveAs = ->
|
||||
if file = Chrome.savePanel()
|
||||
filename = file
|
||||
Chrome.title _.last filename.split('/')
|
||||
save()
|
||||
bindKey = (name, shortcut, callback) ->
|
||||
canon.addCommand
|
||||
name: name
|
||||
exec: callback
|
||||
bindKey:
|
||||
win: null
|
||||
mac: shortcut
|
||||
sender: 'editor'
|
||||
|
||||
|
||||
bindKey 'open', 'Command-O', (env, args, request) ->
|
||||
if file = Chrome.openPanel()
|
||||
filename = file
|
||||
open()
|
||||
|
||||
bindKey 'openURL', 'Command-Shift-O', (env, args, request) ->
|
||||
if url = prompt "Enter URL:"
|
||||
Chrome.openURL url
|
||||
|
||||
bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
|
||||
saveAs()
|
||||
|
||||
bindKey 'save', 'Command-S', (env, args, request) ->
|
||||
if filename then save() else saveAs()
|
||||
|
||||
bindKey 'new', 'Command-N', (env, args, request) ->
|
||||
Chrome.createWindow()
|
||||
|
||||
bindKey 'copy', 'Command-C', (env, args, request) ->
|
||||
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
|
||||
Chrome.writeToPasteboard text
|
||||
|
||||
bindKey 'cut', 'Command-X', (env, args, request) ->
|
||||
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
|
||||
Chrome.writeToPasteboard text
|
||||
editor.session.remove editor.getSelectionRange()
|
||||
|
||||
bindKey 'eval', 'Command-R', (env, args, request) ->
|
||||
eval env.editor.getSession().getValue()
|
||||
|
||||
# textmate
|
||||
|
||||
bindKey 'togglecomment', 'Command-/', (env) ->
|
||||
env.editor.toggleCommentLines()
|
||||
|
||||
bindKey 'tmoutdent', 'Command-[', (env) ->
|
||||
env.editor.blockOutdent()
|
||||
|
||||
bindKey 'tmindent', 'Command-]', (env) ->
|
||||
env.editor.indent()
|
||||
|
||||
# emacs > you
|
||||
|
||||
bindKey 'moveforward', 'Alt-F', (env) ->
|
||||
env.editor.navigateWordRight()
|
||||
|
||||
bindKey 'moveback', 'Alt-B', (env) ->
|
||||
env.editor.navigateWordLeft()
|
||||
|
||||
bindKey 'deleteword', 'Alt-D', (env) ->
|
||||
env.editor.removeWordRight()
|
||||
|
||||
bindKey 'selectwordright', 'Alt-B', (env) ->
|
||||
env.editor.navigateWordLeft()
|
||||
|
||||
bindKey 'home', 'Alt-Shift-,', (env) ->
|
||||
env.editor.navigateFileStart()
|
||||
|
||||
bindKey 'end', 'Alt-Shift-.', (env) ->
|
||||
env.editor.navigateFileEnd()
|
||||
|
||||
bindKey 'fullscreen', 'Command-Shift-Return', (env) ->
|
||||
Chrome.toggleFullscreen()
|
||||
|
||||
exports.bindKey = bindKey
|
||||
|
||||
# HAX
|
||||
# this should go in coffee.coffee or something
|
||||
bindKey 'consolelog', 'Ctrl-L', (env) ->
|
||||
env.editor.insert 'console.log ""'
|
||||
env.editor.navigateLeft()
|
||||
|
||||
bindKey 'toggleProjectDrawer', 'Command-Ctrl-N', (env) ->
|
||||
Project.toggle()
|
||||
|
||||
## load plugins
|
||||
plugins = _.map Dir.list(Chrome.appRoot() + "/plugins"), (plugin) ->
|
||||
require plugin
|
277
src/osx.coffee
277
src/osx.coffee
@ -1,160 +1,157 @@
|
||||
# This is the CoffeeScript API that wraps all of Cocoa.
|
||||
define (require, exports, module) ->
|
||||
# Handles the UI chrome
|
||||
Chrome =
|
||||
addPane: (position, html) ->
|
||||
verticalDiv = $('#app-vertical')
|
||||
horizontalDiv = $('#app-horizontal')
|
||||
|
||||
$ = require 'jquery'
|
||||
el = document.createElement("div")
|
||||
el.setAttribute('class', "pane " + position)
|
||||
el.innerHTML = html
|
||||
|
||||
# Handles the UI chrome
|
||||
Chrome =
|
||||
addPane: (position, html) ->
|
||||
verticalDiv = $('#app-vertical')
|
||||
horizontalDiv = $('#app-horizontal')
|
||||
switch position
|
||||
when 'top', 'main'
|
||||
verticalDiv.prepend(el)
|
||||
when 'left'
|
||||
horizontalDiv.prepend(el)
|
||||
when 'bottom'
|
||||
verticalDiv.append(el)
|
||||
when 'right'
|
||||
horizontalDiv.append(el)
|
||||
else
|
||||
NSLog("I DON'T KNOW HOW TO DEAL WITH #{position}")
|
||||
|
||||
el = document.createElement("div")
|
||||
el.setAttribute('class', "pane " + position)
|
||||
el.innerHTML = html
|
||||
# path - Optional. The String path to the file to base it on.
|
||||
createWindow: (path) ->
|
||||
c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
|
||||
c.window
|
||||
c.window.makeKeyAndOrderFront null
|
||||
|
||||
switch position
|
||||
when 'top', 'main'
|
||||
verticalDiv.prepend(el)
|
||||
when 'left'
|
||||
horizontalDiv.prepend(el)
|
||||
when 'bottom'
|
||||
verticalDiv.append(el)
|
||||
when 'right'
|
||||
horizontalDiv.append(el)
|
||||
# Set the active window's dirty status.
|
||||
setDirty: (bool) ->
|
||||
Chrome.activeWindow().setDocumentEdited bool
|
||||
|
||||
# Returns a boolean
|
||||
dirty: ->
|
||||
Chrome.activeWindow().isDocumentEdited()
|
||||
|
||||
# Returns the active NSWindow object
|
||||
activeWindow: ->
|
||||
OSX.NSApplication.sharedApplication.keyWindow
|
||||
|
||||
# Returns null or a file path.
|
||||
openPanel: ->
|
||||
panel = OSX.NSOpenPanel.openPanel
|
||||
panel.setCanChooseDirectories(true)
|
||||
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
||||
return null
|
||||
panel.filenames.lastObject
|
||||
|
||||
# Returns null or a file path.
|
||||
savePanel: ->
|
||||
panel = OSX.NSSavePanel.savePanel
|
||||
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
||||
return null
|
||||
panel.filenames.lastObject
|
||||
|
||||
writeToPasteboard: (text) ->
|
||||
pb = OSX.NSPasteboard.generalPasteboard
|
||||
pb.declareTypes_owner [OSX.NSStringPboardType], null
|
||||
pb.setString_forType text, OSX.NSStringPboardType
|
||||
|
||||
openURL: (url) ->
|
||||
window.location = url
|
||||
Chrome.title _.last url.replace(/\/$/,'').split '/'
|
||||
|
||||
title: (text) ->
|
||||
WindowController.window.title = text
|
||||
|
||||
toggleFullscreen: ->
|
||||
if Chrome.fullscreen?
|
||||
Chrome.leaveFullscreen()
|
||||
else
|
||||
NSLog("I DON'T KNOW HOW TO DEAL WITH #{position}")
|
||||
Chrome.enterFullscreen()
|
||||
|
||||
# path - Optional. The String path to the file to base it on.
|
||||
createWindow: (path) ->
|
||||
c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
|
||||
c.window
|
||||
c.window.makeKeyAndOrderFront null
|
||||
leaveFullscreen: ->
|
||||
Chrome.fullscreen = false
|
||||
|
||||
# Set the active window's dirty status.
|
||||
setDirty: (bool) ->
|
||||
Chrome.activeWindow().setDocumentEdited bool
|
||||
OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
|
||||
window = WindowController.window
|
||||
|
||||
# Returns a boolean
|
||||
dirty: ->
|
||||
Chrome.activeWindow().isDocumentEdited()
|
||||
enterFullscreen: ->
|
||||
Chrome.fullscreen = true
|
||||
|
||||
# Returns the active NSWindow object
|
||||
activeWindow: ->
|
||||
OSX.NSApplication.sharedApplication.keyWindow
|
||||
OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
|
||||
window = WindowController.window
|
||||
|
||||
# Returns null or a file path.
|
||||
openPanel: ->
|
||||
panel = OSX.NSOpenPanel.openPanel
|
||||
panel.setCanChooseDirectories(true)
|
||||
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
||||
return null
|
||||
panel.filenames.lastObject
|
||||
fullscreenWindow = OSX.NSWindow.alloc.
|
||||
initWithContentRect_styleMask_backing_defer_screen(
|
||||
window.contentRectForFrameRect(window.frame),
|
||||
OSX.NSBorderlessWindowMask,
|
||||
OSX.NSBackingStoreBuffered,
|
||||
true,
|
||||
window.screen)
|
||||
|
||||
# Returns null or a file path.
|
||||
savePanel: ->
|
||||
panel = OSX.NSSavePanel.savePanel
|
||||
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
||||
return null
|
||||
panel.filenames.lastObject
|
||||
contentView = window.contentView
|
||||
window.setContentView OSX.NSView.alloc.init
|
||||
|
||||
writeToPasteboard: (text) ->
|
||||
pb = OSX.NSPasteboard.generalPasteboard
|
||||
pb.declareTypes_owner [OSX.NSStringPboardType], null
|
||||
pb.setString_forType text, OSX.NSStringPboardType
|
||||
fullscreenWindow.setHidesOnDeactivate true
|
||||
fullscreenWindow.setLevel OSX.NSFloatingWindowLevel
|
||||
fullscreenWindow.setContentView contentView
|
||||
fullscreenWindow.setTitle window.title
|
||||
fullscreenWindow.makeFirstResponder null
|
||||
|
||||
openURL: (url) ->
|
||||
window.location = url
|
||||
Chrome.title _.last url.replace(/\/$/,'').split '/'
|
||||
fullscreenWindow.makeKeyAndOrderFront null
|
||||
frame = fullscreenWindow.frameRectForContentRect(fullscreenWindow.screen.frame)
|
||||
fullscreenWindow.setFrame_display_animate frame, true, true
|
||||
|
||||
title: (text) ->
|
||||
WindowController.window.title = text
|
||||
appRoot: ->
|
||||
OSX.NSBundle.mainBundle.resourcePath
|
||||
|
||||
toggleFullscreen: ->
|
||||
if Chrome.fullscreen?
|
||||
Chrome.leaveFullscreen()
|
||||
else
|
||||
Chrome.enterFullscreen()
|
||||
# Handles the file system
|
||||
File =
|
||||
read: (path) ->
|
||||
OSX.NSString.stringWithContentsOfFile File.expand path
|
||||
write: (path, contents) ->
|
||||
str = OSX.NSString.stringWithString contents
|
||||
str.writeToFile_atomically File.expand(path), true
|
||||
expand: (path) ->
|
||||
if /~/.test path
|
||||
OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
|
||||
else if path.indexOf('./') is 0
|
||||
"#{Chrome.appRoot}/#{path}"
|
||||
else
|
||||
path
|
||||
isFile: (path) ->
|
||||
isDir = new outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
|
||||
exists and not isDir.valueOf()
|
||||
|
||||
leaveFullscreen: ->
|
||||
Chrome.fullscreen = false
|
||||
Dir =
|
||||
list: (path, recursive) ->
|
||||
path = File.expand path
|
||||
fm = OSX.NSFileManager.defaultManager
|
||||
if recursive
|
||||
paths = fm.subpathsAtPath path
|
||||
else
|
||||
paths = fm.contentsOfDirectoryAtPath_error path, null
|
||||
_.map paths, (entry) -> "#{path}/#{entry}"
|
||||
isDir: (path) ->
|
||||
isDir = new outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
|
||||
exists and isDir.valueOf()
|
||||
|
||||
OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
|
||||
window = WindowController.window
|
||||
Process =
|
||||
cwd: (path) ->
|
||||
if dir?
|
||||
OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath(path)
|
||||
else
|
||||
OSX.NSFileManager.defaultManager.currentDirectoryPath()
|
||||
|
||||
enterFullscreen: ->
|
||||
Chrome.fullscreen = true
|
||||
env: ->
|
||||
OSX.NSProcess.processInfo.environment()
|
||||
|
||||
OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
|
||||
window = WindowController.window
|
||||
|
||||
fullscreenWindow = OSX.NSWindow.alloc.
|
||||
initWithContentRect_styleMask_backing_defer_screen(
|
||||
window.contentRectForFrameRect(window.frame),
|
||||
OSX.NSBorderlessWindowMask,
|
||||
OSX.NSBackingStoreBuffered,
|
||||
true,
|
||||
window.screen)
|
||||
|
||||
contentView = window.contentView
|
||||
window.setContentView OSX.NSView.alloc.init
|
||||
|
||||
fullscreenWindow.setHidesOnDeactivate true
|
||||
fullscreenWindow.setLevel OSX.NSFloatingWindowLevel
|
||||
fullscreenWindow.setContentView contentView
|
||||
fullscreenWindow.setTitle window.title
|
||||
fullscreenWindow.makeFirstResponder null
|
||||
|
||||
fullscreenWindow.makeKeyAndOrderFront null
|
||||
frame = fullscreenWindow.frameRectForContentRect(fullscreenWindow.screen.frame)
|
||||
fullscreenWindow.setFrame_display_animate frame, true, true
|
||||
|
||||
appRoot: ->
|
||||
OSX.NSBundle.mainBundle.resourcePath
|
||||
|
||||
# Handles the file system
|
||||
File =
|
||||
read: (path) ->
|
||||
OSX.NSString.stringWithContentsOfFile File.expand path
|
||||
write: (path, contents) ->
|
||||
str = OSX.NSString.stringWithString contents
|
||||
str.writeToFile_atomically File.expand(path), true
|
||||
expand: (path) ->
|
||||
if /~/.test path
|
||||
OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
|
||||
else if path.indexOf('./') is 0
|
||||
"#{Chrome.appRoot}/#{path}"
|
||||
else
|
||||
path
|
||||
isFile: (path) ->
|
||||
isDir = new outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
|
||||
exists and not isDir.valueOf()
|
||||
|
||||
Dir =
|
||||
list: (path, recursive) ->
|
||||
path = File.expand path
|
||||
fm = OSX.NSFileManager.defaultManager
|
||||
if recursive
|
||||
paths = fm.subpathsAtPath path
|
||||
else
|
||||
paths = fm.contentsOfDirectoryAtPath_error path, null
|
||||
_.map paths, (entry) -> "#{path}/#{entry}"
|
||||
isDir: (path) ->
|
||||
isDir = new outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
|
||||
exists and isDir.valueOf()
|
||||
|
||||
Process =
|
||||
cwd: (path) ->
|
||||
if dir?
|
||||
OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath(path)
|
||||
else
|
||||
OSX.NSFileManager.defaultManager.currentDirectoryPath()
|
||||
|
||||
env: ->
|
||||
OSX.NSProcess.processInfo.environment()
|
||||
|
||||
exports ?= this # Do we even need this anymore? DOUBT IT!
|
||||
exports.Chrome = Chrome
|
||||
exports.File = File
|
||||
exports.Dir = Dir
|
||||
exports.Chrome = Chrome
|
||||
exports.File = File
|
||||
exports.Dir = Dir
|
||||
|
@ -17,22 +17,20 @@ require = (file) ->
|
||||
__modules[file] = exts[ext]? file
|
||||
__modules[file]
|
||||
|
||||
defines = []
|
||||
define = (cb) ->
|
||||
defines.push ->
|
||||
exports = {}
|
||||
module = exports: exports
|
||||
cb.call exports, require, exports, module
|
||||
exports
|
||||
|
||||
exts =
|
||||
css: (file) -> __read file
|
||||
js: (file) ->
|
||||
code = __read file
|
||||
exports = __modules[file] # Use existing object (if one exists)
|
||||
module = exports: exports
|
||||
|
||||
src = "function define(cb){cb.call(this,require,exports)};"
|
||||
src += """(function(exports, define, module){
|
||||
#{code}
|
||||
/*close open comments*/
|
||||
}).call(exports, exports, define, module);
|
||||
"""
|
||||
eval src
|
||||
|
||||
module.exports
|
||||
code = __read file
|
||||
__jsc__.evalJSString_withScriptPath code, file
|
||||
defines.pop()?.call()
|
||||
|
||||
resolve = (file) ->
|
||||
if /!/.test file
|
||||
@ -83,6 +81,7 @@ __modules = {}
|
||||
|
||||
|
||||
this.require = require
|
||||
this.define = define
|
||||
|
||||
this.require.paths = paths
|
||||
this.require.exts = exts
|
||||
|
@ -71,7 +71,10 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
require('atomicity');
|
||||
require('underscore');
|
||||
require('jquery');
|
||||
require('coffee-script');
|
||||
require('editor');
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user