Skip to content

Instantly share code, notes, and snippets.

@sauloco
Last active September 20, 2023 18:21
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 sauloco/e2b3d9a6f142a603d2a705b65baed755 to your computer and use it in GitHub Desktop.
Save sauloco/e2b3d9a6f142a603d2a705b65baed755 to your computer and use it in GitHub Desktop.
Leptos Components Jetbrains Templates

Leptos Components Jetbrains Templates

Create a File Template

This live template will allow you to quickly create a leptos component when creating a new file.

Will use the file name as component name. Usually names are snake cased, the script will use a camel cased version of file name for the component name. Example: file name gallery_item will result in the GalleryItem component.

Within your Jetbrains IDE navigate to Settings. Main menu > Settings ( , in macOS or Ctrl Alt S in Windows).

Navigate to Editor > File and Code Templates.

Press + icon.

  • Name: Leptos Component
  • Extension: rs
  • File name: [empty]
  • Body:
use leptos::*;

#set( $CamelCaseName = "" )

#foreach( $str in $NAME.split("_") )
  #set( $str = $str.substring(0,1).toUpperCase() + $str.substring(1) )
  #set( $CamelCaseName = $CamelCaseName + $str )
#end

#[component]
pub fn ${CamelCaseName}() -> impl IntoView {
    view! {
        #[[ $END$ ]]#
    }
}

Live Template

This live template will allow you to quickly create a leptos component after input abbreviation lcomp within any Rust file.

Within your Jetbrains IDE navigate to Settings. Main menu > Settings (⌘ + , in macOS or Ctrl + Alt + S in Windows).

Navigate to Editor > Live Templates.

Press + icon > Template Group > Input "Leptos"

Select the new group "Leptos"

Press + icon > Live Template

  • Abbreviation: lcomp (could be anything really)
  • Description: Leptos Component
  • Template text:
#[component]
pub fn $NAME$() -> impl IntoView { 
    view! {
        $END$
    }
}
  • Applicable in: Rust
  • Reformat according to style: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment