From 6b66dbf197424047d811397358953e773999db43 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 13 Dec 2015 00:11:21 -0500 Subject: [PATCH 1/2] Restructure module * Rename `EmberCLI` to `EmberCli` * Restructure files, moving `ember-cli` to `ember_cli` --- README.md | 20 +++++++++---------- ember-cli-rails-deploy-redis.gemspec | 4 ++-- lib/ember-cli/deploy/version.rb | 5 ----- lib/{ember-cli => ember_cli}/deploy/page.rb | 2 +- lib/{ember-cli => ember_cli}/deploy/redis.rb | 4 ++-- lib/ember_cli/deploy/redis/version.rb | 7 +++++++ .../deploy/page_spec.rb | 6 +++--- .../deploy/redis_spec.rb | 6 +++--- spec/spec_helper.rb | 2 +- 9 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 lib/ember-cli/deploy/version.rb rename lib/{ember-cli => ember_cli}/deploy/page.rb (98%) rename lib/{ember-cli => ember_cli}/deploy/redis.rb (97%) create mode 100644 lib/ember_cli/deploy/redis/version.rb rename spec/lib/{ember-cli => ember_cli}/deploy/page_spec.rb (86%) rename spec/lib/{ember-cli => ember_cli}/deploy/redis_spec.rb (95%) diff --git a/README.md b/README.md index a6042b8..05085f1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EmberCLI::Rails - Deploy Redis +# EmberCli::Deploy::Redis [EmberCLI Rails] is an integration story between (surprise suprise) EmberCLI and Rails 3.1 and up. @@ -36,37 +36,37 @@ This project attempts to streamline the process of pushing and serving EmberCLI-built static assets. To integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] -(using the Redis adapter), instantiate an `EmberCLI::Deploy::Redis` +(using the Redis adapter), instantiate an `EmberCli::Deploy::Redis` in your controller: ```ruby -require "ember-cli/deploy/redis" +require "ember_cli/deploy/redis" class ApplicationController < ActionController::Base def index - @deploy = EmberCLI::Deploy::Redis.new(namespace: "frontend") + @deploy = EmberCli::Deploy::Redis.new(namespace: "frontend") render text: @deploy.html, layout: false end end ``` -`EmberCLI::Deploy::Redis` takes a `namespace` (the name of your app declared in +`EmberCli::Deploy::Redis` takes a `namespace` (the name of your app declared in your initializer) and handles all interaction with the Redis instance. This is great for `staging` and `production` deploys, but introduces an extra step in the feedback loop during development. -Luckily, `EmberCLI::Deploy::Redis` also accepts an `index_html` override, which +Luckily, `EmberCli::Deploy::Redis` also accepts an `index_html` override, which will replace the call to the Redis instance. This allows integration with the normal `ember-cli-rails` workflow: ```ruby -require "ember-cli/deploy/redis" +require "ember_cli/deploy/redis" class ApplicationController < ActionController::Base def index - @deploy = EmberCLI::Deploy::Redis.new( + @deploy = EmberCli::Deploy::Redis.new( namespace: "frontend", index_html: index_html, ) @@ -94,11 +94,11 @@ analytics tags: ```ruby -require "ember-cli/deploy" +require "ember_cli/deploy/redis" class ApplicationController < ActionController::Base def index - @deploy = EmberCLI::Deploy::Redis.new( + @deploy = EmberCli::Deploy::Redis.new( namespace: "frontend", index_html: index_html, ) diff --git a/ember-cli-rails-deploy-redis.gemspec b/ember-cli-rails-deploy-redis.gemspec index ba92e52..63d2831 100644 --- a/ember-cli-rails-deploy-redis.gemspec +++ b/ember-cli-rails-deploy-redis.gemspec @@ -1,11 +1,11 @@ # coding: utf-8 lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "ember-cli/deploy/version" +require "ember_cli/deploy/redis/version" Gem::Specification.new do |spec| spec.name = "ember-cli-rails-deploy-redis" - spec.version = EmberCLI::Deploy::VERSION + spec.version = EmberCli::Deploy::Redis::VERSION spec.authors = ["Sean Doyle"] spec.email = ["sean.p.doyle24@gmail.com"] diff --git a/lib/ember-cli/deploy/version.rb b/lib/ember-cli/deploy/version.rb deleted file mode 100644 index a06380e..0000000 --- a/lib/ember-cli/deploy/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module EmberCLI - module Deploy - VERSION = "0.0.2" - end -end diff --git a/lib/ember-cli/deploy/page.rb b/lib/ember_cli/deploy/page.rb similarity index 98% rename from lib/ember-cli/deploy/page.rb rename to lib/ember_cli/deploy/page.rb index 8de5b54..ae2d876 100644 --- a/lib/ember-cli/deploy/page.rb +++ b/lib/ember_cli/deploy/page.rb @@ -1,4 +1,4 @@ -module EmberCLI +module EmberCli module Deploy class Page def initialize(html:) diff --git a/lib/ember-cli/deploy/redis.rb b/lib/ember_cli/deploy/redis.rb similarity index 97% rename from lib/ember-cli/deploy/redis.rb rename to lib/ember_cli/deploy/redis.rb index c7c35c9..9961126 100644 --- a/lib/ember-cli/deploy/redis.rb +++ b/lib/ember_cli/deploy/redis.rb @@ -1,8 +1,8 @@ require "active_support/core_ext/object/blank" -require "ember-cli/deploy/page" +require "ember_cli/deploy/page" require "redis" -module EmberCLI +module EmberCli module Deploy class Redis def initialize(namespace:, index_html: nil, redis_client: build_client) diff --git a/lib/ember_cli/deploy/redis/version.rb b/lib/ember_cli/deploy/redis/version.rb new file mode 100644 index 0000000..9883add --- /dev/null +++ b/lib/ember_cli/deploy/redis/version.rb @@ -0,0 +1,7 @@ +module EmberCli + module Deploy + class Redis + VERSION = "0.1.0" + end + end +end diff --git a/spec/lib/ember-cli/deploy/page_spec.rb b/spec/lib/ember_cli/deploy/page_spec.rb similarity index 86% rename from spec/lib/ember-cli/deploy/page_spec.rb rename to spec/lib/ember_cli/deploy/page_spec.rb index c1db35e..4ded6c7 100644 --- a/spec/lib/ember-cli/deploy/page_spec.rb +++ b/spec/lib/ember_cli/deploy/page_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" -require "ember-cli/deploy/page" +require "ember_cli/deploy/page" -describe EmberCLI::Deploy::Page do +describe EmberCli::Deploy::Page do describe "#build" do it "appends to the body" do page = build_page("

