From 312df2a099b9c318202cb7d9f8ac165a9e1693b1 Mon Sep 17 00:00:00 2001 From: Rahman Usta Date: Mon, 10 Nov 2014 18:39:26 +0200 Subject: [PATCH] - Rendering changes - Css custumazitions --- .../kodcu/controller/AsciiDocController.java | 43 ++++++++++++------- .../com/kodcu/service/DocBookService.java | 23 +++++----- .../com/kodcu/service/Html5BookService.java | 4 +- .../com/kodcu/service/NashornService.java | 2 +- ...rService.java => PathResolverService.java} | 2 +- ...rRenderService.java => RenderService.java} | 4 +- src/main/resources/public/css/custom.css | 15 +++++++ src/main/resources/public/docbooker.html | 2 +- src/main/resources/public/index.html | 12 +++++- 9 files changed, 72 insertions(+), 35 deletions(-) rename src/main/java/com/kodcu/service/{BookPathResolverService.java => PathResolverService.java} (97%) rename src/main/java/com/kodcu/service/{AsciiDoctorRenderService.java => RenderService.java} (92%) diff --git a/src/main/java/com/kodcu/controller/AsciiDocController.java b/src/main/java/com/kodcu/controller/AsciiDocController.java index 66e4c931b..4939312f5 100644 --- a/src/main/java/com/kodcu/controller/AsciiDocController.java +++ b/src/main/java/com/kodcu/controller/AsciiDocController.java @@ -55,13 +55,11 @@ import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; -import org.xml.sax.SAXException; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.net.URISyntaxException; import java.net.URL; -import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -70,6 +68,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.stream.Collectors; import static java.nio.file.StandardOpenOption.CREATE; @@ -98,11 +97,26 @@ public class AsciiDocController extends TextWebSocketHandler implements Initiali public ProgressIndicator indikator; public Hyperlink lastConvertedFileLink; + private Supplier workindDirectorySupplier = () -> { + + DirectoryChooser directoryChooser=new DirectoryChooser(); + directoryChooser.setTitle("Select working directory"); + File file = directoryChooser.showDialog(null); + + workingDirectory = Optional.ofNullable(file.toPath().toString()); + + this.workingDirectory.ifPresent(path->{ + this.fileBrowser.browse(treeView, this, path); + }); + + return file.toPath().toString(); + }; + @Autowired private TablePopupController tablePopupController; @Autowired - private AsciiDoctorRenderService renderService; + private RenderService renderService; @Autowired private DocBookService docBookController; @@ -131,9 +145,6 @@ public class AsciiDocController extends TextWebSocketHandler implements Initiali @Autowired private SampleBookService sampleBookService; - @Autowired - private NashornService nashornService; - private ExecutorService singleWorker = Executors.newSingleThreadExecutor(); private ExecutorService threadPollWorker = Executors.newFixedThreadPool(4); @@ -195,7 +206,7 @@ private void directoryView(ActionEvent event) { @FXML private void generatePdf(ActionEvent event) { - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); docBookController.generateDocbook(previewEngine, currentPath, false); runTaskLater((task) -> { @@ -223,7 +234,7 @@ private void generateSampleBook(ActionEvent event) { @FXML private void convertDocbook(ActionEvent event) { - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); // Path currentPath = initialDirectory.map(path -> Files.isDirectory(path) ? path : path.getParent()).get(); docBookController.generateDocbook(previewEngine, currentPath, true); @@ -241,7 +252,7 @@ private void openLastConvertedFile(ActionEvent event) { private void convertEpub(ActionEvent event) throws Exception { // Path currentPath = initialDirectory.map(path -> Files.isDirectory(path) ? path : path.getParent()).get(); - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); docBookController.generateDocbook(previewEngine, currentPath, false); runTaskLater((task) -> { @@ -279,7 +290,7 @@ protected T call() throws Exception { private void convertMobi(ActionEvent event) throws Exception { - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); if (Objects.nonNull(config.getKindlegenDir())) { if (!Files.exists(Paths.get(config.getKindlegenDir()))) { @@ -308,7 +319,7 @@ private void convertMobi(ActionEvent event) throws Exception { @FXML private void generateHtml(ActionEvent event) { - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); htmlBookService.produceXhtml5(previewEngine, currentPath, configPath); } @@ -882,14 +893,13 @@ public void htmlOnePage(){ return; } - Path currentPath = Paths.get(workingDirectory.get()); + + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); String asciidoc = current.currentEditorValue(); String html = renderService.convertHtmlArticle(previewEngine, IOHelper.normalize(asciidoc)); - this.cutCopy(html); - runTaskLater(task -> { indikatorService.startCycle(); String tabText = current.getCurrentTabText().replace("*", "").trim(); @@ -917,7 +927,7 @@ public void pdfOnePage(){ return; } - Path currentPath = Paths.get(workingDirectory.get()); + Path currentPath = Paths.get(workingDirectory.orElseGet(workindDirectorySupplier)); String docbook = docBookController.generateDocbookArticle(previewEngine,currentPath); @@ -943,6 +953,9 @@ public void saveDoc() { Path currentPath = current.currentPath(); if (currentPath == null) { FileChooser chooser = new FileChooser(); + workingDirectory.ifPresent(path->{ + chooser.setInitialDirectory(Paths.get(path).toFile()); + }); chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Asciidoc","*.asc", "*.asciidoc", "*.adoc", "*.ad", "*.txt")); File file = chooser.showSaveDialog(null); if (file == null) diff --git a/src/main/java/com/kodcu/service/DocBookService.java b/src/main/java/com/kodcu/service/DocBookService.java index 53fe313a6..98cceb523 100644 --- a/src/main/java/com/kodcu/service/DocBookService.java +++ b/src/main/java/com/kodcu/service/DocBookService.java @@ -34,10 +34,10 @@ public class DocBookService { private Pattern compiledRegex = Pattern.compile("(?<=include::)(.*?)(?=\\[(.*?)\\])"); @Autowired - private AsciiDoctorRenderService docConverter; + private RenderService docConverter; @Autowired - private BookPathResolverService bookPathResolver; + private PathResolverService bookPathResolver; @Autowired private AsciiDocController asciiDocController; @@ -59,7 +59,7 @@ public void generateDocbook(WebEngine webEngine, Path currentPath, boolean showI indikatorService.startCycle(); List bookAscLines = Files.readAllLines(bookAsc); - StringBuffer allAscChapters = new StringBuffer(); +// StringBuffer allAscChapters = new StringBuffer(); for (int i = 0; i < bookAscLines.size(); i++) { String bookAscLine = bookAscLines.get(i); @@ -69,9 +69,10 @@ public void generateDocbook(WebEngine webEngine, Path currentPath, boolean showI if (matcher.find()) { String chapterPath = matcher.group(); String chapterContent = IOHelper.readFile(currentPath.resolve(chapterPath)); - allAscChapters.append(chapterContent); - allAscChapters.append("\n\n"); - bookAscLines.remove(i); +// allAscChapters.append(chapterContent); +// allAscChapters.append("\n\n"); +// bookAscLines.remove(i); + bookAscLines.set(i,"\n\n"+chapterContent+"\n\n"); } } @@ -83,17 +84,17 @@ public void generateDocbook(WebEngine webEngine, Path currentPath, boolean showI }); String docBookHeaderContent = docConverter.convertDocbook(webEngine, allAscContent.toString(), true); - String docBookChapterContent = docConverter.convertDocbook(webEngine, allAscChapters.toString(), true); +// String docBookChapterContent = docConverter.convertDocbook(webEngine, allAscChapters.toString(), true); StringReader bookReader = new StringReader(docBookHeaderContent); Match rootDocument = $(new InputSource(bookReader)); bookReader.close(); - bookReader = new StringReader(docBookChapterContent); - Match chapterDocument = $(new InputSource(bookReader)); - bookReader.close(); +// bookReader = new StringReader(docBookChapterContent); +// Match chapterDocument = $(new InputSource(bookReader)); +// bookReader.close(); - rootDocument.append(chapterDocument.find("chapter")); +// rootDocument.append(chapterDocument.find("chapter")); // changes formalpara to figure bug fix rootDocument.find("imageobject").parents("formalpara").each((context) -> { diff --git a/src/main/java/com/kodcu/service/Html5BookService.java b/src/main/java/com/kodcu/service/Html5BookService.java index 783e04ea5..953e27227 100644 --- a/src/main/java/com/kodcu/service/Html5BookService.java +++ b/src/main/java/com/kodcu/service/Html5BookService.java @@ -34,10 +34,10 @@ public class Html5BookService { private AsciiDocController asciiDocController; @Autowired - private BookPathResolverService bookPathResolver; + private PathResolverService bookPathResolver; @Autowired - private AsciiDoctorRenderService docConverter; + private RenderService docConverter; @Autowired private IndikatorService indikatorService; diff --git a/src/main/java/com/kodcu/service/NashornService.java b/src/main/java/com/kodcu/service/NashornService.java index 1378e5693..b4972b8ff 100644 --- a/src/main/java/com/kodcu/service/NashornService.java +++ b/src/main/java/com/kodcu/service/NashornService.java @@ -16,7 +16,7 @@ /** * Created by usta on 19.10.2014. */ -@Component +//@Component public class NashornService { diff --git a/src/main/java/com/kodcu/service/BookPathResolverService.java b/src/main/java/com/kodcu/service/PathResolverService.java similarity index 97% rename from src/main/java/com/kodcu/service/BookPathResolverService.java rename to src/main/java/com/kodcu/service/PathResolverService.java index a7d1292d4..d5c858e23 100644 --- a/src/main/java/com/kodcu/service/BookPathResolverService.java +++ b/src/main/java/com/kodcu/service/PathResolverService.java @@ -12,7 +12,7 @@ * Created by usta on 07.09.2014. */ @Component -public class BookPathResolverService { +public class PathResolverService { private static final List rootList = Arrays.asList("book.asc", "book.txt", "book.asciidoc", "book.adoc", "book.ad"); diff --git a/src/main/java/com/kodcu/service/AsciiDoctorRenderService.java b/src/main/java/com/kodcu/service/RenderService.java similarity index 92% rename from src/main/java/com/kodcu/service/AsciiDoctorRenderService.java rename to src/main/java/com/kodcu/service/RenderService.java index ff83ddfe3..97e873bac 100644 --- a/src/main/java/com/kodcu/service/AsciiDoctorRenderService.java +++ b/src/main/java/com/kodcu/service/RenderService.java @@ -13,7 +13,7 @@ * Created by usta on 19.07.2014. */ @Component -public class AsciiDoctorRenderService { +public class RenderService { @Autowired AsciiDocController controller; @@ -21,7 +21,7 @@ public class AsciiDoctorRenderService { @Autowired Current current; - private static Logger logger = LoggerFactory.getLogger(AsciiDoctorRenderService.class); + private static Logger logger = LoggerFactory.getLogger(RenderService.class); public String convertBasicHtml(WebEngine webEngine, String text) { diff --git a/src/main/resources/public/css/custom.css b/src/main/resources/public/css/custom.css index 87fd47256..f4883bffb 100644 --- a/src/main/resources/public/css/custom.css +++ b/src/main/resources/public/css/custom.css @@ -25,7 +25,18 @@ body{ float: left; } +.save-html { + float: left; + color: #dddddd; + cursor: pointer; +} + +.save-html:hover { + color: #b0b0b0; +} + .copy-source { + margin-left: 15px; float: left; color: #dddddd; cursor: pointer; @@ -83,4 +94,8 @@ pre.highlight > code { .columns > a { padding-top: 10px; +} + +#placeholder{ + margin-top: 30px; } \ No newline at end of file diff --git a/src/main/resources/public/docbooker.html b/src/main/resources/public/docbooker.html index 727223ee3..510642b1f 100644 --- a/src/main/resources/public/docbooker.html +++ b/src/main/resources/public/docbooker.html @@ -15,7 +15,7 @@