0.0
No commit activity in last 3 years
No release in over 3 years
An (extremely) simple gem for creating JS component mount points.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
>= 0
~> 5.2.3
~> 10.0
~> 3.0
~> 0.67.2
 Project Readme

MountPoint

An (extremely) simple gem for creating JS component mount points.

MountPoint facilitates transferring data from a Rails controller to a JavaScript component by creating an intermediate DOM node that stores data in a data-props attribute.

MountPoint creates uniform DOM nodes to mount JavaScript components, but it does not mount the components. To mount components to MountPoint nodes use rails-mount-point Node package.

Usage

sample.html.erb:

<%= javascript_pack_tag 'sample' %>
<h1>Sample App</h1>

# Typically the "props" hash would be created as a controller instance variable
<%= mount_point('my_component_name', props: {toWho: 'World'}) %>

MountPoint gem does not handle mounting the JavaScript component. To mount components to MountPoint nodes use rails-mount-point Node package:

javascript/components/HelloWorld.js:

import React from "react";

const HelloWorld = props => {
  return <h1>Hello {props.toWho}</h1>;
};

export default Hello;

javascript/packs/sample.js

import mount from "rails-mount-point";
import HelloWorld from "../components/HelloWorld";

document.addEventListener("DOMContentLoaded", () => {
  mount(HelloWorld);
});

Installation

Add this line to your application's Gemfile:

gem 'mount_point'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mount_point

MountPoint gem does not handle mounting the JavaScript component. To mount components to MountPoint nodes install rails-mount-point Node package:

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/westonkd/mount_point. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

Code of Conduct

Everyone interacting in the MountPoint project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.