packages feed

lucid-hyperscript (empty) → 0.1.0.0

raw patch · 9 files changed

+219/−0 lines, 9 filesdep +basedep +luciddep +lucid-hyperscriptsetup-changed

Dependencies added: base, lucid, lucid-hyperscript, template-haskell, text

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for lucid-hyperscript++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2022++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# lucid-hyperscript
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,4 @@+module Main where++main :: IO ()+main = print "_hyperscript ftw!"
+ lucid-hyperscript.cabal view
@@ -0,0 +1,72 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name:           lucid-hyperscript+version:        0.1.0.0+synopsis:       Use _hyperscript with lucid+description:    Please see the README on GitHub at <https://github.com/MonadicSystems/lucid-hyperscript#readme>+category:       Web+homepage:       https://github.com/MonadicSystems/lucid-hyperscript#readme+bug-reports:    https://github.com/MonadicSystems/lucid-hyperscript/issues+author:         Monadic Systems LLC+maintainer:     tech@monadic.systems+copyright:      2022 Monadic Systems LLC+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/MonadicSystems/lucid-hyperscript++library+  exposed-modules:+      Lucid.Hyperscript+      Lucid.Hyperscript.QuasiQuoter+  other-modules:+      Paths_lucid_hyperscript+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+    , lucid+    , template-haskell+    , text+  default-language: Haskell2010++executable lucid-hyperscript-exe+  main-is: Main.hs+  other-modules:+      Paths_lucid_hyperscript+  hs-source-dirs:+      app+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.7 && <5+    , lucid+    , lucid-hyperscript+    , template-haskell+    , text+  default-language: Haskell2010++test-suite lucid-hyperscript-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_lucid_hyperscript+  hs-source-dirs:+      test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.7 && <5+    , lucid+    , lucid-hyperscript+    , template-haskell+    , text+  default-language: Haskell2010
+ src/Lucid/Hyperscript.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE OverloadedStrings #-}++module Lucid.Hyperscript (useHyperscript, useHyperscriptVersion, _hs, __) where++import Data.Text ( pack, Text )+import Lucid (Html, HtmlT, script_, src_)+import Lucid.Base (Attribute, makeAttribute)+import Lucid.Hyperscript.QuasiQuoter (__, _hs)++useHyperscript :: Monad m => HtmlT m ()+useHyperscript = script_ [src_ "https://unpkg.com/hyperscript.org"] ("" :: Html ())++useHyperscriptVersion :: Monad m => (Int, Int, Int) -> HtmlT m ()+useHyperscriptVersion (major, minor, patch) = script_ [src_ url] ("" :: Html ())+  where+    url :: Text+    url =+      "https://unpkg.com/hyperscript.org@"+        <> showT major+        <> "."+        <> showT minor+        <> "."+        <> showT patch++    showT :: Show a => a -> Text+    showT = pack . show
+ src/Lucid/Hyperscript/QuasiQuoter.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}++module Lucid.Hyperscript.QuasiQuoter (_hs, __) where++import Data.Text (Text)+import qualified Data.Text as Text+import GHC.Exts (IsString (..))+import qualified Language.Haskell.TH as TH+import Language.Haskell.TH.Quote (QuasiQuoter (QuasiQuoter))+import Lucid (script_, toHtml, type_)+import Lucid.Base (makeAttribute)++__ :: QuasiQuoter+__ =+  QuasiQuoter+    ((\text -> [|makeAttribute "_" text|]) . processString)+    (error "Cannot use __ as a pattern")+    (error "Cannot use __ as a type")+    (error "Cannot use __ as a dec")++_hs :: QuasiQuoter+_hs =+  QuasiQuoter+    ((\text -> [|script_ [type_ "text/hyperscript"] $ toHtml text|]) . processString)+    (error "Cannot use _hs as a pattern")+    (error "Cannot use _hs as a type")+    (error "Cannot use _hs as a dec")++processString :: String -> Text+processString = Text.strip . removeCRs . Text.pack+  where+    removeCRs = Text.filter (/= '\r')
+ test/Spec.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE OverloadedStrings #-}++import Lucid+import Lucid.Base (Attribute)+import Lucid.Hyperscript++main :: IO ()+main = do+    print $ renderText ex1+    print $ renderText ex2+    print $ renderText ex3+    print $ renderText ex4++ex1 :: Monad m => HtmlT m ()+ex1 = button_ [[__|on click call alert('You clicked me!')|]] "Click me!"++ex2 :: Monad m => HtmlT m ()+ex2 = [_hs|+on mousedown+  halt the event -- prevent text selection...+  -- do other stuff...+end+|]++ex3 :: Monad m => HtmlT m ()+ex3 = [_hs|+behavior Removable(removeButton)+  on click from removeButton+    remove me+  end+end+|]++ex4 :: Monad m => HtmlT m ()+ex4 = input_+    [ type_ "text"+    , placeholder_ "Search Quotes..."+    , [__|+        on keyup+          if the event's key is 'Escape'+            set my value to ''+            trigger keyup+          else+            show <blockquote/> in #quotes when its textContent contains my value+      |]+    ]