|
| 1 | +# EmberCLI Rails - Deploy Redis |
| 2 | + |
| 3 | +[EmberCLI Rails] is an integration story between (surprise suprise) EmberCLI and |
| 4 | +Rails 3.1 and up. |
| 5 | + |
| 6 | +[ember-cli-deploy] is a simple, flexible deployment for your Ember CLI app. |
| 7 | + |
| 8 | +[ember-deploy-redis] is the redis-adapter implementation to use Redis with ember-deploy. |
| 9 | + |
| 10 | +`ember-cli-rails-deploy-redis` wires up all three. |
| 11 | + |
| 12 | +[EmberCLI Rails]: https://github.com/rwz/ember-cli-rails |
| 13 | +[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy |
| 14 | +[ember-deploy-redis]: https://github.com/LevelbossMike/ember-deploy-redis |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Add this line to your application's Gemfile: |
| 19 | + |
| 20 | +```ruby |
| 21 | +gem 'ember-cli-rails-deploy-redis' |
| 22 | +``` |
| 23 | + |
| 24 | +And then execute: |
| 25 | + |
| 26 | +```bash |
| 27 | +$ bundle |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +The EmberCLI community recently unified the various deployment techniques into a |
| 33 | +single, core-team supported project: [ember-cli-deploy][ember-cli-deploy]. |
| 34 | + |
| 35 | +This project attempts to streamline the process of pushing and serving |
| 36 | +EmberCLI-built static assets. |
| 37 | + |
| 38 | +To integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] |
| 39 | +(using the Redis adapter), instantiate an `EmberCLI::Deploy` in your controller: |
| 40 | + |
| 41 | +```ruby |
| 42 | +require "ember-cli/deploy" |
| 43 | + |
| 44 | +class ApplicationController < ActionController::Base |
| 45 | + def index |
| 46 | + @deploy = EmberCLI::Deploy.new(namespace: "frontend") |
| 47 | + |
| 48 | + render text: @deploy.html, layout: false |
| 49 | + end |
| 50 | +end |
| 51 | +``` |
| 52 | + |
| 53 | +`EmberCLI::Deploy` takes a `namespace` (the name of your app declared in your |
| 54 | +initializer) and handles all interaction with the Redis instance. |
| 55 | + |
| 56 | +This is great for `staging` and `production` deploys, but introduces an extra |
| 57 | +step in the feedback loop during development. |
| 58 | + |
| 59 | +Luckily, `EmberCLI::Deploy` also accepts an `index_html` override, which will |
| 60 | +replace the call to the Redis instance. This allows integration with the normal |
| 61 | +`ember-cli-rails` workflow: |
| 62 | + |
| 63 | +```ruby |
| 64 | +require "ember-cli/deploy" |
| 65 | + |
| 66 | +class ApplicationController < ActionController::Base |
| 67 | + def index |
| 68 | + @deploy = EmberCLI::Deploy.new( |
| 69 | + namespace: "frontend", |
| 70 | + index_html: index_html, |
| 71 | + ) |
| 72 | + |
| 73 | + render text: @deploy.html, layout: false |
| 74 | + end |
| 75 | + |
| 76 | + private |
| 77 | + |
| 78 | + def index_html |
| 79 | + if serve_with_ember_cli_rails? |
| 80 | + render_to_string(:index) |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + def serve_with_ember_cli_rails? |
| 85 | + ! %w[production staging].include?(Rails.env) |
| 86 | + end |
| 87 | +end |
| 88 | +``` |
| 89 | + |
| 90 | +Additionally, having access to the outbound HTML beforehand also enables |
| 91 | +controllers to inject additional markup, such as metadata, CSRF tokens, or |
| 92 | +analytics tags: |
| 93 | + |
| 94 | + |
| 95 | +```ruby |
| 96 | +require "ember-cli/deploy" |
| 97 | + |
| 98 | +class ApplicationController < ActionController::Base |
| 99 | + def index |
| 100 | + @deploy = EmberCLI::Deploy.new( |
| 101 | + namespace: "frontend", |
| 102 | + index_html: index_html, |
| 103 | + ) |
| 104 | + |
| 105 | + @deploy.append_to_head(render_to_string(partial: "my_csrf_and_metadata") |
| 106 | + @deploy.append_to_body(render_to_string(partial: "my_analytics") |
| 107 | + |
| 108 | + render text: @deploy.html, layout: false |
| 109 | + end |
| 110 | + # ... |
| 111 | +end |
| 112 | +``` |
| 113 | + |
| 114 | +[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy |
| 115 | +[lightning]: https://github.com/ember-cli/ember-cli-deploy#lightning-approach-workflow |
| 116 | + |
| 117 | +## Development |
| 118 | + |
| 119 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. |
| 120 | + |
| 121 | +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 122 | + |
| 123 | +## Contributing |
| 124 | + |
| 125 | +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ember-cli-rails-deploy-redis. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct. |
| 126 | + |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). |
| 131 | + |
0 commit comments