Exemplo n.º 1
0
    def run(self, edit):

        current_file = self.view.file_name()

        if current_file is None:
            return None
        else:
            file_parts = path.splitext(current_file)

        if file_parts[1] == ".js":
            fileType = "js"
        elif file_parts[1] == ".css":
            fileType = "css"
        else:
            fileType = None

        if fileType is None:
            sublime.error_message("Please focus on the .js or .css file you wish to minify.")
            return None

            # do stuff
        region = sublime.Region(0, self.view.size())
        text = self.view.substr(region)
        if fileType == "js":
            result = jsmin(text)
        elif fileType == "css":
            result = cssmin.cssmin(text)

            # write stuff
        min_file_suffix = ".min"
        file_name = file_parts[0] + min_file_suffix + file_parts[1]

        file_path = path.join(path.dirname(current_file), file_name)

        with open(file_path, "w+", 0) as min_file:
            min_file.write(result)

        sublime.status_message("Minipie saved %s" % (file_path))
Exemplo n.º 2
0
try:
  from cssmin import cssmin
except ImportError, e:
  sys.path.append("../../tool/pylib/cssmin")
  import cssmin

args = sys.argv[:]
args.pop(0)

if len(args) < 2:
  print "At least two arguments needed"
  sys.exit(1)

targetFileName = args.pop()

minifiedCss = ""
for sourceFileName in args:
  css = open(sourceFileName, "r").read()
  minifiedCss += cssmin.cssmin(css)

targetFile = open(targetFileName, "r")
targetFileContent = targetFile.read()
targetFile.close()

minifiedCss = minifiedCss.replace("'", r"\'")
replaced = re.sub("%{Styles}", minifiedCss, targetFileContent)
targetFile = open(targetFileName, "w+")
targetFile.write(replaced)
targetFile.close()
Exemplo n.º 3
0
 def compress_string(self, data):
     return self.apply_header(cssmin.cssmin(data, 4096 * 2))
Exemplo n.º 4
0
                  type="string",
                  help="File to inject optimized CSS into")

(options, args) = parser.parse_args()

try:
    from cssmin import cssmin
except ImportError, e:
    modulePath = os.path.join(options.qooxdooDir, "tool/pylib/cssmin")
    sys.path.append(modulePath)
    import cssmin

if len(args) < 2:
    print "At least two arguments needed"
    sys.exit(1)

minifiedCss = ""
for sourceFileName in args:
    css = open(sourceFileName, "r").read()
    minifiedCss += cssmin.cssmin(css)

targetFile = open(options.target, "r")
targetFileContent = targetFile.read()
targetFile.close()

minifiedCss = minifiedCss.replace("'", r"\'")
replaced = re.sub("%{Styles}", minifiedCss, targetFileContent)
targetFile = open(options.target, "w+")
targetFile.write(replaced)
targetFile.close()