Use the interface provided by Http://tool.oschina.net/less to send requests for remote compilation.
The compiled less is then saved in a file with the same name as the suffix CSS.
The first time you use Python, the code is pieced together. You need to add a thread to make an asynchronous request, but not ...
Copy the Code code as follows:
Import Sublime, Sublime_plugin
Import Urllib
Import JSON
Class Examplecommand (Sublime_plugin. Textcommand):
def run (self, edit):
File_name=self.view.file_name ();
If File_name.find ('. less ') = =-1:
Print (' only. less file can compile to css!! ');
Return
File_object_from = open (file_name);
All_the_text = File_object_from.read ();
url = "Http://tool.oschina.net/action/less/less_compile";
data = All_the_text.encode (encoding= ' UTF8 ');
headers = {' user-agent ': ' Sublime_plugin '};
req = Urllib.request.Request (url,data,headers);
Response = Urllib.request.urlopen (req);
The_page = Response.read ();
Css=json.loads (The_page.decode ("UTF8")) [' CSS '];
file_object_to = open (Self.view.file_name (). replace ('. less ', '. css '), ' W ')
File_object_to.write (CSS);
File_object_from.close ();
File_object_to.close ();
Print (CSS);