@Override public Collection<Import> apply(final String url, final Import previous) { String fname = nameWithExtension(url); List<String> segments = Splitter.on('/').trimResults().omitEmptyStrings() .splitToList(previous.getAbsoluteUri().toString()); String relative = segments.subList(0, segments.size() - 1).stream() .collect(Collectors.joining("/", "/", "")); return Arrays.asList(relative + fname, fname) .stream() .map(resolver::apply) .filter(it -> it != null) .findFirst() .map(throwingFunction(it -> Try.with(it.toURL()::openStream) .apply(in -> new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8)) .map(content -> Arrays.asList(new Import(it, it, content))) .get() )) .orElse(null); }
Import buildImport(String importUri) { try { String contents = read(url); return new Import(importUri, absoluteUri, contents); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
Import buildImport(String importUri) { try { String contents = read(url); return new Import(importUri, absoluteUri, contents); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * Try to determine the import object for a given path. * * @param path The path to resolve. * @return The import object or {@code null} if the file was not found. */ private Collection<Import> resolveImport(Path path) throws IOException, URISyntaxException { URL resource = resolveResource(path); if (null == resource) { return null; } final URI uri = resource.toURI(); final String source = IOUtils.toString(resource, StandardCharsets.UTF_8); final Import scssImport = new Import(uri, uri, source); return Collections.singleton(scssImport); }
private NativeImport createPostImport(Import importSource) { StringBuilder postSource = new StringBuilder(); // $jsass-void: jsass_import_stack_pop() !global; postSource.append("$jsass-void: jsass_import_stack_pop() !global;\n"); try { return new NativeImport( new Import( new URI(importSource.getAbsoluteUri() + "/JSASS_POST_IMPORT.scss"), new URI(importSource.getAbsoluteUri() + "/JSASS_POST_IMPORT.scss"), postSource.toString() ) ); } catch (URISyntaxException e) { throw new RuntimeException(e); } } }
private NativeImport createPreImport(Import importSource) { int id = importStack.register(importSource); StringBuilder preSource = new StringBuilder(); // $jsass-void: jsass_import_stack_push(<id>) !global; preSource.append( String.format( "$jsass-void: jsass_import_stack_push(%d) !global;\n", id ) ); try { return new NativeImport( new Import( new URI(importSource.getAbsoluteUri() + "/JSASS_PRE_IMPORT.scss"), new URI(importSource.getAbsoluteUri() + "/JSASS_PRE_IMPORT.scss"), preSource.toString() ) ); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
private static NativeImport createPostImport(Import importSource) { StringBuilder postSource = new StringBuilder(); // $jsass-void: jsass_import_stack_pop() !global; postSource .append("$jsass-void: jsass_import_stack_pop() !global;") .append(System.lineSeparator()); try { return new NativeImport( new Import( new URI(importSource.getAbsoluteUri() + "/JSASS_POST_IMPORT.scss"), new URI(importSource.getAbsoluteUri() + "/JSASS_POST_IMPORT.scss"), postSource.toString() ) ); } catch (URISyntaxException e) { throw new ImportException(e); } } }
private Import createCustomHeaderImport(Import previous) { int id = importStack.register(previous); StringBuilder source = new StringBuilder(); // $jsass-void: jsass_import_stack_push(<id>) !global; source.append( String.format( "$jsass-void: jsass_import_stack_push(%d) !global;\n", id ) ); try { return new Import( new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"), new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"), source.toString() ); } catch (URISyntaxException e) { throw new RuntimeException(e); } } }
private NativeImport createPreImport(Import importSource) { int id = importStack.register(importSource); StringBuilder preSource = new StringBuilder(); // $jsass-void: jsass_import_stack_push(<id>) !global; preSource.append( String.format( "$jsass-void: jsass_import_stack_push(%d) !global;%n", id ) ); try { return new NativeImport( new Import( new URI(importSource.getAbsoluteUri() + "/JSASS_PRE_IMPORT.scss"), new URI(importSource.getAbsoluteUri() + "/JSASS_PRE_IMPORT.scss"), preSource.toString() ) ); } catch (URISyntaxException e) { throw new ImportException(e); } }
private Import createCustomHeaderImport(Import previous) { int id = importStack.register(previous); StringBuilder source = new StringBuilder(); // $jsass-void: jsass_import_stack_push(<id>) !global; source.append( String.format( "$jsass-void: jsass_import_stack_push(%d) !global;%n", id ) ); try { return new Import( new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"), new URI(previous.getAbsoluteUri() + "/JSASS_CUSTOM.scss"), source.toString() ); } catch (URISyntaxException e) { throw new ImportException(e); } } }
public Collection<NativeImport> apply(String url, NativeImport previousNative) { try { Import previous = new Import( previousNative.importPath, previousNative.absolutePath,
try { return ImmutableList.of( new Import(uri, abs, byteSource(is).asCharSource(StandardCharsets.UTF_8).read())); } catch (RuntimeException e) {
public Collection<NativeImport> apply(String url, NativeImport previousNative) { try { Import previous = new Import(
return Collections.singletonList(new Import( new URI(resource.getName()), new URI(resource.getName()),
Import newImport = new Import(newURI, newURI, content); return Collections.singletonList(newImport);