Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Updates for PureScript 0.9 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyb authored Jul 28, 2016
1 parent a48d89f commit b1631a1
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
/bower_components/
/node_modules/
/output/
/tmp/
/test/dist/test.js
17 changes: 17 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"preset": "grunt",
"disallowSpacesInFunctionExpression": null,
"requireSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": null,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInsideObjectBrackets": null,
"requireSpacesInsideObjectBrackets": "all",
"validateQuoteMarks": "\"",
"requireCurlyBraces": null
}
19 changes: 19 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bitwise": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"funcscope": true,
"futurehostile": true,
"strict": "global",
"latedef": true,
"noarg": true,
"nocomma": true,
"nonew": true,
"notypeof": true,
"singleGroups": true,
"undef": true,
"unused": true,
"eqnull": true,
"predef": ["exports", "require"]
}
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
language: node_js
sudo: false
node_js:
- 0.12.7
dist: trusty
sudo: required
node_js: 6
install:
- npm install -g gulp bower
- npm install -g bower
- npm install
- bower install
script:
- npm run build
- bower install --production
- npm run -s build
- bower install
- npm run -s test
after_success:
- >-
test $TRAVIS_TAG &&
echo $GITHUB_TOKEN | pulp login &&
echo y | pulp publish --no-push
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# purescript-browserfeatures

