<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="ExDoc v0.19.1"> <title>Mix.Generator – Mix v1.7.2</title> <link rel="stylesheet" href="dist/app-240d7fc7e5.css" /> <link rel="canonical" href="https://hexdocs.pm/mix/v1.7/Mix.Generator.html" /> <script src="dist/sidebar_items-0c0044e6e4.js"></script> </head> <body data-type="modules"> <script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script> <div class="main"> <button class="sidebar-button sidebar-toggle"> <span class="icon-menu" aria-hidden="true"></span> <span class="sr-only">Toggle Sidebar</span> </button> <button class="sidebar-button night-mode-toggle"> <span class="icon-theme" aria-hidden="true"></span> <span class="sr-only">Toggle Theme</span> </button> <section class="sidebar"> <a href="http://elixir-lang.org/docs.html" class="sidebar-projectLink"> <div class="sidebar-projectDetails"> <h1 class="sidebar-projectName"> Mix </h1> <h2 class="sidebar-projectVersion"> v1.7.2 </h2> </div> <img src="assets/logo.png" alt="Mix" class="sidebar-projectImage"> </a> <form class="sidebar-search" action="search.html"> <button type="submit" class="search-button"> <span class="icon-search" aria-hidden="true"></span> </button> <input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" /> </form> <ul class="sidebar-listNav"> <li><a id="extras-list" href="#full-list">Pages</a></li> <li><a id="modules-list" href="#full-list">Modules</a></li> <li><a id="exceptions-list" href="#full-list">Exceptions</a></li> <li><a id="tasks-list" href="#full-list">Mix Tasks</a></li> </ul> <div class="gradient"></div> <ul id="full-list" class="sidebar-fullList"></ul> </section> <section class="content"> <div class="content-outer"> <div id="content" class="content-inner"> <h1> <small class="visible-xs">Mix v1.7.2</small> Mix.Generator <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/generator.ex#L1" title="View Source" class="view-source" rel="help"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> </h1> <section id="moduledoc"> <p>Conveniences for working with paths and generating content.</p> <p>All of these functions are verbose, in the sense they log the action to be performed via <a href="Mix.html#shell/0"><code class="inline">Mix.shell/0</code></a>.</p> </section> <section id="summary" class="details-list"> <h1 class="section-heading"> <a class="hover-link" href="#summary"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this section</span> </a> Summary </h1> <div class="summary-functions summary"> <h2> <a href="#functions">Functions</a> </h2> <div class="summary-row"> <div class="summary-signature"> <a href="#create_directory/1">create_directory(path)</a> </div> <div class="summary-synopsis"><p>Creates a directory if one does not exist yet</p> </div> </div> <div class="summary-row"> <div class="summary-signature"> <a href="#create_file/3">create_file(path, contents, opts \\ [])</a> </div> <div class="summary-synopsis"><p>Creates a file with the given contents. If the file already exists, asks for user confirmation</p> </div> </div> <div class="summary-row"> <div class="summary-signature"> <a href="#embed_template/2">embed_template(name, contents)</a> </div> <div class="summary-synopsis"><p>Embeds a template given by <code class="inline">contents</code> into the current module</p> </div> </div> <div class="summary-row"> <div class="summary-signature"> <a href="#embed_text/2">embed_text(name, contents)</a> </div> <div class="summary-synopsis"><p>Embeds a text given by <code class="inline">contents</code> into the current module</p> </div> </div> </div> </section> <section id="functions" class="details-list"> <h1 class="section-heading"> <a class="hover-link" href="#functions"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this section</span> </a> Functions </h1> <div class="detail" id="create_directory/1"> <div class="detail-header"> <a href="#create_directory/1" class="detail-link" title="Link to this function"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this function</span> </a> <span class="signature">create_directory(path)</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/generator.ex#L48" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <div class="specs"> <pre>create_directory(<a href="https://hexdocs.pm/elixir/Path.html#t:t/0">Path.t</a>()) :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()</pre> </div> </div> <section class="docstring"> <p>Creates a directory if one does not exist yet.</p> <p>This function does nothing if the given directory already exists; in this case, it still logs the directory creation.</p> <h2 id="create_directory/1-examples" class="section-heading"> <a href="#create_directory/1-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a> Examples </h2> <pre><code class="nohighlight makeup elixir"><span class="gp unselectable">iex> </span><span class="nc">Mix.Generator</span><span class="o">.</span><span class="n">create_directory</span><span class="p" data-group-id="0142113664-1">(</span><span class="s">"path/to/dir"</span><span class="p" data-group-id="0142113664-1">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">creating</span><span class="w"> </span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">dir</span><span class="w"> </span><span class="ss">:ok</span></code></pre> </section> </div> <div class="detail" id="create_file/3"> <span id="create_file/2"></span> <div class="detail-header"> <a href="#create_file/3" class="detail-link" title="Link to this function"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this function</span> </a> <span class="signature">create_file(path, contents, opts \\ [])</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/generator.ex#L25" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <div class="specs"> <pre>create_file(<a href="https://hexdocs.pm/elixir/Path.html#t:t/0">Path.t</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">iodata</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">keyword</a>()) :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()</pre> </div> </div> <section class="docstring"> <p>Creates a file with the given contents. If the file already exists, asks for user confirmation.</p> <h2 id="create_file/3-options" class="section-heading"> <a href="#create_file/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a> Options </h2> <ul> <li><code class="inline">:force</code> - forces installation without a shell prompt. </li> </ul> <h2 id="create_file/3-examples" class="section-heading"> <a href="#create_file/3-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a> Examples </h2> <pre><code class="nohighlight makeup elixir"><span class="gp unselectable">iex> </span><span class="nc">Mix.Generator</span><span class="o">.</span><span class="n">create_file</span><span class="p" data-group-id="8388026612-1">(</span><span class="s">".gitignore"</span><span class="p">,</span><span class="w"> </span><span class="s">"_build</span><span class="se">\n</span><span class="s">deps</span><span class="se">\n</span><span class="s">"</span><span class="p" data-group-id="8388026612-1">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">creating</span><span class="w"> </span><span class="o">.</span><span class="n">gitignore</span><span class="w"> </span><span class="ss">:ok</span></code></pre> </section> </div> <div class="detail" id="embed_template/2"> <div class="detail-header"> <a href="#embed_template/2" class="detail-link" title="Link to this macro"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this macro</span> </a> <span class="signature">embed_template(name, contents)</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/generator.ex#L73" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <span class="note">(macro)</span> </div> <section class="docstring"> <p>Embeds a template given by <code class="inline">contents</code> into the current module.</p> <p>It will define a private function with the <code class="inline">name</code> followed by <code class="inline">_template</code> that expects assigns as arguments.</p> <p>This function must be invoked passing a keyword list. Each key in the keyword list can be accessed in the template using the <code class="inline">@</code> macro.</p> <p>For more information, check <a href="https://hexdocs.pm/eex/EEx.SmartEngine.html"><code class="inline">EEx.SmartEngine</code></a>.</p> <h2 id="embed_template/2-examples" class="section-heading"> <a href="#embed_template/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a> Examples </h2> <pre><code class="nohighlight makeup elixir"><span class="kd">defmodule</span><span class="w"> </span><span class="nc">Mix.Tasks.MyTask</span><span class="w"> </span><span class="k" data-group-id="3529721028-1">do</span><span class="w"> </span><span class="kn">require</span><span class="w"> </span><span class="nc">Mix.Generator</span><span class="w"> </span><span class="nc">Mix.Generator</span><span class="o">.</span><span class="n">embed_template</span><span class="p" data-group-id="3529721028-2">(</span><span class="ss">:log</span><span class="p">,</span><span class="w"> </span><span class="s">"Log: <%= @log %>"</span><span class="p" data-group-id="3529721028-2">)</span><span class="w"> </span><span class="k" data-group-id="3529721028-1">end</span></code></pre> </section> </div> <div class="detail" id="embed_text/2"> <div class="detail-header"> <a href="#embed_text/2" class="detail-link" title="Link to this macro"> <span class="icon-link" aria-hidden="true"></span> <span class="sr-only">Link to this macro</span> </a> <span class="signature">embed_text(name, contents)</span> <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/generator.ex#L110" class="view-source" rel="help" title="View Source"> <span class="icon-code" aria-hidden="true"></span> <span class="sr-only">View Source</span> </a> <span class="note">(macro)</span> </div> <section class="docstring"> <p>Embeds a text given by <code class="inline">contents</code> into the current module.</p> <p>It will define a private function with the <code class="inline">name</code> followed by <code class="inline">_text</code> that expects no arguments.</p> <h2 id="embed_text/2-examples" class="section-heading"> <a href="#embed_text/2-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a> Examples </h2> <pre><code class="nohighlight makeup elixir"><span class="kd">defmodule</span><span class="w"> </span><span class="nc">Mix.Tasks.MyTask</span><span class="w"> </span><span class="k" data-group-id="9539679154-1">do</span><span class="w"> </span><span class="kn">require</span><span class="w"> </span><span class="nc">Mix.Generator</span><span class="w"> </span><span class="nc">Mix.Generator</span><span class="o">.</span><span class="n">embed_text</span><span class="p" data-group-id="9539679154-2">(</span><span class="ss">:error</span><span class="p">,</span><span class="w"> </span><span class="s">"There was an error!"</span><span class="p" data-group-id="9539679154-2">)</span><span class="w"> </span><span class="k" data-group-id="9539679154-1">end</span></code></pre> </section> </div> </section> <footer class="footer"> <p> <span class="line"> Built using <a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v0.19.1), </span> <span class="line"> designed by <a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>. </span> </p> </footer> </div> </div> </section> </div> <script src="dist/app-a0c90688fa.js"></script> </body> </html>