Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elm-spa

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elm-spa

single page apps made easy

  • 4.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
421
decreased by-24.69%
Maintainers
1
Weekly downloads
 
Created
Source

elm-spa

Build Status

single page apps made easy

this is the cli tool for the ryannhg/elm-spa package.

It comes with a few commands to help you build single page applications in Elm!

installation

npm install -g elm-spa

available commands

elm-spa init

elm-spa init <directory>

  Create a new elm-spa app in the <directory>
  folder specified.

  examples:
  elm-spa init .
  elm-spa init my-app

elm-spa add

elm-spa add <static|sandbox|element|component> <name>

  Create a new page of type <static|sandbox|element|component>
  with the module name <name>.

  examples:
  elm-spa add static Top
  elm-spa add sandbox Posts.Top
  elm-spa add element Posts.Dynamic
  elm-spa add component SignIn

elm-spa build

elm-spa build [dir]

  Create "Generated.Route" and "Generated.Pages" modules for
  this project, based on the files in "src/Pages"

  Here are more details on how that works:
  https://www.npmjs.com/package/elm-spa#naming-conventions

  examples:
  elm-spa build
  elm-spa build ../some/other-folder
  elm-spa build ./help

naming conventions

the elm-spa build command is pretty useful, because it automatically generates Routes.elm and Pages.elm code for you, based on the naming convention in src/Pages/*.elm

Here's an example project structure:

src/
└─ Pages/
   ├─ Top.elm
   ├─ About.elm
   ├─ Posts/
   |   ├─ Top.elm
   |   └─ Dynamic.elm
   └─ Authors/
       └─ Dynamic/
           └─ Posts/
               └─ Dynamic.elm

When you run elm-spa build with these files in the src/Pages directory, elm-spa can automatically generate routes like these:

PageRouteExample
Top.elm/-
About.elm/about-
Posts/Top.elm/posts-
Posts/Dynamic.elm/posts/:param1/posts/123
Authors/Dynamic/Posts/Dynamic.elm/authors/:param1/posts/:param2/authors/ryan/posts/123

top-level and dynamic routes

  • Top.elm represents the top-level index in the folder.
  • Dynamic.elm means that a dynamic parameter should match there.
  • Dynamic can also be used as a folder, supporting nested dynamic routes.

accessing url parameters

These dynamic parameters are available as Flags for the given page.

Here are some specific examples from the routes above:

module Pages.About exposing (..)

type alias Flags =
    ()
module Pages.Posts.Dynamic exposing (..)

type alias Flags =
    { param1 : String
    }
module Pages.Authors.Dynamic.Posts.Dynamic exposing (..)

type alias Flags =
    { param1 : String
    , param2 : String
    }

These Flags are automatically passed in to the init function of any element or component page.

the elm package

Need more details? Feel free to check out the official elm package documentation!

Keywords

FAQs

Package last updated on 30 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc