Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/mix/talon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ defmodule Mix.Talon do
def prompt_project_structure(binding) do
Mix.shell.info [
"Cannot automatically detect the project structure!\n",
"1. Use phx 1.3 structure (lib/#{binding.base}/web)\n",
"1. Use phx 1.3 structure (lib/#{binding.base}_web)\n",
"2. Use phoenix structure (web)\n",
"3. Abort\n",
]
Expand Down Expand Up @@ -212,7 +212,7 @@ defmodule Mix.Talon do
def web_path(opts \\ []) do
path =
case detect_project_structure() do
:phx -> Path.join ["lib", otp_app_path(), "web"]
:phx -> Path.join ["lib", otp_app_path() <> "_web"]
_ -> "web"
end

Expand Down Expand Up @@ -267,6 +267,14 @@ defmodule Mix.Talon do
def web_namespace(:phx), do: "Web."
def web_namespace(:phoenix), do: ""

@spec controller_namespace(:phx | :phoenix) :: String.t
def controller_namespace(:phx), do: ""
def controller_namespace(:phoenix), do: ".Web"

@spec web_base(String.t, :phx | :phoenix) :: String.t
def web_base(base, :phx), do: base <> "Web"
def web_base(base, :phoenix), do: base

@spec web_module(String.t | nil) :: String.t
def web_module("Web."), do: "Web"
def web_module(_), do: ""
Expand Down
14 changes: 11 additions & 3 deletions lib/mix/tasks/talon.gen.components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ defmodule Mix.Tasks.Talon.Gen.Components do
|> Path.wildcard
|> Enum.map(&Path.basename/1)

binding = Kernel.binding() ++ [base: config.base, theme_name: config.theme_name,
theme_module: config.theme_module, web_namespace: config.web_namespace,
view_opts: config.view_opts, concern_path: config.concern_path, concern: config.concern]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
theme_name: config.theme_name,
theme_module: config.theme_module,
web_namespace: config.web_namespace,
view_opts: config.view_opts,
concern_path: config.concern_path,
concern: config.concern
]

infos =
file_names
Expand Down Expand Up @@ -161,6 +168,7 @@ defmodule Mix.Tasks.Talon.Gen.Components do
web_namespace: web_namespace(proj_struct),
boilerplate: bin_opts[:boilerplate] || Config.boilerplate() || true,
base: base,
web_base: web_base(base, proj_struct),
}
end

Expand Down
15 changes: 12 additions & 3 deletions lib/mix/tasks/talon.gen.concern.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,16 @@ defmodule Mix.Tasks.Talon.Gen.Concern do
layout = Module.concat([config.base, config.concern, config.theme_module,
web_module, LayoutView])
layout = ~s/{#{inspect layout}, "app.html"}/
binding = Kernel.binding() ++ [base: config.base, concern: config.concern,
boilerplate: config[:boilerplate], web_namespace: config.web_namespace,
layout: layout, web_module: web_module]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
concern: config.concern,
boilerplate: config[:boilerplate],
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
layout: layout,
web_module: web_module
]
target_path = Path.join([config.root_path, "controllers", config.path_prefix])
unless config.dry_run do
File.mkdir_p! target_path
Expand Down Expand Up @@ -165,10 +172,12 @@ defmodule Mix.Tasks.Talon.Gen.Concern do
theme_module: theme_module,
project_structure: proj_struct,
web_namespace: web_namespace(proj_struct),
controller_namespace: controller_namespace(proj_struct),
concern: concern,
concern_path: concern_path(concern),
boilerplate: bin_opts[:boilerplate] || Config.boilerplate() || true,
base: base,
web_base: web_base(base, proj_struct),
app: app
}
end
Expand Down
16 changes: 12 additions & 4 deletions lib/mix/tasks/talon.gen.resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,17 @@ defmodule Mix.Tasks.Talon.Gen.Resource do
unless config.dry_run do
# Enum.each config.themes, fn theme ->
theme = config.target_name
binding = config.binding ++ [base: config[:base], resource: config.resource,
theme_module: theme_module_name(theme), theme_name: theme, view_opts: config.view_opts,
web_namespace: config.web_namespace, concern: config.concern,
concern_path: config.concern_path]
binding = config.binding ++ [
base: config[:base],
web_base: config.web_base,
resource: config.resource,
theme_module: theme_module_name(theme),
theme_name: theme,
view_opts: config.view_opts,
web_namespace: config.web_namespace,
concern: config.concern,
concern_path: config.concern_path
]
target_path = Path.join([config.root_path, "views", config.path_prefix,
config.concern_path, theme])
copy_from paths(),
Expand Down Expand Up @@ -193,6 +200,7 @@ defmodule Mix.Tasks.Talon.Gen.Resource do
project_structure: proj_struct,
boilerplate: bin_opts[:boilerplate] || Application.get_env(:talon, :boilerplate, true),
base: base,
web_base: web_base(base, proj_struct),
}
# |> IO.inspect(label: "contfig")
end
Expand Down
40 changes: 32 additions & 8 deletions lib/mix/tasks/talon.gen.theme.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ defmodule Mix.Tasks.Talon.Gen.Theme do
defp gen_components(config), do: config

