Skip to content

Commit

Permalink
Add flareDoc command
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jan 16, 2016
1 parent 4608822 commit 47958b4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 21 deletions.
19 changes: 19 additions & 0 deletions docs/Test/FlareCheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ gCreateUI :: forall a e. (Generic a) => UI e a -> UI e Renderable

A `createUI` implementation for types with a `Generic` instance.

#### `flareDoc'`

``` purescript
flareDoc' :: forall t e. (Interactive t) => ElementId -> Label -> Maybe String -> t -> Eff (chan :: Chan, dom :: DOM | e) Unit
```

Run an interactive test. The ID specifies the parent element to which
the test will be appended and the label provides a title for the test.
The String argument is an optional documentation string.

#### `flareDoc`

``` purescript
flareDoc :: forall t e. (Interactive t) => Label -> Maybe String -> t -> Eff (chan :: Chan, dom :: DOM | e) Unit
```

Run an interactive test. The label provides a title for the test. The
String argument is an optional documentation string.

#### `flareCheck'`

``` purescript
Expand Down
40 changes: 24 additions & 16 deletions src/Test/FlareCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@

exports.appendTest = function(parentId) {
return function(title) {
return function(elements) {
return function() {
var parent = document.getElementById(parentId);
var fieldset = document.createElement("fieldset");
fieldset.className = "flarecheck-test";
var legend = document.createElement("legend");
legend.textContent = title;
fieldset.appendChild(legend);
return function(doc) {
return function(elements) {
return function() {
var parent = document.getElementById(parentId);
var fieldset = document.createElement("fieldset");
fieldset.className = "flarecheck-test";
var legend = document.createElement("legend");
legend.textContent = title;
fieldset.appendChild(legend);

for (var i = 0; i < elements.length; i++) {
fieldset.appendChild(elements[i]);
}
if (doc !== "") {
var docEl = document.createElement("p");
docEl.innerHTML = doc;
fieldset.appendChild(docEl);
}

var output = document.createElement("div");
output.className = "flarecheck-output";
fieldset.appendChild(output);
for (var i = 0; i < elements.length; i++) {
fieldset.appendChild(elements[i]);
}

parent.appendChild(fieldset);
var output = document.createElement("div");
output.className = "flarecheck-output";
fieldset.appendChild(output);

return output;
parent.appendChild(fieldset);

return output;
};
};
};
};
Expand Down
34 changes: 29 additions & 5 deletions src/Test/FlareCheck.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Test.FlareCheck
, foldableCreateUI
, gCreateUI
, Renderable()
, flareDoc'
, flareDoc
, flareCheck'
, flareCheck
, module Flare
Expand Down Expand Up @@ -263,9 +265,10 @@ instance interactiveFunction :: (Flammable a, Interactive b) => Interactive (a -
createUI f = createUI (f <*> spark)

-- | Append a new interactive test. The arguments are the ID of the parent
-- | element, the title for the test and the list of Flare components. Returns
-- | the element for the output of the test.
-- | element, the title for the test, a documentation string and the list of
-- | Flare components. Returns the element for the output of the test.
foreign import appendTest :: forall e. ElementId
-> String
-> String
-> Array Element
-> Eff (dom :: DOM | e) Element
Expand Down Expand Up @@ -295,17 +298,38 @@ render output (SetHTML markup) = setHTML output (H.render markup)

-- | Run an interactive test. The ID specifies the parent element to which
-- | the test will be appended and the label provides a title for the test.
flareCheck' :: forall t e. (Interactive t)
-- | The String argument is an optional documentation string.
flareDoc' :: forall t e. (Interactive t)
=> ElementId
-> Label
-> Maybe String
-> t
-> Eff (chan :: Chan, dom :: DOM | e) Unit
flareCheck' parentId title x = do
flareDoc' parentId title doc x = do
let flare = createUI (pure x)
{ components, signal } <- setupFlare flare
output <- appendTest parentId title components
let docString = fromMaybe "" doc
output <- appendTest parentId title docString components
runSignal (render output <$> signal)

-- | Run an interactive test. The label provides a title for the test. The
-- | String argument is an optional documentation string.
flareDoc :: forall t e. (Interactive t)
=> Label
-> Maybe String
-> t
-> Eff (chan :: Chan, dom :: DOM | e) Unit
flareDoc = flareDoc' "tests"

-- | Run an interactive test. The ID specifies the parent element to which
-- | the test will be appended and the label provides a title for the test.
flareCheck' :: forall t e. (Interactive t)
=> ElementId
-> Label
-> t
-> Eff (chan :: Chan, dom :: DOM | e) Unit
flareCheck' id label = flareDoc' id label Nothing

-- | Run an interactive test. The label provides a title for the test.
flareCheck :: forall t e. (Interactive t)
=> Label
Expand Down

0 comments on commit 47958b4

Please sign in to comment.