Skip to content

Fix bug in conversion from Number to String #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
/bower_components/
/node_modules/
/output/
/.pulp-cache/
/generated-docs/
/.psc-package/
/.psc*
/.purs*
/.psa*
/.spago
104 changes: 104 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{-
Welcome to your new Dhall package-set!

Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.

## Use Cases

Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set

This file will continue to work whether you use one or both options.
Instructions for each option are explained below.

### Overriding/Patching a package

Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo

Syntax:
where `entityName` is one of the following:
- dependencies
- repo
- version
-------------------------------
let upstream = --
in upstream
with packageName.entityName = "new value"
-------------------------------

Example:
-------------------------------
let upstream = --
in upstream
with halogen.version = "master"
with halogen.repo = "https://example.com/path/to/git/repo.git"

with halogen-vdom.version = "v4.0.0"
with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies
-------------------------------

### Additions

Purpose:
- Add packages that aren't already included in the default package set

Syntax:
where `<version>` is:
- a tag (i.e. "v4.0.0")
- a branch (i.e. "master")
- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977")
-------------------------------
let upstream = --
in upstream
with new-package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"<version>"
}
-------------------------------

Example:
-------------------------------
let upstream = --
in upstream
with benchotron =
{ dependencies =
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
, repo =
"https://github.com/hdgarrood/purescript-benchotron.git"
, version =
"v7.0.0"
}
-------------------------------
-}
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.5-20220127/packages.dhall sha256:8ccbd53dbc7dbfd92a9cba9cca7a8bf36cb120a0a3e21106bf19a16d3ad6863e

in upstream
29 changes: 29 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{-
Welcome to a Spago project!
You can edit this file as you like.

Need help? See the following resources:
- Spago documentation: https://github.com/purescript/spago
- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html

When creating a new Spago project, you can use
`spago init --no-comments` or `spago init -C`
to generate this file without the comments in this block.
-}
{ name = "halogen-vdom-string-renderer"
, dependencies =
[ "arrays"
, "foreign"
, "halogen-vdom"
, "maybe"
, "numbers"
, "ordered-collections"
, "prelude"
, "psci-support"
, "strings"
, "tuples"
, "unsafe-coerce"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
}
14 changes: 8 additions & 6 deletions src/Halogen/VDom/DOM/StringRenderer.purs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
module Halogen.VDom.DOM.StringRenderer (render) where

import Prelude
import Halogen.VDom (VDom, ElemName(..))
import Halogen.VDom.DOM.Prop (Prop(..), PropValue)
import Data.Array as A
import Foreign (unsafeToForeign, typeOf)
import Data.Maybe (Maybe(..))
import Data.String as S
import Data.Number.Format
import Data.Set as Set
import Data.String as S
import Foreign (unsafeToForeign, typeOf)
import Halogen.VDom (VDom, ElemName(..))
import Halogen.VDom.DOM.Prop (Prop(..), PropValue)
import Halogen.VDom.StringRenderer as VSR
import Halogen.VDom.StringRenderer.Util (escape)
import Prelude
import Unsafe.Coerce (unsafeCoerce)
import Data.Number.Format (toString)

render ∷ ∀ i w. (w → String) → VDom (Array (Prop i)) w → String
render renderWidget = VSR.render getTagType renderProps renderWidget
Expand Down Expand Up @@ -42,7 +44,7 @@ propNameToAttrName = case _ of
renderProperty ∷ String → PropValue → Maybe String
renderProperty name prop = case typeOf (unsafeToForeign prop) of
"string" → renderAttr name' $ (unsafeCoerce ∷ PropValue → String) prop
"number" → renderAttr name' $ show ((unsafeCoerce ∷ PropValue → String) prop)
"number" → renderAttr name' $ toString ((unsafeCoerce ∷ PropValue → Number) prop)
"boolean" → Just $ escape name'
_ → Nothing
where
Expand Down