Skip to content

Commit

Permalink
- Rendering changes
Browse files Browse the repository at this point in the history
- Css custumazitions
  • Loading branch information
rahmanusta committed Nov 10, 2014
1 parent 93c8f25 commit 312df2a
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
43 changes: 28 additions & 15 deletions src/main/java/com/kodcu/controller/AsciiDocController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -98,11 +97,26 @@ public class AsciiDocController extends TextWebSocketHandler implements Initiali
public ProgressIndicator indikator;
public Hyperlink lastConvertedFileLink;

private Supplier<String> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) -> {
Expand Down Expand Up @@ -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);

Expand All @@ -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) -> {
Expand Down Expand Up @@ -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()))) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/kodcu/service/DocBookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +59,7 @@ public void generateDocbook(WebEngine webEngine, Path currentPath, boolean showI
indikatorService.startCycle();

List<String> 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);
Expand All @@ -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");
}

}
Expand All @@ -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) -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/kodcu/service/Html5BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kodcu/service/NashornService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Created by usta on 19.10.2014.
*/
@Component
//@Component
public class NashornService {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Created by usta on 07.09.2014.
*/
@Component
public class BookPathResolverService {
public class PathResolverService {

private static final List<String> rootList =
Arrays.asList("book.asc", "book.txt", "book.asciidoc", "book.adoc", "book.ad");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* Created by usta on 19.07.2014.
*/
@Component
public class AsciiDoctorRenderService {
public class RenderService {

@Autowired
AsciiDocController controller;

@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) {

Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,4 +94,8 @@ pre.highlight > code {

.columns > a {
padding-top: 10px;
}

#placeholder{
margin-top: 30px;
}
2 changes: 1 addition & 1 deletion src/main/resources/public/docbooker.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<button onclick="convert()">Convert</button>
<script>
function convert(){
var docbookOpts = Opal.hash2(['attributes','header_footer'], {'attributes': ['backend=docbook5', 'doctype=article'],'header_footer':true});
var docbookOpts = Opal.hash2(['attributes','header_footer'], {'attributes': ['backend=docbook5', 'doctype=book'],'header_footer':true});
var result = Opal.Asciidoctor.$render($("#input").val(),docbookOpts);
$("#output").val(result);
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
<div class="utility">
<div class="row">
<div class="columns justify large-10 large-centered medium-12 small-12" style="height:30px">
<a class="copy-source" onclick="htmlOnePage()">
<a class="save-html" onclick="htmlOnePage()">
<i class="fa fa-html5"></i>
HTML
</a>
<a class="save-pdf" onclick="pdfOnePage()">
<i class="fa fa-file-pdf-o"></i>
PDF
</a>
<a class="copy-source" onclick="copySource()">
<i class="fa fa-file-code-o"></i>
Source
</a>
<a class="external-browser" onclick="externalBrowse()">
<i class="fa fa-bolt"></i>
External Browser
Browser
</a>
</div>
</div>
Expand Down Expand Up @@ -89,6 +93,10 @@
app.htmlOnePage();
}

var copySource = function(){
app.cutCopy($("#placeholder").html());
}

var pdfOnePage = function () {
app.pdfOnePage();
}
Expand Down

0 comments on commit 312df2a

Please sign in to comment.