Skip to content

Commit 0e462a0

Browse files
committed
Integrate with ember-cli-rails
EmberCLI-Rails supports configuring alternative [deployment strategies]. Modify the gem to properly expose itself as a deployment strategy. [deployment strategies]:https://github.com/thoughtbot/ember-cli-rails#deployment-strategies
1 parent 712a3e6 commit 0e462a0

File tree

6 files changed

+66
-265
lines changed

6 files changed

+66
-265
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
master
2+
------
3+
4+
* Integrate with `ember-cli-rails` deployment strategies. [#4]
5+
* Rename `EmberCLI` module to `EmberCli`. [#4]
6+
* Rename `ember-cli` directories to `ember_cli`. [#4]
7+
8+
[#4]: https://github.com/seanpdoyle/ember-cli-rails-deploy-redis/pull/4

README.md

Lines changed: 31 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,66 @@
11
# EmberCli::Deploy::Redis
22

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.
54

65
[ember-cli-deploy] is a simple, flexible deployment for your Ember CLI app.
76

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.
99

10-
`ember-cli-rails-deploy-redis` wires up all three.
10+
`ember-cli-rails-deploy-redis` is a gem that integrates all three.
1111

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.
1514

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
1720

1821
Add this line to your application's Gemfile:
1922

2023
```ruby
21-
gem 'ember-cli-rails-deploy-redis'
24+
group :production do
25+
gem 'ember-cli-rails-deploy-redis'
26+
end
2227
```
2328

2429
And then execute:
2530

2631
```bash
27-
$ bundle
32+
$ bundle install
2833
```
2934

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::Redis`
40-
in your controller:
41-
42-
```ruby
43-
require "ember_cli/deploy/redis"
44-
45-
class ApplicationController < ActionController::Base
46-
def index
47-
@deploy = EmberCli::Deploy::Redis.new(namespace: "frontend")
48-
49-
render text: @deploy.html, layout: false
50-
end
51-
end
52-
```
35+
## Setup
5336

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.
37+
First, [configure your application to integrate with
38+
`ember-cli-rails`][ember-cli-rails-setup].
5639

57-
This is great for `staging` and `production` deploys, but introduces an extra
58-
step in the feedback loop during development.
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:
5943

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:
44+
[ember-cli-rails-setup]: https://github.com/thoughtbot/ember-cli-rails#setup
6345

6446
```ruby
65-
require "ember_cli/deploy/redis"
66-
67-
class ApplicationController < ActionController::Base
68-
def index
69-
@deploy = EmberCli::Deploy::Redis.new(
70-
namespace: "frontend",
71-
index_html: index_html,
72-
)
73-
74-
render text: @deploy.html, layout: false
75-
end
76-
77-
private
78-
79-
def index_html
80-
if serve_with_ember_cli_rails?
81-
render_to_string(:index)
82-
end
83-
end
47+
# config/initializers/ember.rb
8448

85-
def serve_with_ember_cli_rails?
86-
! %w[production staging].include?(Rails.env)
87-
end
49+
EmberCli.configure do |config|
50+
config.app :frontend, deploy: { production: EmberCli::Deploy::Redis }
8851
end
8952
```
9053

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:
54+
Finally, set `ENV["REDIS_URL"]` to the URL
55+
[ember-cli-deploy-redis references][redis-config].
9456

57+
[redis-config]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#configuration-options
9558

96-
```ruby
97-
require "ember_cli/deploy/redis"
98-
99-
class ApplicationController < ActionController::Base
100-
def index
101-
@deploy = EmberCli::Deploy::Redis.new(
102-
namespace: "frontend",
103-
index_html: index_html,
104-
)
105-
106-
@deploy.append_to_head(render_to_string(partial: "my_csrf_and_metadata")
107-
@deploy.append_to_body(render_to_string(partial: "my_analytics")
59+
## Deploy
10860

109-
render text: @deploy.html, layout: false
110-
end
111-
# ...
112-
end
113-
```
61+
Deploy your application through [ember-cli-deploy-redis][deploy].
11462

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
63+
[deploy]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#quick-start
11764

11865
## Development
11966

lib/ember_cli/deploy/page.rb

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/ember_cli/deploy/redis.rb

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,54 @@
11
require "active_support/core_ext/object/blank"
2-
require "ember_cli/deploy/page"
32
require "redis"
43

54
module EmberCli
65
module Deploy
76
class Redis
8-
def initialize(namespace:, index_html: nil, redis_client: build_client)
9-
@redis_client = redis_client
10-
@namespace = namespace
11-
@index_html = index_html
12-
@body_markup = []
13-
@head_markup = []
7+
def initialize(app)
8+
@app = app
149
end
1510

16-
def append_to_body(markup)
17-
body_markup << markup
18-
end
19-
20-
def append_to_head(markup)
21-
head_markup << markup
11+
def index_html
12+
redis_client.get(deploy_key).presence || index_html_missing!
2213
end
2314

24-
def html
25-
if index_html.present?
26-
page = Page.new(html: index_html)
27-
28-
body_markup.each do |markup|
29-
page.append_to_body(markup)
30-
end
15+
private
3116

32-
head_markup.each do |markup|
33-
page.append_to_head(markup)
34-
end
17+
attr_reader :app
3518

36-
page.build
37-
else
38-
index_html_missing!
39-
end
19+
def redis_client
20+
@redis_client ||= ::Redis.new(url: ENV.fetch("REDIS_URL"))
4021
end
4122

42-
private
43-
44-
attr_reader :body_markup, :head_markup, :namespace, :redis_client
45-
46-
def index_html
47-
@index_html ||= redis_client.get(deploy_key).presence
23+
def namespace
24+
app.name
4825
end
4926

5027
def current_key
5128
"#{namespace}:current"
5229
end
5330

5431
def deploy_key
55-
redis_client.get(current_key).presence || deployment_not_activated!
56-
end
32+
key = redis_client.get(current_key).presence ||
33+
deployment_not_activated!
5734

58-
def build_client
59-
::Redis.new(url: ENV.fetch("REDIS_URL"))
35+
"#{namespace}:#{key}"
6036
end
6137

6238
def index_html_missing!
63-
message = <<-FAIL
39+
raise KeyError.new <<-FAIL
6440
HTML for #{deploy_key} is missing.
6541
6642
Did you forget to call `ember deploy`?
6743
FAIL
68-
69-
raise KeyError, message
7044
end
7145

7246
def deployment_not_activated!
73-
message = <<-FAIL
47+
raise KeyError.new <<-FAIL
7448
#{current_key} is empty.
7549
7650
Did you forget to call `ember deploy:activate`?
7751
FAIL
78-
79-
raise KeyError, message
8052
end
8153
end
8254
end

spec/lib/ember_cli/deploy/page_spec.rb

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)