Skip to content

Commit

Permalink
Make it possible to use installed asciidoctor instance #147
Browse files Browse the repository at this point in the history
- removed unnecessary dependency to OSGI wrapper from editor
- implemented speciall asciidoctor implementation which
  just uses installed variant
- preferences added + defaults
  • Loading branch information
de-jcup committed Oct 9, 2018
1 parent 8364b08 commit c2db472
Show file tree
Hide file tree
Showing 14 changed files with 1,239 additions and 103 deletions.
4 changes: 2 additions & 2 deletions asciidoctor-editor-libs/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<classpathentry exported="true" kind="lib" path="diagram/plantuml.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="asciidoctorj-1.5.6.jar" sourcepath="/tmp/.org.sf.feeling.decompiler1527503365951/source/asciidoctorj-1.5.6-sources.jar"/>
<classpathentry exported="true" kind="lib" path="asciidoctorj-1.5.6.jar" sourcepath="C:/Users/ATRIGNA/AppData/Local/Temp/.org.sf.feeling.decompiler1536851835958/source/asciidoctorj-1.5.6-sources-1536878523289.jar"/>
<classpathentry exported="true" kind="lib" path="asciidoctorj-diagram-1.5.4.1.jar"/>
<classpathentry exported="true" kind="lib" path="commons-io-2.4.jar"/>
<classpathentry exported="true" kind="lib" path="jcommander-1.35.jar"/>
<classpathentry exported="true" kind="lib" path="jruby-complete-1.7.26.jar"/>
<classpathentry exported="true" kind="lib" path="jruby-complete-1.7.26.jar" sourcepath="C:/Users/ATRIGNA/AppData/Local/Temp/.org.sf.feeling.decompiler1539089748141/source/jruby-complete-1.7.26-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
18 changes: 18 additions & 0 deletions asciidoctor-editor-other/doc/00_External.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
== Install asciidoctor
For details look also at https://asciidoctor.org/docs/install-toolchain/

=== Windows

==== Install ruby
First of all - if not already done - we must install ruby from
https://rubyinstaller.org/ (e.g. `rubyinstaller-devkit-2.4.4-2-x64.exe` )

==== Install asciidoc

`gem install asciidoctor`

`gem install asciidoctor-diagram`
https://rubygems.org/gems/asciidoctor-diagram/versions/1.2.1

https://asciidoctor.org/docs/asciidoctor-pdf/
`gem install asciidoctor-pdf --pre` (pre necessary because pdf still alpha...)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[plantuml, sample-plantuml-diagram-u1, alt="Use case diagram 1"]
----
@startuml AWS icon test
!include <aws/common>
!include <aws/ApplicationServices/AmazonAPIGateway/AmazonAPIGateway>
AMAZONAPIGATEWAY(gateway,"",rectangle)
@enduml
----
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public AsciiDoctorEditor() {
this.editorTempIdentifier = System.nanoTime();
setSourceViewerConfiguration(createSourceViewerConfig());
this.modelBuilder = new AsciiDoctorScriptModelBuilder();
asciidoctorWrapper = new AsciiDoctorWrapper(editorTempIdentifier, AsciiDoctorEclipseLogAdapter.INSTANCE);
asciidoctorWrapper = new AsciiDoctorWrapper(editorTempIdentifier, AsciiDoctorEclipseLogAdapter.INSTANCE, AsciiDoctorEditorPreferences.getInstance().isUsingInstalledAsciidoctor());

contentTransformer = createCustomContentTransformer();
if (contentTransformer == null) {
Expand Down Expand Up @@ -922,7 +922,7 @@ protected void showRebuildingInPreviewAndTriggerFullHTMLRebuildAsJob(BuildAsciiD
try {
outputBuildSemaphore.acquire();
if (initializing) {
File previewInitializingFile = new File(AsciiDoctorOSGIWrapper.INSTANCE.getAddonsFolder(),
File previewInitializingFile = new File(asciidoctorWrapper.getAddonsFolder(),
"html/initialize/preview_initializing.html");
boolean previewInitializingFileFound = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,52 @@
import de.jcup.asciidoctoreditor.provider.AsciiDoctorProviderContext;

public class AsciiDoctorWrapper {


private LogAdapter logAdapter;

private Path tempFolder;

private AsciiDoctorProviderContext context;

public AsciiDoctorWrapper(long tempIdentifier, LogAdapter logAdapter) {
if (logAdapter==null){
public AsciiDoctorWrapper(long tempIdentifier, LogAdapter logAdapter, boolean useInstalled) {
if (logAdapter == null) {
throw new IllegalArgumentException("log adapter may not be null!");
}
this.logAdapter=logAdapter;
this.logAdapter = logAdapter;
initTempFolderOrFail(tempIdentifier);
this.context = new AsciiDoctorProviderContext(AsciiDoctorOSGIWrapper.INSTANCE.getAsciidoctor(), AsciiDoctorEclipseLogAdapter.INSTANCE);
Asciidoctor asciidoctor = null;
if (useInstalled) {
asciidoctor = new InstalledAsciidoctor();
} else {
asciidoctor = AsciiDoctorOSGIWrapper.INSTANCE.getAsciidoctor();
}
this.context = new AsciiDoctorProviderContext(asciidoctor, AsciiDoctorEclipseLogAdapter.INSTANCE);
context.setOutputFolder(tempFolder);

}

public AsciiDoctorProviderContext getContext() {
return context;
}

public void convertToHTML(File asciiDocFile) throws Exception{
public void convertToHTML(File asciiDocFile) throws Exception {
context.setAsciidocFile(asciiDocFile);
AsciiDoctorEditorPreferences preferences = AsciiDoctorEditorPreferences.getInstance();
int tocLevels = preferences.getIntegerPreference(AsciiDoctorEditorPreferenceConstants.P_EDITOR_TOC_LEVELS);
context.setTocLevels(tocLevels);
try{
try {
AsciiDoctorOptionsProvider optionsProvider = context.getOptionsProvider();
Map<String, Object> defaultOptions = optionsProvider.createDefaultOptions();

Asciidoctor asciiDoctor = context.getAsciiDoctor();
asciiDoctor.convertFile(asciiDocFile, defaultOptions);
}catch(Exception e){
logAdapter.logError("Cannot convert to html:"+asciiDocFile, e);

} catch (Exception e) {
logAdapter.logError("Cannot convert to html:" + asciiDocFile, e);
throw e;
}
}


/**
* Resets cached values: baseDir, imagesDir
*/
Expand All @@ -82,14 +87,13 @@ public void resetCaches() {
context.setOutputFolder(tempFolder);
}



public String buildHTMLWithCSS(String html, int refreshAutomaticallyInSeconds) {
StringBuilder sb = new StringBuilder();
sb.append(buildPrefixHTML(refreshAutomaticallyInSeconds));
sb.append(html);
if (refreshAutomaticallyInSeconds > 0) {
sb.append("<script type=\"text/javascript\">pageloadEvery("+refreshAutomaticallyInSeconds*1000+");</script>");
sb.append("<script type=\"text/javascript\">pageloadEvery(" + refreshAutomaticallyInSeconds * 1000
+ ");</script>");
}
sb.append("</body>");
sb.append("</html>");
Expand Down Expand Up @@ -123,8 +127,7 @@ private String buildPrefixHTML(int refreshAutomaticallyInSeconds) {
prefixSb.append(createLinkToFile(file));
}
prefixSb.append("</head>\n");



prefixSb.append("<body ");
if (context.isTOCVisible()) {
prefixSb.append("class=\"article toc2 toc-left\">");
Expand Down Expand Up @@ -152,13 +155,15 @@ protected void initTempFolderOrFail(long tempIdentifier) {
}

/**
* Returns temp folder which cannot be null because of {@link #initTempFolderOrFail(long)} called on constructor time
* Returns temp folder which cannot be null because of
* {@link #initTempFolderOrFail(long)} called on constructor time
*
* @return temp folder never <code>null</code>
*/
public Path getTempFolder() {
return tempFolder;
}

public File getTempFileFor(File editorFile, TemporaryFileType type) {
File parent = null;
if (tempFolder == null) {
Expand Down Expand Up @@ -197,4 +202,8 @@ public void setTocVisible(boolean tocVisible) {
public boolean isTocVisible() {
return context.isTOCVisible();
}

public File getAddonsFolder() {
return AsciiDoctorOSGIWrapper.INSTANCE.getAddonsFolder();
}
}
Loading

0 comments on commit c2db472

Please sign in to comment.