All Projects → bowd → cljs-rails

bowd / cljs-rails

Licence: MIT license
Clojurescript integration for Rails inspired by webpack-rails

Programming Languages

ruby
36898 projects - #4 most used programming language
clojure
4091 projects

Labels

Projects that are alternatives of or similar to cljs-rails

Tunnel
Use Ngrok In Termux With Advanced Options
Stars: ✭ 133 (+224.39%)
Mutual labels:  boot
Rufus
The Reliable USB Formatting Utility
Stars: ✭ 16,917 (+41160.98%)
Mutual labels:  boot
spring-boot-learning
精通Spring Boot系列教程 基于spring boot 2.x
Stars: ✭ 89 (+117.07%)
Mutual labels:  boot
Boot
Build tooling for Clojure.
Stars: ✭ 1,722 (+4100%)
Mutual labels:  boot
Configurator
Client-side component of the configurator
Stars: ✭ 184 (+348.78%)
Mutual labels:  boot
Dracut
dracut the event driven initramfs infrastructure
Stars: ✭ 229 (+458.54%)
Mutual labels:  boot
Booster
Fast and secure initramfs generator
Stars: ✭ 113 (+175.61%)
Mutual labels:  boot
Tow-Boot
An opinionated distribution of U-Boot. — https://matrix.to/#/#Tow-Boot:matrix.org?via=matrix.org
Stars: ✭ 338 (+724.39%)
Mutual labels:  boot
Bootscale
Speedup applications boot by caching require calls
Stars: ✭ 190 (+363.41%)
Mutual labels:  boot
OS-X-Yosemite-on-Unsupported-Macs
Install OS X Yosemite on Unsupported Macs
Stars: ✭ 23 (-43.9%)
Mutual labels:  boot
Grub Btrfs
Include btrfs snapshots at boot options. (Grub menu)
Stars: ✭ 153 (+273.17%)
Mutual labels:  boot
Ubnt Edgerouter Example Configs
Example config.boot files for UBNT EdgeRouters with Google, Comcast, and Charter
Stars: ✭ 175 (+326.83%)
Mutual labels:  boot
Bootboot
Dualboot your Ruby app made easy
Stars: ✭ 239 (+482.93%)
Mutual labels:  boot
Saapas
Example project for Cljs using Boot instead of Lein. Inspired by Chestnut.
Stars: ✭ 136 (+231.71%)
Mutual labels:  boot
bootutils
Utilities to create bootable disks, remaster ISO images, make multiboot ISO images
Stars: ✭ 18 (-56.1%)
Mutual labels:  boot
Xps 9360 Macos
XPS 13 (9360) with macOS Catalina
Stars: ✭ 118 (+187.8%)
Mutual labels:  boot
Netboot.xyz
Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE.
Stars: ✭ 2,753 (+6614.63%)
Mutual labels:  boot
MultiOS-USB
Boot operating systems directly from ISO files
Stars: ✭ 106 (+158.54%)
Mutual labels:  boot
debian-headless
Create a debian headless/remote installation image
Stars: ✭ 92 (+124.39%)
Mutual labels:  boot
Cattlepi
effortlessly boot, configure, update and monitor your raspberry pi ☁️
Stars: ✭ 250 (+509.76%)
Mutual labels:  boot

Build Status Gem Version Gem Downloads

logo cljs-rails

Join the functional bandwagon now in just a few easy steps!

If you're reading this you're either:

  • (a) sitting in lawnchair relaxed because you've found happiness
  • (b) on your way to becoming fundamentally a better person

cljs-rails wants to help you integrate clojurescript into an existing Rails application without too much hassle. It depends on boot to compile your clojurescript and provides a minimal template to get up and running fast with that functional goodness.

My drive towards clojurescript was cristalized by re-frame. So I'm working on an updated version with an option that sets up a re-frame app scheleton with potential db schemas derived from the Rails models. Stay tuned!

