How to define the default grammar for new file extensions - atom-editor

I'm opening files in Atom with a new file extension, a file extension that is not recognized by any of the existing grammars (i.e. Plain Test, C, C#, etc.). How can I associate my new file extension with one of the already-available grammars?
Success is being able to open a file with my new file extension and have Atom default to my chosen grammar automatically.
I tried the suggestion but Atom bounced it back at me:
customFileTypes:
"source.fs": [
"*.seedsource"
]

For personal use, you can register a custom file type in the Atom config file (config.cson by default).
Here's a minimal example of what config.cson might look like. Make sure to insert the customFileTypes part at the correct indentation, since CSON files are indentation-sensitive.
"*":
core:
customFileTypes:
"source.c": [
"*.custom-extension"
]
If you want to share this configuration with other users, it's probably better to create a package that contains a grammar file (e.g. grammars/custom.cson):
fileTypes: [
"custom-extension"
]
patterns: [
{
include: "source.c"
}
]
scopeName: "source.c.custom"
In both cases, example.custom-extension would be opened with C syntax highlighting.

Related

Live SASS Compiler creating extra files?

I'm currently trying to learn how to implement SASS into my web development projects but I'm struggling a little bit with figuring out how to properly compile my .scss files into one single .css file.
When I run sass --version in my terminal, I receive 1.53.0 compiled with dart2js 2.17.3. As far as extensions go, I'm using Live Sass Compiler by Glenn Marks, and within the settings.json file, my configuration looks like this:
{
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
},
],
"liveSassCompile.settings.excludeList": [
"**/node_modules/**",
".vscode/**"
],
"liveSassCompile.settings.generateMap": true,
"liveSassCompile.settings.autoprefix": [
"defaults"
]
}
This is my current project directory:
Current Project Directory Structure
My current issue is that whenever I click Watch Sass, the only file I want to be output is the main.css and main.css.map but it creates an index.css and index.css.map file as well.
I'm trying to implement something similar to the 7 - 1 SASS Architecture, and within each of those folders I created an index.scss that'll contain each file in it's directory, which will then be #forward to the main.scss.
Is there any particular way I can avoid the extra files being created? I'm not too familiar with npm but I've heard it would be more beneficial to learn it in order to utilize SASS as opposed to using a VS Code extension and I'm more than open to taking that approach and scrapping the entire extension as a whole if it proves to be more efficient.
Thank you for your help in advanced, I hope I provided enough information!
Dart sass comes with an inbuilt compiler
Just run the code
sass --watch sass/main.scss css/main.css
This one faulty line is probably the reason for your problem.
Change this:
"liveSassCompile.settings.generateMap": true,
to this:
"liveSassCompile.settings.generateMap": false,
If you decide to stick with my extension then you can specify a single file to output/watch with the liveSassCompile.settings.includeItems setting - as shown below
{
"liveSassCompile.settings.includeItems": [ "/path/to/main.scss" ]
}
Alternatively, and possibly a better solution, you can use a negative glob expression in the liveSassCompile.settings.partialsList to treat every other file as a partial. Then, when any SASS file is saved, it triggers compilation of just your main.scss file

How do I change sass output directory?

