|
1 | 1 | # EmberCli::Deploy::Redis
|
2 | 2 |
|
3 |
| -[EmberCLI Rails] is an integration story between (surprise suprise) EmberCLI and |
4 |
| -Rails 3.1 and up. |
| 3 | +[EmberCLI Rails] is a tool to unify your EmberCLI and Rails Workflows. |
5 | 4 |
|
6 | 5 | [ember-cli-deploy] is a simple, flexible deployment for your Ember CLI app.
|
7 | 6 |
|
8 |
| -[ember-deploy-redis] is the redis-adapter implementation to use Redis with ember-deploy. |
| 7 | +[ember-cli-deploy-redis] is an `ember-cli-deploy` plugin to upload `index.html` |
| 8 | +to a Redis store. |
9 | 9 |
|
10 |
| -`ember-cli-rails-deploy-redis` wires up all three. |
| 10 | +`ember-cli-rails-deploy-redis` is a gem that integrates all three. |
11 | 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 |
| 12 | +This project streamlines the process of pushing and serving EmberCLI-built |
| 13 | +assets from Rails. |
15 | 14 |
|
16 |
| -## Installation |
| 15 | +[EmberCLI Rails]: https://github.com/thoughtbot/ember-cli-rails |
| 16 | +[ember-cli-deploy]: http://ember-cli.com/ember-cli-deploy/ |
| 17 | +[ember-cli-deploy-redis]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis |
| 18 | + |
| 19 | +## Install |
17 | 20 |
|
18 | 21 | Add this line to your application's Gemfile:
|
19 | 22 |
|
20 | 23 | ```ruby
|
21 |
| -gem 'ember-cli-rails-deploy-redis' |
| 24 | +group :production do |
| 25 | + gem "ember-cli-rails-deploy-redis" |
| 26 | +end |
22 | 27 | ```
|
23 | 28 |
|
24 | 29 | And then execute:
|
25 | 30 |
|
26 | 31 | ```bash
|
27 |
| -$ bundle |
| 32 | +$ bundle install |
28 | 33 | ```
|
29 | 34 |
|
30 |
| -## Usage |
| 35 | +## Setup |
31 | 36 |
|
32 |
| -The EmberCLI community recently unified the various deployment techniques into a |
33 |
| -single, core-team supported project: [ember-cli-deploy][ember-cli-deploy]. |
| 37 | +First, [configure your application to integrate with |
| 38 | +`ember-cli-rails`][ember-cli-rails-setup]. |
34 | 39 |
|
35 |
| -This project attempts to streamline the process of pushing and serving |
36 |
| -EmberCLI-built static assets. |
| 40 | +Then, to integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] |
| 41 | +(using the Redis adapter) in `production`, instantiate configure EmberCLI-Rails |
| 42 | +to deploy with the `EmberCli::Deploy::Redis` strategy: |
37 | 43 |
|
38 |
| -To integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] |
39 |
| -(using the Redis adapter), instantiate an `EmberCli::Deploy::Redis` |
40 |
| -in your controller: |
| 44 | +[ember-cli-rails-setup]: https://github.com/thoughtbot/ember-cli-rails#setup |
41 | 45 |
|
42 | 46 | ```ruby
|
43 |
| -require "ember_cli/deploy/redis" |
44 |
| - |
45 |
| -class ApplicationController < ActionController::Base |
46 |
| - def index |
47 |
| - @deploy = EmberCli::Deploy::Redis.new(namespace: "frontend") |
| 47 | +# config/initializers/ember.rb |
48 | 48 |
|
49 |
| - render text: @deploy.html, layout: false |
50 |
| - end |
| 49 | +EmberCli.configure do |config| |
| 50 | + config.app :frontend, deploy: { production: EmberCli::Deploy::Redis } |
51 | 51 | end
|
52 | 52 | ```
|
53 | 53 |
|
54 |
| -`EmberCli::Deploy::Redis` takes a `namespace` (the name of your app declared in |
55 |
| -your initializer) and handles all interaction with the Redis instance. |
| 54 | +Finally, set `ENV["REDIS_URL"]` to the URL |
| 55 | +[ember-cli-deploy-redis references][redis-config]. |
56 | 56 |
|
57 |
| -This is great for `staging` and `production` deploys, but introduces an extra |
58 |
| -step in the feedback loop during development. |
| 57 | +[redis-config]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#configuration-options |
59 | 58 |
|
60 |
| -Luckily, `EmberCli::Deploy::Redis` also accepts an `index_html` override, which |
61 |
| -will replace the call to the Redis instance. This allows integration with the |
62 |
| -normal `ember-cli-rails` workflow: |
| 59 | +## Deploy |
63 | 60 |
|
64 |
| -```ruby |
65 |
| -require "ember_cli/deploy/redis" |
| 61 | +Deploy your application through [ember-cli-deploy-redis][deploy]. |
66 | 62 |
|
67 |
| -class ApplicationController < ActionController::Base |
68 |
| - def index |
69 |
| - @deploy = EmberCli::Deploy::Redis.new( |
70 |
| - namespace: "frontend", |
71 |
| - index_html: index_html, |
72 |
| - ) |
| 63 | +[deploy]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#quick-start |
73 | 64 |
|
74 |
| - render text: @deploy.html, layout: false |
75 |
| - end |
| 65 | +## Use without `ember-cli-rails` |
76 | 66 |
|
77 |
| - private |
| 67 | +Although this gem was designed to integrate with `ember-cli-rails`, there isn't |
| 68 | +a direct dependency on it. |
78 | 69 |
|
79 |
| - def index_html |
80 |
| - if serve_with_ember_cli_rails? |
81 |
| - render_to_string(:index) |
82 |
| - end |
83 |
| - end |
| 70 | +Similar behavior can be achieved by using a gem like [`html_page`][html_page]: |
84 | 71 |
|
85 |
| - def serve_with_ember_cli_rails? |
86 |
| - ! %w[production staging].include?(Rails.env) |
87 |
| - end |
88 |
| -end |
89 |
| -``` |
| 72 | +[html_page]: https://github.com/seanpdoyle/html_page |
90 | 73 |
|
91 |
| -Additionally, having access to the outbound HTML beforehand also enables |
92 |
| -controllers to inject additional markup, such as metadata, CSRF tokens, or |
93 |
| -analytics tags: |
| 74 | +```rb |
| 75 | +require "html_page" |
94 | 76 |
|
| 77 | +class EmberHelper |
| 78 | + def render_html(html) |
| 79 | + capturer = HtmlPage::Capture.new(self, &block) |
95 | 80 |
|
96 |
| -```ruby |
97 |
| -require "ember_cli/deploy/redis" |
| 81 | + head, body = capturer.capture |
98 | 82 |
|
99 |
| -class ApplicationController < ActionController::Base |
100 |
| - def index |
101 |
| - @deploy = EmberCli::Deploy::Redis.new( |
102 |
| - namespace: "frontend", |
103 |
| - index_html: index_html, |
| 83 | + renderer = HtmlPage::Renderer.new( |
| 84 | + content: html, |
| 85 | + head: head, |
| 86 | + body: body, |
104 | 87 | )
|
105 | 88 |
|
106 |
| - @deploy.append_to_head(render_to_string(partial: "my_csrf_and_metadata") |
107 |
| - @deploy.append_to_body(render_to_string(partial: "my_analytics") |
| 89 | + render inline: renderer.render |
| 90 | + end |
| 91 | +end |
| 92 | + |
| 93 | +class EmberController |
| 94 | + def index |
| 95 | + redis = EmberCli::Deploy::Redis.new(ember_app) |
108 | 96 |
|
109 |
| - render text: @deploy.html, layout: false |
| 97 | + @html_from_redis = redis.index_html |
| 98 | + |
| 99 | + render layout: false |
| 100 | + end |
| 101 | + |
| 102 | + private |
| 103 | + |
| 104 | + def ember_app |
| 105 | + OpenStruct.new(name: "my-ember-app") |
110 | 106 | end
|
111 |
| - # ... |
112 | 107 | end
|
113 | 108 | ```
|
114 | 109 |
|
115 |
| -[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy |
116 |
| -[lightning]: https://github.com/ember-cli/ember-cli-deploy#lightning-approach-workflow |
| 110 | +```erb |
| 111 | +<!-- app/views/ember/index.html.erb --> |
| 112 | +<%= render_html @html_from_redis do |head, body| %> |
| 113 | + <% head.append do %> |
| 114 | + <title>Appended to the `head` element</title> |
| 115 | + <% end %> |
| 116 | +
|
| 117 | + <% body.append do %> |
| 118 | + <p>Appended to the `body` element</p> |
| 119 | + <% end %> |
| 120 | +<% end %> |
| 121 | +``` |
117 | 122 |
|
118 | 123 | ## Development
|
119 | 124 |
|
|
0 commit comments