defp gen_layout_view(%{layouts: true} = config) do
binding = Kernel.binding() ++ [base: config.base, target_name: config.target_name,
target_module: config.target_module, web_namespace: config.web_namespace,
view_opts: config.view_opts, concern: config.concern]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
target_name: config.target_name,
target_module: config.target_module,
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
view_opts: config.view_opts,
concern: config.concern
]
theme = config.theme
view_path = Path.join([config.root_path, "views", config.path_prefix,
config.concern_path, config.target_name])
Expand Down Expand Up @@ -213,8 +220,15 @@ defmodule Mix.Tasks.Talon.Gen.Theme do
defp gen_layout_templates(config), do: config

defp gen_generators(%{generators: true} = config) do
binding = Kernel.binding() ++ [base: config.base, target_name: config.target_name,
target_module: config.target_module, web_namespace: config.web_namespace, concern: config.concern]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
target_name: config.target_name,
target_module: config.target_module,
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
concern: config.concern
]
theme = config.theme
template_path = Path.join([config.root_path, "templates", config.path_prefix,
config.concern_path, config.target_name, "generators"])
Expand Down Expand Up @@ -254,9 +268,17 @@ defmodule Mix.Tasks.Talon.Gen.Theme do
def gen_dashboard(config), do: config

defp gen_dashboard_view(%{dashboard: true} = config) do
binding = Kernel.binding() ++ [base: config.base, target_name: config.target_name,
target_module: config.target_module, web_namespace: config.web_namespace,
view_opts: config.view_opts, concern: config.concern, page: "Dashboard"]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
target_name: config.target_name,
target_module: config.target_module,
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
view_opts: config.view_opts,
concern: config.concern,
page: "Dashboard"
]

theme = config.theme
view_path = Path.join([config.root_path, "views", config.path_prefix, config.concern_path, config.target_name])
Expand Down Expand Up @@ -449,10 +471,12 @@ defmodule Mix.Tasks.Talon.Gen.Theme do
dry_run: bin_opts[:dry_run],
project_structure: proj_struct,
web_namespace: web_namespace(proj_struct),
controller_namespace: controller_namespace(proj_struct),
view_opts: view_opts,
binding: binding,
boilerplate: bin_opts[:boilerplate] || Application.get_env(:talon, :boilerplate, true),
base: base,
web_base: web_base(base, proj_struct),
})
|> set_config_onlys(bin_opts)
end
Expand Down
56 changes: 37 additions & 19 deletions lib/mix/tasks/talon.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,16 @@ defmodule Mix.Tasks.Talon.New do
layout = Module.concat([config.base, config.concern, config.theme_module,
web_module, LayoutView])
layout = ~s/{#{layout}, "app.html"}/
binding = Kernel.binding() ++ [base: config.base, concern: config.concern,
boilerplate: config[:boilerplate], web_namespace: config.web_namespace,
layout: layout, web_module: web_module]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
concern: config.concern,
boilerplate: config[:boilerplate],
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
layout: layout,
web_module: web_module
]
target_path = Path.join([config.root_path, "controllers", config.path_prefix])
unless config.dry_run do
File.mkdir_p! target_path
Expand All @@ -180,9 +187,16 @@ defmodule Mix.Tasks.Talon.New do
layout = Module.concat([config.base, config.concern, config.theme_module,
web_module, LayoutView])
layout = ~s/{#{layout}, "app.html"}/ # TODO: DJS handle layout
binding = Kernel.binding() ++ [base: config.base, concern: config.concern,
boilerplate: config[:boilerplate], web_namespace: config.web_namespace,
layout: layout, web_module: web_module]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
concern: config.concern,
boilerplate: config[:boilerplate],
web_namespace: config.web_namespace,
controller_namespace: config.controller_namespace,
layout: layout,
web_module: web_module
]
target_path = Path.join([config.root_path, "controllers", config.path_prefix])
unless config.dry_run do
File.mkdir_p! target_path
Expand Down Expand Up @@ -211,10 +225,15 @@ defmodule Mix.Tasks.Talon.New do
def gen_web(config) do
fname = "talon_web.ex"
theme = config.theme_name
binding = Kernel.binding() ++
[base: config.base, web_namespace: config.web_namespace, theme: theme,
theme_module: Inflex.camelize(theme), root_path: config.root_path,
path_prefix: config.path_prefix]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
web_namespace: config.web_namespace,
theme: theme,
theme_module: Inflex.camelize(theme),
root_path: config.root_path,
path_prefix: config.path_prefix
]
target_path = Path.join config.root_path, config.path_prefix
unless config.dry_run do
copy_from paths(),
Expand All @@ -227,8 +246,11 @@ defmodule Mix.Tasks.Talon.New do

