From: Vladimír Vondruš Date: Thu, 14 Jun 2018 11:58:41 +0000 (+0200) Subject: m.components: provide roles for labels. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=61dc2583cf4cec0165800035549068f95218fcd8;p=blog.git m.components: provide roles for labels. I got extremely tired of writing this myself *every time*. --- diff --git a/doc/css/components.rst b/doc/css/components.rst index 282d15c1..3365afe3 100644 --- a/doc/css/components.rst +++ b/doc/css/components.rst @@ -442,6 +442,12 @@ of surrounding text.

That's how things are now. clarified

+.. note-info:: + + The `Pelican Components plugin <{filename}/plugins/components.rst#labels>`__ + provides convenience :rst:`:label-:` and :rst:`:label-flat-:` interpreted + text roles for labels as well. + `Tables`_ ========= diff --git a/doc/plugins/components.rst b/doc/plugins/components.rst index 5c91fc40..bf9bd12f 100644 --- a/doc/plugins/components.rst +++ b/doc/plugins/components.rst @@ -301,6 +301,24 @@ Mark your reST table with :rst:`..class:: m-table` to give it styling. .. todo: cell coloring, footer etc. +`Labels`_ +========= + +Use :rst:`:label-default:` etc. or :rst:`:label-flat-default:` etc. to create +inline `text labels <{filename}/css/components.rst#labels>`_. + +.. code-figure:: + + .. code:: rst + + - Design direction and project goals :label-success:`done` + - Automated testing :label-danger:`missing` + :label-flat-warning:`in progress` + + - Design direction and project goals :label-success:`done` + - Automated testing :label-danger:`missing` + :label-flat-warning:`in progress` + `Other m.css features`_ ======================= @@ -340,25 +358,19 @@ arranging content in three-column grid can be done like this: Right column content. -For inline components, derive a custom role with additional CSS classes. For -example: +For inline components not mentioned above, derive a custom role with additional +CSS classes. For example: .. code-figure:: .. code:: rst - .. role:: label-success - :class: m-label m-success - .. role:: label-danger - :class: m-label m-danger + .. role:: text-em-strong + :class: m-text m-em m-strong - - Design direction and project goals :label-success:`done` - - Automated testing :label-danger:`missing` + You *should* be **very** aware of the :text-em-strong:`potential danger`. - .. role:: label-success - :class: m-label m-success - .. role:: label-danger - :class: m-label m-danger + .. role:: text-em-strong + :class: m-text m-em m-strong - - Design direction and project goals :label-success:`done` - - Automated testing :label-danger:`missing` + You *should* be **very** aware of the :text-em-strong:`potential danger`. diff --git a/pelican-plugins/m/components.py b/pelican-plugins/m/components.py index b3771957..d554dc35 100644 --- a/pelican-plugins/m/components.py +++ b/pelican-plugins/m/components.py @@ -295,6 +295,51 @@ class DimButton(Button): class FlatButton(Button): style_class = 'm-flat' +def label(style_classes, name, rawtext, text, lineno, inliner, options, content): + return [nodes.inline(rawtext, text, classes=['m-label'] + style_classes)], [] + +def label_default(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-default'], name, rawtext, text, lineno, inliner, options, content) + +def label_primary(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-primary'], name, rawtext, text, lineno, inliner, options, content) + +def label_success(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-success'], name, rawtext, text, lineno, inliner, options, content) + +def label_warning(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-warning'], name, rawtext, text, lineno, inliner, options, content) + +def label_danger(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-danger'], name, rawtext, text, lineno, inliner, options, content) + +def label_info(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-info'], name, rawtext, text, lineno, inliner, options, content) + +def label_dim(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-dim'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_default(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-default'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_primary(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-primary'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_success(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-success'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_warning(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-warning'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_danger(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label('m-flat', ['m-danger'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_info(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-info'], name, rawtext, text, lineno, inliner, options, content) + +def label_flat_dim(name, rawtext, text, lineno, inliner, options={}, content=[]): + return label(['m-flat', 'm-dim'], name, rawtext, text, lineno, inliner, options, content) + def register(): rst.directives.register_directive('transition', Transition) @@ -335,3 +380,19 @@ def register(): rst.directives.register_directive('button-info', InfoButton) rst.directives.register_directive('button-dim', DimButton) rst.directives.register_directive('button-flat', FlatButton) + + rst.roles.register_canonical_role('label-default', label_default) + rst.roles.register_canonical_role('label-primary', label_primary) + rst.roles.register_canonical_role('label-success', label_success) + rst.roles.register_canonical_role('label-warning', label_warning) + rst.roles.register_canonical_role('label-danger', label_danger) + rst.roles.register_canonical_role('label-info', label_info) + rst.roles.register_canonical_role('label-dim', label_dim) + + rst.roles.register_canonical_role('label-flat-default', label_flat_default) + rst.roles.register_canonical_role('label-flat-primary', label_flat_primary) + rst.roles.register_canonical_role('label-flat-success', label_flat_success) + rst.roles.register_canonical_role('label-flat-warning', label_flat_warning) + rst.roles.register_canonical_role('label-flat-danger', label_flat_danger) + rst.roles.register_canonical_role('label-flat-info', label_flat_info) + rst.roles.register_canonical_role('label-flat-dim', label_flat_dim) diff --git a/pelican-plugins/m/test/components/page.html b/pelican-plugins/m/test/components/page.html index 1184932e..e5a62ff5 100644 --- a/pelican-plugins/m/test/components/page.html +++ b/pelican-plugins/m/test/components/page.html @@ -75,6 +75,8 @@ Second text.
Flat button
+

Inline elements: Primary label, +Flat warning label.

diff --git a/pelican-plugins/m/test/components/page.rst b/pelican-plugins/m/test/components/page.rst index b28a7dc1..68e05789 100644 --- a/pelican-plugins/m/test/components/page.rst +++ b/pelican-plugins/m/test/components/page.rst @@ -76,3 +76,6 @@ m.components .. button-flat:: # Flat button + +Inline elements: :label-primary:`Primary label`, +:label-flat-warning:`Flat warning label`.