MDL Theme

1.0.0

Author

Miguel Angel Rivera Notararigo

Contact
@ntrrg
Date
2018-06-21T00:30:00-04:00
License

MIT

NtWeb

This is a Material Design Lite theme for NtDocutils. This page was built with it, so you can see what is possible to do, but if you want to see all the styles, checkout the demo site.

Features

  • Filter content by OS, distributions, categories or any other filters you want (see this section).

Install

Requirements:

  • Python >= 3.4

$ pip install ntdocutils-theme-mdl==1.0.0
C:\> pip install ntdocutils-theme-mdl==1.0.0

Usage

Basically, you have to do two things:

  1. Create a .rst file:

    example.rst:

    ==========
    My Article
    ==========
    
    :Author: Vultur Gryphus
    :Contact: info@vultur.org.ve
    
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  2. Process your file:

    $ ntdocutils -T mdl example.rst example.html
    C:\> ntdocutils -T mdl example.rst example.html

And that's it, you already have some like this:

images/example.png

Filtering

You can filter content just adding the fl fl-{{ filter name }} classes in the elements you want filter, NtDocutils will create the buttons dynamically at the left bottom corner and set the first filter that it finds as default. E.g:

.. class:: fl fl-linux

**Text for Linux**

.. class:: fl fl-windows

**Text for Windows**

Will result in:

Text for Linux

Text for Windows

And creates two buttons at the bottom left corner with the filters names.

Attachments

You can set a list of useful files in the attachments-button button by adding the following lines in the article:

.. raw:: html

    <script>
      ATTACHMENTS = [
        {
          url: 'index.rst',
          name: 'NtDocutils MDL Theme 1.0.0.rst',
          icon: 'code'
        }
      ]
    </script>

Syntax

ATTACHMENTS is a global array, it store the files list showed in the attachments-button button, each file must be defined as an object with the following properties:

url (string)

URL to the file.

name (string)

Optional. Name displayed at the list, also overwrites the attachment name.

icon (string)

Optional. Material icon displayed at the list, by default this theme uses an icon related to the file extension.

.. raw:: html

    <script>
      ATTACHMENTS = [
        {
          "url": URL,
          "name": DISPLAY_NAME,
          "icon": ICON_NAME
        },
        ...
        {
          "url": URL_N,
          "name": DISPLAY_NAME_N,
          "icon": ICON_NAME_N
        }
      ]
    </script>

Translations

You can link article translations in the lang-button button by adding the following lines in the article:

.. raw:: html

    <script>
      LANGS = [
        {
          url: '/es/articulos/ntdocutils/',
          name: 'Español (Spanish)'
        }
      ]
    </script>

Syntax

LANGS is a global array, it store the translations list showed in the lang-button button, each translation must be defined as an object with the following properties:

url (string)

URL to the translation page.

name (string)

Name displayed at the list.

.. raw:: html

    <script>
      LANGS = [
        {
          "url": URL,
          "name": DISPLAY_NAME
        },
        ...
        {
          "url": URL_N,
          "name": DISPLAY_NAME_N
        }
      ]
    </script>

Versions

You can link article versions in the versions-button button by adding the following lines in the article:

.. raw:: html

    <script>
      VERSIONS = [
        {
          url: 'v1.0.0/',
          name: 'v1.0.0'
        }
      ];
    </script>

Syntax

VERSIONS is a global array, it store the versions list showed in the versions-button button, each version must be defined as an object with the following properties:

url (string)

URL to the version page.

name (string)

Name displayed at the list.

.. raw:: html

    <script>
      VERSIONS = [
        {
          "url": URL,
          "name": DISPLAY_VERSION_NUMBER
        },
        ...
        {
          "url": URL_N,
          "name": DISPLAY_VERSION_NUMBER_N
        }
      ];
    </script>

Printing

There are some special classes that let you improve the way your article is printed when something goes wrong; for example, some content doesn't fit at the page or simply can't be showed as it should in paper. These classes are:

  • .media-screen: shows the element just in a screen.

  • .media-print: shows the element just in paper.

Examples:

  • White spaces for paper (useful for ensure printing format):

.. Page break

.. |pb| raw:: html

    <div class="media-print" style="page-break-after: always"></div>

.. Line break

.. |lb| raw:: html

    <br class="media-print"/>
  • Display content for specific device:

.. Screen

.. raw:: html

    <object data="example.html" type="text/html" height="400px"
        width="100%" class="media-screen">
    </object>

.. Paper

.. image:: images/example.png
    :class: media-print

Responsiveness

With responsiveness classes is easy to improve how the article is viewed in different sized screens, just use large-screen and small-screen when you want it work, try it, resize the window.

##########################
# LARGE SCREEN DETECTED! #
##########################
##########################
# SMALL SCREEN DETECTED! #
##########################
.. code:: text
    :class: large-screen

    ##########################
    # LARGE SCREEN DETECTED! #
    ##########################

.. code:: text
    :class: small-screen

    ##########################
    # SMALL SCREEN DETECTED! #
    ##########################

Theme customization

You can use the customize tool from the MDL site to get a custom .css with your preferred colors, after that, you must setup some styles by creating a file with the following template:

customize.css

1 /* Ribbon */
2 
3     .ribbon {
4         background-color: {{ Primary color }};
5     }
6 
7 /* ... */
83 /* ... */
84 
85 /* Links */
86 
87     /*a {
88         color: {{ Accent color }};
89     }*/
90 
91 /* ... */

The recommended color for the ribbon background (line 4) is the primary color from the theme, you can get this value searching the property color at the rule .mdl-button.mdl-button--colored in the file downloaded from MDL (material.min.css). The links (line 88) use the accent color from the theme, but in some cases this make them a little unreadable, so you could uncomment it and use the primary color. You should feel free editing the others rules, but usually they will be fine with that values. When you are ready, you have to run NtDocutils with the following option:

$ ntdocutils -T mdl \
    --stylesheet=path/to/material.min.css,path/to/customize.css \
    source.rst destination.html
C:\> ntdocutils -T mdl \
       --stylesheet=path/to/material.min.css,path/to/customize.css \
       source.rst destination.html

Uninstall

# pip uninstall ntdocutils-theme-mdl
C:\> pip uninstall ntdocutils-theme-mdl

Acknowledgment

Working on this project I use/used:

Docutils Team. reStructuredText. http://docutils.sourceforge.net/rst.html

Mozilla Developer Network. JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript