{"id":13493246,"url":"https://github.com/namusyaka/react-sinatra","last_synced_at":"2025-08-24T22:35:04.818Z","repository":{"id":56897350,"uuid":"77734877","full_name":"namusyaka/react-sinatra","owner":"namusyaka","description":"React on Sinatra Integration, Server Side Rendering","archived":false,"fork":false,"pushed_at":"2018-06-19T23:13:22.000Z","size":256,"stargazers_count":42,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-14T19:42:44.247Z","etag":null,"topics":["padrino","react","ruby","sinatra"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/namusyaka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-31T09:58:33.000Z","updated_at":"2023-07-06T16:36:41.000Z","dependencies_parsed_at":"2022-08-21T01:50:48.836Z","dependency_job_id":null,"html_url":"https://github.com/namusyaka/react-sinatra","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namusyaka%2Freact-sinatra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namusyaka%2Freact-sinatra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namusyaka%2Freact-sinatra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namusyaka%2Freact-sinatra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/namusyaka","download_url":"https://codeload.github.com/namusyaka/react-sinatra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221673943,"owners_count":16861740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["padrino","react","ruby","sinatra"],"created_at":"2024-07-31T19:01:13.505Z","updated_at":"2024-10-27T12:14:01.466Z","avatar_url":"https://github.com/namusyaka.png","language":"Ruby","funding_links":[],"categories":["Server Side Rendering"],"sub_categories":[],"readme":"# react-sinatra\n\n[![Build Status](https://travis-ci.org/namusyaka/react-sinatra.svg?branch=master)](https://travis-ci.org/namusyaka/react-sinatra)\n[![Dependency Status](https://gemnasium.com/badges/github.com/namusyaka/react-sinatra.svg)](https://gemnasium.com/github.com/namusyaka/react-sinatra)\n[![Gem Version](https://badge.fury.io/rb/react-sinatra.svg)](https://badge.fury.io/rb/react-sinatra)\n[![GitHub issues](https://img.shields.io/github/issues/namusyaka/react-sinatra.svg)](https://github.com/namusyaka/react-sinatra/issues)\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/namusyaka/react-sinatra/master/LICENSE.txt)\n\n`react-sinatra` makes it easy to use React in your Sinatra and Padrino application.\n\nPlease see [a sample](https://github.com/namusyaka/react-sinatra-sample).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'react-sinatra'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install react-sinatra\n\n## Anti-Features\n\n`react-sinatra` does not:\n\n- transform `.jsx` files or JSX syntax.\n- transpile asset using babel.\n- support asset-pipeline.\n- have generator for registering this extension.\n\nI think those features should be solved by using [webpack](https://webpack.js.org/), or other build tools.\n\n## Usage\n\n### Sinatra Plug-in\n\nIt's easy to register `react-sinatra` in your application, next section will describe three steps for introduction.\n\n#### 1. Add react-sinatra and runtime into your Gemfile\n\n```ruby\nsource 'https://rubygems.org'\n\ngem 'react-sinatra'\ngem 'execjs'\ngem 'mini_racer' # also `therubyracer` may be available, but mini_racer is simpler and faster.\n```\n\n#### 2. Register react-sinatra and configure.\n\n```ruby\nclass App \u003c Sinatra::Base\n  register React::Sinatra\n\n  configure do\n    React::Sinatra.configure do |config|\n      # configures for bundled React.js\n      config.use_bundled_react = true\n      config.env = ENV['RACK_ENV'] || :development\n      config.addon = true\n\n      # The asset should be able to be compiled by your server side runtime.\n      # react-sinatra does not transform jsx into js, also ES2015 may not be worked through.\n      config.asset_path = File.join('client', 'dist', 'server.js')\n      config.runtime = :execjs\n    end\n  end\nend\n```\n\n#### 3. Use `react_component` on your view or sinatra application.\n\n```erb\n\u003c%= react_component('Hello', { name: 'namusyaka' }, prerender: true) %\u003e\n```\n\n```ruby\nget '/:name' do |name|\n  component = react_component('Hello', { name: name }, prerender: true)\n  # ...\nend\n```\n\nThe react component **must** be able to be referred from global scope, so you should be careful for your asset javascript.\nIn 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.\n\n```javascript\nclass Hello extends React.Component {\n  render() {\n    return (\n      \u003cdiv className=\"hello\"\u003e\n        Hello, {this.props.name}!\n      \u003c/div\u003e\n    );\n  }\n}\n\nglobal.Hello = Hello;\n```\n\n### React.js\n\n#### Bundled React.js\n\nYou can use bundled React.js by specifying configurations.\n\n```ruby\nReact::Sinatra.configure do |config|\n  config.use_bundled_react = true # Defaults to false\nend\n```\n\nYou can also specify `addon` and `env` for each environments.\n\n```ruby\nReact::Sinatra.configure do |config|\n  config.addon = false # Defaults to false\n  config.env = ENV['RACK_ENV'] || :development\nend\n```\n\n#### Note\n\n**If you want to use your own react, you must include React.js and react-server source code in the asset.**\n\n```ruby\nReact::Sinatra.configure do |config|\n  config.asset_path = 'client/dist/*.js'\nend\n```\n\n### TODO\n\n- Support nodejs as a runtime\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/namusyaka/react-sinatra.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamusyaka%2Freact-sinatra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnamusyaka%2Freact-sinatra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamusyaka%2Freact-sinatra/lists"}