Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Last active August 29, 2015 14:01
Show Gist options
  • Save jonschlinkert/20ace9c79ff161705c77 to your computer and use it in GitHub Desktop.
Save jonschlinkert/20ace9c79ff161705c77 to your computer and use it in GitHub Desktop.
Create a theme with Assemble
# I'm only using a few fields here to demonstrate how this works
# Site theme
theme: slides
# Assets
# The assets path is based on the theme,
# the other paths can build on the assets path
assets: assets/<%= site.theme %>
images: <%= site.assets %>/images
fonts: <%= site.assets %>/fonts
# Styles
styles: styles/themes
# Templates
# Same here, template paths are based on the theme path
templates: templates/themes/<%= site.theme %>/
pages: <%= site.templates %>
includes: <%= site.templates %>/includes
layouts: <%= site.templates %>/layouts

Styles

  • Each theme has its own directory in the styles/themes dir.
  • Each theme has two files, variables.less/sass and index.less/sass
  • Each theme may have its own components, utilities and other stylesheets
  • All themes can use common, generic styles, structural classes, mixins and so on.
styles/
  themes/
    slides/
    ├── index.less
    └── variables.less
      components/
      mixins/
      
    docs/
    ├── index.less
    └── variables.less
      components/
      mixins/

Example options config

Here is how you might configure the less task in your Gruntfile, it's not much different for sass

less: {
  options: {
    paths: [
      '<%= site.styles %>/mixins', // generic mixins
      '<%= site.styles %>/<%= site.theme %>'  // current theme directory
    ]
  },
  dest: {
    src: ['<%= site.styles %>/<%= site.theme %>/index.less'],
    dest: '<%= site.assets %>/css/<%= site.theme %>.css'
  }
}

Use similar patterns for other tasks that use the theme.

Templates

  • Each theme has its own directory in the templates/themes dir.
  • Each theme may have its own components, layouts, pages, and helpers (when necessary)
  • All themes can use common, generic templates, structural markup, includes and so on.
templates/
  themes/
    slides/
    ├── about.hbs
    └── index.hbs
      includes/
      layouts/
      
    docs/
    ├── about.hbs
    └── index.hbs
      includes/
      layouts/

Markup

Now you can do things like this in your templates

<link rel="stylesheet" href="{{assets}}/css/{{site.theme}}.css">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment