-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for loading FS templates/CSS
The templates still exist in source, but the main copy are now the .mustache files (and Site.css) in the package root. Custom template directories can now be specified using the `-t`/`--templates` argument for full customization.
- Loading branch information
Showing
23 changed files
with
714 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<h2>docc2html Templates (Code) | ||
<img src="http://zeezide.com/img/docz/docc2html100.png" | ||
align="right" width="100" height="100" /> | ||
</h2> | ||
|
||
This folder contains the default Mustache templates used, | ||
plus the `Site.css` containing the default CSS. | ||
|
||
It is used as a fallback if the `Templates` (resource) directory in the package root cannot | ||
be reached, or not `-t/--templates` option was specified. | ||
When PR'ing changes, please do so in the resource directory. | ||
|
||
|
||
### Who | ||
|
||
**docc2html** is brought to you by | ||
the | ||
[Always Right Institute](http://www.alwaysrightinstitute.com) | ||
and | ||
[ZeeZide](http://zeezide.de). | ||
We like | ||
[feedback](https://twitter.com/ar_institute), | ||
GitHub stars, | ||
cool [contract work](http://zeezide.com/en/services/services.html), | ||
presumably any form of praise you can think of. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// LoadTemplates.swift | ||
// docc2html | ||
// | ||
// Created by Helge Heß. | ||
// Copyright © 2021 ZeeZide GmbH. All rights reserved. | ||
// | ||
|
||
import mustache | ||
import Foundation | ||
import DocCHTMLExporter // @docczz/docc2html | ||
|
||
func loadTemplatesAndStylesheet(from path: String) | ||
-> ( templates: DZRenderingContext.Templates, stylesheet: String ) | ||
{ | ||
let baseURL = URL(fileURLWithPath: path) | ||
let cssURL = baseURL.appendingPathComponent("site.css") | ||
|
||
let stylesheet = (try? String(contentsOf: cssURL)) | ||
?? DZRenderingContext.defaultStyleSheet | ||
|
||
var templates = DZRenderingContext.Templates() | ||
|
||
func load(_ name: String) -> Mustache? { | ||
let url = baseURL.appendingPathComponent(name) | ||
.appendingPathExtension("mustache") | ||
guard FileManager.default.fileExists(atPath: url.path) else { | ||
logger.trace("No filesystem template for:", name) | ||
return nil | ||
} | ||
|
||
do { | ||
let s = try String(contentsOf: url) | ||
let m = Mustache(s) | ||
logger.trace("Did load template:", name, "from:", url.path) | ||
return m | ||
} | ||
catch { | ||
logger.error("Failed to load template:", name, error) | ||
return nil | ||
} | ||
} | ||
|
||
if let m = load("Page") { templates.htmlWrapper = m } | ||
if let m = load("DocumentContent") { templates.documentContent = m } | ||
if let m = load("Navigation") { templates.navigation = m } | ||
if let m = load("PrimaryContent") { templates.primaryContentGrid = m } | ||
if let m = load("CodeListing") { templates.codeListing = m } | ||
if let m = load("StepContent") { templates.step = m } | ||
if let m = load("DeclarationSection") { templates.declarationSection = m } | ||
if let m = load("ParametersSection") { templates.parametersSection = m } | ||
if let m = load("Sections") { templates.contentTableSection = m } | ||
if let m = load("TopicTitle") { templates.topicTitle = m } | ||
if let m = load("Hero") { templates.hero = m } | ||
if let m = load("Task") { templates.task = m } | ||
if let m = load("TaskIntro") { templates.taskIntro = m } | ||
if let m = load("Volume") { templates.volume = m } | ||
|
||
return ( templates: templates, stylesheet: stylesheet ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div data-syntax="{{syntax}}" class="code-listing"> | ||
<div class="container-general"> | ||
<pre><code>{{#lines}}<span class="code-line-container"><span data-line-number="{{{line}}}" class="code-number" style="display: none;"></span><span class="code-line">{{code}}</span></span> | ||
{{/lines}}</code></pre> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<section id='declaration' class='declaration'> | ||
<h2>{{title}}</h2> | ||
<div class='declaration-group'> | ||
<pre class='source indented'><code>{{{tokensHTML}}}</code></pre> | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{{navigationHTML}}} | ||
<main id="main" role="main" class="main"> | ||
{{{topicTitleHTML}}} | ||
{{{primaryContentHTML}}} | ||
{{#sectionsContentHTML}} | ||
<div class="sections">{{{sectionsContentHTML}}}</div> | ||
{{/sectionsContentHTML}} | ||
{{{topicSectionsHTML}}} | ||
{{{seeAlsoHTML}}} | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div id="introduction" class="tutorial-hero"> | ||
<div class="hero dark"> | ||
{{#backgroundImage}} | ||
<div class="bg" | ||
style="background-image: url("{{backgroundImage}}");"></div> | ||
{{/backgroundImage}} | ||
|
||
<div class="row"> | ||
<div class="col large-7 medium-9 small-12"> | ||
<div class="headline"><span class="eyebrow">{{eyebrow}}</span> | ||
<h1 class="heading">{{title}}</h1> | ||
</div> | ||
</div> | ||
<div class="intro"> | ||
<div class="content">{{{contentHTML}}}</div> | ||
</div> | ||
<div class="metadata"> | ||
<div class="item"> | ||
<div class="content"> | ||
<div class="duration">{{duration}} | ||
<div class="minutes">min</div> | ||
</div> | ||
</div> | ||
<div class="bottom">Estimated Time</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<nav role="navigation" class="nav documentation-nav"> | ||
<div class="nav__wrapper"> | ||
<div class="nav__background"></div> | ||
<div class="nav-content"> | ||
<div class="nav-title"> | ||
<span class="nav-title-link inactive">{{title}}</span> | ||
</div> | ||
<div class="nav-menu"> | ||
<div class="nav-menu-tray"> | ||
<ul class="nav-menu-items hierarchy"> | ||
{{#navitems}} | ||
<li class="nav-menu-item hierarchy-item"> | ||
{{#isCurrent}} | ||
<span class="current item">{{title}}</span> | ||
{{/isCurrent}} | ||
{{^isCurrent}} | ||
<a href="{{link}}" class="item">{{title}}</a> | ||
{{/isCurrent}} | ||
</li> | ||
{{/navitems}} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> |
Oops, something went wrong.