GithubHelp home page GithubHelp logo

isabella232 / french_toast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thoughtbot/french_toast

0.0 0.0 0.0 2.29 MB

Communicate information about background jobs

License: MIT License

Ruby 70.65% Shell 1.22% JavaScript 4.09% HTML 24.05%

french_toast's Introduction

French Toast

Build Status Code Climate

Communicate information about background jobs in Rails seamlessly.

FrenchToast attempts to streamline some progressive enhancement by providing a simple and opinionated interface. In order to best take advantage of this, it is important to render that information on the backend. This allows FrenchToast to figure out the best possible communication stream, by starting the most basic functionality and slowly building up to more enhanced features.

With FrenchToast it will:

  1. Communicate through websockets
  2. If that is unavailable, communicate on next page refresh
  3. If the user hasn't seen the content, send them an email

Installation

  • Add the FrenchToast gem to your Gemfile:

    gem "french_toast"
    
  • Run bundle install from your shell.

  • Generate migrations so FrenchToast can render information when javascript isn't available.

rails generate french_toast:install
rake db:migrate

Usage

General

The #french_toast helper provides the simplest interface for FrenchToast. It can be used, for example, on the application layout.

# application.html.erb
<%= french_toast %>

FrenchToast looks for templates by default in the views/french_toast folder.

# _foo.html.erb
<div>You'll see me eventually! <%= your_name %></div>

Use #notify with the name of the template to be rendered to render that template on the page.

# something_job.rb
class SomethingJob
  def perform
    FrenchToast.notify("foo", locals: { your_name: "Jim-bob" })
  end
end

Where you specified #french_toast you will see the foo.html.erb template fully rendered using the best channel available to your user.

Specifying sections

FrenchToast gives you the option to be more specific about what kind of content should be rendered.

Provide a namespace to #french_toast helper

# posts/index.html.erb
<%= french_toast :post %>

Referencing a template the same way, provide name attribute to #notify will render the template only where it is namespaced.

#... something_job.rb
def perform
  FrenchToast.notify("foo", name: :post)
end

Where #french_toast was specified with :post, the foo.html.erb template will be rendered.

Synchronous render control

FrenchToast by default will store information in your database to be displayed later if a user is unable to receive information asynchronously. This can be prevented if there is already a faster, simpler way to communicate information on page load.

For example, FrenchToast is being used to update a list of posts on a page through websockets, but there is already a code to render each post on the server. You can prevent FrenchToast from storing that content on the server.

On the #french_toast helper you can specify the synchronous attribute, which helps specify the type of communication allowed.

<%= french_toast :post, synchronous: false %>

Granular template control

FrenchToast by default assumes HTML templates are being rendered on the page. There are times that require more granular control of the template because the information being sent is not HTML.

A custom template can be specified and referenced using the template attribute on the #french_toast helper.

<%= french_toast :text, template: "text_only" %>

Create a template in french_toast/templates and use the #french_toast_tag helper to generate the necessary HTML that can be identified by FrenchToast.

# _text_only.html.erb
<div class="my-own-thing" >
  <%= french_toast_tag :p %>
</div>

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

French Toast is Copyright (c) 2016-2017 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

thoughtbot logo

French Toast is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or hire us to help build your product.

french_toast's People

Contributors

geoffharcourt avatar mike-burns avatar tabfugnic avatar tysongach 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.