Boot vs Leiningen

Potential for flamewar, check.

I'm new to the clojurescript universe and, after playing around a bit with the tools, I found boot to provide a smoother startup experience. Especially for people who are just getting started with the ecosystem. Granted the design choices diverge a bit from the data all the way down that we hold dear, their arguments seem to hold water.

Installation

First install boot. See the install guide for more info.

Add this line to your application's Gemfile:

gem 'cljs-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cljs-rails

Run the generator

$ bundle exec rails generate cljs_rails:install <optional app-name, defaults to the rails app name>

Bundle install again because the generator adds a new dependency (foreman)

$ bundle

Post-Install

Because the cljs build (powered by boot) needs to be run in parallel with the rails server, foreman was added to the gemfile and a basic Procfile that starts both these processes. So from now on instead of bundle exec rails server you should do:

$ foreman start

Because of the way clojure works the first time you start foreman (or run boot dev) it will download all dependencies and also build your project. This is the equivalent, in webpack world, of doing both the npm install and webpack build. Subsequent builds will not download depndencies and of course the dev tasks starts a watch that does hot-reloading and incremental builds (2k17).

Currently the bundle isn't loaded anywhere in your Rails app, you must add it to your layout using the cljs_main_path helper:

<%= javascript_include_tag cljs_main_path %>

After doing this you should navigate to an action and see clojurescript devtools messages in your browser console.

Also, the generated core/main function injects "Hello world" into the document body. You can go to cljs/src/<app-name>/core.cljs and edit the text there. It should automagically recompile and run again in the browser! Yey!

Production

The production build is configured by default to output to app/assets/cljs-build/. This means that the sprockets can now find it. The cljs_main_path helper will just return "main.js" when in production so sprokets will pickup the build file. In development/test it uses the dev-server settings.

You should add the precompile path to production.rb:

config.assets.precompile += [ 'main.js' ]

By default app/assets/cljs-build is added to gitignore just in case, but you might want to (due to some limitations in your environemnt, but you shouldn't) commit your build artefacts to the repo.

Deployment to Heroku

See the sample-cljs-rails-app.

Deploy

The relevent parts of app.json are:

  "env": {
    "BOOTBUILD_CMD": {
      "description": "The command used by the boot buildback to compile cljs",
      "value": "boot prod"
    }
  },
  "buildpacks": [
    { "url": "https://github.com/taylorSando/heroku-buildpack-boot" },
    { "url": "https://github.com/heroku/heroku-buildpack-ruby" }
  ]

To deploy to Heroku your app needs:

  • BOOTBUILD_CMD env var that specifies the build command (boot prod in the default case)
  • a boot buildpack next to the ruby one
Procfile

Heroku also uses the Procfile in production to spin up your web/worker dynos. To avoid this clash you can createProcfile.dev that contains the processes that need to run on development. Then you can either:

  • (a) run foreman start -f Procfile.dev or
  • (b) create a .foreman file (that's .gitignored). and add procfile: Procfile.dev in it. You can then do foreman start as usual.

Custom deployment

There's a rake tasks provided cljs:compile that builds for production (with advanced optimisations). It just runs boot #{production_task}. Production task defaults to "prod" and is defined in the build.boot template, but you can configure it via config.cljs.production_build_task.

You can enhance the assets:precompile task so that it runs cljs:compile every time. Add this to a rake file:

Rake::Task['assets:precompile'].enhance ['cljs:compile']

Just make sure that the server that's precompiling your assets has boot setup.

Notes

Structure

The generator sets up a cljs folder with the source, a main and a namespace derived from the rails app name.

▾ cljs/
  ▾ src/
    ▾ <app-name>/
        core.cljs
      main.cljs.edn

You can provide a different name as the first argument of the install generator.

Prior art

Contributing

  1. Fork it ( https://github.com/bogdan-dumitru/cljs-rails/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].