Comments (2)
code examples
Sure. The context is I need to render some (actually quite a few) routes into PDFs. I didn't want to have to add logic for each and every action I need this for. Thus, I have this type:
data PdfController where
PdfAction :: (Typeable c, Eq c, Show c, CanRoute c, HasPath c) => c -> PdfController
with corresponding instances:
instance Eq PdfController where
(PdfAction a) == (PdfAction b) = Just a == cast b
deriving stock instance Show PdfController
instance HasPath PdfController where
pathTo (PdfAction x) = "/Pdf" <> pathTo x
instance All Controller Pdfables => CanRoute PdfController where
parseRoute' = string "/Pdf" *> choice
( tyApMany @Pdfables @ControllerC $
\(Proxy @_ @x) -> PdfAction <$> parseRoute' @x
)
where Pdfables
is a type-level list of controllers I need to produce PDFs for, and tyApMany
and All
are type-level helpers for working with this list (I can post these, too, if you're interested, but they're somewhat trivial and the code isn't pretty). ControllerC
is just a synonym type class for Data a, Controller a, CanRoute a
(here Data
should've been Typeable
, but isn't due to this issue)
At the moment, I also require this (unused, bogus) instance:
instance Data PdfController where
gunfold _ _ = error "PdfController.gunfold"
toConstr = error "PdfController.toConstr"
dataTypeOf = error "PdfController.dataTypeOf"
I also do this in FrontController
:
type Controllers
= ... -- controllers that don't need to be "pdfable" go here
: PdfController
: Pdfables
instance FrontController WebApplication where
controllers =
[ ... -- any non-parseRoute routes go here, atm it's only startPage
] <> tyApMany @Controllers @ControllerC (\(Proxy @_ @x) -> parseRoute @x)
This all looks a tad overengineered, probably. The main goal was to make PDF generation as plug-and-play as possible, and it is: I just stick the controller I want to add PDFs for into the appropriate list, and I'm done.
from ihp.
Good catch, thanks for reporting 👍 Fixed via #1744
This is an inconvenience, as I have to write bogus Data instances for generic routes (which I represent with existential types).
Can you share some code examples of what you're doing? As it seems unusual I'm interested in what you're doing :)
from ihp.
Related Issues (20)
- Add example on how to run a Job via tests
- Add to docs/ core the way to encode JSON via hsx HOT 4
- custom dependency HOT 1
- Implement `instance EnvVarReader PortNumber` for esier config
- Allow deploy without any migration
- Underscore in ID column leads to compile error in code generation
- Upgrade `system.stateVersion` of nixos packages to latest `23.11`
- `deploy-to-nixos` deletes active sessions HOT 3
- Proper support for non "id" primary keys. HOT 1
- Adding the `autocapitalize` attribute for `<input>` and `<textarea>` elements
- `deploy-to-nixos` Grub issue HOT 5
- Solve all GHC warnings with GHC9.8
- Allow decorating logs for more log types
- How to use github repo as dependency? HOT 2
- IHP codegen does not enforce capitalised View names HOT 3
- Docs: is the 'Package not Found?' section still needed? HOT 1
- IHP IDE: 'DEPLOY' link leads to site with an invalid certificate HOT 3
- ihp-new --elm v1.3.0 could not find a flake.nix file
- Documentation on integrating a form into a View
- `poolMaxResources must not be smaller than numStripes` error after upgrading to IHP 1.3 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ihp.