Skip to content

Commit

Permalink
Merge pull request #19 from mvdwg/use-app-prefix
Browse files Browse the repository at this point in the history
Take app name from the configuration
  • Loading branch information
san650 authored Jul 12, 2017
2 parents f7b6cde + b2cbd20 commit e79ac45
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def deps do
end
```

and then you have to add one config to your config file

```elixir
config :phoenix_components, app_name: MyApp
```

where `MyApp` is the module that represents your phoenix app.

## Quick start

This is a quick overview of how to create and use a component in your application.
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use Mix.Config

config :phoenix_components, path: "test/fixtures"
config :phoenix_components, path: "test/fixtures", app_name: MyApp
7 changes: 6 additions & 1 deletion lib/mix/tasks/phoenix.gen.component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ defmodule Mix.Tasks.Phoenix.Gen.Component do
defp generate(component_name: name) do
path = Application.get_env(:phoenix_components, :path, "web/components")
path = Path.join(path, name)
[module_base] =
:phoenix_components
|> Application.fetch_env!(:app_name)
|> Module.split

assigns = %{
name: name,
module_name: to_pascal_case(name),
module_base: to_pascal_case(Mix.Phoenix.otp_app),
module_base: module_base,
}

# Creates component
Expand Down
3 changes: 2 additions & 1 deletion lib/phoenix_components/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ defmodule PhoenixComponents.View do

defp do_component(name, content, attrs) do
safe_content = html_escape(content)
appModule = Application.fetch_env!(:phoenix_components, :app_name)

name
|> to_pascal_case
|> prefix_module(Components)
|> prefix_module(to_pascal_case(Mix.Phoenix.otp_app))
|> prefix_module(appModule)
|> render("template.html", attrs: Enum.into(attrs, %{}), content: safe_content)
end

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/components/button/view.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule PhoenixComponents.Components.Button do
defmodule MyApp.Components.Button do
use PhoenixComponents.Component
end
2 changes: 1 addition & 1 deletion test/fixtures/components/compound/view.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PhoenixComponents.Components.Compound do
defmodule MyApp.Components.Compound do
use PhoenixComponents.Component

import_components [:button, :jumbotron]
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/components/jumbotron/view.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule PhoenixComponents.Components.Jumbotron do
defmodule MyApp.Components.Jumbotron do
use PhoenixComponents.Component

def class(color) do
Expand Down

0 comments on commit e79ac45

Please sign in to comment.