DSL

A domain specific language is a language that's written to deal with a specific domain or set of concerns.

There are a wide vuriety of DSLs, ranging from widely used languages for common domains, such as HTML for web pages, css for style sheet, down to languages used by only one or a few pieces of software, such as Emacs Lisp for GNU Emacs and XEmacs, Ruby template language like slim, haml, JS template language like Jade.

Examples:

Jade

doctype html
html(lang="en")
  head
    - var name = 'Jade'
    title= name
    meta(charset="utf-8")
    link(rel="stylesheet", type="text/css" href="/stylesheets/style.css")

  body
    h1 Jade - node template engine
    #container.col
      if name === 'Jade'
        p #{name} is very cool
      else
        p Get on Jade
    footer
      p.
        Jade is a terse and simplae
        templating language with a
        strong focus on performance
        and powerful features.

To HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Jade</title>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
</head>
<body>
  <h1>Jade - node template engine</h1>
  <div id="container" class="col">
    <p>Jade is very cool</p>
  </div>
  <footer>
    <p>
      Jade is a terse and simplae
      templating language with a
      strong focus on performance
      and powerful features.
    </p>
  </footer>
</body>
</html>

Haml

#content
  .left.column
    %h2 Welcome to our site!
    %p= print_information
  .right.column
    = render :partial => "sidebar"

To Erb

<div id='content'>
  <div class='left column'>
    <h2>Welcome to our site!</h2>
    <p><%= print_information %></p>
  </div>
  <div class="right column">
    <%= render :partial => "sidebar" %>
  </div>
</div>

Puppet DSL

A good understanding of the Puppet DSL is a key first step in learning how to use Puppet effectively. While tools like the PE console give you quite a bit of power to make configuration changes at a level above the code implementation, it always helps to have a solid understanding of the Puppet code under the hood.

Puppet DSL is a declarative language rather than an imperative one. This means that instead of defining a process or set of commands, Puppet code describes (or declares) only the desired end state. With this desired state described, Puppet relies on built-in providers to handle implementation.

One of the points where there is a nice carry over from Ruby is the hash syntax. It provides a clean way to format this kind of declarative model, and is the basis for the resource declarations you'll learn about in this quest.

As we mentioned above, a key feature of Puppet's declarative model is that it goes both ways; that is, you can inspect the current state of any existing resource in the same syntax you would use to declare a desired state.

Manifests

In puppet, all puppet programs are called manifests which are files with puppet code with the .pp extension.

results matching ""

    No results matching ""