!doctype html> Sculpin and Drupal

Sculpin and Drupal

Karl Kedrovsky
VML
karl.kedrovsky@vml.com
karl@kedrovsky.com
@karlkedrovsky

Goals

  • Understand how Sculpin works
  • Tips or "Best practices" for Drupal developers
  • Extending Sculpin / Integrating with Drupal

Overview

  • Why Sculpin For Drupalistas
  • Setup and Installation
  • How Sculpin Works
  • Integrating With Drupal

Why A Static Site (Generator)?

  • MUCH simpler than a CMS
  • Easier and cheaper to deploy
  • More secure
  • Faster and easier to scale
  • A generator lets you use a static site on larger projects
  • Helps you avoid The Golden Hammer

Why Sculpin?

Out of the 398 static site generators (staticsitegenerators.net) why pick Sculpin?

  • Well supported and maintained
  • General purpose
  • Extendable

Why Sculpin?

Technology

  • Written in PHP
  • Uses modern PHP tooling
  • Leverages Symfony components (yay Drupal 8!)
  • Themes/templates use Twig (yay Drupal 8!)
  • Config files are in YAML (yay Drupal 8!)

Setup and Installation

  1. Download and install the Sculpin executable (PHAR file)
  2. Create a simple directory structure
  3. Create a file in the right directory
  4. run 'sculpin generate'

Download And Install Sculpin

  • curl -O https://download.sculpin.io/sculpin.phar
  • chmod +x sculpin.phar
  • mv sculpin.phar ~/bin/sculpin
  • PATH=$PATH:$HOME/bin

Directory Structure

Two options:

  1. Use a starter kit
  2. Create the files and directories yourself

DEMO!

How Sculpin Works

Configuration Files

  • Two files, both under app/config
  • sculpin_kernel.yml - settings for file generation
  • sculpin_site.yml - settings for the site itself
  • Both are optional and only used to add meta data or override defaults
  • Can have per-environment site files - sculpin_site_prod.yml

DEMO!

How Sculpin Works

Sources

  • Sources are files under the the "source" directory

How Sculpin Works

Sources

How source files are handled.

  1. Markdown translated to HTML
  2. Files without "front matter"
    • Copied as-is
  3. Files with "front matter"
    • Processed - templates, URLs, etc.

DEMO!

How Sculpin Works

Templating

There are two ways to organize your templates, css, etc.

  1. Basic - In subdirectories directly under "source"
  2. Theme - In a theme sub-directory under "source"

How Sculpin Works

Templating

 source
 ├── _includes
 ├── _layouts
 ├── _partials
 └── _views
            
 source
 └── themes
   └── karlkedrovsky
     └── drupalcorn
       ├── _includes
       ├── _layouts
       ├── _partials
       └── _views
            

DEMO!

Content Types

  • Content type based on one of two things:
    • Path - subdirectory of "source"
    • Meta - Key from "front matter"
  • Different default layout
  • Different permalink (URL)
  • Etc.

DEMO!

Integrating With Drupal

  • Don't fight the tool (use pages)
  • Keep in mind we're bending the tool a bit
  • Can be good for things like consilidating info from multiple sites.

Integrating With Drupal

Options

  • Create a custom Symfony bundle
  • Create a Twig extension

DEMO!

Integrating With Drupal

  • SculpinKernel.php loads DrupalBundle
  • DrupalBundle loads DependencyInjection/DrupalExtension.php
  • DrupalExtension specifies services.yml
  • servcies.yml specifies the new Twig functions

Resources

Thank You!

Questions?