Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
163 lines (110 sloc) 5.01 KB

Code compilation

First thing first: using "alternative" languages is not a constrain. Wordless scaffolded theme uses the following languages by default:

  • PHUG for views as alternative to PHP+HTML
  • CoffeeScript 2 for JS (ES6 ready)
  • Sass for CSS

You could decide to use plain languages, just by renaming (and rewriting) your files.

Wordless' functions which want filenames as arguments such as

<?php

render_partial("posts/post")

// or

javascript_url("application")

will always require extension-less names and they will find your files whatever extension they have.

.. seealso::

    PHUG paragraph @ :ref:`PlainPhp`

Anyway we think that default languages are powerful, more productive, more pleasant to read and to write.

Add the fact that wordless will take care of all compilation tasks, giving you focus on writing: we think this is a win-win scenario.

PHUG

Pug is a robust, elegant, feature rich template engine for Node.js. Here we use a terrific PHP port of the language: Phug. You can find huge documentation on the official site https://www.phug-lang.com/, where you can also find a neat live playground (click on the "Try Phug" menu item).

It comes from the JS world, so most front-end programmers should be familiar with it, but it is also very similar to other template languages such as SLIM and HAML (old!).

We love it because it is concise, clear, tidy and clean.

For sure becoming fluent in PUG usage could have a not-so-flat learning curve, but starting from the basics shuold be affordable and the reward is high.

Who compiles PUG?

When a .html.pug template is loaded, Wordless plugin will automatically compile (and cache) it. As far as you have the plugin activated you are ok.

Important

By deafult, you have nothing to do to deploy in production, but if performance is crucial in your project, than you can optimize. See :ref:`PHUG optimizer` for more informations.

CoffeeScript and Sass

Here we are in the Webpack domain; from the compilation point of view there is nothing Wordless specific but file path configuration.

The default webpack configuration file is written itself in coffeescript, because it is natively supported by Webpack and because it make the code more affordable to read.

Configuration is pretty standard, so it's up to you to read Webpack's documentation. Let's see how paths are configured in webpack.config.coffee.

Paths

Paths are based on the Wordless scaffold. Variables are defined at top:

.. literalinclude:: /../../wordless/theme_builder/vanilla_theme/webpack.config.coffee
    :language: coffeescript
    :caption: webpack.config.coffee
    :lineno-start: 4
    :lines: 4-7

and are used by entry and output configurations:

.. literalinclude:: /../../wordless/theme_builder/vanilla_theme/webpack.config.coffee
    :language: coffeescript
    :caption: webpack.config.coffee
    :lineno-start: 18
    :lines: 18-23

CSS will be extracted from the bundle by the usual extract-text-webpack-plugin

.. literalinclude:: /../../wordless/theme_builder/vanilla_theme/webpack.config.coffee
    :language: coffeescript
    :caption: webpack.config.coffee
    :lineno-start: 69
    :lines: 69-82
    :emphasize-lines: 10

Compiled files inclusion

Wrapping up: result files will be

  • assets/javascripts/application.js
  • assets/stylesheets/screen.css

As far as those files remain as-is, the theme will automatically load them.

If you want to edit names and/or paths, you have only to edit WordPress assets enqueueing configurations:

.. literalinclude:: /../../wordless/theme_builder/vanilla_theme/config/initializers/default_hooks.php
    :caption: config/initializers/default_hooks.php
    :language: php
    :linenos:
    :emphasize-lines: 6,16

Note

stylesheet_url and javascript_url Wordless' helpers will search for a file named as per the passed parameter inside the default paths, so if you'll use default paths and custom file naming, you'll be ok, but if you'll change the path you'll have to supply it using other WordPress functinons.

.. seealso::
    `stylesheet_url signature`_

    `javascript_url signature`_