Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
fix include-all bug when the file is at depth 0, export depth in pagi…
Browse files Browse the repository at this point in the history
…nation object, update todo, remove unused locale aware wrapping if we are using only one locale
  • Loading branch information
syjer committed Jun 1, 2015
1 parent 45361cd commit ec5ec25
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
5 changes: 4 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ TODO:
- support a "documentation use case". WIP:
- TBD:
- tests

- export a breadcrumb variable (should contain link + document title)
- export a start number variable for OL http://stackoverflow.com/a/779052 so the numbers are coherent
with the main ToC (/!\ some possible issue when there is no attached document with a directory)

- see http://www.mkdocs.org/
- we want to generate something like http://docs.jboss.org/seam/3/latest/reference/en-US/html/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ public List<PathAndModelSupplier> generateOutputPaths(FileResource resource, Loc
throw new IllegalArgumentException(p + " must be inside of the basedirectory: "
+ baseDirectory);// cannot be outside
}

Directory toIncludeAllDir =
new LocaleAwareDirectory(locale, new RootResource(resourceFactory, p),
FileResourceWithMetadataSection::new);



final Directory toIncludeAllDir;

if(configuration.getLocales().size() > 1) {
toIncludeAllDir = new LocaleAwareDirectory(locale, new RootResource(resourceFactory, p),
FileResourceWithMetadataSection::new);
} else {
toIncludeAllDir = new RootResource(resourceFactory, p);
}

StructuredDocument doc = new StructuredDocument(0, toIncludeAllDir, p);

Expand Down Expand Up @@ -137,7 +144,7 @@ private void addPaginationInfoToModel(List<FlattenedStructuredDocument> res) {
nextPageUrl = PathUtils.relativePathTo(res.get(i + 1).path, current.path);
nextPageTitle = res.get(i + 1).title.orElse(null);
}
current.model.put("pagination", new Pagination(i + 1, resCount, previousPageUrl,
current.model.put("pagination", new Pagination(i + 1, resCount, current.depth, previousPageUrl,
previousPageTitle, nextPageUrl, nextPageTitle));
current.model.put("toc", current.tocRoot.toHtml(current.path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public void process(FileResource resource, Locale locale, ProcessedInputHandler

Path defaultOutputPath = extractOutputPath(resource);


if(!directives.containsKey(metadata.getDirective())) {
throw new IllegalArgumentException("Directive '" + metadata.getDirective() + "' in file "
+ resource.getPath() + " does not exists");
}

List<PathAndModelSupplier> outputPaths =
directives.get(metadata.getDirective()).generateOutputPaths(resource, finalLocale,
defaultOutputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
public class Pagination {
private final int page;
private final int total;
private final int depth;
private final String previousPageUrl;
private final String previousPageTitle;
private final String nextPageUrl;
private final String nextPageTitle;

public Pagination(int page, int total, String previousPageUrl, String previousPageTitle,
public Pagination(int page, int total, int depth, String previousPageUrl, String previousPageTitle,
String nextPageUrl, String nextPageTitle) {
this.page = page;
this.total = total;
this.depth = depth;
this.previousPageUrl = previousPageUrl;
this.previousPageTitle = previousPageTitle;
this.nextPageUrl = nextPageUrl;
Expand All @@ -40,6 +42,10 @@ public int getPage() {
public int getTotal() {
return total;
}

public int getDepth() {
return depth;
}

public String getPreviousPageUrl() {
return previousPageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void toOutputPaths(OutputPathsEnv env, List<FlattenedStructuredDocument>
FileResource v = fileResource.orElseGet(() -> new FileResourcePlaceHolder(relativeToBasePath,
env.configuration));

Path virtualPath = env.resource.getPath().getParent().resolve(this.relativeToBasePath.toString());
Path virtualPath = depth == 0 ? env.resource.getPath() : env.resource.getPath().getParent().resolve(this.relativeToBasePath.toString());

FileResource virtualResource = new VirtualPathFileResource(virtualPath, v);
Path finalOutputPathForResource = env.outputPathExtractor.apply(virtualResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String toHtml(Path path) {
}
sb.append("<li>").append("<a href=\"").append(PathUtils.relativePathTo(h.outputPath, path))
.append("#").append(h.id)
.append("\">").append(h.name).append("</a>").append("</li>");
.append("\">").append(h.name).append("</a>");
}

for (int i = 0; i < opened; i++) {
Expand Down

0 comments on commit ec5ec25

Please sign in to comment.