Skip to content

Commit

Permalink
Defer to EmberCLI build pipeline
Browse files Browse the repository at this point in the history
Closes [#30].

Depends on [rondale-sc/ember-cli-rails-addon#17][#17].

* Symlink `dist/` directly to Asset Pipeline
* Deletes `EmberCli::AssetResolver`
* Improve `bin/setup`, resolve errors.

[#30]: #30
[#17]: rondale-sc/ember-cli-rails-addon#17
  • Loading branch information
seanpdoyle committed Nov 10, 2015
1 parent 4b496c9 commit bb4b03c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 168 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
master
------

* Symlink `dist/` directly to Asset Pipeline [#250]
* Merge EmberCLI-generated `manifest.json` into Sprocket's [#250]
* `manifest.json`. Since we now defer to EmberCLI, we no longer need to
manually resolve asset URLs. [#250]

[#250]: https://github.com/thoughtbot/ember-cli-rails/pull/250

0.4.3
-----

Expand Down
3 changes: 0 additions & 3 deletions bin/bundle

This file was deleted.

10 changes: 3 additions & 7 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env bash
#!/bin/sh

set -e

function makeEmberAppAcceptAllRoutes() {
sed -i -e 's/auto/hash/' spec/dummy/my-app/config/environment.js
}

# Set up Ruby dependencies via Bundler
gem install bundler --conservative
bundle check || bundle install
Expand All @@ -20,13 +16,13 @@ fi
if ! [ -d spec/dummy/my-app ]; then
git clone https://github.com/kellyselden/ember-cli-output.git spec/dummy/my-app

makeEmberAppAcceptAllRoutes
bin/setup_ember
fi

root="$(pwd)"

cd ${root}/spec/dummy/my-app &&
npm install --save-dev ember-cli-rails-addon &&
npm install --save-dev ember-cli-rails-addon@rondale-sc/ember-cli-rails-addon
bower install

cd ${root}/spec/dummy && bundle exec rake ember:install
11 changes: 11 additions & 0 deletions bin/setup_ember
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

# make router catchall routes
sed -i -e 's/auto/hash/' spec/dummy/my-app/config/environment.js

# add an image to a template
echo '<img src="assets/logo.png">' >> spec/dummy/my-app/app/templates/application.hbs
mkdir -p spec/dummy/my-app/public/assets
cp spec/fixtures/logo.png spec/dummy/my-app/public/assets
1 change: 1 addition & 0 deletions ember-cli-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.1.0"

spec.add_dependency "railties", ">= 3.2", "< 5"
spec.add_dependency "non-stupid-digest-assets", "~> 1.0.0"
spec.add_dependency "sprockets", ">= 2.0"
end
19 changes: 8 additions & 11 deletions lib/ember-cli/app.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "timeout"
require "non-stupid-digest-assets"
require "ember-cli/html_page"
require "ember-cli/asset_resolver"

module EmberCli
class App
Expand Down Expand Up @@ -76,12 +76,7 @@ def stop
end

def index_html(sprockets:, head:, body:)
asset_resolver = AssetResolver.new(
app: self,
sprockets: sprockets,
)
html_page = HtmlPage.new(
asset_resolver: asset_resolver,
content: index_file.read,
head: head,
body: body,
Expand All @@ -96,11 +91,11 @@ def exposed_js_assets
alias exposed_css_assets exposed_js_assets

def vendor_assets
"#{name}/vendor"
"#{name}/assets/vendor"
end

def application_assets
"#{name}/#{ember_app_name}"
"#{name}/assets/#{ember_app_name}"
end

def wait
Expand Down Expand Up @@ -268,14 +263,17 @@ def index_file
end

def symlink_to_assets_root
assets_path.make_symlink dist_path.join("assets")
assets_path.make_symlink dist_path
rescue Errno::EEXIST
# Sometimes happens when starting multiple Unicorn workers.
# Ignoring...
end

def add_assets_to_precompile_list
Rails.configuration.assets.precompile << /\A#{name}\//
assets = %r{\A#{name}/}

Rails.configuration.assets.precompile << assets
NonStupidDigestAssets.whitelist << assets
end

def command(watch: false)
Expand Down Expand Up @@ -342,7 +340,6 @@ def excluded_ember_deps
def env_hash
ENV.to_h.tap do |vars|
vars["RAILS_ENV"] = Rails.env
vars["DISABLE_FINGERPRINTING"] = "true"
vars["EXCLUDE_EMBER_ASSETS"] = excluded_ember_deps
vars["BUNDLE_GEMFILE"] = gemfile_path.to_s if gemfile_path.exist?
end
Expand Down
54 changes: 0 additions & 54 deletions lib/ember-cli/asset_resolver.rb

This file was deleted.

23 changes: 8 additions & 15 deletions lib/ember-cli/html_page.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module EmberCli
class HtmlPage
def initialize(content:, asset_resolver:, head: "", body: "")
def initialize(content:, head: "", body: "")
@content = content
@asset_resolver = asset_resolver
@head = head
@body = body
end
Expand All @@ -16,11 +15,13 @@ def render
insert_body_content
end

html
content
end

private

attr_reader :content

def has_head_tag?
head_tag_index >= 0
end
Expand All @@ -30,27 +31,19 @@ def has_body_tag?
end

def insert_head_content
html.insert(head_tag_index, @head.to_s)
content.insert(head_tag_index, @head.to_s)
end

def insert_body_content
html.insert(body_tag_index, @body.to_s)
end

def html
@html ||= resolved_html
content.insert(body_tag_index, @body.to_s)
end

def head_tag_index
html.index("</head") || -1
content.index("</head") || -1
end

def body_tag_index
html.index("</body") || -1
end

def resolved_html
@asset_resolver.resolve_urls(@content)
content.index("</body") || -1
end
end
end
65 changes: 0 additions & 65 deletions spec/ember-cli/asset_resolver_spec.rb

This file was deleted.

13 changes: 0 additions & 13 deletions spec/ember-cli/html_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
it "injects into the <head>" do
content = valid_content
html_page = EmberCli::HtmlPage.new(
asset_resolver: build_asset_resolver(content),
content: content,
head: "injected!",
)
Expand All @@ -21,7 +20,6 @@
it "injects into the <body>" do
content = valid_content
html_page = EmberCli::HtmlPage.new(
asset_resolver: build_asset_resolver(content),
content: content,
body: "injected!",
)
Expand All @@ -38,7 +36,6 @@
it "does nothing" do
content = "<html></html>"
html_page = EmberCli::HtmlPage.new(
asset_resolver: build_asset_resolver(content),
content: content,
head: "injected!",
body: "injected!",
Expand All @@ -50,16 +47,6 @@
end
end

def build_asset_resolver(content)
resolver = double("EmberCli::AssetResolver")
allow(resolver).
to receive(:resolve_urls).
with(content).
and_return(content)

resolver
end

def valid_content
"<html><head><title></title></head><body><h1></h1></body></html>"
end
Expand Down
6 changes: 6 additions & 0 deletions spec/features/user_views_ember_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
scenario "with asset helpers" do
visit page_path("embedded")

expect(page).to have_client_side_asset
expect(page).to have_javascript_rendered_text
end

scenario "with index helper" do
visit page_path("include_index")

expect(page).to have_client_side_asset
expect(page).to have_javascript_rendered_text
expect(page).to have_no_csrf_tags

Expand All @@ -23,6 +25,10 @@
expect(page).to have_rails_injected_text
end

def have_client_side_asset
have_css %{img[src*="logo.png"]}
end

def have_rails_injected_text
have_text "Hello from Rails"
end
Expand Down
Binary file added spec/fixtures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bb4b03c

Please sign in to comment.