mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Use path.extname() instead of fsUtils.extension()
This commit is contained in:
parent
341a327ea0
commit
bdb641ec94
@ -1,8 +1,9 @@
|
||||
window.nakedLoad = (file) ->
|
||||
fsUtils = require 'fs-utils'
|
||||
path = require 'path'
|
||||
file = require.resolve(file)
|
||||
code = fsUtils.read(file)
|
||||
if fsUtils.extension(file) is '.coffee'
|
||||
if path.extname(file) is '.coffee'
|
||||
require('coffee-script').eval(code, filename: file)
|
||||
else
|
||||
window.eval("#{code}\n//@ sourceURL=#{file}")
|
||||
|
@ -54,14 +54,6 @@ describe "fsUtils", ->
|
||||
expect(fsUtils.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"]
|
||||
expect(fsUtils.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"]
|
||||
|
||||
describe ".extension(path)", ->
|
||||
it "returns the extension of a file", ->
|
||||
expect(fsUtils.extension("a/b/corey.txt")).toBe '.txt'
|
||||
expect(fsUtils.extension("a/b/corey.txt.coffee")).toBe '.coffee'
|
||||
|
||||
it "returns an empty string for paths without an extension", ->
|
||||
expect(fsUtils.extension("a/b.not-extension/a-dir")).toBe ''
|
||||
|
||||
describe ".makeTree(path)", ->
|
||||
beforeEach ->
|
||||
fsUtils.remove("/tmp/a") if fsUtils.exists("/tmp/a")
|
||||
|
@ -1,4 +1,5 @@
|
||||
fsUtils = require 'fs-utils'
|
||||
path = require 'path'
|
||||
Theme = require 'theme'
|
||||
|
||||
# Internal: Represents a theme that Atom can use.
|
||||
@ -13,7 +14,7 @@ class AtomTheme extends Theme
|
||||
|
||||
# Loads the stylesheets found in a `package.cson` file.
|
||||
load: ->
|
||||
if fsUtils.extension(@path) in ['.css', '.less']
|
||||
if path.extname(@path) in ['.css', '.less']
|
||||
@loadStylesheet(@path)
|
||||
else
|
||||
metadataPath = fsUtils.resolveExtension(fsUtils.join(@path, 'package'), ['cson', 'json'])
|
||||
|
@ -1,4 +1,5 @@
|
||||
fsUtils = require 'fs-utils'
|
||||
path = require 'path'
|
||||
$ = require 'jquery'
|
||||
less = require 'less'
|
||||
ipc = require 'ipc'
|
||||
@ -140,46 +141,46 @@ window.deserializeConfigWindow = ->
|
||||
window.stylesheetElementForId = (id) ->
|
||||
$("""head style[id="#{id}"]""")
|
||||
|
||||
window.resolveStylesheet = (path) ->
|
||||
if fsUtils.extension(path).length > 0
|
||||
fsUtils.resolveOnLoadPath(path)
|
||||
window.resolveStylesheet = (stylesheetPath) ->
|
||||
if path.extname(stylesheetPath).length > 0
|
||||
fsUtils.resolveOnLoadPath(stylesheetPath)
|
||||
else
|
||||
fsUtils.resolveOnLoadPath(path, ['css', 'less'])
|
||||
fsUtils.resolveOnLoadPath(stylesheetPath, ['css', 'less'])
|
||||
|
||||
window.requireStylesheet = (path) ->
|
||||
if fullPath = window.resolveStylesheet(path)
|
||||
window.requireStylesheet = (stylesheetPath) ->
|
||||
if fullPath = window.resolveStylesheet(stylesheetPath)
|
||||
content = window.loadStylesheet(fullPath)
|
||||
window.applyStylesheet(fullPath, content)
|
||||
else
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
throw new Error("Could not find a file at path '#{stylesheetPath}'")
|
||||
|
||||
window.loadStylesheet = (path) ->
|
||||
if fsUtils.extension(path) == '.less'
|
||||
loadLessStylesheet(path)
|
||||
window.loadStylesheet = (stylesheetPath) ->
|
||||
if path.extname(stylesheetPath) is '.less'
|
||||
loadLessStylesheet(stylesheetPath)
|
||||
else
|
||||
fsUtils.read(path)
|
||||
fsUtils.read(stylesheetPath)
|
||||
|
||||
window.loadLessStylesheet = (path) ->
|
||||
window.loadLessStylesheet = (lessStylesheetPath) ->
|
||||
parser = new less.Parser
|
||||
syncImport: true
|
||||
paths: config.lessSearchPaths
|
||||
filename: path
|
||||
filename: patlessStylesheetPath
|
||||
try
|
||||
content = null
|
||||
parser.parse fsUtils.read(path), (e, tree) ->
|
||||
parser.parse fsUtils.read(lessStylesheetPath), (e, tree) ->
|
||||
throw e if e?
|
||||
content = tree.toCSS()
|
||||
content
|
||||
catch e
|
||||
console.error """
|
||||
Error compiling less stylesheet: #{path}
|
||||
Error compiling less stylesheet: #{lessStylesheetPath}
|
||||
Line number: #{e.line}
|
||||
#{e.message}
|
||||
"""
|
||||
|
||||
window.removeStylesheet = (path) ->
|
||||
unless fullPath = window.resolveStylesheet(path)
|
||||
throw new Error("Could not find a file at path '#{path}'")
|
||||
window.removeStylesheet = (stylesheetPath) ->
|
||||
unless fullPath = window.resolveStylesheet(stylesheetPath)
|
||||
throw new Error("Could not find a file at path '#{stylesheetPath}'")
|
||||
window.stylesheetElementForId(fullPath).remove()
|
||||
|
||||
window.applyStylesheet = (id, text, ttype = 'bundled') ->
|
||||
|
@ -49,7 +49,7 @@ class FuzzyFinderView extends SelectList
|
||||
else if git.isStatusModified(status)
|
||||
@div class: 'status modified'
|
||||
|
||||
ext = fsUtils.extension(filePath)
|
||||
ext = path.extname(filePath)
|
||||
if fsUtils.isReadmePath(filePath)
|
||||
typeClass = 'readme-name'
|
||||
else if fsUtils.isCompressedExtension(ext)
|
||||
|
@ -14,7 +14,7 @@ class ImageEditSession
|
||||
imageExtensions = ['.gif', '.jpeg', '.jpg', '.png']
|
||||
Project = require 'project'
|
||||
Project.registerOpener (filePath) ->
|
||||
if _.include(imageExtensions, fsUtils.extension(filePath))
|
||||
if _.include(imageExtensions, path.extname(filePath))
|
||||
new ImageEditSession(filePath)
|
||||
|
||||
@deserialize: ({path}={}) ->
|
||||
|
@ -22,7 +22,7 @@ class Dialog extends View
|
||||
@miniEditor.setText(initialPath)
|
||||
|
||||
if select
|
||||
extension = fsUtils.extension(initialPath)
|
||||
extension = path.extname(initialPath)
|
||||
baseName = path.basename(initialPath)
|
||||
if baseName is extension
|
||||
selectionEnd = initialPath.length
|
||||
|
@ -1,6 +1,7 @@
|
||||
{View} = require 'space-pen'
|
||||
$ = require 'jquery'
|
||||
fsUtils = require 'fs-utils'
|
||||
path = require 'path'
|
||||
|
||||
module.exports =
|
||||
class FileView extends View
|
||||
@ -16,7 +17,7 @@ class FileView extends View
|
||||
if @file.symlink
|
||||
@fileName.addClass('symlink-icon')
|
||||
else
|
||||
extension = fsUtils.extension(@getPath())
|
||||
extension = path.extname(@getPath())
|
||||
if fsUtils.isReadmePath(@getPath())
|
||||
@fileName.addClass('readme-icon')
|
||||
else if fsUtils.isCompressedExtension(extension)
|
||||
|
@ -773,7 +773,7 @@ describe "TreeView", ->
|
||||
waits 50 # The move specs cause too many false positives because of their async nature, so wait a little bit before we cleanup
|
||||
|
||||
it "opens a move dialog with the file's current path (excluding extension) populated", ->
|
||||
extension = fsUtils.extension(filePath)
|
||||
extension = path.extname(filePath)
|
||||
fileNameWithoutExtension = path.basename(filePath, extension)
|
||||
expect(moveDialog).toExist()
|
||||
expect(moveDialog.prompt.text()).toBe "Enter the new path for the file."
|
||||
|
@ -35,18 +35,6 @@ module.exports =
|
||||
exists: (path) ->
|
||||
path? and fs.existsSync(path)
|
||||
|
||||
# Returns the extension of a file. The extension of a file is the
|
||||
# last dot (excluding any number of initial dots) followed by one or
|
||||
# more non-dot characters. Returns an empty string if no valid
|
||||
# extension exists.
|
||||
extension: (path) ->
|
||||
return '' unless typeof path is 'string'
|
||||
match = Path.basename(path).match(/\.[^\.]+$/)
|
||||
if match
|
||||
match[0]
|
||||
else
|
||||
""
|
||||
|
||||
join: (paths...) ->
|
||||
return paths[0] if paths.length == 1
|
||||
[first, rest...] = paths
|
||||
@ -113,8 +101,7 @@ module.exports =
|
||||
ext
|
||||
else
|
||||
'.' + ext.replace(/^\./, '')
|
||||
paths.filter (path) =>
|
||||
_.include(extensions, @extension(path))
|
||||
paths.filter (path) -> _.include(extensions, Path.extname(path))
|
||||
|
||||
listTree: (rootPath) ->
|
||||
paths = []
|
||||
@ -309,7 +296,7 @@ module.exports =
|
||||
], ext, true) >= 0
|
||||
|
||||
isReadmePath: (path) ->
|
||||
extension = @extension(path)
|
||||
extension = Path.extname(path)
|
||||
base = Path.basename(path, extension).toLowerCase()
|
||||
base is 'readme' and (extension is '' or @isMarkdownExtension(extension))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user