Skip to content

Commit

Permalink
doc: Strong-Mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Nov 16, 2016
1 parent 1f3a2bb commit 8604ad8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
15 changes: 15 additions & 0 deletions .analysis_options
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
# ------------------------------------------------------------------------------
# Config for Analyzer
# More: https://pub.dartlang.org/packages/analyzer
#
# Analyzer options:
# https://www.dartlang.org/guides/language/analysis-options
#

analyzer:
strong-mode: true

# Exclude wegen https://github.com/dart-lang/sdk/issues/26420
# und https://github.com/dart-lang/test/issues/436
# exclude:
# - test/**
1 change: 0 additions & 1 deletion lib/sitegen.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library sitegen;
import 'dart:io'; import 'dart:io';
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:isolate';
import 'dart:math'; import 'dart:math';


import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Config.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Config {
_settings[Config._CONF_SASS_PATH] = ""; _settings[Config._CONF_SASS_PATH] = "";
_settings[Config._CONF_BROWSER] = "Chromium"; _settings[Config._CONF_BROWSER] = "Chromium";


_settings[Config._CONF_SITE_OPTIONS] = {}; _settings[Config._CONF_SITE_OPTIONS] = <String,String>{};


_settings[Options._ARG_IP] = "127.0.0.1"; _settings[Options._ARG_IP] = "127.0.0.1";
_settings[Config._CONF_PORT] = "8080"; _settings[Config._CONF_PORT] = "8080";
Expand Down Expand Up @@ -112,7 +112,7 @@ class Config {


String get sasspath => _sasspath; String get sasspath => _sasspath;


Map<String,String> get siteoptions => _settings[Config._CONF_SITE_OPTIONS]; Map<String,String> get siteoptions => _settings[Config._CONF_SITE_OPTIONS] as Map<String,String>;


String get ip => _settings[Options._ARG_IP]; String get ip => _settings[Options._ARG_IP];


Expand Down
16 changes: 9 additions & 7 deletions lib/src/Generator.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class Generator {


_logger.fine("\nFile: ${relativeFileName}, Path: $relativePath"); _logger.fine("\nFile: ${relativeFileName}, Path: $relativePath");
final List<String> lines = file.readAsLinesSync(); final List<String> lines = file.readAsLinesSync();
Map<String,dynamic> pageOptions = {}; Map<String,dynamic> pageOptions = <String,dynamic>{};


final bool hasYamlBlock = _hasYamlBlock(config.yamldelimeter,lines,extension); final bool hasYamlBlock = _hasYamlBlock(config.yamldelimeter,lines,extension);
if (hasYamlBlock) { if (hasYamlBlock) {
List<String> yamlBlock = _extractYamlBlockFrom(config.yamldelimeter,lines,extension); List<String> yamlBlock = _extractYamlBlockFrom(config.yamldelimeter,lines,extension);
if(yamlBlock.length > 0) { if(yamlBlock.length > 0) {
pageOptions.addAll(yaml.loadYaml(yamlBlock.join('\n'))); pageOptions.addAll(yaml.loadYaml(yamlBlock.join('\n')) as Map<String,String>);
_resolvePartialsInYamlBlock(partialsDir,pageOptions,config.usemarkdown); _resolvePartialsInYamlBlock(partialsDir,pageOptions,config.usemarkdown);


// +1 for the YAML-Block-Delimiter ("~~~") line // +1 for the YAML-Block-Delimiter ("~~~") line
Expand All @@ -77,7 +77,8 @@ class Generator {
pageOptions = _fillInDefaultPageOptions(config.dateformat,file, pageOptions,config.siteoptions); pageOptions = _fillInDefaultPageOptions(config.dateformat,file, pageOptions,config.siteoptions);
pageOptions['_data'] = dataMap; pageOptions['_data'] = dataMap;
pageOptions['_content'] = renderTemplate(lines.join('\n'), pageOptions, pageOptions['_content'] = renderTemplate(lines.join('\n'), pageOptions,
_partialsResolver(partialsDir,isMarkdownSupported: config.usemarkdown)); _partialsResolver(partialsDir,isMarkdownSupported: config.usemarkdown)
);


pageOptions['_template'] = "none"; pageOptions['_template'] = "none";


Expand All @@ -101,7 +102,8 @@ class Generator {
} }


final String content = _fixPathRefs(renderTemplate(templateContent, pageOptions, final String content = _fixPathRefs(renderTemplate(templateContent, pageOptions,
_partialsResolver(partialsDir,isMarkdownSupported: config.usemarkdown)),config); _partialsResolver(partialsDir,isMarkdownSupported: config.usemarkdown)
),config);


final String outputFilename = "${path.basenameWithoutExtension(relativeFileName)}.${outputExtension}"; final String outputFilename = "${path.basenameWithoutExtension(relativeFileName)}.${outputExtension}";
final Directory outputPath = _createOutputPath(outputDir,relativePath); final Directory outputPath = _createOutputPath(outputDir,relativePath);
Expand Down Expand Up @@ -166,7 +168,7 @@ class Generator {
* Example: * Example:
* Name: category.house -> category/house.[html | md] * Name: category.house -> category/house.[html | md]
*/ */
Function _partialsResolver(final Directory partialsDir,{ final bool isMarkdownSupported: true}) { PartialsResolver _partialsResolver(final Directory partialsDir,{ final bool isMarkdownSupported: true}) {
Validate.notNull(partialsDir); Validate.notNull(partialsDir);


mustache.Template resolver(final String name) { mustache.Template resolver(final String name) {
Expand Down Expand Up @@ -319,7 +321,7 @@ class Generator {
return startsWithString; return startsWithString;
} }


Map _fillInDefaultPageOptions(final String defaultDateFormat,final File file, Map pageOptions,final Map<String,String> siteOptions) { Map<String,dynamic> _fillInDefaultPageOptions(final String defaultDateFormat,final File file,final Map<String,dynamic> pageOptions,final Map<String,String> siteOptions) {
final String filename = path.basenameWithoutExtension(file.path); final String filename = path.basenameWithoutExtension(file.path);
pageOptions.putIfAbsent('title', () => filename); pageOptions.putIfAbsent('title', () => filename);


Expand Down Expand Up @@ -482,7 +484,7 @@ class Generator {
_logger.fine(" ${"".padRight(nestingLevel * 2)} $key."); _logger.fine(" ${"".padRight(nestingLevel * 2)} $key.");


if(value is Map) { if(value is Map) {
_showMap(value,nestingLevel + 1); _showMap(value as Map<String,dynamic>,nestingLevel + 1);


} else { } else {
String valueAsString = value.toString().replaceAll(new RegExp("(\n|\r|\\s{2,}|${_NEWLINE_PROTECTOR})",multiLine: true),""); String valueAsString = value.toString().replaceAll(new RegExp("(\n|\r|\\s{2,}|${_NEWLINE_PROTECTOR})",multiLine: true),"");
Expand Down
12 changes: 7 additions & 5 deletions samples/simple/.sitegen/html/_content/markdown.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default_vars:
- "`_content`: post content (only accessible from templates, not markdown)" - "`_content`: post content (only accessible from templates, not markdown)"


# Alternate List Syntax # Alternate List Syntax
authors: [foo, bar, baz] authors: [hallo,foo,bar,baz]


# A list of Dictionaries # A list of Dictionaries
links: links:
Expand Down Expand Up @@ -68,17 +68,19 @@ Some vars that are always available by default:
Image: ![Logo](assets/images/ios-desktop.png) Image: ![Logo](assets/images/ios-desktop.png)
{{#each items}} ----
{{#_data.items}}
<li> <li>
{{name}} {{name}}
{{#if items}} {{#if items}}
<ul> <ul>
{{> list}} {{> list}}
</ul> </ul>
{{/if}} {{/if items}}
</li> </li>
{{/each}} {{/_data.items}}
----
{{#default_vars}} {{#default_vars}}
{{.}} {{.}}
Expand Down
2 changes: 2 additions & 0 deletions samples/simple/web/main.dart
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:html' as html;

import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:console_log_handler/console_log_handler.dart'; import 'package:console_log_handler/console_log_handler.dart';


Expand Down
17 changes: 15 additions & 2 deletions samples/simple/web/markdown.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,11 +91,24 @@ <h4>Subheadline</h4>
<p>And anything beyond that gets interpreted as <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a>!</p> <p>And anything beyond that gets interpreted as <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a>!</p>
<p>You can even use template tags in here, for any variables you set in in the top YAML block, or in your <code>site.yaml</code> file:</p> <p>You can even use template tags in here, for any variables you set in in the top YAML block, or in your <code>site.yaml</code> file:</p>
<p>This post's title is: "Markdown"</p> <p>This post's title is: "Markdown"</p>
<p>This file was last modified on 2/19/2016</p> <p>This file was last modified on 11/16/2016</p>
<p>Link to <a href="about/">subpages</a></p> <p>Link to <a href="about/">subpages</a></p>
<p>Note that variables beginning with an underscore designate <em>implicit</em> metadata added by <strong>SiteGen</strong>.</p> <p>Note that variables beginning with an underscore designate <em>implicit</em> metadata added by <strong>SiteGen</strong>.</p>
<p>Some vars that are always available by default:</p> <p>Some vars that are always available by default:</p>
<p>Image: <a href="assets/images/ios-desktop.png"><img alt="Logo" src="assets/images/ios-desktop.png"></img></a></p> <p>Image: <a href="assets/images/ios-desktop.png"><img alt="Logo" src="assets/images/ios-desktop.png"></img></a></p>
<hr /><li>
foo1
</li>
<li>
foo2
</li>
<li>
foo3
</li>
<li>
foo8
</li>
<hr />
<pre><code>`title`: post title, automatically set to name of markdown file if left blank <pre><code>`title`: post title, automatically set to name of markdown file if left blank
`_site`: site.yaml values `_site`: site.yaml values
`_date`: post 'last modified' date `_date`: post 'last modified' date
Expand All @@ -108,7 +121,7 @@ <h4>Subheadline</h4>
<a href="http://google.com">Google</a><br /> <a href="http://google.com">Google</a><br />
<a href="http://github.com">Github</a> </p><ul><li><a href="https://github.com/MikeMitterer/dart-sitegen">SiteGen</a></li><li><a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a></li><li><a href="http://mustache.github.io/mustache.5.html">Mustache</a></li><li> <a href="http://github.com">Github</a> </p><ul><li><a href="https://github.com/MikeMitterer/dart-sitegen">SiteGen</a></li><li><a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a></li><li><a href="http://mustache.github.io/mustache.5.html">Mustache</a></li><li>
<p><a href="http://rhnh.net/2011/01/31/yaml-tutorial">YAML</a></p></li><li> <p><a href="http://rhnh.net/2011/01/31/yaml-tutorial">YAML</a></p></li><li>
<p>foo</p></li><li>bar</li><li>baz</li></ul> <p>hallo</p></li><li>foo</li><li>bar</li><li>baz</li></ul>
<p>Note how you need to use a <code>.</code> to access a list item, but can access map/dict keys directly.</p> <p>Note how you need to use a <code>.</code> to access a list item, but can access map/dict keys directly.</p>
<p>You can of course disable these markdown templating features by setting <code>markdown_templating: true</code> in your site.yaml file. <p>You can of course disable these markdown templating features by setting <code>markdown_templating: true</code> in your site.yaml file.
Same ideas apply when writing your actual HTML templates. See <a href="http://mustache.github.io/mustache.5.html">mustache's docs</a> for more templating info.</p> Same ideas apply when writing your actual HTML templates. See <a href="http://mustache.github.io/mustache.5.html">mustache's docs</a> for more templating info.</p>
Expand Down
2 changes: 1 addition & 1 deletion tool/grind.dart
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:grinder/grinder.dart'; import 'package:grinder/grinder.dart';


main(args) => grind(args); main(final List<String> args) => grind(args);


@Task() @Task()
@Depends(test,buildSamples) @Depends(test,buildSamples)
Expand Down

0 comments on commit 8604ad8

Please sign in to comment.