-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fixes handling of CSS file name to theme name #8677
Conversation
You can remove both the options ( |
@@ -83,7 +83,7 @@ define(function (require, exports, module) { | |||
// the name of the file to be unique | |||
|
|||
this.file = file; | |||
this.name = options.name || (options.title || fileName.replace(/.[\w]+$/gi, '')).toLocaleLowerCase().replace(/[\W]/g, '-'); | |||
this.name = options.name || (options.title || fileName.replace(/\.[\w]+$/gi, '')).toLocaleLowerCase().replace(/[\W]/g, '-'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a FileUtils._getFilenameWithoutExtension()
utility... maybe we should just make that public and use it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method only removes the last extension, while I still think we should remove all the extensions.
A regex like
fileName.replace(/\..+$/, "");
could do that.
@MiguelCastillo Why is it that not stripping the extension breaks raw CodeMirror themes? Or did you just mean (in #8673) that the display in the dropdown is uglier? (Seems like the answer to @marcelgerber's question sort of depends on why the extension was a problem in the first place...) |
@peterflynn So, here is a quick rundown. When we process themes as a extensions, there is a package.json with a So, the theme For example, /~https://github.com/adobe/CodeMirror2/blob/master/theme/ambiance.css would generate a class |
@peterflynn You are right, we should just expose _getFilenameWithoutExtension. |
@MiguelCastillo It looks like CodeMirror expects a class of |
Yup, it expects that. How themes work in CM is that you give CM the name of the theme you want to set as the theme... For example you tell CM to set its theme to So, I misspoke. We don't wrap the entire theme with the name of the class. CM handles that. |
I guess the part of confusion which I am having trouble articulating is that we tell CM to load the name of a theme, and CM will take the name and automatically prefix it with So, when I say CM expects that I am really saying that it is expecting that to be in the style file. E.g. ambiance.css will have rules with |
@peterflynn Yes this PR is to strip off the extension to generate "correct" theme names from style files. I will add a comment to explain that. Also, This PR is also to compliment #8673 because I didn't escape the @marcelgerber |
Also added appropriate comments to explain why we need to remove the file extension when the filename is used as the name of the theme
@peterflynn I added some more comments around the whole file extension treatment... I also exposed the getFilenameWithoutExtension so that we don't use a regex. |
You need to remove the |
} | ||
|
||
// We do a bit of string treatment here to make sure we generate theme names that can be | ||
// used as a CSS class names by CodeMirror. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should be name
(singular)
@MiguelCastillo I think that @marcelgerber's point about options.name = FileUtils.getFilenameWithoutExtension(fileName)
.replace(/\.min$/, ""); ...but this is an API that has few consumers (your Themes extension being one of them), so I leave it to you to decide if it's worth handling that special case. |
@dangoor It's not very common to minify theme files, but it can only help if we handled such cases. |
Should I rename the PR to some a less obscure? |
Looks good. Merging. |
Thanks @dangoor! |
Fixes handling of CSS file name to theme name
Fixed issue with regex not properly handling dot in file names without extensions
Here is a link to test the regex http://regex101.com/r/iI6oQ0/2