Skip to content

Commit

Permalink
Rename IHP.HtmlSupport Modules To IHP.HSX
Browse files Browse the repository at this point in the history
  • Loading branch information
s0kil committed May 19, 2021
1 parent 34452ba commit ff6b73e
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Guide/hsx.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ in

**If the variable is another HSX expression, a blaze HTML element, a text or string**: it is just included as you would expect.

**If the variable is any other custom Haskell data structure**: it will first be converted to a string representation by calling `show` on it. You can add a custom `ToHtml` (import it from `IHP.HtmlSupport.ToHtml`) instance, to customize rendering a data structure.
**If the variable is any other custom Haskell data structure**: it will first be converted to a string representation by calling `show` on it. You can add a custom `ToHtml` (import it from `IHP.HSX.ToHtml`) instance, to customize rendering a data structure.

You can also write more complex code like:

Expand Down Expand Up @@ -266,4 +266,4 @@ action CreateUserAction = do
|> createRecord
```

Now when the country input field is empty when creating the user, the `country` field will be set to `Nothing` instead of `Just ""`.
Now when the country input field is empty when creating the user, the `country` field will be set to `Nothing` instead of `Just ""`.
2 changes: 1 addition & 1 deletion IHP/AutoRefresh/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module IHP.AutoRefresh.View where
import IHP.Prelude
import IHP.ViewSupport
import IHP.AutoRefresh.Types
import IHP.HtmlSupport.QQ (hsx)
import IHP.HSX.QQ (hsx)
import qualified Text.Blaze.Html5 as Html5
import IHP.Controller.Context

Expand Down
4 changes: 2 additions & 2 deletions IHP/ErrorController.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import qualified Database.PostgreSQL.Simple.FromField as PG
import qualified Data.ByteString.Char8 as ByteString
import qualified Data.ByteString.Lazy as LBS

import IHP.HtmlSupport.QQ (hsx)
import IHP.HSX.QQ (hsx)
import Database.PostgreSQL.Simple.FromField (ResultError (..))
import qualified IHP.ModelSupport as ModelSupport
import IHP.FrameworkConfig
Expand Down Expand Up @@ -442,4 +442,4 @@ renderError errorTitle view = H.docTypeHtml ! A.lang "en" $ [hsx|
<a href="https://gitter.im/digitallyinduced/ihp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge" target="_blank">Gitter</a>
<a href="https://www.reddit.com/r/IHPFramework/" target="_blank">Reddit</a>
</div>
|]
|]
2 changes: 1 addition & 1 deletion IHP/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import qualified Database.PostgreSQL.Simple.Types as PG
import GHC.OverloadedLabels
import IHP.ModelSupport
import qualified Data.ByteString.Builder as Builder
import IHP.HtmlSupport.ToHtml
import IHP.HSX.ToHtml
import qualified Data.ByteString.Char8 as ByteString
import qualified Data.ByteString.Lazy as LByteString
import qualified Control.DeepSeq as DeepSeq
Expand Down
14 changes: 7 additions & 7 deletions IHP/HtmlSupport/Parser.hs → IHP/HSX/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module IHP.HtmlSupport.Parser
module IHP.HSX.Parser
( parseHsx
, Node (..)
, Attribute (..)
Expand Down Expand Up @@ -39,13 +39,13 @@ data Node = Node !Text ![Attribute] ![Node] !Bool
-- | Parses a HSX text and returns a 'Node'
--
-- __Example:__
--
--
-- > let filePath = "my-template"
-- > let line = 0
-- > let col = 0
-- > let position = Megaparsec.SourcePos filePath (Megaparsec.mkPos line) (Megaparsec.mkPos col)
-- > let hsxText = "<strong>Hello</strong>"
-- >
-- >
-- > let (Right node) = parseHsx position hsxText
parseHsx :: SourcePos -> Text -> Either (ParseErrorBundle Text Void) Node
parseHsx position code = runParser (setPosition position *> parser) "" code
Expand Down Expand Up @@ -124,7 +124,7 @@ hsxNodeAttributes :: Parser a -> Parser [Attribute]
hsxNodeAttributes end = staticAttributes
where
staticAttributes = do
attributes <- manyTill (hsxNodeAttribute <|> hsxSplicedAttributes) end
attributes <- manyTill (hsxNodeAttribute <|> hsxSplicedAttributes) end
let staticAttributes = List.filter isStaticAttribute attributes
let keys = List.map (\(StaticAttribute name _) -> name) staticAttributes
let uniqueKeys = List.nub keys
Expand Down Expand Up @@ -391,7 +391,7 @@ leafs = Set.fromList

stripTextNodeWhitespaces nodes = stripLastTextNodeWhitespaces (stripFirstTextNodeWhitespaces nodes)

stripLastTextNodeWhitespaces nodes =
stripLastTextNodeWhitespaces nodes =
let strippedLastElement = if List.length nodes > 0
then case List.last nodes of
TextNode text -> Just $ TextNode (Text.stripEnd text)
Expand All @@ -401,7 +401,7 @@ stripLastTextNodeWhitespaces nodes =
Just last -> (fst $ List.splitAt ((List.length nodes) - 1) nodes) <> [last]
Nothing -> nodes

stripFirstTextNodeWhitespaces nodes =
stripFirstTextNodeWhitespaces nodes =
let strippedFirstElement = if List.length nodes > 0
then case List.head nodes of
TextNode text -> Just $ TextNode (Text.stripStart text)
Expand All @@ -415,7 +415,7 @@ stripFirstTextNodeWhitespaces nodes =
collapseSpace :: Text -> Text
collapseSpace text = cs $ filterDuplicateSpaces (cs text)
where
filterDuplicateSpaces :: String -> String
filterDuplicateSpaces :: String -> String
filterDuplicateSpaces string = filterDuplicateSpaces' string False

filterDuplicateSpaces' :: String -> Bool -> String
Expand Down
8 changes: 4 additions & 4 deletions IHP/HtmlSupport/QQ.hs → IHP/HSX/QQ.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# LANGUAGE TemplateHaskell, UndecidableInstances, BangPatterns #-}

module IHP.HtmlSupport.QQ (hsx) where
module IHP.HSX.QQ (hsx) where

import ClassyPrelude
import IHP.HtmlSupport.Parser
import IHP.HSX.Parser
import qualified "template-haskell" Language.Haskell.TH as TH
import qualified "template-haskell" Language.Haskell.TH.Syntax as TH
import Language.Haskell.TH.Quote
Expand All @@ -13,7 +13,7 @@ import Text.Blaze.Html5.Attributes as A
import Text.Blaze.Html (Html)
import Text.Blaze.Internal (attribute, MarkupM (Parent, Leaf), StaticString (..))
import Data.String.Conversions
import IHP.HtmlSupport.ToHtml
import IHP.HSX.ToHtml
import Control.Monad.Fail
import qualified Text.Megaparsec as Megaparsec
import qualified Text.Blaze.Html.Renderer.String as BlazeString
Expand Down Expand Up @@ -49,7 +49,7 @@ compileToHaskell (Node name attributes children isLeaf) =
stringAttributes = TH.listE $ map toStringAttribute attributes
openTag :: Text
openTag = "<" <> tag
tag :: Text
tag :: Text
tag = cs name
in
if isLeaf
Expand Down
6 changes: 3 additions & 3 deletions IHP/HtmlSupport/ToHtml.hs → IHP/HSX/ToHtml.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# LANGUAGE UndecidableInstances #-}

module IHP.HtmlSupport.ToHtml where
import qualified Text.Blaze.Html5 as Html5
module IHP.HSX.ToHtml where

import qualified Text.Blaze.Html5 as Html5
import qualified Text.Blaze.Internal
import ClassyPrelude
import Data.String.Conversions (cs)
Expand Down Expand Up @@ -35,4 +36,3 @@ instance {-# OVERLAPPABLE #-} Show a => ToHtml (Maybe a) where
instance {-# OVERLAPPABLE #-} Show a => ToHtml a where
{-# INLINE toHtml #-}
toHtml value = cs (show value)

6 changes: 3 additions & 3 deletions IHP/Modal/ViewFunctions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module IHP.Modal.ViewFunctions (modal, renderModal) where

import IHP.Prelude
import IHP.Controller.Context
import IHP.HtmlSupport.QQ (hsx)
import IHP.HSX.QQ (hsx)
import IHP.Modal.Types
import Text.Blaze.Html5 (Html, preEscapedText)

Expand Down Expand Up @@ -52,7 +52,7 @@ renderModalHeader title closeUrl = [hsx|
|]

modal :: (?context :: ControllerContext) => Html
modal =
modal =
case maybeFromFrozenContext of
Just (ModalContainer html) -> html
Nothing -> mempty
Nothing -> mempty
2 changes: 1 addition & 1 deletion IHP/QueryBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import qualified Database.PostgreSQL.Simple.Types as PG
import GHC.OverloadedLabels
import IHP.ModelSupport
import qualified Data.ByteString.Builder as Builder
import IHP.HtmlSupport.ToHtml
import IHP.HSX.ToHtml
import qualified Data.ByteString.Char8 as ByteString
import qualified Data.ByteString.Lazy as LByteString
import qualified Control.DeepSeq as DeepSeq
Expand Down
6 changes: 3 additions & 3 deletions IHP/View/CSSFramework.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module IHP.View.CSSFramework where
import IHP.Prelude
import IHP.FlashMessages.Types
import qualified Text.Blaze.Html5 as Blaze
import IHP.HtmlSupport.QQ (hsx)
import IHP.HtmlSupport.ToHtml
import IHP.HSX.QQ (hsx)
import IHP.HSX.ToHtml
import IHP.View.Types
import IHP.View.Classes

Expand Down Expand Up @@ -40,7 +40,7 @@ instance Default CSSFramework where
}
where
styledFlashMessages cssFramework flashMessages = forEach flashMessages (styledFlashMessage cssFramework cssFramework)

styledFormField :: CSSFramework -> FormField -> Blaze.Html
styledFormField cssFramework formField =
case get #fieldType formField of
Expand Down
36 changes: 18 additions & 18 deletions IHP/View/Form.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import IHP.View.ConvertibleStrings ()
import IHP.ViewErrorMessages
import IHP.ViewSupport
import qualified Text.Blaze.Html5 as Html5
import IHP.HtmlSupport.ToHtml
import IHP.HSX.ToHtml
import IHP.NameSupport
import GHC.Types
import IHP.RouterSupport hiding (get)
import IHP.ModelSupport (getModelName, inputValue, isNew, GetModelName, Id', NormalizeModel, MetaBag, InputValue)
import IHP.HtmlSupport.QQ (hsx)
import IHP.HSX.QQ (hsx)
import IHP.View.Types
import IHP.View.Classes
import IHP.View.Classes
import qualified Network.Wai as Wai
import IHP.Controller.Context

Expand All @@ -46,12 +46,12 @@ import IHP.Controller.Context
-- > <label for="post_title">Title</label>
-- > <input type="text" name="title" id="post_title" class="form-control" />
-- > </div>
-- >
-- >
-- > <div class="form-group" id="form-group-post_body">
-- > <label for="post_body">Body</label>
-- > <textarea name="body" id="post_body" class="form-control"></textarea>
-- > </div>
-- >
-- >
-- > <button class="btn btn-primary">Create Post</button>
-- > </form>
--
Expand Down Expand Up @@ -115,7 +115,7 @@ formFor record formBody = formForWithOptions @record @id @application record (\c
-- > {textareaField #body}
-- > {submitButton}
-- > |]
-- >
-- >
-- > formOptions :: FormContext Post -> FormContext Post
-- > formOptions formContext = formContext
-- > |> set #formId "post-form"
Expand Down Expand Up @@ -153,7 +153,7 @@ formForWithOptions record applyOptions formBody = buildForm (applyOptions (creat
-- > {textareaField #body}
-- > {submitButton}
-- > |]
-- >
-- >
-- > formOptions :: FormContext Post -> FormContext Post
-- > formOptions formContext = formContext
-- > |> set #disableJavascriptSubmission True
Expand All @@ -174,23 +174,23 @@ formForWithoutJavascript record formBody = formForWithOptions @record @id @appli
-- | Allows a custom form action (form submission url) to be set
--
-- The URL where the form is going to be submitted to is specified in HTML using the form's @action@ attribute. When using 'formFor' the @action@ attribute is automatically set to the expected path.
--
--
-- E.g. given the below 'formFor' code, the @action@ is set to @/CreatePost@ or @/UpdatePost@:
--
--
-- > renderForm :: Post -> Html
-- > renderForm post = formFor post [hsx|
-- > {textField #title}
-- > {textareaField #body}
-- > {submitButton}
-- > |]
--
--
-- To override the auto-generated @action@ attribute use the 'formFor\'' function:
--
--
-- > renderForm :: Post -> Html
-- > renderForm post = formFor' post "/my-custom-endpoint" [hsx||]
--
--
-- If you pass an action to that, you need to wrap it with 'pathTo':
--
--
-- > renderForm :: Post -> Html
-- > renderForm post = formFor' post (pathTo CreateDraftAction) [hsx||]
--
Expand Down Expand Up @@ -328,7 +328,7 @@ submitButton =
--
-- > <div class="form-group" id="form-group-post_title">
-- > <label for="post_title">Title</label>
-- >
-- >
-- > <input type="text" name="title" id="post_title" class="form-control" />
-- > <small class="form-text text-muted">Max. 140 characters</small>
-- > </div>
Expand Down Expand Up @@ -376,7 +376,7 @@ submitButton =
--
-- > <div class="form-group" id="form-group-post_title">
-- > <label for="post_title">Title</label>
-- >
-- >
-- > <input
-- > type="text"
-- > name="title"
Expand All @@ -397,7 +397,7 @@ submitButton =
--
-- > <div class="form-group" id="form-group-post_title">
-- > <label for="post_title">Title</label>
-- >
-- >
-- > <input
-- > type="text"
-- > name="title"
Expand All @@ -417,7 +417,7 @@ submitButton =
--
-- > <div class="form-group" id="form-group-post_title">
-- > <label for="post_title">Title</label>
-- >
-- >
-- > <input
-- > type="text"
-- > name="title"
Expand Down Expand Up @@ -781,4 +781,4 @@ instance (
in
init path
|> (\path -> [""] <> (fromMaybe [] path) <> [action])
|> intercalate "/"
|> intercalate "/"
6 changes: 3 additions & 3 deletions IHP/ViewPrelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import IHP.ViewSupport
import Text.Blaze (preEscapedText, stringValue, text, (!))
import Text.Blaze.Html5 (preEscapedToHtml)
import IHP.View.Form
import IHP.HtmlSupport.QQ (hsx)
import IHP.HtmlSupport.ToHtml
import IHP.HSX.QQ (hsx)
import IHP.HSX.ToHtml
import IHP.View.TimeAgo
import IHP.ValidationSupport
import IHP.Controller.RequestContext
Expand All @@ -65,4 +65,4 @@ import IHP.Job.Types
import IHP.LoginSupport.Helper.View
import IHP.PageTitle.ViewFunctions

import IHP.Assets.ViewFunctions
import IHP.Assets.ViewFunctions

0 comments on commit ff6b73e

Please sign in to comment.