r00k / elm-rails

View helpers for incorporating Elm modules into Rails views

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

elm-rails

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

Installation

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

    gem "elm-rails"
  2. Add the elm_modules asset to your application.js manifest file

    //= require elm_modules
  3. Create a new directory to house all Elm modules

    mkdir app/assets/elm
  4. Disable asset caching in config/environments/development.rb

    config.assets.configure do |env|
      env.cache = ActiveSupport::Cache.lookup_store(:null_store)
    end
  5. Update .gitignore to ignore elm files

    /elm-stuff
    

Usage

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

    app/assets/Hello.elm

    module Hello where
    
    import Graphics.Element exposing (show)
    
    port noun : String
    
    main =
      show ("Hello " ++ noun)
  2. 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!' }) %>
  3. That's it!

About

View helpers for incorporating Elm modules into Rails views

License:MIT License


Languages

Language:Ruby 80.3%Language:HTML 19.7%