Skip to content

Commit

Permalink
Generate proper static path in umbrellas
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Aug 31, 2015
1 parent 3c4e986 commit 53a4b56
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
8 changes: 7 additions & 1 deletion installer/lib/phoenix_new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ defmodule Mix.Tasks.Phoenix.New do
# some storages.
{adapter_app, adapter_module, adapter_config} = get_ecto_adapter(db, String.downcase(app))
pubsub_server = get_pubsub_server(mod)
in_umbrella? = in_umbrella?(path)

{brunch_deps_prefix, static_deps_prefix} =
if in_umbrella?, do: {"../../", "../../../"}, else: {"", ""}

binding = [application_name: app,
application_module: mod,
Expand All @@ -167,7 +171,9 @@ defmodule Mix.Tasks.Phoenix.New do
secret_key_base: random_string(64),
prod_secret_key_base: random_string(64),
signing_salt: random_string(8),
in_umbrella: in_umbrella?(path),
in_umbrella: in_umbrella?,
brunch_deps_prefix: brunch_deps_prefix,
static_deps_prefix: static_deps_prefix,
brunch: brunch,
ecto: ecto,
adapter_app: adapter_app,
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/static/brunch/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// If you no longer want to use a dependency, remember
// to also remove its path from "config.paths.watched".
import "deps/phoenix_html/web/static/js/phoenix_html"
import "<%= static_deps_prefix %>deps/phoenix_html/web/static/js/phoenix_html"

// Import local files
//
Expand Down
4 changes: 2 additions & 2 deletions installer/templates/static/brunch/brunch-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ exports.config = {
// Phoenix paths configuration
paths: {
// Dependencies and current project directories to watch
watched: ["<%= phoenix_path %>/web/static",
"deps/phoenix_html/web/static",
watched: ["<%= brunch_deps_prefix %><%= phoenix_path %>/web/static",
"<%= brunch_deps_prefix %>deps/phoenix_html/web/static",
"web/static", "test/static"],

// Where to compile files to
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/static/brunch/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// To use Phoenix channels, the first step is to import Socket
// and connect at the socket path in "lib/my_app/endpoint.ex":
import {Socket} from "<%= phoenix_static_path %>/web/static/js/phoenix"
import {Socket} from "<%= static_deps_prefix %><%= phoenix_static_path %>/web/static/js/phoenix"

let socket = new Socket("/socket")

Expand Down
11 changes: 11 additions & 0 deletions installer/test/phoenix_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ defmodule Mix.Tasks.Phoenix.NewTest do
assert file =~ "deps_path: \"../../deps\""
assert file =~ "lockfile: \"../../mix.lock\""
end

assert_file "photo_blog/brunch-config.js", fn(file) ->
assert file =~ ~s["../../deps/phoenix/web/static"]
assert file =~ ~s["../../deps/phoenix_html/web/static"]
end

assert_file "photo_blog/web/static/js/socket.js",
~s["../../../deps/phoenix/web/static/js/phoenix"]

assert_file "photo_blog/web/static/js/app.js",
~s["../../../deps/phoenix_html/web/static/js/phoenix_html"]
end
end
end
Expand Down

0 comments on commit 53a4b56

Please sign in to comment.