angel_markdown 2.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 60

markdown #

Pub

Markdown view generator for Angel.

With this plug-in, you can easily serve static sites without doing more than writing simple Markdown. Thus, it is a friendly choice for writing API documentation or other tedious HTML-writing tasks.

Installation #

In your pubspec.yaml:

dependencies:
  angel_framework: ^1.0.0
  angel_markdown: ^1.0.0

Usage #

It's very straightforward to configure an Angel server to use Markdown. Keep in mind to use package:file instead of dart:io:

configureServer(Angel app) async {
  var fs = LocalFileSystem();
  await app.configure(markdown(
    // The directory where your views are located.
    fs.directory('views'),
  ));
}

You can then generate HTML on-the-fly in a request handler. Assuming your view directory contained a file named hello.md, the following would render it as an HTML response:

configureServer(Angel app) async {
  app.get('/hello', (res) => res.render('hello'));
}

package:angel_markdown by default searches for files with a .md extension; however, you can easily override this.

Interpolation #

angel_markdown can interpolate the values of data from locals before building the Markdown.

For example, with the following template species.md:

# Species: {{species.name}}
The species *{{species.genus.name}} {{species.name}}* is fascinating...

You can render as follows:

requestHandler(ResponseContext res) {
  return res.render('species', {
    'species': new Species('sapiens', genius: 'homo')
  });
}

To disable interpolation for a single bracket, prefix it with an @, ex: @{{raw | not_interpolated | angular}}.

Templates #

Markdown is frequently used to build the content of sites, but not the templates. You might want to wrap the content of pages in a custom template to apply pretty CSS and JS, etc:

configureServer(Angel app) async {
  await app.configure(
    markdown(
        // The directory where your views are located.
        fs.directory('views'), template: (content, Map locals) {
      return '''<!DOCTYPE html>
<html>
    <head>
        <title>${locals['title']} - My Site</title>
    </head>
    <body>
      $content
    </body>
</html>
        ''';
    }),
  );
}

The template function will have access to whatever values were passed to the renderer, or an empty Map.

Enhancing Markdown #

You can pass an extensionSet to add additional features to the Markdown renderer. By default, this plug-in configures it to enable Github-flavored Markdown.

2.0.0 #

  • Angel 2 + Dart 2 updates.
  • Use package:file.

example/main.dart

import 'dart:async';
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_markdown/angel_markdown.dart';
import 'package:file/local.dart';

main() async {
  var app = await createServer();
  var http = AngelHttp(app);
  var server = await http.startServer(InternetAddress.loopbackIPv4, 3000);
  print('Listening at http://${server.address.address}:${server.port}');
}

Future<Angel> createServer() async {
  // Create a new server, and install the Markdown renderer.
  var app = new Angel();
  var fs = LocalFileSystem();
  await app
      .configure(markdown(fs.directory('views'), template: (content, locals) {
    return '''
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>${locals['title'] ?? 'Example Site'} - Example Site</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css">
  </head>
  <body>
    <div class="ui top fixed menu">
      <a class="header item" href="/">
        <i class="home icon"></i>
        Home
      </a>
    </div>
    <div class="ui container" style="margin-top: 5em;">
      $content
    </div>
  </body>
</html>
    ''';
  }));

  // Compile a landing page
  app.get('/', (req, res) => res.render('hello', {'title': 'Welcome'}));

  return app;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angel_markdown: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angel_markdown/angel_markdown.dart';
  
Version Uploaded Documentation Archive
2.0.0 Apr 11, 2019 Go to the documentation of angel_markdown 2.0.0 Download angel_markdown 2.0.0 archive
1.0.0+1 Aug 13, 2017 Go to the documentation of angel_markdown 1.0.0+1 Download angel_markdown 1.0.0+1 archive
1.0.0 Aug 13, 2017 Go to the documentation of angel_markdown 1.0.0 Download angel_markdown 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Jun 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: other

Primary library: package:angel_markdown/angel_markdown.dart with components: io, mirrors.

Health suggestions

Fix lib/angel_markdown.dart. (-0.50 points)

Analysis of lib/angel_markdown.dart reported 1 hint:

line 44 col 13: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_framework ^2.0.0-alpha 2.0.3
file ^5.0.0 5.0.8+1
markdown ^2.0.0 2.0.3
Transitive dependencies
angel_container 1.0.4
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.0.6
args 1.5.2
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.11
combinator 1.1.0
convert 2.1.1
crypto 2.0.6
dart2_constant 1.0.2+dart2
http2 1.0.0
http_parser 3.1.3
http_server 0.9.8+2
intl 0.15.8
logging 0.11.3+2
matcher 0.12.5
merge_map 1.0.2
meta 1.1.7
mime 0.9.6+3
mock_request 1.0.5
path 1.6.2
quiver 2.0.3
quiver_hashcode 2.0.0
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
tuple 1.0.2
typed_data 1.1.6
uuid 2.0.2
Dev dependencies
angel_test ^2.0.0
pedantic ^1.0.0 1.7.0
test ^1.0.0