From b1631a1e83cf0e0fcf3ea86c744caac20d72002b Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 28 Jul 2016 18:25:54 +0100 Subject: [PATCH] Updates for PureScript 0.9 (#13) --- .gitignore | 2 +- .jscsrc | 17 ++++++++ .jshintrc | 19 +++++++++ .travis.yml | 19 ++++++--- README.md | 13 ++++-- bower.json | 14 ++++--- docs/DOM/BrowserFeatures/Detectors.md | 11 ----- docs/Data/BrowserFeatures.md | 9 ---- docs/Data/BrowserFeatures/InputType.md | 44 -------------------- gulpfile.js | 55 ------------------------- package.json | 26 +++++------- src/DOM/BrowserFeatures/Detectors.js | 2 +- src/DOM/BrowserFeatures/Detectors.purs | 44 ++++++++++---------- src/Data/BrowserFeatures/InputType.purs | 10 ++--- test/{ => dist}/index.html | 2 +- test/{ => src}/Main.purs | 14 ++++--- 16 files changed, 114 insertions(+), 187 deletions(-) create mode 100644 .jscsrc create mode 100644 .jshintrc delete mode 100644 docs/DOM/BrowserFeatures/Detectors.md delete mode 100644 docs/Data/BrowserFeatures.md delete mode 100644 docs/Data/BrowserFeatures/InputType.md delete mode 100644 gulpfile.js rename test/{ => dist}/index.html (50%) rename test/{ => src}/Main.purs (60%) diff --git a/.gitignore b/.gitignore index 748273b..995750a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ /bower_components/ /node_modules/ /output/ -/tmp/ +/test/dist/test.js diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..2561ce9 --- /dev/null +++ b/.jscsrc @@ -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 +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..cbc1c5f --- /dev/null +++ b/.jshintrc @@ -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"] +} diff --git a/.travis.yml b/.travis.yml index f37be8d..97b5fac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index ba5f14f..0f9dea7 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/bower.json b/bower.json index 52f000b..3e78ba7 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/docs/DOM/BrowserFeatures/Detectors.md b/docs/DOM/BrowserFeatures/Detectors.md deleted file mode 100644 index 6dfb07d..0000000 --- a/docs/DOM/BrowserFeatures/Detectors.md +++ /dev/null @@ -1,11 +0,0 @@ -## Module DOM.BrowserFeatures.Detectors - -#### `detectBrowserFeatures` - -``` purescript -detectBrowserFeatures :: forall e. Eff (dom :: DOM | e) BrowserFeatures -``` - -Detect browser features by testing them using the DOM. - - diff --git a/docs/Data/BrowserFeatures.md b/docs/Data/BrowserFeatures.md deleted file mode 100644 index 95c6b62..0000000 --- a/docs/Data/BrowserFeatures.md +++ /dev/null @@ -1,9 +0,0 @@ -## Module Data.BrowserFeatures - -#### `BrowserFeatures` - -``` purescript -type BrowserFeatures = { inputTypeSupported :: InputType -> Boolean } -``` - - diff --git a/docs/Data/BrowserFeatures/InputType.md b/docs/Data/BrowserFeatures/InputType.md deleted file mode 100644 index b022d73..0000000 --- a/docs/Data/BrowserFeatures/InputType.md +++ /dev/null @@ -1,44 +0,0 @@ -## Module Data.BrowserFeatures.InputType - -#### `InputType` - -``` purescript -data InputType - = Color - | Date - | DateTime - | DateTimeLocal - | Time - | Month - | Week - | Email - | Url - | Number - | Search - | Range - | Text -``` - -##### Instances -``` purescript -Show InputType -Eq InputType -Ord InputType -``` - -#### `allInputTypes` - -``` purescript -allInputTypes :: Array InputType -``` - -#### `renderInputType` - -``` purescript -renderInputType :: InputType -> String -``` - -Render an `InputType` into the corresponding value of the `type` attribute -on an `input` element. - - diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 0674402..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict" - -var gulp = require("gulp"), - purescript = require("gulp-purescript"), - webpack = require("webpack-stream"); - -var sources = [ - "src/**/*.purs", - "bower_components/purescript-*/src/**/*.purs", - "test/*.purs" -]; -var foreigns = [ - "src/**/*.js", - "bower_components/purescript-*/src/**/*.js", - "test/*/*.js" -]; - -gulp.task("make", function() { - return purescript.psc({ src: sources, ffi: foreigns }); -}); - -gulp.task("docs", function() { - return purescript.pscDocs({ - src: sources, - docgen: { - "Data.BrowserFeatures": "docs/Data/BrowserFeatures.md", - "Data.BrowserFeatures.InputType": "docs/Data/BrowserFeatures/InputType.md", - "DOM.BrowserFeatures.Detectors": "docs/DOM/BrowserFeatures/Detectors.md" - } - }); -}); - -gulp.task("bundle", ["make"], function() { - return purescript.pscBundle({ - src: "output/**/*.js", - output: "tmp/test.js", - main: "Test.Main" - }); -}); - -gulp.task("bundle-test", ["bundle"], function() { - return gulp.src("tmp/test.js") - .pipe(webpack({ - resolve: { moduleDirectories: ["node_modules"] }, - output: { filename: "test.js" } - })) - .pipe(gulp.dest("tmp")); -}); - -gulp.task("dotpsci", function () { - return purescript.psci({ src: sources, ffi: foreigns }) - .pipe(gulp.dest(".")); -}); - -gulp.task("default", ["bundle-test", "docs", "dotpsci"]); diff --git a/package.json b/package.json index 83ba785..2798c7b 100644 --- a/package.json +++ b/package.json @@ -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 ", - "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" } } diff --git a/src/DOM/BrowserFeatures/Detectors.js b/src/DOM/BrowserFeatures/Detectors.js index 848f4d3..c94448e 100644 --- a/src/DOM/BrowserFeatures/Detectors.js +++ b/src/DOM/BrowserFeatures/Detectors.js @@ -1,4 +1,4 @@ -// module DOM.BrowserFeatures.Detectors +"use strict"; exports._getTypeProperty = function (el) { return function () { diff --git a/src/DOM/BrowserFeatures/Detectors.purs b/src/DOM/BrowserFeatures/Detectors.purs index f948b1f..a863d56 100644 --- a/src/DOM/BrowserFeatures/Detectors.purs +++ b/src/DOM/BrowserFeatures/Detectors.purs @@ -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 @@ -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 @@ -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 } - diff --git a/src/Data/BrowserFeatures/InputType.purs b/src/Data/BrowserFeatures/InputType.purs index fa3f2b2..d30aa56 100644 --- a/src/Data/BrowserFeatures/InputType.purs +++ b/src/Data/BrowserFeatures/InputType.purs @@ -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" @@ -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) - diff --git a/test/index.html b/test/dist/index.html similarity index 50% rename from test/index.html rename to test/dist/index.html index 4eda0ee..d230dbf 100644 --- a/test/index.html +++ b/test/dist/index.html @@ -1,6 +1,6 @@ Platform Test - + diff --git a/test/Main.purs b/test/src/Main.purs similarity index 60% rename from test/Main.purs rename to test/src/Main.purs index 065510d..c2538da 100644 --- a/test/Main.purs +++ b/test/src/Main.purs @@ -1,13 +1,15 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Console (CONSOLE(), log) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) + +import Data.BrowserFeatures.InputType as IT import Data.Traversable (for) -import qualified Data.BrowserFeatures.InputType as IT -import DOM -import DOM.BrowserFeatures.Detectors + +import DOM (DOM) +import DOM.BrowserFeatures.Detectors (detectBrowserFeatures) main :: Eff (dom :: DOM, console :: CONSOLE) Unit main = do @@ -20,4 +22,4 @@ main = do queryFeatureSupport = do features <- detectBrowserFeatures void $ for IT.allInputTypes \ty -> - log $ show ty ++ if features.inputTypeSupported ty then " supported" else " not supported" + log $ show ty <> if features.inputTypeSupported ty then " supported" else " not supported"