From f591851cb2cc61eb1bc8a0fabcf409cbed0adee0 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 22 Sep 2015 17:09:38 +0930 Subject: [PATCH] Patch Mithril with a route shortcut attribute Instead of: We can use: --- CHANGELOG.md | 1 + js/lib/utils/patchMithril.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39fd9275b..228cd9891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Migration generator, available via generate:migration console command. - Tags: Ability to set the tags page as the home page. - `bidi` attribute for Mithril elements as a shortcut to set up bidirectional bindings. +- `route` attribute for Mithril elements as a shortcut to link to a route. - Abstract SettingsModal component for quickly building admin config modals. - "Debug" button to inspect the response of a failed AJAX request. diff --git a/js/lib/utils/patchMithril.js b/js/lib/utils/patchMithril.js index 9ca27e1a9..672b2e39e 100644 --- a/js/lib/utils/patchMithril.js +++ b/js/lib/utils/patchMithril.js @@ -14,6 +14,13 @@ export default function patchMithril(global) { m.bidi(node, node.attrs.bidi); } + if (node.attrs.route) { + node.attrs.href = node.attrs.route; + node.attrs.config = m.route; + + delete node.attrs.route; + } + return node; };