Package net.quenchnetworks.sassybarista

Source Code of net.quenchnetworks.sassybarista.ImportProcessor

package net.quenchnetworks.sassybarista;

import net.quenchnetworks.sassybarista.sass.SassParser;
import net.quenchnetworks.sassybarista.sass.models.ImportRule;
import net.quenchnetworks.sassybarista.sass.models.SassSheet;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class ImportProcessor {

    public ImportProcessor() {
    }

    public void importSassFrom(ImportRule importRule, SassParser parent, File... importPaths) {

        if (importPaths.length > 1) {
            throw new RuntimeException("Currently we only support a single import path!");
        }

        File scssFile = new File(importPaths[0], importRule.asScssFile());

        FileReader in = null;

        try {
            System.out.println("Importing: " + scssFile.getAbsolutePath());
            in = new FileReader(scssFile);
            SassParser parser = new SassParser(in);
            SassSheet sheet = parser.parse();

            parent.addFrom(sheet);

        } catch (Exception e) {
            throw new RuntimeException(String.format("Could not import file [%s]", scssFile.getAbsolutePath()), e);
        } finally {
            tryToClose(in);
        }

    }

    private static void tryToClose(Reader in) {
        if (in == null) {
            return;
        }

        try {
            in.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
TOP

Related Classes of net.quenchnetworks.sassybarista.ImportProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.