Example of less compilation plug-in implementation of sublime3 in python

Source: Internet
Author: User
This article mainly introduces the python sublime3 less compilation plug-in example of the relevant information using the interface provided by the http://tool.oschina.net/less, send requests for remote compilation.
Save the compiled less file as a file with the same name and suffix css.
When python is used for the first time, the code is also pooled. the thread needs to be added for asynchronous requests, but not...

The code is 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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.