@notus.sh/cocooned

Companion package for the cocooned Ruby gem.

Usage no npm install needed!

<script type="module">
  import notusShCocooned from 'https://cdn.skypack.dev/@notus.sh/cocooned';
</script>

README

Cocooned

This is a companion package for the cocooned Ruby gem.

Cocooned makes it easier to handle nested forms in a Rails project. It works with standard Rails (>= 4.0, < 6.0), Formtastic or SimpleForm.

This package aims to ease cocooned integration with projects that use npm/Yarn to manage non-ruby dependencies and/or use webpacker to build their assets.

Cocooned depends on jQuery, Ruby (>= 2.2) and Rails (>= 4.0, < 6.0).

Installation

With npm:

npm install @notus.sh/cocooned@<version>

With Yarn:

yarn add @notus.sh/cocooned@<version>

You should specify the same version (and version contraints) as in your Gemfile.

Usage

With Sprockets

In config/initializers/assets.rb, be sure you have something like this:

Rails.configuration.tap do |config|
  # [...]
 
  # Ask Sprockets to load files in ./node_modules
  config.assets.paths << Rails.root.join('node_modules')
  # If you use sass-rails, ask Sass to do the same
  config.sass.load_paths << Rails.root.join('node_modules')
  
  # [...]
end

Then load Cocooned with:

// In a javascript file
//= require '@notus.sh/cocooned/cocooned'
/* In a stylesheet */
/*
 *= require '@notus.sh/cocooned/cocooned'
 */

With Webpacker

// In a javascript file
var Cocooned = require('@notus.sh/cocooned');
/* In a stylesheet */
@import '@notus.sh/cocooned/cocooned';