Home Download Buy Blog Forum Support

Plugin request: Less CSS converter

Plugin request: Less CSS converter

Postby firefusion on Mon Feb 14, 2011 7:32 am

It would be great if I could convert LESS to CSS with a single command. http://lesscss.org/

EDIT: Looks like there is a simple windows command line app http://www.dotlesscss.org/. See documentation. So making a plugin should be very simple.
Last edited by firefusion on Mon Feb 21, 2011 2:25 pm, edited 1 time in total.
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Plugin request: Less CSS converter

Postby firefusion on Mon Feb 14, 2011 8:37 am

Looks like there is a Textmate bundle...

https://github.com/appden/less.tmbundle
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Plugin request: Less CSS converter

Postby tstrokes on Mon Feb 14, 2011 6:21 pm

For a quick solution for ST1.4 take a look at this thread viewtopic.php?f=6&t=1267.
For ST2 not implemented but you can vote for it at the link at the bottom of the thread.
You could probably create a build system for this as well.
tstrokes
 
Posts: 17
Joined: Wed Dec 03, 2008 6:39 pm

Re: Plugin request: Less CSS converter

Postby firefusion on Mon Feb 21, 2011 2:26 pm

Looks like there is a windows commandline app for making a plugin should be easy http://www.dotlesscss.org/
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Plugin request: Less CSS converter

Postby atomi on Mon Feb 28, 2011 8:43 pm

My first plugin - I'll add it to github @atomi when time permits.
Also, this is my first time playing with python.

Comments welcomed.
Code: Select all
import sublime, sublime_plugin, subprocess, os

class CompileLessOnSave(sublime_plugin.EventListener):
   def on_post_save(self, view):

      if not view.scope_name(0).strip().endswith('source.css.less'):
         return

      if os.name == "nt":
         startupinfo = subprocess.STARTUPINFO()
         startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

      process = subprocess.Popen(('dotless.Compiler.exe','-m',view.file_name()),
      stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startupinfo)
      print('Compiled ' + view.file_name())


Thanks to adzenith btw and Default/exec.py :)
Last edited by atomi on Mon Feb 28, 2011 10:34 pm, edited 2 times in total.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Plugin request: Less CSS converter

Postby firefusion on Mon Feb 28, 2011 10:02 pm

I get this error

Code: Select all
Reloading plugin C:\Users\robin\AppData\Roaming\Sublime Text 2\Packages\Less\SaveToCSS.py
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 29, in reload_plugin
  File ".\SaveToCSS.py", line 6
    if os.name == "nt":
                      ^
IndentationError: unindent does not match any outer indentation level
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Plugin request: Less CSS converter

Postby adzenith on Mon Feb 28, 2011 10:15 pm

firefusion wrote:I get this error

Code: Select all
Reloading plugin C:\Users\robin\AppData\Roaming\Sublime Text 2\Packages\Less\SaveToCSS.py
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 29, in reload_plugin
  File ".\SaveToCSS.py", line 6
    if os.name == "nt":
                      ^
IndentationError: unindent does not match any outer indentation level

Change this line:
Code: Select all
         if not view.scope_name(0).strip().endswith('source.css.less'):

to this:
Code: Select all
      if not view.scope_name(0).strip().endswith('source.css.less'):

In python indentation is important. The two ifs have to line up.
adzenith
 
Posts: 1215
Joined: Mon Oct 19, 2009 9:12 pm

Re: Plugin request: Less CSS converter

Postby firefusion on Mon Feb 28, 2011 10:23 pm

Thanks for your help. Ok, now I get this error after saving the change...

Code: Select all
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 29, in reload_plugin
  File ".\CompileLessOnSave.py", line 1, in <module>
    class CompileLessOnSave(sublime_plugin.EventListener):
NameError: name 'sublime_plugin' is not defined


It doesn't output a css file on save.

I have dotless.Compiler.exe set in the system path as it does work.
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Plugin request: Less CSS converter

Postby atomi on Mon Feb 28, 2011 10:30 pm

I'm sorry I forgot to copy over the imports

Code: Select all
import sublime, sublime_plugin, subprocess, os

class CompileLessOnSave(sublime_plugin.EventListener):
...
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Plugin request: Less CSS converter

Postby firefusion on Mon Feb 28, 2011 10:33 pm

Great! That works :)

Anyway I could get "sheetsheet.css.less" to compile to the name "sheetsheet.css" and not "sheetsheet.css.css"?
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests