Chisel and Hammer Integration


#1

You can use Chisel with Hammer, to build content-driven static sites.

We’ve added support to the current Hammer app through the hammer.json configuration.

In the :new: Hammer :hammer: we’ll be providing a dedicated UI for this.

To try out Chisel and Hammer together in the current Hammer for Mac app, you need to install the development branch of the Hammer gem. You do this with the following command in the terminal, this is just until we merge this into the latest branch.

ruby -e "path='/Applications/Hammer.app/'; branch='merged_latest_chisel'; $(curl -fsSL https://raw.githubusercontent.com/Beachio/hammer-gem/merged_latest_chisel/scripts/high-siera_update.rb)"

The current latest version will be 5.4.7.3

Hammer.json Setup

In order to use your Chisel Content inside of Hammer, you need to setup your account and content mappings.

Inside hammer.json, create a new object:

{
  "chisel":{}
}

Chisel Instance Credentials

Firstly, we need to tell Hammer where your Parse-Server backend is hosted. This could be run locally at http://localhost:xxxx/parse or at a remote hosting address. For example if you are hosting your Parse Server using our simple Forge hosting service, then the URL would be something like http://dockerhost.forge-parse-server.c66.me:99/parse

{
  "chisel":{
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse"
  }
}

Next is your Parse App ID, the unique identifier for your Parse Server instance.

{
  "chisel":{
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse",
    "parse_app_id":"123456789123456789"
  }
}

Then finally, in terms of authorisation options, you have a couple of possibilities.

Email / Password

{
  "chisel":{
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse",
    "parse_app_id":"123456789123456789",
    "login":"[email protected]",
    "password":"mysecurepassword"
  }
}

It’s not great practise to use your plaintext password, so we’d generally recommend the next method.

Session Token

You can obtain your Session Token from your Chisel app.

{
  "chisel":{
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse",
    "parse_app_id":"123456789123456789",
    "session_token": "123456789123456789"
  }
}

Chisel Site Info

We need to identify our specific Chisel site, using site_id

{
  "chisel":{
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse",
    "parse_app_id":"123456789123456789",
    "session_token": "123456789123456789",
    "site_id":"123456"
  }
}

Content Model Mapping

Now that’s all done, we need create our mappings to our Chisel content models, so that we can use them inside our templates.

Let’s take a simple example, assuming we have a model called Page inside Chisel. We start by adding our contentTypes object. Inside this object we create pages, which is the plural of our Page model. This is the convention we will typically use for our mappings - singular model, plural variable.

      "pages":{
        "name":"Page"
      }
    }

If you have no further configuration to do, you can also use the shorthand version

"contentTypes":{
      "pages":"Page"
    }

From here, we get to the commonly used additional options

"renderOnBuild":true - tells hammer to build a new html page for each instance of this model, requires a template

"template":"templates/_page.slim" - the template that us used to create each new page for each model instance

"urlAliasSource":"Slug" - the name of the html page hammer will create can be set using a certain field in your content model, the Slug field is perfect for this.

"urlAliasPrefix":"pages" - when hammer builds the html page, you can specify where you want the page to be located, default would be in the root folder. In this example, our new pages will be put into the pages/ directory.

So, in the end, we end up with something like this…

{
  "chisel": {
    "site_id":"123456",
    "parse_app_id":"123456789123456789",
    "parse_server_url":"http://dockerhost.forge-parse-server.c66.me:99/parse",
    "login":"[email protected]",
    "password":"mysecurepassword",
    "contentTypes":{
      "pages":{
        "name":"Page",
        "renderOnBuild":true,
        "template":"templates/_page.slim",
        "urlAliasSource":"Slug",
        "urlAliasPrefix":"pages"
      }
    }
  }
}