mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Handle reading and writing in cson.coffee
Moves helpers from fs.coffee to cson.coffee
This commit is contained in:
@@ -2,6 +2,7 @@ Package = require 'package'
|
||||
fs = require 'fs'
|
||||
_ = nodeRequire 'underscore'
|
||||
$ = require 'jquery'
|
||||
CSON = require 'cson'
|
||||
|
||||
module.exports =
|
||||
class AtomPackage extends Package
|
||||
@@ -69,7 +70,7 @@ class AtomPackage extends Package
|
||||
|
||||
loadMetadata: ->
|
||||
if metadataPath = fs.resolveExtension(fs.join(@path, 'package'), ['cson', 'json'])
|
||||
@metadata = fs.readObject(metadataPath)
|
||||
@metadata = CSON.readObject(metadataPath)
|
||||
@metadata ?= {}
|
||||
|
||||
loadKeymaps: ->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
fs = require 'fs'
|
||||
Theme = require 'theme'
|
||||
CSON = require 'cson'
|
||||
|
||||
module.exports =
|
||||
class AtomTheme extends Theme
|
||||
@@ -13,7 +14,7 @@ class AtomTheme extends Theme
|
||||
else
|
||||
metadataPath = fs.resolveExtension(fs.join(@path, 'package'), ['cson', 'json'])
|
||||
if fs.isFile(metadataPath)
|
||||
stylesheetNames = fs.readObject(metadataPath)?.stylesheets
|
||||
stylesheetNames = CSON.readObject(metadataPath)?.stylesheets
|
||||
if stylesheetNames
|
||||
@loadStylesheet(fs.join(@path, name)) for name in stylesheetNames
|
||||
else
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
fs = require 'fs'
|
||||
_ = nodeRequire 'underscore'
|
||||
EventEmitter = require 'event-emitter'
|
||||
CSON = require 'cson'
|
||||
|
||||
configDirPath = fs.absolute("~/.atom")
|
||||
bundledPackagesDirPath = fs.join(resourcePath, "src/packages")
|
||||
@@ -55,7 +56,7 @@ class Config
|
||||
|
||||
loadUserConfig: ->
|
||||
if fs.exists(@configFilePath)
|
||||
userConfig = fs.readObject(@configFilePath)
|
||||
userConfig = CSON.readObject(@configFilePath)
|
||||
_.extend(@settings, userConfig)
|
||||
|
||||
get: (keyPath) ->
|
||||
@@ -96,6 +97,6 @@ class Config
|
||||
@trigger 'updated'
|
||||
|
||||
save: ->
|
||||
fs.writeObject(@configFilePath, @settings)
|
||||
CSON.writeObject(@configFilePath, @settings)
|
||||
|
||||
_.extend Config.prototype, EventEmitter
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
$ = require 'jquery'
|
||||
_ = nodeRequire 'underscore'
|
||||
fs = require 'fs'
|
||||
CSON = require 'cson'
|
||||
|
||||
BindingSet = require 'binding-set'
|
||||
|
||||
@@ -39,7 +40,7 @@ class Keymap
|
||||
@load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json'])
|
||||
|
||||
load: (path) ->
|
||||
@add(fs.readObject(path))
|
||||
@add(CSON.readObject(path))
|
||||
|
||||
add: (keymap) ->
|
||||
for selector, bindings of keymap
|
||||
|
||||
@@ -2,14 +2,15 @@ _ = nodeRequire 'underscore'
|
||||
fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
Token = require 'token'
|
||||
CSON = require 'cson'
|
||||
{OnigRegExp, OnigScanner} = nodeRequire 'oniguruma'
|
||||
|
||||
module.exports =
|
||||
class TextMateGrammar
|
||||
@readFromPath: (path) ->
|
||||
grammarContent = null
|
||||
if fs.isObjectPath(path)
|
||||
grammarContent = fs.readObject(path)
|
||||
if CSON.isObjectPath(path)
|
||||
grammarContent = CSON.readObject(path)
|
||||
else
|
||||
plist.parseString fs.read(path), (e, data) ->
|
||||
throw new Error(e) if e
|
||||
|
||||
@@ -3,6 +3,7 @@ fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
_ = nodeRequire 'underscore'
|
||||
TextMateGrammar = require 'text-mate-grammar'
|
||||
CSON = require 'cson'
|
||||
|
||||
module.exports =
|
||||
class TextMatePackage extends Package
|
||||
@@ -76,8 +77,8 @@ class TextMatePackage extends Package
|
||||
readObjectFromPath: (path, callback) ->
|
||||
object = null
|
||||
error = null
|
||||
if fs.isObjectPath(path)
|
||||
object = fs.readObject(path)
|
||||
if CSON.isObjectPath(path)
|
||||
object = CSON.readObject(path)
|
||||
else
|
||||
plist.parseString fs.read(path), (e, data) ->
|
||||
error = e
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
fs = require 'fs'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
SnippetBodyParser = require './snippet-body-parser'
|
||||
CSON = require 'cson'
|
||||
|
||||
module.exports =
|
||||
snippetsLoaded: (snippets) ->
|
||||
@@ -20,7 +21,7 @@ module.exports =
|
||||
|
||||
continue if fs.base(snippetsPath).indexOf('.') is 0
|
||||
try
|
||||
if fs.isObjectPath(snippetsPath) and object = fs.readObject(snippetsPath)
|
||||
if CSON.isObjectPath(snippetsPath) and object = CSON.readObject(snippetsPath)
|
||||
snippets.push(object)
|
||||
else if object = fs.readPlist(snippetsPath)
|
||||
snippets.push(object)
|
||||
@@ -37,7 +38,7 @@ module.exports =
|
||||
for snippetsPath in fs.list(snippetsDirPath)
|
||||
continue if fs.base(snippetsPath).indexOf('.') is 0
|
||||
try
|
||||
snippets.push(fs.readObject(snippetsPath))
|
||||
snippets.push(CSON.readObject(snippetsPath))
|
||||
catch e
|
||||
console.warn "Error reading snippets file '#{snippetsPath}'"
|
||||
@snippetsLoaded(snippets)
|
||||
|
||||
@@ -4,6 +4,7 @@ _ = nodeRequire 'underscore'
|
||||
SnippetExpansion = require './snippet-expansion'
|
||||
Snippet = require './snippet'
|
||||
LoadSnippetsTask = require './load-snippets-task'
|
||||
CSON = require 'cson'
|
||||
|
||||
module.exports =
|
||||
snippetsByExtension: {}
|
||||
@@ -28,7 +29,7 @@ module.exports =
|
||||
|
||||
loadFile: (snippetsPath) ->
|
||||
try
|
||||
snippets = fs.readObject(snippetsPath)
|
||||
snippets = CSON.readObject(snippetsPath)
|
||||
catch e
|
||||
console.warn "Error reading snippets file '#{snippetsPath}'"
|
||||
@add(snippets)
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
_ = nodeRequire 'underscore'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
isObjectPath: (path) ->
|
||||
extension = fs.extension(path)
|
||||
extension is '.cson' or extension is '.json'
|
||||
|
||||
readObject: (path) ->
|
||||
contents = fs.read(path)
|
||||
if fs.extension(path) is '.cson'
|
||||
CoffeeScript = nodeRequire 'coffee-script'
|
||||
CoffeeScript.eval(contents, bare: true)
|
||||
else
|
||||
JSON.parse(contents)
|
||||
|
||||
writeObject: (path, object) ->
|
||||
if fs.extension(path) is '.cson'
|
||||
content = @stringify(object)
|
||||
else
|
||||
content = JSON.stringify(object, undefined, 2)
|
||||
fs.write(path, "#{content}\n")
|
||||
|
||||
stringifyIndent: (level=0) -> _.multiplyString(' ', Math.max(level, 0))
|
||||
|
||||
stringifyString: (string) ->
|
||||
|
||||
@@ -212,26 +212,6 @@ module.exports =
|
||||
base = @base(path, extension).toLowerCase()
|
||||
base is 'readme' and (extension is '' or @isMarkdownExtension(extension))
|
||||
|
||||
isObjectPath: (path) ->
|
||||
extension = @extension(path)
|
||||
extension is '.cson' or extension is '.json'
|
||||
|
||||
readObject: (path) ->
|
||||
contents = @read(path)
|
||||
if @extension(path) is '.cson'
|
||||
CoffeeScript = nodeRequire 'coffee-script'
|
||||
CoffeeScript.eval(contents, bare: true)
|
||||
else
|
||||
JSON.parse(contents)
|
||||
|
||||
writeObject: (path, object) ->
|
||||
if @extension(path) is '.cson'
|
||||
CSON = require 'cson'
|
||||
content = CSON.stringify(object)
|
||||
else
|
||||
content = JSON.stringify(object, undefined, 2)
|
||||
@write(path, "#{content}\n")
|
||||
|
||||
readPlist: (path) ->
|
||||
plist = require 'plist'
|
||||
object = null
|
||||
|
||||
Reference in New Issue
Block a user