MyNixOS website logo
Description

LambdaCms "media" extension.

LambdaCms is a Content Management System (CMS) in Haskell using Yesod. This package contains the "media" extension.

lambdacms-media

This is an extension for LambdaCms which allows admins to manage media files.

NOTE: At this point the functionality provided by this extension is very basic. Pull requests adding features are most welcome.

Installing

LambdaCms extensions come as plain Haskell packages and need to be added to the project's .cabal file like any other package dependency.

The following guide expects a newly initialized LambdaCms base application. When you have an existing base app this guide show still be easy to follow.

In the library section of your base application's .cabal file append the following line to build-depends:

                , lambdacms-media

The media extension's admin section needs to be mounted in the base app's router, therefor add the following line to your config/routes file:

/admin/media  MediaAdminR          MediaAdmin   getLambdaCmsMedia

To Application.hs add:

import LambdaCms.Media

As well as the following line (see the comment):

...
    let getLambdaCms = CoreAdmin
        getLambdaCmsMedia = MediaAdmin  -- add this line
        mkFoundation appConnPool = App {..}
...

Then proceed by including the migrateLambdaCmsMedia function to Application.hs as shown in this snippet:

...
    runLoggingT
        (runSqlPool (mapM_ runMigration [migrateAll, migrateLambdaCmsCore, migrateLambdaCmsMedia]) pool)
        (messageLoggerSource theFoundation appLogger)
...

To Foundation.hs also add import LambdaCms.Media and the following two lines (see comments):

...
    , getLambdaCms   :: CoreAdmin
    , getLambdaCmsMedia :: MediaAdmin  -- add this line
    }
...
    adminMenu = (defaultCoreAdminMenu CoreAdminR)
                ++ (defaultMediaAdminMenu MediaAdminR)  -- add this line
    renderLanguages _ = ["en", "nl"]
...

The last line hooks the media admin section into the admin menu.

Finally the following instance needs to be defined in Foundation.hs:

instance LambdaCmsMedia App where
  mediaR       = MediaAdminR
  staticDir y  = appStaticDir $ appSettings y
  staticRoot _ = "/static"

That's it! You can now cabal install the new dependency and run yesod devel to test drive the freshly installed extension.

Using media in another LambdaCms extension

A common usecase would be to use the "media" that are managed using the lambdacms-media extension in other extensions. For example: to add an image to a blog post.

First off all the lambdacms-media package needs to become a package dependency of that particular extension's package.

Then we can add an imageId to the Post model.

Post
  title Text
  body Text
  imageId MediaId Maybe

To make it all work we need to put a constraint on the type class defined in the Foundation.hs:

...
class LambdaCmsMedia master => MysitePostSub master where
...

After this the attachedMaybeMedia function may be used in the handler functions of the blog post extension.

License

All code in this repository is released under the MIT license, as specified in the LICENSE file.

Metadata

Version

0.4.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows