Auto compile SCSS files in Sublime Text 2 - sass

Ok, here is what I want:
I write .scss files, not .sass files
On saving the file, I get the corresponding .css file in the same folder
Now there are plenty of SASS plugins on Sublime Text2 but none seems to provide anything beyond syntax highlighting for me.
Any suggestions on how to get auto-compiling working on Sublime Text2.

I didn't find any existing plugins that did this, so here it is:
Assuming you've installed the SCSS plugin from Package Control, you can save this as Packages/User/SCSS.py.
import sublime_plugin
import subprocess
import os
from threading import Thread
def compile(input_file):
output_file = os.path.splitext(input_file)[0] + ".css"
cmd = "sass '{0}':'{1}'".format(input_file, output_file)
subprocess.call(cmd, shell=True)
class SCSS(sublime_plugin.EventListener):
def on_post_save(self, view):
scope = (view.syntax_name(view.sel()[0].b)).split().pop()
if scope == "source.scss":
input_file = view.file_name()
t = Thread(target=compile, args=(input_file,))
t.start()
Of course, this would be better as an official Package Control plugin with user configurable settings (where to save files, on/off, etc), but this meets your requirements and doesn't block the editor.

You should consider to use build system instead of dedicated plugin of it. It's very simple to do.
http://docs.sublimetext.info/en/latest/file_processing/build_systems.html
Something like this:
{
"cmd": ["sass","$file"],
"selector": "source.scss",
"path": "/usr/local/bin"
}
And just hit ctrl + b t build current file. If you have multiple builds for scss you can select one from build menu (Tools -> Build Systems).

You could use SublimeOnSaveBuild plugin.
And in plugin filter settings just leave .scss files!
It's works for just great!

I was looking for a sass/scss compiler plugin for Sublime Test, but I have my source folders separate from my css folders. So, going off the comments left on here I wrote SassBuilder that runs off a config file stored in your source folder. It has also been submitted to the Sublime Package Control repository. Once they pull the request, you can install it from there.
SassBuilder on github

Sass Builder is the new plugin which is available in Package Manager of sublime text.
This does not require any configuration. Just write your scss and hit cmd + b to compile.
Your css file will be generated in the same folder as scss.

Related

Run tag-dependent Python script on Sphinx build

I need to run a simple Python script to copy a set of files from one directory to another during the build-phase of my Sphinx documentation.
Copying function:
location: source/_plugins/copy_firmware_files.py
import json, os, sys
from pathlib import Path
import shutil
def copy_firmware_files(device):
# copy firmware files
I'm currently importing this module into my conf.py as the Configuration File contains the device name, which would make it a simple way to execute the code. I'm currently doing this as below:
Configuration File (conf.py)
location: source/conf.py
sys.path.append(os.path.abspath("_plugins"))
from copy_firmware_files import *
# initialize files depending on build
copy_firmware_files(device_name)
The above works as intended, i.e. the relevant files are copied to their respective folders before the build. However, I'm unsure if it's the "proper" way to do so. Is there a more correct way of achieving the same result?
There are several ways, but it sounds like two are most appropriate. They are static files and could be treated as such by Sphinx.
html_extra_path is one option.
If you want to present links to download the files, you can use the download directive.
See :download:`this example script <../example.py>`.

How do I refactor module name in Go?

I have a Go module named mymodule, and I'd like to rename it into github.com/hylowaker/awesome-module
Using command go mod edit -module github.com/hylowaker/awesome-module only changes module name in go.mod file, leaving go sources unchanged. I tried Refactor feature in GoLand IDE, but GoLand does not allow renaming with slash(/) characters.
So I had to find and replace every import "mymodule/..." into import "github.com/hylowaker/awesome-module/... from my source files.
Is there a better way to refactor them?
This feature is introduced in GoLand version 2021.1.
You can invoke the Rename refactoring by pressing Shift+F6 on the module name in the go.mod file.
In GoLand just press Ctrl+Shift+R and execute "Replace in Path"
It is safe to perform that in entire project since you only need to change go.mod file and all import clauses

Watch a folder, use a specific entry point, then output a single css file

I have a folder of SCSS files. The main SCSS file is /css/app.scss. It imports all the other SCSS files, like /css/variables.scss and /css/component_a.scss.
How can I have sass watch my /css/ folder for any changes, then recompile starting from /css/app.scss?
Right now it errors since /css/component_a.scss uses variables defined in a different file. But in app.scss they are imported in the correct order.
My answer may be limited because I don't have all the information about how you are compiling sass and what settings you are using.
However I can see that your file names aren't prefixed with an underscore, basically sass will compile every file individually that doesn't have the '_' prefix.
Basically what you want to do is set up your task manager (grunt, gulp, etc) to watch all files ending with '.scss' then tell it to run the sass compile task and have this pointed at your app.scss file.
With the limited information I have from your question I hope that my answer points you in the right direction to solve your problem.

how to write package for sublimeREPL

The SublimeREPL plugin for ST supports lots of languages, but not all of them. It also supports writing your own configuration file for any non-default languages. Once you've written this configuration, is there any way to include it in a regular Sublime Text plugin so that when installed along with SublimeREPL it will work and support the desired language?
This turned out not to be so bad. What I wanted was to be able to distribute files in a package that would work with SublimeREPL without the user moving the files. All of the tutorials I found involved having the user place command and menu files in the SublimeREPL package directory.
Sublime Text doesn't care where it finds configuration files; they're all loaded no matter where in the packages directory they are found. Main.sublime-menu adds to the main menu and *.sublime-commands add commands.
First, fill in and rename Main.sublime-menu.template. Then do a Default.sublime-commands as well (couldn't find a template):
[
{
"caption": "SublimeREPL: XYZ Console",
"command": "run_existing_window_command", "args":
{
"id": "repl_xyz",
"file": "../XYZ-package/Main.sublime-menu"
}
}
]
The thing that was confusing me was how to refer to the menu file from the commands file, but it's simple; SublimeREPL uses the SublimeREPL as the working directory, so simply make a path from there to the menu file in your own package: ../XYZ-package/Main.sublime-menu.
Add these completed files to your package and they will work just fine with SublimeREPL.

Can't use Stylus #import with Rake Pipeline

I have a simple Rake Pipeline setup that does nothing more than run "stylus" on my .styl files, using the rake-pipeline-web-filters gem. (The original pipeline does much more, but I've trimmed it down to the essentials for this question.
=== Assetfile ===
require "rake-pipeline-web-filters"
output "build"
input "app/style" do
# Compile Stylus to CSS
match "*.styl" do
stylus
end
end
This works fine for converting individual .styl files to individual .css files.
However, I am not able to use the Stylus #import command to import one file in another (necessary for mixins, among other things. Instead I get the error
ExecJS::ProgramError: Error: stylus:1
> 1| #import "appmixins"
2|
failed to locate #import file appmixins.styl
All the styl files are in the same folder, and when I execute stylus on the commandline using the npm version, the import works fine, so there's no syntax error.
Is this just something that's missing from the Stylus Filter in rake-pipeline-web-filters, or is there something I can do to make it work?
Ok, it looks like when I run the in Rake Pipeline in assumes all paths are starting from the directory I'm running the pipeline in, and so all the #imports have to be relative to that. Changing my imports to #import "app/style/appmixins" worked. This is different from what the NPM version of Stylus does, since it expects (and the docs specify) that all the paths are relative to the individual stylesheets. Not sure if I could have specified the block differently in the Assetfile to make this work as expected, but no matter, it all works for me now.

Resources