Skip to content

Commit

Permalink
Merge pull request adobe#8677 from MiguelCastillo/fonts-filename
Browse files Browse the repository at this point in the history
Fixes handling of CSS file name to theme name
  • Loading branch information
dangoor committed Aug 7, 2014
2 parents 9efe765 + b2fa881 commit bcf91c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/file/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,11 @@ define(function (require, exports, module) {
}

/**
* @private
* Get the file name without the extension.
* @param {string} filename File name of a file or directory
* @return {string} Returns the file name without the extension
*/
function _getFilenameWithoutExtension(filename) {
function getFilenameWithoutExtension(filename) {
var index = filename.lastIndexOf(".");
return index === -1 ? filename : filename.slice(0, index);
}
Expand All @@ -452,8 +451,8 @@ define(function (require, exports, module) {
cmpNames;

if (brackets.platform === "win") {
filename1 = _getFilenameWithoutExtension(filename1);
filename2 = _getFilenameWithoutExtension(filename2);
filename1 = getFilenameWithoutExtension(filename1);
filename2 = getFilenameWithoutExtension(filename2);
}
cmpNames = filename1.toLocaleLowerCase().localeCompare(filename2.toLocaleLowerCase(), undefined, {numeric: true});

Expand Down Expand Up @@ -516,6 +515,7 @@ define(function (require, exports, module) {
exports.getDirectoryPath = getDirectoryPath;
exports.getBaseName = getBaseName;
exports.getRelativeFilename = getRelativeFilename;
exports.getFilenameWithoutExtension = getFilenameWithoutExtension;
exports.getFileExtension = getFileExtension;
exports.getSmartFileExtension = getSmartFileExtension;
exports.compareFilenames = compareFilenames;
Expand Down
21 changes: 18 additions & 3 deletions src/view/ThemeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,26 @@ define(function (require, exports, module) {
options = options || {};
var fileName = file.name;

// Portip: If no options.name or options.title is provided, then we will rely solely on
// the name of the file to be unique
// If no options.name is provided, then we derive the name of the theme from whichever we find
// first, the options.title or the filename.
if (!options.name) {
if (options.title) {
options.name = options.title;
} else {
// Remove the file extension when the filename is used as the theme name. This is to
// follow CodeMirror conventions where themes are just a CSS file and the filename
// (without the extension) is used to build CSS rules. Also handle removing .min
// in case the ".min" is part of the file name.
options.name = FileUtils.getFilenameWithoutExtension(fileName).replace(/\.min$/, "");
}

// We do a bit of string treatment here to make sure we generate theme names that can be
// used as a CSS class name by CodeMirror.
options.name = options.name.toLocaleLowerCase().replace(/[\W]/g, '-');
}

this.file = file;
this.name = options.name || (options.title || fileName.replace(/.[\w]+$/gi, '')).toLocaleLowerCase().replace(/[\W]/g, '-');
this.name = options.name;
this.displayName = options.title || toDisplayName(fileName);
this.dark = options.theme !== undefined && options.theme.dark === true;
}
Expand Down

0 comments on commit bcf91c5

Please sign in to comment.