Skip to content

Commit

Permalink
Merge branch 'master' into to-field-tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Nov 17, 2023
2 parents 68b5575 + d59a65d commit 0066c06
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 40 deletions.
2 changes: 1 addition & 1 deletion IHP/View/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ selectField field items = FormField
-- If the field is not touched, we don't want to render the value from the model
-- so we force the user to select. If a value was explicitely set in the model, we
-- render that value.
, fieldValue = if IHP.ModelSupport.didTouchField field model
, fieldValue = if IHP.ModelSupport.didTouchField field model || (not $ isNew model)
then inputValue (getField @fieldName model :: SelectValue item)
else ""
, fieldInputId = cs (lcfirst (getModelName @model) <> "_" <> cs fieldName)
Expand Down
5 changes: 4 additions & 1 deletion IHP/ViewSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import qualified IHP.View.CSSFramework as CSSFramework ()
import IHP.View.Types
import qualified IHP.FrameworkConfig as FrameworkConfig
import IHP.Controller.Context

import qualified IHP.HSX.Attribute as HSX

class View theView where
-- | Hook which is called before the render is called
Expand Down Expand Up @@ -262,3 +262,6 @@ liveReloadWebsocketUrl :: (?context :: ControllerContext) => Text
liveReloadWebsocketUrl = ?context.frameworkConfig.ideBaseUrl
|> Text.replace "http://" "ws://"
|> Text.replace "https://" "wss://"

