Get The Base Name of an Elixir Template File
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
5
down vote
favorite
I've got the following Elixir code:
defmodule T do
@eex_extension "eex"
@file_separator "."
def get_base_file_name_from_template_name(template_file_name) do
[base, extension, @eex_extension] = String.split(template_file_name,@file_separator)
base <> @file_separator <> extension
end
end
It works like this:
iex(3)> f = T.get_base_file_name_from_template_name("index.html.eex")
"index.html"
1.) Is there a built-in library function I'm missing that would do this?
2.) Is there a built-in attribute for the eex file extension?
3.) Is there an OS built-in value for the "." BTW, I think file separator is not a great name for that but I can't come up with a better name.
Thoughts, comments, suggestions would be greatly appreciated. Even better yet if this is a built-in function in one of the Elixir libs and I've missed it a pointer to it would be most welcome.
elixir
add a comment |Â
up vote
5
down vote
favorite
I've got the following Elixir code:
defmodule T do
@eex_extension "eex"
@file_separator "."
def get_base_file_name_from_template_name(template_file_name) do
[base, extension, @eex_extension] = String.split(template_file_name,@file_separator)
base <> @file_separator <> extension
end
end
It works like this:
iex(3)> f = T.get_base_file_name_from_template_name("index.html.eex")
"index.html"
1.) Is there a built-in library function I'm missing that would do this?
2.) Is there a built-in attribute for the eex file extension?
3.) Is there an OS built-in value for the "." BTW, I think file separator is not a great name for that but I can't come up with a better name.
Thoughts, comments, suggestions would be greatly appreciated. Even better yet if this is a built-in function in one of the Elixir libs and I've missed it a pointer to it would be most welcome.
elixir
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I've got the following Elixir code:
defmodule T do
@eex_extension "eex"
@file_separator "."
def get_base_file_name_from_template_name(template_file_name) do
[base, extension, @eex_extension] = String.split(template_file_name,@file_separator)
base <> @file_separator <> extension
end
end
It works like this:
iex(3)> f = T.get_base_file_name_from_template_name("index.html.eex")
"index.html"
1.) Is there a built-in library function I'm missing that would do this?
2.) Is there a built-in attribute for the eex file extension?
3.) Is there an OS built-in value for the "." BTW, I think file separator is not a great name for that but I can't come up with a better name.
Thoughts, comments, suggestions would be greatly appreciated. Even better yet if this is a built-in function in one of the Elixir libs and I've missed it a pointer to it would be most welcome.
elixir
I've got the following Elixir code:
defmodule T do
@eex_extension "eex"
@file_separator "."
def get_base_file_name_from_template_name(template_file_name) do
[base, extension, @eex_extension] = String.split(template_file_name,@file_separator)
base <> @file_separator <> extension
end
end
It works like this:
iex(3)> f = T.get_base_file_name_from_template_name("index.html.eex")
"index.html"
1.) Is there a built-in library function I'm missing that would do this?
2.) Is there a built-in attribute for the eex file extension?
3.) Is there an OS built-in value for the "." BTW, I think file separator is not a great name for that but I can't come up with a better name.
Thoughts, comments, suggestions would be greatly appreciated. Even better yet if this is a built-in function in one of the Elixir libs and I've missed it a pointer to it would be most welcome.
elixir
asked Jan 12 at 14:45
Onorio Catenacci
328312
328312
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Since you seem to know what the file extension is, you can use Path.basename/2.
"foo.html.eex"
|> Path.basename(".eex")
|> IO.puts
If you donâÂÂt know the file extension, you can use Path.extname/1 in conjunction.
filename = "foo.html.eex"
filename
|> Path.basename(Path.extname(filename))
|> IO.puts
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Since you seem to know what the file extension is, you can use Path.basename/2.
"foo.html.eex"
|> Path.basename(".eex")
|> IO.puts
If you donâÂÂt know the file extension, you can use Path.extname/1 in conjunction.
filename = "foo.html.eex"
filename
|> Path.basename(Path.extname(filename))
|> IO.puts
add a comment |Â
up vote
5
down vote
accepted
Since you seem to know what the file extension is, you can use Path.basename/2.
"foo.html.eex"
|> Path.basename(".eex")
|> IO.puts
If you donâÂÂt know the file extension, you can use Path.extname/1 in conjunction.
filename = "foo.html.eex"
filename
|> Path.basename(Path.extname(filename))
|> IO.puts
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Since you seem to know what the file extension is, you can use Path.basename/2.
"foo.html.eex"
|> Path.basename(".eex")
|> IO.puts
If you donâÂÂt know the file extension, you can use Path.extname/1 in conjunction.
filename = "foo.html.eex"
filename
|> Path.basename(Path.extname(filename))
|> IO.puts
Since you seem to know what the file extension is, you can use Path.basename/2.
"foo.html.eex"
|> Path.basename(".eex")
|> IO.puts
If you donâÂÂt know the file extension, you can use Path.extname/1 in conjunction.
filename = "foo.html.eex"
filename
|> Path.basename(Path.extname(filename))
|> IO.puts
edited May 31 at 23:30
answered May 31 at 22:22
RubberDuck
26.8k454153
26.8k454153
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184958%2fget-the-base-name-of-an-elixir-template-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password