Пример #1
0
  private static Map<String, Vertabrae> extract_files(Path dir) throws IOException {
    Map<String, Vertabrae> file_names = new TreeMap<>();

    DirectoryStream<Path> directory_stream = java.nio.file.Files.newDirectoryStream(dir, "*.md");

    for (Path from_file : directory_stream) {

      Vertabrae vertabrae = new Vertabrae(from_file);

      file_names.put(vertabrae.file_name(), vertabrae);
      System.out.println("[SPINE] Vertabrae file name: " + vertabrae.file_name());
    }
    directory_stream.close();
    return file_names;
  }
Пример #2
0
  private static Map<String, String> content_for(
      Set<String> relevant_files, Map<String, Vertabrae> file_names) {

    Map<String, String> result = new HashMap<>();
    for (String file : relevant_files) {
      String index = file.substring(file.length() - 1);

      Vertabrae vertabrae = file_names.get(file);
      ByteSource bs = Files.asByteSource(vertabrae.path().toFile());
      String html;
      try {
        html = md.process(bs.openBufferedStream());
        result.put(index, html);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return result;
  }
Пример #3
0
  private static void generate_markup(
      Path abs_path_from, Path abs_path_to, Map<String, Vertabrae> file_names) throws IOException {
    Function<Vertabrae, String> title = Vertabrae::title;

    Map<String, String> toc = Maps.transformValues(file_names, title);

    Set<String> files = file_names.keySet();

    Set<String> filtered_files =
        files.stream().filter(file -> !file.contains("_")).collect(Collectors.toSet());

    for (String key : filtered_files) {
      Vertabrae vertabrae = file_names.get(key);

      ByteSource bs = Files.asByteSource(vertabrae.path().toFile());
      String html = md.process(bs.openBufferedStream());

      Set<String> relevant_files =
          files.stream().filter(file -> file.contains(key + "_")).collect(Collectors.toSet());

      String template = pick_template(abs_path_from, vertabrae.file_name());

      VelocityContext velocity_context = new VelocityContext();
      velocity_context.put("name", vertabrae.title());
      velocity_context.put("content", html);
      velocity_context.put("pages", toc);

      Map<String, String> content_files = content_for(relevant_files, file_names);

      for (String index : content_files.keySet()) {
        velocity_context.put("content_" + index, content_files.get(index));
      }

      System.out.println("[SPINE] Template: " + template);

      String page = merge(template, velocity_context);

      File to_file = new File(abs_path_to + File.separator + vertabrae.file_name() + ".html");

      Files.write(page, to_file, Charsets.UTF_8);
    }
  }