instance InputValue (PrimaryKey table) => HSX.ApplyAttribute (Id' table) where
applyAttribute attr attr' value h = HSX.applyAttribute attr attr' (inputValue value) h
2 changes: 1 addition & 1 deletion NixSupport/haskell-packages/ihp-graphql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}:
mkDerivation {
pname = "ihp-graphql";
version = "v1.1.0";
version = "v1.2.0";
src = ./../../ihp-graphql;
libraryHaskellDepends = [
aeson attoparsec base ihp postgresql-simple text
Expand Down
2 changes: 1 addition & 1 deletion NixSupport/haskell-packages/ihp-hsx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}:
mkDerivation {
pname = "ihp-hsx";
version = "v1.1.0";
version = "v1.2.0";
src = ./../../ihp-hsx;
isLibrary = true;
isExecutable = false;
Expand Down
2 changes: 1 addition & 1 deletion NixSupport/haskell-packages/ihp-openai.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}:
mkDerivation {
pname = "ihp-openai";
version = "v1.1.0";
version = "v1.2.0";
src = ./../../ihp-openai;
isLibrary = true;
isExecutable = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}:
mkDerivation {
pname = "ihp-postgresql-simple-extra";
version = "v1.1.0";
version = "v1.2.0";
src = ./../../ihp-postgresql-simple-extra;
libraryHaskellDepends = [
aeson attoparsec base basic-prelude bytestring ip postgresql-simple
Expand Down
12 changes: 11 additions & 1 deletion Test/ViewSupportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ tests = beforeAll (mockContextNoDatabase WebApplication config) do
runSession (testGet "test/TestWithParam?param=foo") application >>= assertTextExists "isActiveController TestController: True"
it "should return False on a different route" $ withContext do
application <- makeApplication
runSession (testGet "test/TestWithParam?param=foo") application >>= assertTextExists "isActiveController AnotherTestAction: False"
runSession (testGet "test/TestWithParam?param=foo") application >>= assertTextExists "isActiveController AnotherTestAction: False"

describe "HSX" $ do
it "allow using Id's in HSX attributes without explicitly calling inputValue" $ withContext do
let
id :: Id' "users"
id = Id ("70a10b53-a776-470a-91a8-900cdda06aa2" :: UUID)

(ClassyPrelude.tshow [hsx|<input value={id} />|]) `shouldBe` "<input value=\"70a10b53-a776-470a-91a8-900cdda06aa2\">"

type instance PrimaryKey "users" = UUID
26 changes: 26 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@
This document describes breaking changes, as well as how to fix them, that have occured at given releases.
After updating your project, please consult the segments from your current release until now.

# Upgrade to 1.2.0 from 1.1.0
1. **Switch IHP version**

- **IHP Basic**

Open `flake.nix` and change the git commit in line 3 to the following:

```diff
- ihp.url = "github:digitallyinduced/ihp/v1.1";
+ ihp.url = "github:digitallyinduced/ihp/v1.2";
```

- **IHP Pro & IHP Business**

Visit https://ihp.digitallyinduced.com/Builds and copy the latest v1.2.0 URL into your `flake.nix`.

2. **Remake Env**

Run the following commands:

```bash
direnv reload
```

Now you can start your project as usual with `devenv up`.


# Upgrade to 1.1.0 from 1.0.1

Expand Down
2 changes: 1 addition & 1 deletion ihp-graphql/ihp-graphql.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ihp-graphql
version: 1.1.0
version: 1.2.0
synopsis: GraphQL support for IHP
description: GraphQL support for IHP
license: MIT
Expand Down
1 change: 1 addition & 0 deletions ihp-hsx/.ghci
43 changes: 43 additions & 0 deletions ihp-hsx/IHP/HSX/Attribute.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{-# LANGUAGE UndecidableInstances #-}
{-|
Module: IHP.HSX.Attribute
Copyright: (c) digitally induced GmbH, 2023
-}
module IHP.HSX.Attribute
( ApplyAttribute (..)
) where

import Prelude
import Text.Blaze.Html5 ((!))
import qualified Text.Blaze.Html5 as Html5
import Text.Blaze.Internal (attribute, MarkupM (Parent, Leaf), StaticString (..))
import Data.String.Conversions
import IHP.HSX.ToHtml
import qualified Data.Text as Text
import Data.Text (Text)

class ApplyAttribute value where
applyAttribute :: Text -> Text -> value -> (Html5.Html -> Html5.Html)

instance ApplyAttribute Bool where
applyAttribute attr attr' True h = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') (Html5.textValue value))
where
value = if "data-" `Text.isPrefixOf` attr
then "true" -- "true" for data attributes
else attr -- normal html boolean attriubtes, like <input disabled="disabled"/>, see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
applyAttribute attr attr' false h | "data-" `Text.isPrefixOf` attr = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') "false") -- data attribute set to "false"
applyAttribute attr attr' false h = h -- html boolean attribute, like <input disabled/> will be dropped as there is no other way to specify that it's set to false
{-# INLINE applyAttribute #-}

instance ApplyAttribute attribute => ApplyAttribute (Maybe attribute) where
applyAttribute attr attr' (Just value) h = applyAttribute attr attr' value h
applyAttribute attr attr' Nothing h = h
{-# INLINE applyAttribute #-}

instance ApplyAttribute Html5.AttributeValue where
applyAttribute attr attr' value h = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') value)
{-# INLINE applyAttribute #-}

instance {-# OVERLAPPABLE #-} ConvertibleStrings value Html5.AttributeValue => ApplyAttribute value where
applyAttribute attr attr' value h = applyAttribute attr attr' ((cs value) :: Html5.AttributeValue) h
{-# INLINE applyAttribute #-}
27 changes: 1 addition & 26 deletions ihp-hsx/IHP/HSX/QQ.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import qualified Text.Blaze.Html.Renderer.String as BlazeString
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.List (foldl')
import IHP.HSX.Attribute

hsx :: QuasiQuoter
hsx = QuasiQuoter {
Expand Down Expand Up @@ -109,31 +110,5 @@ textToStaticString :: Text -> StaticString
textToStaticString text = StaticString (Text.unpack text ++) (Text.encodeUtf8 text) text
{-# INLINE textToStaticString #-}

class ApplyAttribute value where
applyAttribute :: Text -> Text -> value -> (Html5.Html -> Html5.Html)

instance ApplyAttribute Bool where
applyAttribute attr attr' True h = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') (Html5.textValue value))
where
value = if "data-" `Text.isPrefixOf` attr
then "true" -- "true" for data attributes
else attr -- normal html boolean attriubtes, like <input disabled="disabled"/>, see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
applyAttribute attr attr' false h | "data-" `Text.isPrefixOf` attr = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') "false") -- data attribute set to "false"
applyAttribute attr attr' false h = h -- html boolean attribute, like <input disabled/> will be dropped as there is no other way to specify that it's set to false
{-# INLINE applyAttribute #-}

instance ApplyAttribute attribute => ApplyAttribute (Maybe attribute) where
applyAttribute attr attr' (Just value) h = applyAttribute attr attr' value h
applyAttribute attr attr' Nothing h = h
{-# INLINE applyAttribute #-}

instance ApplyAttribute Html5.AttributeValue where
applyAttribute attr attr' value h = h ! (attribute (Html5.textTag attr) (Html5.textTag attr') value)
{-# INLINE applyAttribute #-}

instance {-# OVERLAPPABLE #-} ConvertibleStrings value Html5.AttributeValue => ApplyAttribute value where
applyAttribute attr attr' value h = applyAttribute attr attr' ((cs value) :: Html5.AttributeValue) h
{-# INLINE applyAttribute #-}

instance Show (MarkupM ()) where
show html = BlazeString.renderHtml html
5 changes: 3 additions & 2 deletions ihp-hsx/ihp-hsx.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ihp-hsx
version: 1.1.0
version: 1.2.0
synopsis: JSX-like but for Haskell
description: JSX-like templating syntax for Haskell
license: MIT
Expand Down Expand Up @@ -86,4 +86,5 @@ library
, IHP.HSX.ToHtml
, IHP.HSX.ConvertibleStrings
, IHP.HSX.HaskellParser
, IHP.HSX.HsExpToTH
, IHP.HSX.HsExpToTH
, IHP.HSX.Attribute
2 changes: 1 addition & 1 deletion ihp-openai/ihp-openai.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ihp-openai
version: 1.1.0
version: 1.2.0
synopsis: Call GPT4 from IHP
description: Call GPT4 from IHP
license: MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ihp-postgresql-simple-extra
version: 1.1.0
version: 1.2.0
synopsis: Extra data types for postgresql-simple
description: This package is included by default in IHP apps and implements support for postgres data types that are not supported by the postgresql-simple package by default
license: MIT
Expand Down
2 changes: 1 addition & 1 deletion ihp.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ihp
version: 1.1.0
version: 1.2.0
synopsis: Haskell Web Framework
description: The Integrated Haskell Platform is a full stack framework focused on rapid application development while striving for robust code quality.
license: NONE
Expand Down
2 changes: 1 addition & 1 deletion ihp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}:
mkDerivation {
pname = "ihp";
version = "v1.1.0";
version = "v1.2.0";
src = filter { root = ./.; include = ["IHP" "ihp.cabal" "exe" "LICENSE" "lib"]; };
isLibrary = true;
isExecutable = true;
Expand Down

0 comments on commit 0066c06

Please sign in to comment.