// Copyright 2020 The Flutter team. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'dart:convert'; import 'data.dart'; import 'util.dart' as util; String _escapeAttribute(String s) => HtmlEscape(HtmlEscapeMode.attribute).convert(s); String _escapeElement(String s) => HtmlEscape(HtmlEscapeMode.element).convert(s); String description(Sample sample) => ''' $_descriptionHeader ${_descriptionPage(sample)} $_footer '''; String index(List samples) => ''' $_indexHeader ${_indexBody(samples)} $_footer '''; String _indexHeader = ''' Flutter samples '''; String _descriptionHeader = ''' Flutter samples '''; String _navbar = ''' '''; String _footer = ''' '''; String _indexBody(List samples) => '''
${util.indent(_navbar, 4)}

All Samples

A curated list of Flutter samples and apps

All
Sample
Cookbook
Web Demos
${util.indent(_indexCards(samples), 6)}
'''; String _backgroundImage(String url) => _escapeAttribute('background-image: url(\'$url\');'); String _indexCards(List samples) => samples.map(_indexCard).join(); String _indexCard(Sample sample) => '''
${_escapeElement(sample.type)}

${_escapeElement(sample.name)}

${sample.shortDescription}
'''; String _descriptionPage(Sample sample) => '''
${util.indent(_navbar, 4)}

${sample.name}

${sample.type}

By ${sample.author}

${util.indent(_descriptionButtons(sample), 6)}
local_offer Tags
${util.indent(_tags(sample), 8)}
${util.indent(_descriptionScreenshots(sample), 4)}
${util.indent(_descriptionText(sample), 4)}
'''; String _descriptionButtons(Sample sample) { var buf = StringBuffer(); if (sample?.web?.isNotEmpty == true) { buf.write( ''''''); } if (sample.type == 'app' || sample.type == 'sample' || sample.type == 'demo') { buf.write( ''''''); } if (sample.type == 'cookbook') { buf.write( ''''''); } return buf.toString(); } String _tags(Sample sample) { var buf = StringBuffer(); for (var tag in sample.tags) { buf.write('$tag\n'); } return buf.toString(); } String _descriptionScreenshots(Sample sample) { var buf = StringBuffer(); for (var screenshot in sample.screenshots) { buf.write( '''
${screenshot.alt}
\n'''); } return buf.toString(); } String _descriptionText(Sample sample) { return '

${sample.description}

'; }