Git Product home page Git Product logo

simple-decorator's Introduction

Simple decorator

A simple sitemesh-like rack filter for Rails apps

This gem lets you specify a url to a place to fetch the layout for your application using a method in you controllers.

Installation

In your Gemfile

gem 'simple_decorator'

Create a decorator lets say at 'http://www.mysite.com/decorator' containing your site's layout:

<html>
  <head>
    <title>$title - SiteName</title>
    $head
  </head>
  <body>
    <div class="somestyling">
      $body
    </div>
  </body>
</html>

In your layout file (typically application.html.erb)

<html>
  <head>
    <title>My apps page</title>
    <link rel="stylesheet" href="my_app_styles.css" type="text/css" media="screen" />
  </head>
  <body>
    <h1>My apps dynamic response</h1>
  </body>
</html>

In any controller

# usually you put this in your ApplicationController
# but feel free to override in any other controller
def decorator_url
  "http://www.mysite.com/decorator"
end

# or, if you have the need to set some headers while trying to call the decorator_url
def decorator_url
  {
    url:      "http://www.mysite.com/decorator"
    headers:  { 'authorization' => "Bearer #{some token}" }
  }
end

The response will now have the layout of your decorator, but display dynamic contents from your app, including your stylesheets and javacripts

<html>
  <head>
    <title>My apps page - SiteName</title>
    <link rel="stylesheet" href="my_app_styles.css" type="text/css" media="screen" />
  </head>
  <body>
    <div class="somestyling">
      <h1>My apps dynamic response</h1>
    </div>
  </body>
</html>

Code status

Code Climate

simple-decorator's People

Contributors

donv avatar eiriklied avatar nicohvi avatar paresharma 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.