Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Created September 20, 2022 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fadhlirahim/b3cce12a99426201ab6e35f375a1e2f4 to your computer and use it in GitHub Desktop.
Save fadhlirahim/b3cce12a99426201ab6e35f375a1e2f4 to your computer and use it in GitHub Desktop.
VSCode elixir snippet
{
"lv_module": {
"prefix": "lv",
"body": [
"defmodule ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web.${4}Live do",
" use ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web, :live_view",
"end",
],
"description": "LiveView module"
},
"lc_module": {
"prefix": "lc",
"body": [
"defmodule ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web.${4}Component do",
" use ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web, :live_component",
"end"
],
"description": "LiveComponent 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",
" ~L\"\"\"",
" ${0}",
" \"\"\"",
"end"
],
"description": "LiveView render function"
},
"lvh_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}, socket) do",
" socket = assign(socket, ${2:key}: ${3:value})",
" {:noreply, socket}",
"end"
],
"description": "LiveView handle_info function"
},
"lv_handle_params": {
"prefix": "hp",
"body": [
"def handle_params(params, _url, socket) do",
" {:noreply, socket}",
"end"
],
"description": "LiveView handle_params function"
},
"lv_template": {
"prefix": "lt",
"body": [
"~L\"\"\"",
"${0}",
"\"\"\""
],
"description": "LiveView inline template"
},
"lv_test_module": {
"prefix": "lvtest",
"body": [
"defmodule ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}Web.${4}Test do",
" use ${WORKSPACE_NAME/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}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_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"
},
"pipe_op": {
"prefix": "pp",
"body": [
"|> $1 "
],
"description": "pipe operator"
}
}
{
// 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