From ae03aee09933ec029ca0eb98f3a533eb406254fa Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Fri, 6 May 2016 10:23:31 +0000 Subject: [PATCH] Replace JS minifier with a custom all-discarding one --- src/Text/Jasmine/Local.hs | 42 +++++++++++++++++++++++++++++++++++++++ src/Vervis/Foundation.hs | 5 +++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Text/Jasmine/Local.hs diff --git a/src/Text/Jasmine/Local.hs b/src/Text/Jasmine/Local.hs new file mode 100644 index 0000000..711e5cb --- /dev/null +++ b/src/Text/Jasmine/Local.hs @@ -0,0 +1,42 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +-- | Some of the handler and widget utilities Yesod provides include snippets +-- of Javascript which gets inserted into the page. Usually there is no way to +-- tell these utilities not to include the script. When you don't want it to be +-- included, one way to avoid it to maintain modified versions of the +-- utilities. Another, much easier way, is to use a modified Javascript +-- minifier. +-- +-- I don't know whether a modified minifier can be a good filter which discards +-- some scripts and enables others, but there's definitely one case in which it +-- works well: Discarding all scripts. +-- +-- This module collects such modified minifiers. +module Text.Jasmine.Local + ( discardm + , reportm + ) +where + +import Prelude + +import qualified Data.ByteString.Lazy as BL (ByteString, empty) + +discardm :: BL.ByteString -> Either String BL.ByteString +discardm _ = Right BL.empty + +reportm :: BL.ByteString -> Either String BL.ByteString +reportm _ = Left "The app disables all JS through the minifier" diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index 6191fd3..b50f148 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -19,7 +19,7 @@ import Prelude (init, last) import Database.Persist.Sql (ConnectionPool, runSqlPool) import Text.Hamlet (hamletFile) -import Text.Jasmine (minifym) +--import Text.Jasmine (minifym) import Yesod.Auth.HashDB (authHashDB) import Yesod.Auth.Message (AuthMessage (IdentifierNotFound)) import Yesod.Default.Util (addStaticContentExternal) @@ -30,6 +30,7 @@ import qualified Yesod.Core.Unsafe as Unsafe import Data.Text as T (pack) --import qualified Data.Text.Encoding as TE +import Text.Jasmine.Local (discardm) import Vervis.Import.NoFoundation hiding (last) import Vervis.Widget (breadcrumbBar) @@ -137,7 +138,7 @@ instance Yesod App where master <- getYesod let staticDir = appStaticDir $ appSettings master addStaticContentExternal - minifym + discardm genFileName staticDir (StaticR . flip StaticRoute [])