The gem requires that your project root be a Compass project and expects that you have a folder structure matching the following in the root of your project:
To use with bundler add this to your Gemfile:
Or install it yourself:
$ gem install microservice_precompiler
To build all assets and templates into the distribution (./dist by default) folder:
require 'microservice_precompiler' precompiler = ::. precompiler.compile
Or with initialize options:
require 'microservice_precompiler' precompiler = ::. precompiler.project_root = "." precompiler.build_path = "dist" precompiler.mustaches_filename = "mustaches.yml" precompiler.compile
This runs all the precompiling options. Each can also be invoked individually:
# Clears the dist folder and sass cache files precompiler.cleanup # Runs the Compass build, which sends SASS to cachs precompiler.compass_build # Runs the Sprockets build which compiles CoffeeScript, minifies assets and moves to dist folder precompiler.sprockets_build # Runs the Mustache template build, which creates output files with the same syntax from the mustaches config yaml precompiler.mustache_build
SASS and CoffeeScript
These two parts are pretty simple. They are contained within their relevant directories and are written in their respective technologies. Because Sprockets is used to compile them the folders may contain subfolders which are automatically included in-line if the following line is present in a top-level file (where dependencies is the name of the subfolder you wish to include):
/* *=require_tree ./dependencies */
The mustache builder requires you to provide a template file and a logic file from which to build the template. You can create a complex folder structure in the templates directory as long as it's logic is matched in the mustaches.yml config file. An example of the mustaches.yml follows:
templates: - Sample: - Sample - Sample1 - SampleFolder: - Sample2: - Sample2 - SampleFolder: - Sample2 - sample_with_underscore
- The case of the files is preserved from the mustaches config yaml. However, files like the above 'sample_with_underscore' are assumed to contain a class SampleWithUnderscore since this is the standard ruby practice.
- The top level is the directory you are building from. Multiple directories will work as well.
- The top level directory contains an array of template names, each of which is a hash of logic files to use the template. ** For example, Sample and Sample1 are two logic files which implement a mustache template called Sample.
- If one of the logic files is itself a hash it is assumed to be a directory. The mustache builder will treat this the same as the top level directory, reading the array of template file hashes with their array of logic files. ** In the above example, SampleFolder is a folder which contains a mustache template called Sample2 and a logic file Sample2 which implements the template Sample2. The following SampleFolder with only Sample2 beneath is does the same thing.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request