[![Latest release](http://img.shields.io/bower/v/purescript-browserfeatures.svg)](https://github.com/slamdata/purescript-browserfeatures/releases)
[![Build Status](https://travis-ci.org/slamdata/purescript-browserfeatures.svg?branch=master)](https://travis-ci.org/slamdata/purescript-browserfeatures)
[![Dependency Status](https://www.versioneye.com/user/projects/579a398a3815c8003b2a6cb4/badge.svg?style=flat)](https://www.versioneye.com/user/projects/579a398a3815c8003b2a6cb4)

A data type for browser features and detectors to test for the features.

To build, run
## Installation

```
gulp
bower install purescript-browserfeatures
```

Then open `test/index.html` and observe the console to see this in action.
## Documentation

Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-browserfeatures).
14 changes: 8 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
],
"license": "Apache-2.0",
"dependencies": {
"purescript-base": "^0.2.0",
"purescript-exceptions": "^0.3.0",
"purescript-prelude": "^0.1.2",
"purescript-dom": "^0.2.6",
"purescript-maps": "^0.5.0",
"purescript-refs": "^0.2.0"
"purescript-dom": "^1.2.0",
"purescript-exceptions": "^1.0.0",
"purescript-maps": "^1.0.0",
"purescript-prelude": "^1.0.1",
"purescript-refs": "^1.0.0"
},
"devDependencies": {
"purescript-console": "^1.0.0"
}
}
11 changes: 0 additions & 11 deletions docs/DOM/BrowserFeatures/Detectors.md

This file was deleted.

9 changes: 0 additions & 9 deletions docs/Data/BrowserFeatures.md

This file was deleted.

44 changes: 0 additions & 44 deletions docs/Data/BrowserFeatures/InputType.md

This file was deleted.

55 changes: 0 additions & 55 deletions gulpfile.js

This file was deleted.

26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"name": "purescript-browserfeatures",
"description": "A PureScript interface to browserfeatures.js.",
"repository": {
"type": "git",
"url": "https://github.com/slamdata/purescript-browserfeatures.git"
},
"author": "Jon Sterling <[email protected]>",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "npm install && gulp bundle-test"
"clean": "rimraf output && rimraf .pulp-cache",
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
"test": "pulp browserify -I test/src --main Test.Main --to test/dist/test.js"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-purescript": "^0.7.0",
"purescript": "^0.7.6",
"webpack-stream": "^2.1.0"
},
"dependencies": {
"easyimage": "^2.1.0",
"jscs": "^2.8.0",
"jshint": "^2.9.1",
"pulp": "^9.0.1",
"purescript-psa": "^0.3.8",
"purescript": "^0.9.1",
"rimraf": "^2.5.0"
}
}
2 changes: 1 addition & 1 deletion src/DOM/BrowserFeatures/Detectors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// module DOM.BrowserFeatures.Detectors
"use strict";

exports._getTypeProperty = function (el) {
return function () {
Expand Down
44 changes: 22 additions & 22 deletions src/DOM/BrowserFeatures/Detectors.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ module DOM.BrowserFeatures.Detectors
) where

import Prelude
import Control.Monad.Eff
import qualified Control.Monad.Eff.Unsafe as Unsafe
import Control.Monad.Eff.Exception
import Control.Monad.Eff.Ref

import qualified Data.List as L
import qualified Data.Map as M
import Data.Maybe (Maybe(..), fromMaybe)
import Control.Monad.Eff (Eff, runPure)
import Control.Monad.Eff.Exception (catchException)
import Control.Monad.Eff.Ref (modifyRef, readRef, newRef)
import Control.Monad.Eff.Unsafe as Unsafe

import Data.BrowserFeatures (BrowserFeatures)
import Data.BrowserFeatures.InputType as IT
import Data.Foldable (foldr)
import Data.List as L
import Data.Map as M
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Traversable (traverse)
import Data.Tuple
import Data.Tuple (Tuple(..))

import qualified DOM as DOM
import qualified DOM.HTML as DOM
import qualified DOM.HTML.Types as DOM
import qualified DOM.Node.Types as DOM
import qualified DOM.HTML.Window as Win
import qualified DOM.Node.Document as Doc
import qualified DOM.Node.Element as Elem
import Data.BrowserFeatures
import qualified Data.BrowserFeatures.InputType as IT
import DOM (DOM)
import DOM.HTML (window) as DOM
import DOM.HTML.Types (htmlDocumentToDocument) as DOM
import DOM.HTML.Window as Win
import DOM.Node.Document as Doc
import DOM.Node.Element as Elem
import DOM.Node.Types (Element) as DOM

foreign import _getTypeProperty :: forall e. DOM.Element -> Eff (dom :: DOM.DOM | e) String
foreign import _getTypeProperty :: forall e. DOM.Element -> Eff (dom :: DOM | e) String

type InputTypeMap = M.Map IT.InputType Boolean

Expand All @@ -44,7 +45,7 @@ memoizeEff f =
modifyRef cacheRef (M.insert i o)
pure o

detectInputTypeSupport :: forall e. IT.InputType -> Eff (dom :: DOM.DOM | e) Boolean
detectInputTypeSupport :: forall e. IT.InputType -> Eff (dom :: DOM | e) Boolean
detectInputTypeSupport =
memoizeEff \it -> do
window <- DOM.window
Expand All @@ -57,16 +58,15 @@ detectInputTypeSupport =
ty' <- _getTypeProperty element
pure $ ty == ty'

detectInputTypeSupportMap :: forall e. Eff (dom :: DOM.DOM | e) InputTypeMap
detectInputTypeSupportMap :: forall e. Eff (dom :: DOM | e) InputTypeMap
detectInputTypeSupportMap = M.fromList <$> traverse (\t -> Tuple t <$> detectInputTypeSupport t) inputTypes
where
inputTypes :: L.List IT.InputType
inputTypes = foldr L.Cons L.Nil IT.allInputTypes

-- | Detect browser features by testing them using the DOM.
detectBrowserFeatures :: forall e. Eff (dom :: DOM.DOM | e) BrowserFeatures
detectBrowserFeatures :: forall e. Eff (dom :: DOM | e) BrowserFeatures
detectBrowserFeatures = do
inputTypeSupportMap <- detectInputTypeSupportMap
pure { inputTypeSupported : fromMaybe false <<< flip M.lookup inputTypeSupportMap
}

10 changes: 3 additions & 7 deletions src/Data/BrowserFeatures/InputType.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ allInputTypes =
, Text
]

derive instance eqInputType :: Eq InputType
derive instance ordInputType :: Ord InputType

instance showInputType :: Show InputType where
show Color = "Color"
show Date = "Date"
Expand Down Expand Up @@ -69,10 +72,3 @@ renderInputType Number = "number"
renderInputType Search = "search"
renderInputType Range = "range"
renderInputType Text = "text"

instance eqInputType :: Eq InputType where
eq x y = renderInputType x == renderInputType y

instance ordInputType :: Ord InputType where
compare x y = compare (renderInputType x) (renderInputType y)

2 changes: 1 addition & 1 deletion test/index.html → test/dist/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>Platform Test</title>
<script src="../tmp/test.js" type="text/javascript"></script>
<script src="test.js" type="text/javascript"></script>
</head>
</html>
Loading

0 comments on commit b1631a1

Please sign in to comment.