Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
code snippets for the elixir.json
{
// Place your snippets for elixir here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
// Snippets for the LiveView Module name of the APP
// "lv_module": {
// "scope": "elixir, html-eex",
// "prefix": "lv",
// "body": [
// "defmodule ${1}Web.${2}Live do",
// " use ${1}Web, :live_view",
// "end"
// ],
// "description": "LiveView module"
// },
// Snippets of the course Phoenix Live View By PragProg
"app_name": {
"prefix": "an",
"body": [
"FoodOrder"
],
"description": "The name of the App"
},
"app_name_web": {
"prefix": "anw",
"body": [
"FoodOrderWeb"
],
"description": "The name of the App with Web( AppModuleWeb )"
},
"lv_module": {
"prefix": "lv",
"body": [
"defmodule ${1:Module}Web.${2:ModuleName}Live do",
" use ${1:Module}Web, :live_view",
"end"
],
"description": "LiveView module"
},
"lc_module": {
"prefix": "lc",
"body": [
"defmodule ${1:Module}Web.${2:Name}Component do",
" use ${1:Module}Web, :live_component",
"end"
],
"description": "LiveComponent module"
},
"lc_module_helpers": {
"prefix": "lh",
"body": [
"defmodule ${1:Module}Web.Live.LiveHelpers do",
" use Phoenix.LiveComponent",
"",
" def ${2:name}(assigns) do",
" ~H\"\"\"",
" ${0}",
" \"\"\"",
" end",
"",
"end"
],
"description": "LiveComponent Helpers module"
},
"lv_mount": {
"prefix": "mount",
"body": [
"def mount(_params, _session, socket) do",
" socket = assign(socket, ${1:key}: ${2:value})",
" {:ok, socket}",
"end"
],
"description": "LiveView mount function"
},
"lv_rend": {
"prefix": "rend",
"body": [
"def render(assigns) do",
" ~H\"\"\"",
" ${0}",
" \"\"\"",
"end"
],
"description": "LiveView render function"
},
"lv_handle_event": {
"prefix": "he",
"body": [
"def handle_event(\"${1:event}\", _, socket) do",
" socket = assign(socket, ${2:key}: ${3:value})",
" {:noreply, socket}",
"end"
],
"description": "LiveView handle_event function"
},
"lv_handle_info": {
"prefix": "hi",
"body": [
"def handle_info({:${1:message}, ${2:key}}, socket) do",
" socket = update(socket, :${2:key}: ${3:fun})",
" send_update(PoeticoinsWeb.ProductComponent, id: ${2:key}.${4:value}, ${2:key}: ${2:key})",
" {:noreply, socket}",
"end"
],
"description": "LiveView handle_info function"
},
"lv_handle_params": {
"prefix": "hp",
"body": [
"def handle_params(%{\"${1:params}s\" => ${1:params}}=_params, _url, socket) do",
" {:noreply, socket}",
"end"
],
"description": "LiveView handle_params function"
},
"lv_h_sigil": {
"prefix": "sh",
"body": [
"~H\"\"\"",
"${0}",
"\"\"\""
],
"description": "The '~H' sigil. LiveView inline template. "
},
"lv_render_slot": {
"prefix": "rs",
"body": [
"<%= render_slot(@inner_block) %>",
],
"description": "'<%= render_slot(@inner_block) %>' render_slot function with the tag block"
},
"lv_component_tag": {
"prefix": "<.",
"body": [
"<.${1:name}>",
" $2",
"</.${1:name}>"
],
"description": "<. > component tag block"
},
"lv_component_render": {
"prefix": "<.m",
"body": [
"<.live_component module={${1:ModuleName}} id=\"${2:id-name}\" />"
],
"description": "LiveView Component render block"
},
"lv_component_render_with_module_name": {
"prefix": "<.mn",
"body": [
"<${1:ModuleName} id=\"${2:id-name}\" />"
],
"description": "LiveView Component render block without the imported module name"
},
"lv_test_module": {
"prefix": "lvtest",
"body": [
"defmodule ${1:ModuleName}Web.${2:ModuleTestName}Test do",
" use ${1}Web.ConnCase, async: true",
"",
" import Phoenix.LiveViewTest",
"",
" ${0}",
"end"
],
"description": "LiveView test module"
},
"lv_test": {
"prefix": "test",
"body": [
"test \"${1:description}\", %{conn: conn} do",
" {:ok, view, _html} = live(conn, \"${2:path}\")",
" ${0}",
"end"
],
"description": "LiveView test"
},
"eex_datalist": {
"prefix": "data",
"body": [
"<datalist id=\"${1}\">",
" ${0}",
"</datalist>",
""
],
"description": "EEx datalist"
},
"eex_input": {
"prefix": "input",
"body": [
"<input type=\"text\" name=\"${1}\" value=\"${2}\"",
" placeholder=\"${3}\" />"
],
"description": "EEx text input"
},
"eex_hidden_input": {
"prefix": "hidden",
"body": [
"<input type=\"hidden\" name=\"${1}\" value=\"${2}\" />"
],
"description": "EEx hidden input"
},
"eex_form": {
"prefix": "eform",
"body": [
"<div>",
" <.form let={f} for={@changeset} id={@id} phx-change=\"validate\" phx-target={@myself}>",
" <div class=\"mb-4\">",
" <%= label f, :${1:name} %>",
" <%= ${2:type} f, :${1:name} %>",
" <%= error_tag f, :${1:name} %>",
" </div>",
" <div class=\"flex\">",
" <%= submit \"${3:Button Name}\", phx_disable_with: \"Creating...\", class: \"btn-primary\" %>",
" </div>",
" </.form>",
"</div>"
],
"description": "EEx form"
},
"eex_label_input_error_tags": {
"prefix": "liet",
"body": [
" <%= label f, :${1:name} %>",
" <%= ${2:type} f, :${1:name} %>",
" <%= error_tag f, :${1:name} %>",
],
"description": "EEx for the form use the label, type of the input and errot_tag f"
},
"eex_checkbox_input": {
"prefix": "checkbox",
"body": [
"<input type=\"checkbox\" id=\"${1}\" name=\"${2}\" value=\"${3}\"/>"
],
"description": "EEx checkbox input"
},
"eex_render_block": {
"prefix": "et",
"body": [
"<%= $1 %>"
],
"description": "<%= %> render block"
},
"eex_end_tag": {
"prefix": "eend",
"body": [
"<% end %>$1"
],
"description": "<% end %> end tag"
},
"for": {
"prefix": "efor",
"body": [
"<%= for ${1:item} <- @$1s do %>",
" $2",
"<% end %>"
],
"description": "EEx for"
},
"fori": {
"prefix": "efori",
"body": [
"<%= for ${1:item} <- @$1s do %>",
" $2",
"<% end %>"
],
"description": "EEx for comprehension with items"
},
"eex_ifa": {
"prefix": "eifa",
"body": [
"<%= if $1, do: \"{$1}\" %>"
],
"description": "EEx if for attribute"
},
"eex_if": {
"prefix": "eif",
"body": [
"<%= if $1 do %>",
" $2",
"<% end %>"
],
"description": "EEx if"
},
"eex_if_else": {
"prefix": "eife",
"body": [
"<%= if $1 do %>",
" $2",
"<% else %>",
" $3",
"<% end %>"
],
"description": "EEx if else"
},
"eex_else": {
"prefix": "eelse",
"body": [
"<% else %>"
],
"description": "EEx else"
},
"eex_cond": {
"prefix": "econd",
"body": [
"<%= cond do %>",
" <% $1 -> %>",
" $2",
" <% true -> %>",
" $3",
"<% end %>"
],
"description": "EEx cond"
},
"eex_unless": {
"prefix": "eunless",
"body": [
"<%= unless $1 do %>",
" $2",
"<% end %>"
],
"description": "EEx unless"
}
}
{
// Place your snippets for html-eex here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"lv_component_tag": {
"prefix": "<.",
"body": [
"<.${1:name}>",
" $2",
"</.${1:name}>"
],
"description": "<. > component tag block"
},
"lv_render_slot": {
"prefix": "rs",
"body": [
"<%= render_slot(@inner_block) %>",
],
"description": "'<%= render_slot(@inner_block) %>' render_slot function with the tag block"
},
"lv_component_render": {
"prefix": "lct",
"body": [
"<.live_component module={${1:ModuleName}} id=\"${2:id-name}\" />"
],
"description": "LiveView Component render block"
},
"lv_component_render_with_module_name": {
"prefix": "lctm",
"body": [
"<${1:ModuleName} id=\"${2:id-name}\" />"
],
"description": "LiveView Component render block without the imported module name"
},
"eex_datalist": {
"prefix": "data",
"body": [
"<datalist id=\"${1}\">",
" ${0}",
"</datalist>",
""
],
"description": "EEx datalist"
},
"eex_input": {
"prefix": "input",
"body": [
"<input type=\"text\" name=\"${1}\" value=\"${2}\"",
" placeholder=\"${3}\" />"
],
"description": "EEx text input"
},
"eex_hidden_input": {
"prefix": "hidden",
"body": [
"<input type=\"hidden\" name=\"${1}\" value=\"${2}\" />"
],
"description": "EEx hidden input"
},
"eex_form": {
"prefix": "eform",
"body": [
"<div>",
" <.form let={f} for={@changeset} id={@id} phx-change=\"validate\" phx-target={@myself}>",
" <div class=\"mb-4\">",
" <%= label f, :${1:name} %>",
" <%= ${2:type} f, :${1:name} %>",
" <%= error_tag f, :${1:name} %>",
" </div>",
" <div class=\"flex\">",
" <%= submit \"${3:Button Name}\", phx_disable_with: \"Creating...\", class: \"btn-primary\" %>",
" </div>",
" </.form>",
"</div>"
],
"description": "EEx form"
},
"eex_label_input_error_tags": {
"prefix": "liet",
"body": [
" <%= label f, :${1:name} %>",
" <%= ${2:type} f, :${1:name} %>",
" <%= error_tag f, :${1:name} %>",
],
"description": "EEx for the form use the label, type of the input and errot_tag f"
},
"eex_checkbox_input": {
"prefix": "checkbox",
"body": [
"<input type=\"checkbox\" id=\"${1}\" name=\"${2}\" value=\"${3}\"/>"
],
"description": "EEx checkbox input"
},
"eex_render_block": {
"prefix": "et",
"body": [
"<%= $1 %>"
],
"description": "<%= %> render block"
},
"eex_end_tag": {
"prefix": "eend",
"body": [
"<% end %>$1"
],
"description": "<% end %> end tag"
},
"for": {
"prefix": "efor",
"body": [
"<%= for ${1:item} <- @$1s do %>",
" $2",
"<% end %>"
],
"description": "EEx for"
},
"fori": {
"prefix": "efori",
"body": [
"<%= for ${1:item} <- @$1s do %>",
" $2",
"<% end %>"
],
"description": "EEx for comprehension with items"
},
"eex_ifa": {
"prefix": "eifa",
"body": [
"<%= if $1, do: \"{$1}\" %>"
],
"description": "EEx if for attribute"
},
"eex_if": {
"prefix": "eif",
"body": [
"<%= if $1 do %>",
" $2",
"<% end %>"
],
"description": "EEx if"
},
"eex_if_else": {
"prefix": "eife",
"body": [
"<%= if $1 do %>",
" $2",
"<% else %>",
" $3",
"<% end %>"
],
"description": "EEx if else"
},
"eex_else": {
"prefix": "eelse",
"body": [
"<% else %>"
],
"description": "EEx else"
},
"eex_cond": {
"prefix": "econd",
"body": [
"<%= cond do %>",
" <% $1 -> %>",
" $2",
" <% true -> %>",
" $3",
"<% end %>"
],
"description": "EEx cond"
},
"eex_unless": {
"prefix": "eunless",
"body": [
"<%= unless $1 do %>",
" $2",
"<% end %>"
],
"description": "EEx unless"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment