Skip to content

Instantly share code, notes, and snippets.

@hoangbits
Last active September 20, 2021 11:11
Show Gist options
  • Save hoangbits/60f0f29588526c6af5cab3591b3c35a9 to your computer and use it in GitHub Desktop.
Save hoangbits/60f0f29588526c6af5cab3591b3c35a9 to your computer and use it in GitHub Desktop.
Liveview snippets for VS-code
//
// To install these snippets, select "User Snippets" under "File >
// Preferences" ("Code > Preferences" on macOS), and then select
// elixir.json. Paste the snippets below into that file. If you already
// have snippets in that file, you'll need to put all the snippets in one
// top-level JavaScript object, so remove the outer braces in the code
// below.
//
// JSON doesn't allow comments, so you must remove these comment lines! :-)
//
{
"lv_module": {
"prefix": "lv",
"body": [
"defmodule LiveViewStudioWeb.${1}Live do",
" use LiveViewStudioWeb, :live_view",
"end"
],
"description": "LiveView module"
},
"lc_module": {
"prefix": "lc",
"body": [
"defmodule LiveViewStudioWeb.${1}Component do",
" use LiveViewStudioWeb, :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"
},
"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 LiveViewStudioWeb.${1}Test do",
" use LiveViewStudioWeb.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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment