chiark / gitweb /
m.components: provide roles for labels.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 14 Jun 2018 11:58:41 +0000 (13:58 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 17 Jun 2018 11:06:50 +0000 (13:06 +0200)
I got extremely tired of writing this myself *every time*.

doc/css/components.rst
doc/plugins/components.rst
pelican-plugins/m/components.py
pelican-plugins/m/test/components/page.html
pelican-plugins/m/test/components/page.rst

index 282d15c11a3842602ee5f1b0c95cd15423880203..3365afe361905b9ab27f7649391283386c111ebb 100644 (file)
@@ -442,6 +442,12 @@ of surrounding text.
         <p class="m-text m-dim">That's how things are now.
         <span class="m-label m-flat m-primary">clarified</span></p>
 
+.. 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`_
 =========
 
index 5c91fc40873119b76975fa9f1582b85edd997ca1..bf9bd12fe64dc9050058bc7d65e8243172fda16e 100644 (file)
@@ -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`.
index b3771957d717295c9e3ab0cc8bb2d6ca0fc2a709..d554dc35d3436a65f63db74e59e901e0dd698b9f 100644 (file)
@@ -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)
index 1184932e63548867ea5ebcb73271745f96d89c15..e5a62ff5394508cb43a58e3d27916f770537952e 100644 (file)
@@ -75,6 +75,8 @@ Second text.</div>
 <div class="m-button m-flat">
 <a href="#"><span>Flat button</span></a>
 </div>
+<p>Inline elements: <span class="m-label m-primary">Primary label</span>,
+<span class="m-label m-flat m-warning">Flat warning label</span>.</p>
 <!-- /content -->
       </div>
     </div>
index b28a7dc124e8c8ab1c59567eeff36aab17b2582b..68e057898c0f065466af4d4694a610413dc89980 100644 (file)
@@ -76,3 +76,6 @@ m.components
 .. button-flat:: #
 
     Flat button
+
+Inline elements: :label-primary:`Primary label`,
+:label-flat-warning:`Flat warning label`.