Giter Site home page Giter Site logo

dynamicmatic's Introduction

DynamicMatic

DynamicMatic is a tiny Sinatra extension that integrates Sinatra with StaticMatic. It allows most of your site to be static while having a few dynamic pages that can use the StaticMatic layouts and partials.

Setup

Your Sinatra and StaticMatic apps live side-by-side. The StaticMatic site directory is used as the directory for Sinatra's public files, and the src directory contains the source for the static pages and the layouts that are shared between StaticMatic and Sinatra. Otherwise the standard Sinatra directories are used.

If the Sinatra :root option is changed, DynamicMatic will respect that and set the StaticMatic paths appropriately.

Usage

If you're using a classic-style Sinatra application, all you have to do is require 'sinatra/dynamicmatic'. If you're using a modular application, you'll also have to include Sinatra::DynamicMatic in your Sinatra::Base subclass.

How it Works

The static pages and stylesheets in the StaticMatic src directory are served statically - they should be compiled before the server is started. This can be done using staticmatic.run("build") in your Sinatra app.

Any dynamic Sinatra pages can make use of the StaticMatic layouts and helpers, but are rendered dynamically on each request.

Layouts

StaticMatic layouts are made available as normal Sinatra templates. For example, if you have src/layouts/application.haml and src/layouts/help.haml, application.haml will be used as the :application template, and help.haml will be used as the :help template. application.haml will also be used for the default layout for Sinatra pages.

Helpers

All the StaticMatic helpers, including those for partial-rendering, are available in Sinatra views. The reverse is not true; Sinatra helpers are generally not available for StaticMatic pages, since they are rendered statically.

Sinatra helpers are, however, available for StaticMatic layouts but only when they're being used for dynamic views. It's not safe to rely on them being there, although you can check for their existence with defined? and call them if they're there.

Configuration

StaticMatic is configured using src/configuration.rb. Sinatra is configured using the set method. In other words, configuration happens as usual.

Preview

When you run your app in development mode, your static pages are actually generated dynamically on each request, just like with staticmatic preview. Once you're in production, though, they're all served swiftly from the site folder.

dynamicmatic's People

Contributors

nex3 avatar

Watchers

Rohith Dharavath avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.