|
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: |
56 | 55 |
|
57 |
| -This is great for `staging` and `production` deploys, but introduces an extra |
58 |
| -step in the feedback loop during development. |
| 56 | +* `ENV["REDIS_URL"]` to the URL [ember-cli-deploy-redis references][redis-config] |
| 57 | +* `ENV["SKIP_EMBER"] = 1` to skip EmberCLI compilation during deploys and |
| 58 | + requests |
59 | 59 |
|
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: |
| 60 | +[redis-config]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#configuration-options |
63 | 61 |
|
64 |
| -```ruby |
65 |
| -require "ember_cli/deploy/redis" |
| 62 | +## Deploy |
66 | 63 |
|
67 |
| -class ApplicationController < ActionController::Base |
68 |
| - def index |
69 |
| - @deploy = EmberCli::Deploy::Redis.new( |
70 |
| - namespace: "frontend", |
71 |
| - index_html: index_html, |
72 |
| - ) |
| 64 | +Deploy your application through [ember-cli-deploy-redis][deploy]. |
73 | 65 |
|
74 |
| - render text: @deploy.html, layout: false |
75 |
| - end |
| 66 | +[deploy]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#quick-start |
76 | 67 |
|
77 |
| - private |
| 68 | +## Use without `ember-cli-rails` |
78 | 69 |
|
79 |
| - def index_html |
80 |
| - if serve_with_ember_cli_rails? |
81 |
| - render_to_string(:index) |
82 |
| - end |
83 |
| - end |
| 70 | +Although this gem was designed to integrate with `ember-cli-rails`, there isn't |
| 71 | +a direct dependency on it. |
84 | 72 |
|
85 |
| - def serve_with_ember_cli_rails? |
86 |
| - ! %w[production staging].include?(Rails.env) |
87 |
| - end |
88 |
| -end |
89 |
| -``` |
| 73 | +Similar behavior can be achieved by using a gem like [`html_page`][html_page]: |
90 | 74 |
|
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: |
| 75 | +[html_page]: https://github.com/seanpdoyle/html_page |
94 | 76 |
|
| 77 | +```rb |
| 78 | +require "html_page" |
95 | 79 |
|
96 |
| -```ruby |
97 |
| -require "ember_cli/deploy/redis" |
| 80 | +class EmberHelper |
| 81 | + def render_html(html) |
| 82 | + capturer = HtmlPage::Capture.new(self, &block) |
98 | 83 |
|
99 |
| -class ApplicationController < ActionController::Base |
100 |
| - def index |
101 |
| - @deploy = EmberCli::Deploy::Redis.new( |
102 |
| - namespace: "frontend", |
103 |
| - index_html: index_html, |
| 84 | + head, body = capturer.capture |
| 85 | + |
| 86 | + renderer = HtmlPage::Renderer.new( |
| 87 | + content: html, |
| 88 | + head: head, |
| 89 | + body: body, |
104 | 90 | )
|
105 | 91 |
|
106 |
| - @deploy.append_to_head(render_to_string(partial: "my_csrf_and_metadata") |
107 |
| - @deploy.append_to_body(render_to_string(partial: "my_analytics") |
| 92 | + render inline: renderer.render |
| 93 | + end |
| 94 | +end |
| 95 | + |
| 96 | +class EmberController |
| 97 | + def index |
| 98 | + redis = EmberCli::Deploy::Redis.new(ember_app) |
108 | 99 |
|
109 |
| - render text: @deploy.html, layout: false |
| 100 | + @html_from_redis = redis.index_html |
| 101 | + |
| 102 | + render layout: false |
| 103 | + end |
| 104 | + |
| 105 | + private |
| 106 | + |
| 107 | + def ember_app |
| 108 | + OpenStruct.new(name: "my-ember-app") |
110 | 109 | end
|
111 |
| - # ... |
112 | 110 | end
|
113 | 111 | ```
|
114 | 112 |
|
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 |
| 113 | +```erb |
| 114 | +<!-- app/views/ember/index.html.erb --> |
| 115 | +<%= render_html @html_from_redis do |head, body| %> |
| 116 | + <% head.append do %> |
| 117 | + <title>Appended to the `head` element</title> |
| 118 | + <% end %> |
| 119 | +
|
| 120 | + <% body.append do %> |
| 121 | + <p>Appended to the `body` element</p> |
| 122 | + <% end %> |
| 123 | +<% end %> |
| 124 | +``` |
117 | 125 |
|
118 | 126 | ## Development
|
119 | 127 |
|
|
0 commit comments