All Projects → namusyaka → react-sinatra

namusyaka / react-sinatra

Licence: MIT license
React on Sinatra Integration, Server Side Rendering

Programming Languages

ruby
36898 projects - #4 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-sinatra

serverless-rack
Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems
Stars: ✭ 58 (+34.88%)
Mutual labels:  sinatra, padrino
Pagy
🏆 The Best Pagination Ruby Gem 🥇
Stars: ✭ 3,340 (+7667.44%)
Mutual labels:  sinatra, padrino
Config
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Pandrino and other Ruby projects.
Stars: ✭ 1,821 (+4134.88%)
Mutual labels:  sinatra, padrino
Rack Reducer
Declaratively filter data via URL params, in any Rack app, with any ORM.
Stars: ✭ 241 (+460.47%)
Mutual labels:  sinatra
jpl-space-calendar
An app for parsing and publishing the JPL Space Calendar in JSON and ICalendar formats.
Stars: ✭ 13 (-69.77%)
Mutual labels:  sinatra
rack-cargo
🚚 Batch requests for Rack apps (works with Rails, Sinatra, etc)
Stars: ✭ 17 (-60.47%)
Mutual labels:  sinatra
ruby-whatsapp-bots
A repo of WhatsApp bots built in Ruby
Stars: ✭ 18 (-58.14%)
Mutual labels:  sinatra
Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (+390.7%)
Mutual labels:  sinatra
veterinary-list-api
Veterinary List REST API
Stars: ✭ 18 (-58.14%)
Mutual labels:  sinatra
rubynepal.github.io
Official website of Ruby Nepal
Stars: ✭ 21 (-51.16%)
Mutual labels:  sinatra
sickbay
Get the HTTP status of a bunch of URLs in a single JSON response. Ideal for monitoring a lot of services at once.
Stars: ✭ 19 (-55.81%)
Mutual labels:  sinatra
webvalve
Betterment's framework for locally developing and testing service-oriented apps in isolation with WebMock and Sinatra-based fakes
Stars: ✭ 111 (+158.14%)
Mutual labels:  sinatra
gitlab-live
Interactive online shell for GitLab API
Stars: ✭ 21 (-51.16%)
Mutual labels:  sinatra
fp-sin
Simple Sinatra shell with all the goodies.
Stars: ✭ 13 (-69.77%)
Mutual labels:  sinatra
pifi-radio
MPD web client to listen to radio, written in React and Sinatra.
Stars: ✭ 36 (-16.28%)
Mutual labels:  sinatra
Scalatra
Tiny Scala high-performance, async web framework, inspired by Sinatra
Stars: ✭ 2,529 (+5781.4%)
Mutual labels:  sinatra
gitron
A web game using GitHub APIs based on Tron 🥏
Stars: ✭ 20 (-53.49%)
Mutual labels:  sinatra
sinatra-bootstrap
My opinionated Sinatra base application
Stars: ✭ 14 (-67.44%)
Mutual labels:  sinatra
example-ruby-sinatra
A simple Ruby app for Deis, the open source PaaS
Stars: ✭ 18 (-58.14%)
Mutual labels:  sinatra
api
Tendrl API
Stars: ✭ 16 (-62.79%)
Mutual labels:  sinatra

react-sinatra

Build Status Dependency Status Gem Version GitHub issues GitHub license

react-sinatra makes it easy to use React in your Sinatra and Padrino application.

Please see a sample.

Installation

Add this line to your application's Gemfile:

gem 'react-sinatra'

And then execute:

$ bundle

Or install it yourself as:

$ gem install react-sinatra

Anti-Features

react-sinatra does not:

  • transform .jsx files or JSX syntax.
  • transpile asset using babel.
  • support asset-pipeline.
  • have generator for registering this extension.

I think those features should be solved by using webpack, or other build tools.

Usage

Sinatra Plug-in

It's easy to register react-sinatra in your application, next section will describe three steps for introduction.

1. Add react-sinatra and runtime into your Gemfile

source 'https://rubygems.org'

gem 'react-sinatra'
gem 'execjs'
gem 'mini_racer' # also `therubyracer` may be available, but mini_racer is simpler and faster.

2. Register react-sinatra and configure.

class App < Sinatra::Base
  register React::Sinatra

  configure do
    React::Sinatra.configure do |config|
      # configures for bundled React.js
      config.use_bundled_react = true
      config.env = ENV['RACK_ENV'] || :development
      config.addon = true

      # The asset should be able to be compiled by your server side runtime.
      # react-sinatra does not transform jsx into js, also ES2015 may not be worked through.
      config.asset_path = File.join('client', 'dist', 'server.js')
      config.runtime = :execjs
    end
  end
end

3. Use react_component on your view or sinatra application.

<%= react_component('Hello', { name: 'namusyaka' }, prerender: true) %>
get '/:name' do |name|
  component = react_component('Hello', { name: name }, prerender: true)
  # ...
end

The react component must be able to be referred from global scope, so you should be careful for your asset javascript. In the above example, you need to provide an asset that puts the component called Hello in a state that it can be referred to from the global.

class Hello extends React.Component {
  render() {
    return (
      <div className="hello">
        Hello, {this.props.name}!
      </div>
    );
  }
}

global.Hello = Hello;

React.js

Bundled React.js

You can use bundled React.js by specifying configurations.

React::Sinatra.configure do |config|
  config.use_bundled_react = true # Defaults to false
end

You can also specify addon and env for each environments.

React::Sinatra.configure do |config|
  config.addon = false # Defaults to false
  config.env = ENV['RACK_ENV'] || :development
end

Note

If you want to use your own react, you must include React.js and react-server source code in the asset.

React::Sinatra.configure do |config|
  config.asset_path = 'client/dist/*.js'
end

TODO

  • Support nodejs as a runtime

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/namusyaka/react-sinatra.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].