I have this folder structure:
sass/main.sass
css/main.css
js/...
img/...
I want the sass output to go to the css folder, but each time I run sass watcher it creates a new css file within the sass directory among sass files.
Thx for information about using 'Live SASS Compiler' in VS Code.
To set special otuput pathes to your project you need to add the settings for output pathes to the settigns.json of your project:
File: `projectDIR/.vscode/settings.json'
Example for setting the save pathes to output directory:
"settings": {
// output: generate files to ...
// ~ = path starts relative from scss-file
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "~/../assets"
},
// ad a compressed version
{
"format": "compressed",
"extensionName": ".min.css",
"savePath": "~/../assets"
}
// optional: add more outputs ...
],
}
See also official example in web: https://github.com/ritwickdey/vscode-live-sass-compiler/blob/master/docs/settings.md
Additional hint:
VERSION OFF 'LIVE SASS COMPILER' MAY BE OUTDATED
The actual commmon used Extension Live Sass Compiler is not longer supported (for years now). It uses an outdated SASS Version. The most recent features like #use are not supported in that version. You use that outdated version if author is 'Ritwick Dey'.
But there is an active supported fork with same name 'Live SASS Compiler' build by 'Glenn Marks'. As fork it works the same way and the settings are almost the same. Or you can use another actual compiler which is faster as you can use an direct installed SASS Version on your system. In that case you need to change the settings for your project.
Information about that you will find here:
https://stackoverflow.com/a/66207572/9268485
Updated: Correction name of author of supported extension 'Live SASS Compiler' to correct identification of extension.
Go to path: C:\Users\your user\AppData\Roaming\Code\User\settings.json
and change there the "liveSassCompile.settings.formats" section
for example:
the parameter : "savePath": "/Python/CSS",

How to update Site.less/site.css and bundle/minify to generate output with BuildBundlerMinifier

I have several questions on my ASP.NET MVC CORE 2.2 project.
The main goal is very simple, i want to update my stylesheet and then deploy this result. I have a Site.less, site.css, site.min.css, site.min.css.gz that i want to update with a css class style, a bundleconfig.json with my input css, javascript files to be bundled and a compilerconfig.json that has Site.less as an input and site.css as output. I also have BuildBundlerMinifier installed on my project (NuGet).
Questions:
1- What file should i update when adding some new style: Site.less, site.css or both?
2- What are the steps to minify and bundle before i publish my app?
bundleconfig.json:
[
{
"outputFileName": "wwwroot/css/bundle.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
(...)
"wwwroot/css/Site.min.css"
]
},
(...)
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
compilerconfig.json
[
{
"inputFile": "wwwroot/css/Site.less",
"outputFile": "wwwroot/css/site.css"
}
]
When i rebuild my project in my Output window (Visual Studio 2017) i have the following messages.
Cleaning output from bundleconfig.json,
Done cleaning output file from bundleconfig.json, Begin processing bundleconfig.json, Minified wwwroot/css/bundle.min.css, Done processing bundleconfig.json
Thank you.
My first question is answered.
I have installed an extension in Visual Studio 2017 (Tools -> Extensions and Updates) named Web Compiler. When i make an update in my less file, the css file and min.css are auto generated (min.css.gz is not and don't know why). The files that the code is auto generated are water marked with Generated keyword.
To produce the auto generated files you only need to rebuild the project.
This works with other files but in my case i am only using this ones.
EDIT
My second question is also answered.
I have installed another extension: Bundler & Minifier
To produce bundle you need to have those config json files i have posted in my first post and then open Task Runner Explorer and double click on wwwroot/css/bundle.min.css (inside StyleSheets menu) and the bundle file will be auto generated.

Open cshtml files as HTML in Atom

Based on this issue (https://github.com/atom/atom/issues/1718) from atom's github concerning the customFileTypes option, I have the following in my config.cson.
"*":
core:
customFileTypes:
"source.html": [
"cshtml"
]
My intention is for cshtml files to be automatically opened with the HTML grammar for syntax highlighting, however, my cshtml files still open as Plain Text.
If I change "source.html" to "source.gfm", then my cshtml files open as Github Flavoured Markdown, so I suspect that "source.html" isn't the name I should be using.
How can I get this to work? And, where can I get a list of names for grammars?
Made this work by using text.html.basic as the scope name, so my config looks like this:
"*":
core:
customFileTypes:
"text.html.basic": [
"cshtml"
]
To get a list of eligible scope names, open the Atom console (Ctrl+Alt+I in Windows, Ctrl+Shift+I in Linux) and run Object.keys(atom.grammars.grammarsByScopeName).
You get an array in return, so Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n') will give you a nicely sorted list.
In case you want to display the file with the ASP.NET Razor theme (standard for .cshtml files), go ahead and do the following:
Download the language-cshtml package
https://atom.io/packages/language-cshtml
Change you ~/.atom/config.cson to include the following:
"*":
core:
customFileTypes:
"text.html.cshtml": "cshtml"

Grunt-init copyAndProcess function: Can I pass in multiple values to 'noProcess' option?

I'm using grunt-init to build a template for a site structure I repeat regularly.
The template.js file uses the init.copyAndProcess function to customize most of files but a few of them get corrupted by the file processing (some fonts and image files) and I want to include those files in the 'noProcess' option. If these files all existed in the same directory, I could use the noProcess option as mentioned in the documentation [ See: http://gruntjs.com/project-scaffolding#copying-files ] and pass in a string like and it works:
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: 'app/fonts/**'} );
Unfortunately the files that I need to have no processing performed on are not all in the same directory and I'd like to be able to pass in an array of them, something like the following block of code, but this does not work.
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: ['app/fonts/**', 'app/images/*.png', 'app/images/*.jpg']} );
Any thoughts on how I can have multiple targets for the 'noProcess' option?
As soon as I posted the question, I realized that my proposed code did work. I simply had an invalid path when I'd renamed my 'app' directory to 'dev'.

Resources