") @@ -28,5 +28,5 @@ end def build_page(html) - EmberCLI::Deploy::Page.new(html: html) + EmberCli::Deploy::Page.new(html: html) end diff --git a/spec/lib/ember-cli/deploy/redis_spec.rb b/spec/lib/ember_cli/deploy/redis_spec.rb similarity index 95% rename from spec/lib/ember-cli/deploy/redis_spec.rb rename to spec/lib/ember_cli/deploy/redis_spec.rb index 6871b33..b06129a 100644 --- a/spec/lib/ember-cli/deploy/redis_spec.rb +++ b/spec/lib/ember_cli/deploy/redis_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" -require "ember-cli/deploy/redis" +require "ember_cli/deploy/redis" -describe EmberCLI::Deploy::Redis do +describe EmberCli::Deploy::Redis do describe "#append_to_head" do it "injects the string into the tag" do provided_html = "" @@ -85,7 +85,7 @@ end def build_ember_cli_deploy(index_html: nil) - EmberCLI::Deploy::Redis.new(namespace: namespace, index_html: index_html) + EmberCli::Deploy::Redis.new(namespace: namespace, index_html: index_html) end def namespace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c61149b..7fc448c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require "ember-cli/deploy/redis" +require "ember_cli/deploy/redis" require "fakeredis" require "climate_control" From eb0c587754b94733d4e62f3d842f9ad4509bd9c6 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 13 Dec 2015 00:48:08 -0500 Subject: [PATCH 2/2] 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 --- CHANGELOG.md | 6 + README.md | 145 +++++++++++++----------- lib/ember_cli/deploy/page.rb | 55 --------- lib/ember_cli/deploy/redis.rb | 59 +++------- spec/lib/ember_cli/deploy/page_spec.rb | 32 ------ spec/lib/ember_cli/deploy/redis_spec.rb | 55 ++------- 6 files changed, 105 insertions(+), 247 deletions(-) delete mode 100644 lib/ember_cli/deploy/page.rb delete mode 100644 spec/lib/ember_cli/deploy/page_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a76fc..204fd4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ master ------ +* Integrate with `ember-cli-rails` deployment strategies. [#4] +* Rename `EmberCLI` module to `EmberCli`. [#4] +* Rename `ember-cli` directories to `ember_cli`. [#4] + +[#4]: https://github.com/seanpdoyle/ember-cli-rails-deploy-redis/pull/4 + 0.0.2 ----- diff --git a/README.md b/README.md index 05085f1..1828e83 100644 --- a/README.md +++ b/README.md @@ -1,119 +1,126 @@ # EmberCli::Deploy::Redis -[EmberCLI Rails] is an integration story between (surprise suprise) EmberCLI and -Rails 3.1 and up. +[EmberCLI Rails] is a tool to unify your EmberCLI and Rails Workflows. [ember-cli-deploy] is a simple, flexible deployment for your Ember CLI app. -[ember-deploy-redis] is the redis-adapter implementation to use Redis with ember-deploy. +[ember-cli-deploy-redis] is an `ember-cli-deploy` plugin to upload `index.html` +to a Redis store. -`ember-cli-rails-deploy-redis` wires up all three. +`ember-cli-rails-deploy-redis` is a gem that integrates all three. -[EmberCLI Rails]: https://github.com/rwz/ember-cli-rails -[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy -[ember-deploy-redis]: https://github.com/LevelbossMike/ember-deploy-redis +This project streamlines the process of pushing and serving EmberCLI-built +assets from Rails. -## Installation +[EmberCLI Rails]: https://github.com/thoughtbot/ember-cli-rails +[ember-cli-deploy]: http://ember-cli.com/ember-cli-deploy/ +[ember-cli-deploy-redis]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis + +## Install Add this line to your application's Gemfile: ```ruby -gem 'ember-cli-rails-deploy-redis' +group :production do + gem "ember-cli-rails-deploy-redis" +end ``` And then execute: ```bash -$ bundle +$ bundle install ``` -## Usage +## Setup -The EmberCLI community recently unified the various deployment techniques into a -single, core-team supported project: [ember-cli-deploy][ember-cli-deploy]. +First, [configure your application to integrate with +`ember-cli-rails`][ember-cli-rails-setup]. -This project attempts to streamline the process of pushing and serving -EmberCLI-built static assets. +Then, to integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] +(using the Redis adapter) in `production`, instantiate configure EmberCLI-Rails +to deploy with the `EmberCli::Deploy::Redis` strategy: -To integrate with `ember-cli-deploy`'s ["Lightning Fast Deploys"][lightning] -(using the Redis adapter), instantiate an `EmberCli::Deploy::Redis` -in your controller: +[ember-cli-rails-setup]: https://github.com/thoughtbot/ember-cli-rails#setup ```ruby -require "ember_cli/deploy/redis" - -class ApplicationController < ActionController::Base - def index - @deploy = EmberCli::Deploy::Redis.new(namespace: "frontend") +# config/initializers/ember.rb - render text: @deploy.html, layout: false - end +EmberCli.configure do |config| + config.app :frontend, deploy: { production: EmberCli::Deploy::Redis } end ``` -`EmberCli::Deploy::Redis` takes a `namespace` (the name of your app declared in -your initializer) and handles all interaction with the Redis instance. +Finally, set `ENV["REDIS_URL"]` to the URL [ember-cli-deploy-redis references][redis-config]. -This is great for `staging` and `production` deploys, but introduces an extra -step in the feedback loop during development. +If you're deploying from Redis in `development` or `test`, disable +EmberCLI-Rails' build step by setting `ENV["SKIP_EMBER"] = true`. -Luckily, `EmberCli::Deploy::Redis` also accepts an `index_html` override, which -will replace the call to the Redis instance. This allows integration with the -normal `ember-cli-rails` workflow: +[redis-config]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#configuration-options -```ruby -require "ember_cli/deploy/redis" +## Deploy -class ApplicationController < ActionController::Base - def index - @deploy = EmberCli::Deploy::Redis.new( - namespace: "frontend", - index_html: index_html, - ) +Deploy your application through [ember-cli-deploy-redis][deploy]. - render text: @deploy.html, layout: false - end +[deploy]: https://github.com/ember-cli-deploy/ember-cli-deploy-redis#quick-start - private +## Use without `ember-cli-rails` - def index_html - if serve_with_ember_cli_rails? - render_to_string(:index) - end - end +Although this gem was designed to integrate with `ember-cli-rails`, there isn't +a direct dependency on it. - def serve_with_ember_cli_rails? - ! %w[production staging].include?(Rails.env) - end -end -``` +Similar behavior can be achieved by using a gem like [`html_page`][html_page]: -Additionally, having access to the outbound HTML beforehand also enables -controllers to inject additional markup, such as metadata, CSRF tokens, or -analytics tags: +[html_page]: https://github.com/seanpdoyle/html_page +```rb +require "html_page" -```ruby -require "ember_cli/deploy/redis" +class EmberHelper + def render_html(html) + capturer = HtmlPage::Capture.new(self, &block) -class ApplicationController < ActionController::Base - def index - @deploy = EmberCli::Deploy::Redis.new( - namespace: "frontend", - index_html: index_html, + head, body = capturer.capture + + renderer = HtmlPage::Renderer.new( + content: html, + head: head, + body: body, ) - @deploy.append_to_head(render_to_string(partial: "my_csrf_and_metadata") - @deploy.append_to_body(render_to_string(partial: "my_analytics") + render inline: renderer.render + end +end + +class EmberController + def index + redis = EmberCli::Deploy::Redis.new(ember_app) - render text: @deploy.html, layout: false + @html_from_redis = redis.index_html + + render layout: false + end + + private + + def ember_app + OpenStruct.new(name: "my-ember-app") end - # ... end ``` -[ember-cli-deploy]: https://github.com/ember-cli/ember-cli-deploy -[lightning]: https://github.com/ember-cli/ember-cli-deploy#lightning-approach-workflow +```erb + +<%= render_html @html_from_redis do |head, body| %> + <% head.append do %> + Appended to the `head` element + <% end %> + + <% body.append do %> +

Appended to the `body` element

+ <% end %> +<% end %> +``` ## Development diff --git a/lib/ember_cli/deploy/page.rb b/lib/ember_cli/deploy/page.rb deleted file mode 100644 index ae2d876..0000000 --- a/lib/ember_cli/deploy/page.rb +++ /dev/null @@ -1,55 +0,0 @@ -module EmberCli - module Deploy - class Page - def initialize(html:) - @html = html.clone - @body_markup = [] - @head_markup = [] - end - - def build - if has_head? - head_markup.each do |markup| - html.insert(head_position, markup) - end - end - - if has_body? - body_markup.each do |markup| - html.insert(body_position, markup) - end - end - - html - end - - def append_to_body(markup) - body_markup << markup - end - - def append_to_head(markup) - head_markup << markup - end - - private - - attr_reader :body_markup, :head_markup, :html - - def has_head? - html.include?("

") - - page.append_to_body("

") - page.append_to_body("

") - - expect(page.build).to eq( - "

" - ) - end - - it "appends to the head" do - page = build_page("") - - page.append_to_head("") - page.append_to_head("") - - expect(page.build).to eq( - "" - ) - end - end -end - -def build_page(html) - EmberCli::Deploy::Page.new(html: html) -end diff --git a/spec/lib/ember_cli/deploy/redis_spec.rb b/spec/lib/ember_cli/deploy/redis_spec.rb index b06129a..aa5ba4e 100644 --- a/spec/lib/ember_cli/deploy/redis_spec.rb +++ b/spec/lib/ember_cli/deploy/redis_spec.rb @@ -2,53 +2,13 @@ require "ember_cli/deploy/redis" describe EmberCli::Deploy::Redis do - describe "#append_to_head" do - it "injects the string into the tag" do - provided_html = "" - ember_cli_deploy = build_ember_cli_deploy(index_html: provided_html) - - ember_cli_deploy.append_to_head("") - index_html = ember_cli_deploy.html - - expect(index_html).to eq( - "" - ) - end - end - - describe "#append_to_body" do - it "injects the string into the tag" do - provided_html = "
" - ember_cli_deploy = build_ember_cli_deploy(index_html: provided_html) - - ember_cli_deploy.append_to_body("") - ember_cli_deploy.append_to_body("") - index_html = ember_cli_deploy.html - - expect(index_html).to eq( - "
" - ) - end - end - - describe "#html" do - context "when the HTML is provided" do - it "returns the HTML" do - provided_html = "

Hello World

" - ember_cli_deploy = build_ember_cli_deploy(index_html: provided_html) - - index_html = ember_cli_deploy.html - - expect(index_html).to eq(provided_html) - end - end - + describe "#index_html" do context "when the keys are present" do it "retrieves the HTML from Redis" do stub_index_html(html: "

Hello World

") ember_cli_deploy = build_ember_cli_deploy - index_html = ember_cli_deploy.html + index_html = ember_cli_deploy.index_html expect(index_html).to eq("

Hello World

") end @@ -60,7 +20,7 @@ stub_index_html(html: nil, deploy_key: deploy_key) ember_cli_deploy = build_ember_cli_deploy - expect { ember_cli_deploy.html }.to raise_error( + expect { ember_cli_deploy.index_html }.to raise_error( /HTML for #{namespace}:#{deploy_key} is missing/ ) end @@ -71,7 +31,7 @@ stub_current_key(nil) ember_cli_deploy = build_ember_cli_deploy - expect { ember_cli_deploy.html }.to raise_error( + expect { ember_cli_deploy.index_html }.to raise_error( /#{namespace}:current is empty/ ) end @@ -84,12 +44,13 @@ end end - def build_ember_cli_deploy(index_html: nil) - EmberCli::Deploy::Redis.new(namespace: namespace, index_html: index_html) + def build_ember_cli_deploy + app = double(name: namespace) + EmberCli::Deploy::Redis.new(app) end def namespace - "human-health" + "ember-cli-rails-deploy-redis" end def stub_current_key(deploy_key)