Project

elm-rails

0.05
Low commit activity in last 3 years
There's a lot of open issues
No release in over a year
Compile Elm through Sprockets
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
~> 3.0

Runtime

 Project Readme

elm-rails

Build Status

elm-rails makes it easy to use Elm modules in your Ruby on Rails applications. This project was heavily inspired by react-rails.

Compatibility

Only works with Elm 0.19.

This gem is tested against Ruby versions 2.7, 3.0, and 3.1; and Rails versions 6.1, and 7.0. It may work on other versions, and if you want to open a PR adding tests against those versions they would be welcome.

Installation

  1. Add elm-rails to your Gemfile and run bundle install

    gem "elm-rails"
  2. Create a new directory to house all Elm modules

    mkdir app/assets/elm
  3. Update .gitignore to ignore elm files

    /elm-stuff
    

Usage

  1. Define your elm modules in the app/assets/elm directory.

    app/assets/elm/Hello.elm

    module Hello exposing (..)
    
    import Html exposing (text)
    
    port noun : String
    
    main =
      text ("Hello " ++ noun)
  2. Open your app/assets/javascripts/application.js and require your Hello.elm.

//= require Hello
  1. Use the view helper to insert your component into your view. Pass port values as a Hash.

    <h1>This is an Elm component!</h1>
    <%= elm_embed('Elm.Hello', { noun: 'World!' }) %>
  2. That's it!

Configuration

By default, elm-rails uses elm-compiler under the hood, which will use the version of elm available in your system path, and then installing its own copy in /tmp if needed. If you wish, you may configure this path in an initializer: config/initializers/elm_compiler.rb erb Elm::Compiler.elm_path = "bin/elm"