Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/siegy22/better_frame

A better iframe for rails
https://github.com/siegy22/better_frame

Last synced: about 5 hours ago
JSON representation

A better iframe for rails

Awesome Lists containing this project

README

        

# BetterFrame

Everyone hates iframes. This is why this rails plugin exists.

You'll get a much smoother usage of your app when embedded.
Basically what this plugin does is the following:

* Inject your html code onto the foreign website.
* Handle all events (link clicking, form submitting) with javascript.
* Write the browser history to make the navigation as normal as possible.
* Write rails path + parameter onto the foreign site.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'better_frame'
```

And then execute:

$ bundle

## Usage

### Internal (in your rails app)

**NOTE: you need to make all your forms `remote: true` as this should not
redirect to the rails app if you're submitting a form.

To start, you need to mount the engine in your rails routes:

```ruby
# config/routes.rb
Rails.application.routes.draw do
mount BetterFrame::Engine => "/better_frame"

...
end
```

As this only works with setting the `Access-Control-Allow-Origin` header, you'll
need to include a concern to your controllers to make it available for
better_frame to load. (You also may include it in your ApplicationController if
you want.)

```ruby
# app/controllers/examples_controller.rb
class ExamplesController < ApplicationController
include BetterFrameable
end
```

You'll have to set the `Access-Control-Allow-Origin` using the
`BETTER_FRAME_ORIGIN` environment variable.

$ export BETTER_FRAME_ORIGIN=http://example.com

Or using [dotenv](https://github.com/bkeepers/dotenv)

```
BETTER_FRAME_ORIGIN=http://example.com
```

Side note: If you have `protect_from_forgery with: ...` in your controller you
have to delete that because of the cross site origin requests.

#### Javascript:

If you need something like `$(document).ready`, better_frame fires an event with
`better_frame:load`.
This event is fired everytime the side is loaded with better_frame.

Usage:

```javascript
$("#app-content").on("better_frame:load", function(){
alert("site was loaded with better_frame!");
});
```

### HTML

By default, `better_frame` will override all anchor tags, except the ones with `target=_blank`.
If you want to skip some specific links from being catched by better_frame you can use
the `data-ignore-better-frame` attribute (e.g. mailto: links):

```html
mail example user"
```

### External (on your website which should embed the rails app)

**NOTE: you need to have jQuery on the website which is embedding your rails
app**

On your website do the following:

```html

```

In `