Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mustache4dart copy inside dartdoc and use 'mustache' pub package #1894

Merged
merged 10 commits into from
Jan 9, 2019
Prev Previous commit
Next Next commit
Mustache shave passes tests
jcollins-g committed Jan 5, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ff8b185f882a4671160df7b0b25d0d735245295c
7 changes: 3 additions & 4 deletions lib/src/html/html_generator_instance.dart
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ import 'package:dartdoc/src/html/templates.dart';
import 'package:dartdoc/src/logging.dart';
import 'package:dartdoc/src/model.dart';
import 'package:dartdoc/src/model_utils.dart';
import 'package:dartdoc/src/third_party/pkg/mustache4dart/lib/mustache4dart.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:mustache/mustache.dart';
import 'package:path/path.dart' as pathLib;

typedef void FileWriter(String path, Object content, {bool allowOverwrite});
@@ -377,9 +377,8 @@ class HtmlGeneratorInstance {
}
}

void _build(String filename, TemplateRenderer template, TemplateData data) {
String content = template(data,
assumeNullNonExistingProperty: false, errorOnMissingProperty: true);
void _build(String filename, Template template, TemplateData data) {
String content = template.renderString(data);

_writer(filename, content);
if (data.self is Indexable) _indexedElements.add(data.self as Indexable);
40 changes: 20 additions & 20 deletions lib/src/html/templates.dart
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import 'dart:async' show Future;
import 'dart:io' show File;

import 'package:dartdoc/src/html/resource_loader.dart' as loader;
import 'package:dartdoc/src/third_party/pkg/mustache4dart/lib/mustache4dart.dart';
import 'package:mustache/mustache.dart';

const _partials = const <String>[
'callable',
@@ -83,21 +83,21 @@ Future<String> _getTemplateFile(String templateFileName) =>
loader.loadAsString('package:dartdoc/templates/$templateFileName');

class Templates {
final TemplateRenderer categoryTemplate;
final TemplateRenderer classTemplate;
final TemplateRenderer enumTemplate;
final TemplateRenderer constantTemplate;
final TemplateRenderer constructorTemplate;
final TemplateRenderer errorTemplate;
final TemplateRenderer functionTemplate;
final TemplateRenderer indexTemplate;
final TemplateRenderer libraryTemplate;
final TemplateRenderer methodTemplate;
final TemplateRenderer mixinTemplate;
final TemplateRenderer propertyTemplate;
final TemplateRenderer topLevelConstantTemplate;
final TemplateRenderer topLevelPropertyTemplate;
final TemplateRenderer typeDefTemplate;
final Template categoryTemplate;
final Template classTemplate;
final Template enumTemplate;
final Template constantTemplate;
final Template constructorTemplate;
final Template errorTemplate;
final Template functionTemplate;
final Template indexTemplate;
final Template libraryTemplate;
final Template methodTemplate;
final Template mixinTemplate;
final Template propertyTemplate;
final Template topLevelConstantTemplate;
final Template topLevelPropertyTemplate;
final Template typeDefTemplate;

static Future<Templates> create(
{List<String> headerPaths,
@@ -106,17 +106,17 @@ class Templates {
var partials =
await _loadPartials(headerPaths, footerPaths, footerTextPaths);

String _partial(String name) {
Template _partial(String name) {
String partial = partials[name];
if (partial == null || partial.isEmpty) {
throw new StateError('Did not find partial "$name"');
}
return partial;
return Template(partial);
}

Future<TemplateRenderer> _loadTemplate(String templatePath) async {
Future<Template> _loadTemplate(String templatePath) async {
String templateContents = await _getTemplateFile(templatePath);
return compile(templateContents, partial: _partial);
return Template(templateContents, partialResolver: _partial);
}

var indexTemplate = await _loadTemplate('index.html');
11 changes: 5 additions & 6 deletions lib/templates/_head.html
Original file line number Diff line number Diff line change
@@ -10,18 +10,17 @@
<meta name="description" content="{{ metaDescription }}">
<title>{{ title }}</title>
{{ #relCanonicalPrefix }}
<link rel="canonical" href="{{relCanonicalPrefix}}/{{self.href}}">
<link rel="canonical" href="{{{relCanonicalPrefix}}}/{{{self.href}}}">
{{ /relCanonicalPrefix}}
{{#htmlBase}}
<!-- required because all the links are pseudo-absolute -->
<base href="{{htmlBase}}">
<base href="{{{htmlBase}}}">
{{/htmlBase}}

<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
<link rel="stylesheet" href="static-assets/github.css">
<link rel="stylesheet" href="static-assets/styles.css">
<link rel="icon" href="static-assets/favicon.png">

<!-- header placeholder -->
</head>

@@ -33,16 +32,16 @@
<button id="sidenav-left-toggle" type="button">&nbsp;</button>
<ol class="breadcrumbs gt-separated dark hidden-xs">
{{#navLinks}}
<li><a href="{{href}}">{{name}}</a></li>
<li><a href="{{{href}}}">{{name}}</a></li>
{{/navLinks}}
{{#navLinksWithGenerics}}
<li><a href="{{href}}">{{name}}{{#hasGenericParameters}}<span class="signature">{{{genericParameters}}}</span>{{/hasGenericParameters}}</a></li>
<li><a href="{{{href}}}">{{name}}{{#hasGenericParameters}}<span class="signature">{{{genericParameters}}}</span>{{/hasGenericParameters}}</a></li>
{{/navLinksWithGenerics}}
{{^hasHomepage}}
<li class="self-crumb">{{{ layoutTitle }}}</li>
{{/hasHomepage}}
{{#hasHomepage}}
<li><a href="{{homepage}}">{{{ layoutTitle }}}</a></li>
<li><a href="{{{homepage}}}">{{{ layoutTitle }}}</a></li>
{{/hasHomepage}}
</ol>
<div class="self-name">{{self.name}}</div>
6 changes: 3 additions & 3 deletions lib/templates/_search_sidebar.html
Original file line number Diff line number Diff line change
@@ -6,16 +6,16 @@

<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
{{#navLinks}}
<li><a href="{{href}}">{{name}}</a></li>
<li><a href="{{{href}}}">{{name}}</a></li>
{{/navLinks}}
{{#navLinksWithGenerics}}
<li><a href="{{href}}">{{name}}{{#hasGenericParameters}}<span class="signature">{{{genericParameters}}}</span>{{/hasGenericParameters}}</a></li>
<li><a href="{{{href}}}">{{name}}{{#hasGenericParameters}}<span class="signature">{{{genericParameters}}}</span>{{/hasGenericParameters}}</a></li>
{{/navLinksWithGenerics}}
{{^hasHomepage}}
<li class="self-crumb">{{{ layoutTitle }}}</li>
{{/hasHomepage}}
{{#hasHomepage}}
<li><a href="{{homepage}}">{{{ layoutTitle }}}</a></li>
<li><a href="{{{homepage}}}">{{{ layoutTitle }}}</a></li>
{{/hasHomepage}}
</ol>

18 changes: 9 additions & 9 deletions lib/templates/_sidebar_for_category.html
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
<ol>
{{#self.hasPublicLibraries}}
<li class="section-title"><a href="{{self.href}}#libraries">Libraries</a></li>
<li class="section-title"><a href="{{{self.href}}}#libraries">Libraries</a></li>
{{#self.publicLibraries}}
<li>{{{ linkedName }}}</li>
{{/self.publicLibraries}}
{{/self.hasPublicLibraries}}

{{#self.hasPublicMixins}}
<li class="section-title"><a href="{{library.href}}#mixins">Mixins</a></li>
<li class="section-title"><a href="{{{library.href}}}#mixins">Mixins</a></li>
{{#self.publicMixins}}
<li>{{{ linkedName }}}</li>
{{/self.publicMixins}}
{{/self.hasPublicMixins}}

{{#self.hasPublicClasses}}
<li class="section-title"><a href="{{self.href}}#classes">Classes</a></li>
<li class="section-title"><a href="{{{self.href}}}#classes">Classes</a></li>
{{#self.publicClasses}}
<li>{{{ linkedName }}}</li>
{{/self.publicClasses}}
{{/self.hasPublicClasses}}

{{#self.hasPublicConstants}}
<li class="section-title"><a href="{{self.href}}#constants">Constants</a></li>
<li class="section-title"><a href="{{{self.href}}}#constants">Constants</a></li>
{{#self.publicConstants}}
<li>{{{ linkedName }}}</li>
{{/self.publicConstants}}
{{/self.hasPublicConstants}}

{{#self.hasPublicProperties}}
<li class="section-title"><a href="{{self.href}}#properties">Properties</a></li>
<li class="section-title"><a href="{{{self.href}}}#properties">Properties</a></li>
{{#self.publicProperties}}
<li>{{{ linkedName }}}</li>
{{/self.publicProperties}}
{{/self.hasPublicProperties}}

{{#self.hasPublicFunctions}}
<li class="section-title"><a href="{{self.href}}#functions">Functions</a></li>
<li class="section-title"><a href="{{{self.href}}}#functions">Functions</a></li>
{{#self.publicFunctions}}
<li>{{{ linkedName }}}</li>
{{/self.publicFunctions}}
{{/self.hasPublicFunctions}}

{{#self.hasPublicEnums}}
<li class="section-title"><a href="{{self.href}}#enums">Enums</a></li>
<li class="section-title"><a href="{{{self.href}}}#enums">Enums</a></li>
{{#self.publicEnums}}
<li>{{{ linkedName }}}</li>
{{/self.publicEnums}}
{{/self.hasPublicEnums}}

{{#self.hasPublicTypedefs}}
<li class="section-title"><a href="{{self.href}}#typedefs">Typedefs</a></li>
<li class="section-title"><a href="{{{self.href}}}#typedefs">Typedefs</a></li>
{{#self.publicTypedefs}}
<li>{{{ linkedName }}}</li>
{{/self.publicTypedefs}}
{{/self.hasPublicTypedefs}}

{{#self.hasPublicExceptions}}
<li class="section-title"><a href="{{self.href}}#exceptions">Exceptions</a></li>
<li class="section-title"><a href="{{{self.href}}}#exceptions">Exceptions</a></li>
{{#self.publicExceptions}}
<li>{{{ linkedName }}}</li>
{{/self.publicExceptions}}
74 changes: 38 additions & 36 deletions lib/templates/_sidebar_for_class.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
<ol>
{{#clazz.hasPublicConstructors}}
<li class="section-title"><a href="{{clazz.href}}#constructors">Constructors</a></li>
{{#clazz.publicConstructors}}
<li><a{{#isDeprecated}} class="deprecated"{{/isDeprecated}} href="{{href}}">{{shortName}}</a></li>
{{/clazz.publicConstructors}}
{{/clazz.hasPublicConstructors}}
{{#clazz}}
{{#hasPublicConstructors}}
<li class="section-title"><a href="{{{href}}}#constructors">Constructors</a></li>
{{#publicConstructors}}
<li><a{{#isDeprecated}} class="deprecated"{{/isDeprecated}} href="{{{href}}}">{{shortName}}</a></li>
{{/publicConstructors}}
{{/hasPublicConstructors}}

{{#clazz.hasPublicProperties}}
{{#hasPublicProperties}}
<li class="section-title{{ #allPublicInstancePropertiesInherited }} inherited{{ /allPublicInstancePropertiesInherited }}">
<a href="{{clazz.href}}#instance-properties">Properties</a>
<a href="{{{href}}}#instance-properties">Properties</a>
</li>
{{#clazz.allPublicInstanceProperties}}
{{#allPublicInstanceProperties}}
<li{{ #isInherited }} class="inherited"{{ /isInherited}}>{{{ linkedName }}}</li>
{{/clazz.allPublicInstanceProperties}}
{{/clazz.hasPublicProperties}}
{{/allPublicInstanceProperties}}
{{/hasPublicProperties}}

{{#clazz.hasPublicMethods}}
<li class="section-title{{ #allPublicInstanceMethodsInherited }} inherited{{ /allPublicInstanceMethodsInherited }}"><a href="{{clazz.href}}#instance-methods">Methods</a></li>
{{#clazz.allPublicInstanceMethods}}
{{#hasPublicMethods}}
<li class="section-title{{ #allPublicInstanceMethodsInherited }} inherited{{ /allPublicInstanceMethodsInherited }}"><a href="{{{href}}}#instance-methods">Methods</a></li>
{{#allPublicInstanceMethods}}
<li{{ #isInherited }} class="inherited"{{ /isInherited}}>{{{ linkedName }}}</li>
{{/clazz.allPublicInstanceMethods}}
{{/clazz.hasPublicMethods}}
{{/allPublicInstanceMethods}}
{{/hasPublicMethods}}

{{#clazz.hasPublicOperators}}
<li class="section-title{{ #allPublicOperatorsInherited }} inherited{{ /allPublicOperatorsInherited}}"><a href="{{clazz.href}}#operators">Operators</a></li>
{{#clazz.allPublicOperators}}
{{#hasPublicOperators}}
<li class="section-title{{ #allPublicOperatorsInherited }} inherited{{ /allPublicOperatorsInherited}}"><a href="{{{href}}}#operators">Operators</a></li>
{{#allPublicOperators}}
<li{{ #isInherited }} class="inherited"{{ /isInherited}}>{{{ linkedName }}}</li>
{{/clazz.allPublicOperators}}
{{/clazz.hasPublicOperators}}
{{/allPublicOperators}}
{{/hasPublicOperators}}

{{#clazz.hasPublicStaticProperties}}
<li class="section-title"><a href="{{clazz.href}}#static-properties">Static properties</a></li>
{{#clazz.publicStaticProperties}}
{{#hasPublicStaticProperties}}
<li class="section-title"><a href="{{{href}}}#static-properties">Static properties</a></li>
{{#publicStaticProperties}}
<li>{{{ linkedName }}}</li>
{{/clazz.publicStaticProperties}}
{{/clazz.hasPublicStaticProperties}}
{{/publicStaticProperties}}
{{/hasPublicStaticProperties}}

{{#clazz.hasPublicStaticMethods}}
<li class="section-title"><a href="{{clazz.href}}#static-methods">Static methods</a></li>
{{#clazz.publicStaticMethods}}
{{#hasPublicStaticMethods}}
<li class="section-title"><a href="{{{href}}}#static-methods">Static methods</a></li>
{{#publicStaticMethods}}
<li>{{{ linkedName }}}</li>
{{/clazz.publicStaticMethods}}
{{/clazz.hasPublicStaticMethods}}
{{/publicStaticMethods}}
{{/hasPublicStaticMethods}}

{{#clazz.hasPublicConstants}}
<li class="section-title"><a href="{{clazz.href}}#constants">Constants</a></li>
{{#clazz.publicConstants}}
{{#hasPublicConstants}}
<li class="section-title"><a href="{{{href}}}#constants">Constants</a></li>
{{#publicConstants}}
<li>{{{linkedName}}}</li>
{{/clazz.publicConstants}}
{{/clazz.hasPublicConstants}}
{{/publicConstants}}
{{/hasPublicConstants}}
{{/clazz}}
</ol>
Loading