web-view-colonnade: Build HTML tables using web-view and colonnade.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Build HTML tables using web-view and colonnade. This module provides functionality similar to lucid-colonnade and blaze-colonnade but for the web-view library.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.0.1
Change log None available
Dependencies base (>=4.18.2.1 && <5), colonnade (>=1.2.0 && <1.3), containers (>=0.6.7 && <0.9), text (>=2.0.2 && <2.2), vector (>=0.13.2 && <0.14), web-view (>=0.6.0 && <0.8) [details]
License MIT
Author José Lorenzo Rodríguez
Maintainer lorenzo@users.noreply.github.com
Category Web
Home page https://github.com/lorenzo/web-view-colonnade
Source repo head: git clone https://github.com/lorenzo/web-view-colonnade
Uploaded by lorenzo at 2025-03-03T10:20:24Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for web-view-colonnade-0.1.0.0

[back to package description]

Web View Colonnade

Build HTML tables using colonnade and rendering with the web-view library in Haskell.

This library provides functionality similar to lucid-colonnade and blaze-colonnade, but for the web-view library. It lets you build complex HTML tables with minimal boilerplate.

Installation

Add the following to your package.yaml or .cabal file:

dependencies:
  - colonnade
  - web-view
  - web-view-colonnade

Examples

Basic Example

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Text as T
import qualified Colonnade as C
import qualified Web.View.View as V
import qualified Web.View.Element as E
import Web.View (renderText)
import WebView.Colonnade

-- Define a data type to represent our data
data Person = Person
  { name :: T.Text
  , age :: Int
  }

-- Define some data
people :: [Person]
people =
  [ Person "Alice" 30
  , Person "Bob" 25
  , Person "Carol" 35
  ]

-- Define the table structure
personTable :: C.Colonnade C.Headed Person (V.View c ())
personTable = mconcat
  [ C.headed "Name" (E.text . name)
  , C.headed "Age" (E.text . T.pack . show . age)
  ]

main :: IO ()
main = do
  -- Render a table with custom attributes
  let html = encodeHtmlTable (V.extClass "person-table") personTable people
  putStrLn $ renderText html

This produces:

<table class='person-table'>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>30</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>25</td>
    </tr>
    <tr>
      <td>Carol</td>
      <td>35</td>
    </tr>
  </tbody>
</table>

Cell Attributes

The Cell type allows you to add attributes to individual table cells:

personCellTable :: C.Colonnade C.Headed Person (Cell c)
personCellTable = mconcat
  [ C.headed "Name" (\p -> Cell (V.extClass "name-cell") (E.text $ name p))
  , C.headed "Age" (\p -> Cell (V.extClass "age-cell") (E.text . T.pack . show $ age p))
  ]

main :: IO ()
main = do
  let html = encodeCellTable (V.extClass "person-table") personCellTable people
  putStrLn $ renderText html

This will render each cell with the appropriate class attributes.

Contributing

We welcome contributions to web-view-colonnade! This project uses a nix-based devenv shell for development.

Setting Up the Development Environment

  1. Make sure you have Nix installed
  2. Install devenv
  3. Clone this repository:
    git clone https://github.com/lorenzo/web-view-colonnade.git
    cd web-view-colonnade
    
  4. Start the development shell:
    devenv shell
    
  5. Build the project:
    cabal build
    
  6. Run the tests:
    cabal test
    

Pull Requests

  1. Fork the repository
  2. Create a new branch for your feature
  3. Add tests for your new feature
  4. Ensure all tests pass
  5. Submit a pull request

License

This project is licensed under the MIT license - see the LICENSE file for details.