Merge remote-tracking branch 'origin/dev' into fuzzy

This commit is contained in:
Corey Johnson
2013-01-21 15:20:31 -08:00
5 changed files with 19 additions and 7 deletions

View File

@@ -0,0 +1 @@
This is a hidden file. Don't even try to load it as a snippet

View File

@@ -0,0 +1 @@
This file isn't CSON, but shouldn't be a big deal

View File

@@ -207,12 +207,17 @@ describe "Snippets extension", ->
expect(editor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]]
describe "snippet loading", ->
it "loads snippets from all atom packages with a snippets directory", ->
it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
spyOn(console, 'warn')
jasmine.unspy(AtomPackage.prototype, 'loadSnippets')
snippets.loadAll()
expect(syntax.getProperty(['.test'], 'snippets.test')?.constructor).toBe Snippet
# warn about junk-file, but don't even try to parse a hidden file
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.length).toBe 1
it "loads snippets from all TextMate packages with snippets", ->
jasmine.unspy(TextMatePackage.prototype, 'loadSnippets')
snippets.loadAll()

View File

@@ -4,9 +4,7 @@ fs = require 'fs'
AtomPackage.prototype.loadSnippets = ->
snippetsDirPath = fs.join(@path, 'snippets')
if fs.exists(snippetsDirPath)
for snippetsPath in fs.list(snippetsDirPath)
snippets.load(snippetsPath)
snippets.loadDirectory(snippetsDirPath) if fs.exists(snippetsDirPath)
TextMatePackage.prototype.loadSnippets = ->
snippetsDirPath = fs.join(@path, 'Snippets')

View File

@@ -19,11 +19,18 @@ module.exports =
for pack in atom.getPackages()
pack.loadSnippets()
for snippetsPath in fs.list(@userSnippetsDir)
@load(snippetsPath)
@loadDirectory(@userSnippetsDir) if fs.exists(@userSnippetsDir)
loadDirectory: (snippetsDirPath) ->
for snippetsPath in fs.list(snippetsDirPath) when fs.base(snippetsPath).indexOf('.') isnt 0
snippets.load(snippetsPath)
load: (snippetsPath) ->
@add(fs.readObject(snippetsPath))
try
snippets = fs.readObject(snippetsPath)
catch e
console.warn "Error reading snippets file '#{snippetsPath}'"
@add(snippets)
add: (snippetsBySelector) ->
for selector, snippetsByName of snippetsBySelector