def gen_messages(config) do
fname = "talon_messages.ex"
binding = Kernel.binding() ++
[base: config.base, web_namespace: config.web_namespace]
binding = Kernel.binding() ++ [
base: config.base,
web_base: config.web_base,
web_namespace: config.web_namespace,
]
target_path = Path.join config.root_path, config.path_prefix
unless config.dry_run do
copy_from paths(),
Expand Down Expand Up @@ -294,12 +316,6 @@ defmodule Mix.Tasks.Talon.New do
end

defp print_route_instructions(config) do
namespace =
if config.project_structure == :phx do
"#{config.base}.Web"
else
config.base
end
full_concern = Module.concat config.base, config.concern

route_scope = Inflex.underscore(config.concern)
Expand All @@ -311,7 +327,7 @@ defmodule Mix.Tasks.Talon.New do
use Talon.Router

# your app's routes
scope "/#{route_scope}", #{namespace} do
scope "/#{route_scope}", #{config.web_base} do
pipe_through :browser
talon_routes(#{to_s full_concern})
end
Expand Down Expand Up @@ -357,9 +373,11 @@ defmodule Mix.Tasks.Talon.New do
app_path_name: app_path_name,
project_structure: proj_struct,
web_namespace: web_namespace(proj_struct),
controller_namespace: controller_namespace(proj_struct),
binding: binding,
boilerplate: bin_opts[:boilerplate] || Application.get_env(:talon, :boilerplate, true),
base: bin_opts[:module] || binding[:base],
web_base: web_base(bin_opts[:module] || binding[:base], proj_struct),
})
end

Expand Down
4 changes: 2 additions & 2 deletions priv/templates/talon.new/config/concern_config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ config :<%= config.app %>, <%= config.base %>.<%= config.concern %>,
root_path: "<%= config.root_path %>",
path_prefix: "<%= config.path_prefix %>",
repo: <%= config.base %>.Repo,
router: <%= config.base %>.Web.Router,
endpoint: <%= config.base %>.Web.Endpoint,
router: <%= config.web_base %>.Router,
endpoint: <%= config.web_base %>.Endpoint,
schema_adapter: Talon.Schema.Adapters.Ecto,
messages_backend: <%= config.base %>.Talon.Messages

4 changes: 2 additions & 2 deletions priv/templates/talon.new/web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule <%= base %>.<%= web_namespace %><%= concern %>PageController do
use <%= base %>.Web, :controller
defmodule <%= web_base %>.<%= concern %>PageController do
use <%= web_base %><%= controller_namespace %>, :controller
use Talon.PageController, concern: <%= base %>.<%= concern %>

plug Talon.Plug.LoadConcern, concern: <%= base %>.<%= concern %>, web_namespace: <%= web_module %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule <%= base %>.<%= web_namespace %><%= concern %>ResourceController do
use <%= base %>.Web, :controller
defmodule <%= web_base %>.<%= concern %>ResourceController do
use <%= web_base %><%= controller_namespace %>, :controller
use Talon.Controller, repo: <%= base %>.Repo, concern: <%= base %>.<%= concern %>

plug Talon.Plug.LoadConcern, concern: <%= base %>.<%= concern %>, web_namespace: <%= web_module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/talon.new/web/talon_messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule <%= base %>.Talon.Messages do
"""
@behaviour Talon.Messages

import <%= base %>.<%= web_namespace %>Gettext
import <%= web_base %>.Gettext

# Change this to override the "talon" gettext domain. If you would like
# the talon message to be part of your projects domain change it to "default"
Expand Down
Loading