Skip to content

Commit 6311b7e

Browse files
authored
Merge pull request #40 from essandess/hlint
adblock2privoxy: Update to version 2.3.0
2 parents 551def2 + 655a001 commit 6311b7e

25 files changed

+157
-296
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ If no source URLs are specified, task file is used to determine sources: previou
105105
Domain of CSS web server (required for Element Hide functionality)
106106
-u, --useHTTP
107107
Use HTTP for CSS web server; the default is HTTPS to avoid mixed content
108+
-g INT, --debugLevel=INT
109+
Debug Level. 0: Off; 1: top directory CSS; 2: full directory.
108110
-t PATH, --taskFile=PATH
109111
Path to task file containing urls to process and options.
110112
-f, --forced

adblock2privoxy-utils/adblock2privoxy-utils.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: adblock2privoxy-utils
2-
version: 2.2.0
2+
version: 2.3.0
33
cabal-version: >= 1.10
44
build-type: Simple
55
tested-with: GHC==8.10.7
@@ -45,4 +45,4 @@ source-repository this
4545
type: git
4646
location: https://github.com/essandess/adblock2privoxy.git
4747
subdir: adblock2privoxy-utils
48-
tag: v2.2.0
48+
tag: v2.3.0

adblock2privoxy/changelog adblock2privoxy/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.3.0
2+
* hlint mods
3+
* Add debug code with new DebugLevel option
4+
15
2.2.0
26
* Remove unused debug code
37

adblock2privoxy/README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Options
5656
Css files output path
5757
-d DOMAIN, --domainCSS=DOMAIN
5858
Domain of CSS web server (required for Element Hide functionality)
59+
-u, --useHTTP
60+
Use HTTP for CSS web server; the default is HTTPS to avoid mixed content
61+
-g INT, --debugLevel=INT
62+
Debug Level. 0: Off; 1: top directory CSS; 2: full directory.
5963
-t PATH, --taskFile=PATH
6064
Path to task file containing urls to process and options.
6165
-f, --forced

adblock2privoxy/adblock2privoxy.cabal

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: adblock2privoxy
2-
version: 2.2.0
2+
version: 2.3.0
33
cabal-version: >= 1.10
44
build-type: Simple
55
tested-with:
@@ -65,28 +65,29 @@ executable adblock2privoxy
6565
FlexibleContexts
6666
build-depends:
6767
base >= 4 && < 9.9,
68-
parsec,
69-
mtl,
70-
containers,
71-
filepath,
72-
directory,
73-
MissingH >=1.4.3.0,
74-
parsec-permutation >=0.1.2.0,
75-
time >=1.4,
76-
old-locale >=1.0,
77-
strict >=0.3,
78-
network >=2.4,
79-
http-conduit,
80-
text >=0.11,
81-
network-uri,
82-
case-insensitive
68+
MissingH >= 1.6.0 && < 1.7,
69+
containers >= 0.6.7 && < 0.7,
70+
directory >= 1.3.8 && < 1.4,
71+
filepath >= 1.4.200 && < 1.5,
72+
mtl >= 2.3.1 && < 2.4,
73+
time >= 1.12.2 && < 1.13,
74+
network >= 3.1.4 && < 3.2,
75+
old-locale >= 1.0.0 && < 1.1,
76+
parsec >= 3.1.16 && < 3.2,
77+
text >= 2.0.2 && < 2.1,
78+
case-insensitive >= 1.2.1 && < 1.3,
79+
http-conduit >= 2.3.8 && < 2.4,
80+
network-uri >= 2.6.4 && < 2.7,
81+
strict >= 0.5 && < 0.6,
82+
parsec-permutation >= 0.1.2 && < 0.2
8383
ghc-options: -Wall
8484
other-modules:
8585
ElementBlocker,
8686
InputParser,
8787
Network,
8888
OptionsConverter,
8989
ParsecExt,
90+
ParserExtTests,
9091
Paths_adblock2privoxy,
9192
PatternConverter,
9293
PolicyTree,
@@ -103,4 +104,4 @@ source-repository this
103104
type: git
104105
location: https://github.com/essandess/adblock2privoxy.git
105106
subdir: adblock2privoxy
106-
tag: v2.2.0
107+
tag: v2.3.0

adblock2privoxy/src/ElementBlocker.hs

+24-44
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
{-# LANGUAGE StrictData #-}
2+
13
module ElementBlocker (
24
elemBlock
35
) where
46
import InputParser hiding (Policy(..))
57
import qualified InputParser
68
import PolicyTree
9+
import ProgramOptions (DebugLevel(DebugLevel))
710
import qualified Data.Map as Map
811
import Data.Maybe
912
import Utils
@@ -19,51 +22,45 @@ import Data.String.Utils (startswith)
1922
type BlockedRulesTree = DomainTree [Pattern]
2023
data ElemBlockData = ElemBlockData [Pattern] BlockedRulesTree deriving Show
2124

22-
elemBlock :: String -> [String] -> [Line] -> IO ()
23-
elemBlock path info = writeElemBlock . elemBlockData
25+
elemBlock :: String -> [String] -> DebugLevel -> [Line] -> IO ()
26+
elemBlock path info debug = writeElemBlock . elemBlockData
2427
where
2528
writeElemBlock :: ElemBlockData -> IO ()
2629
writeElemBlock (ElemBlockData flatPatterns rulesTree) =
2730
do
28-
let filteredInfo = filter ((||) <$> not . startswith "Url:" <*> startswith "Url: http") info
29-
-- debugPath = path </> "debug"
31+
let debugPath = path </> "debug"
32+
filteredInfo = filter ((||) <$> not . startswith "Url:" <*> startswith "Url: http") info
3033
createDirectoryIfMissing True path
3134
cont <- getDirectoryContents path
32-
_ <- sequence $ removeOld <$> cont
33-
-- createDirectoryIfMissing True debugPath
34-
-- writeBlockTree path debugPath rulesTree
35-
writeBlockTree path rulesTree
36-
writePatterns_with_debug filteredInfo (path </> "ab2p.common.css") "" flatPatterns
37-
-- writePatterns_with_debug filteredInfo (path </> "ab2p.common.css") (debugPath </> "ab2p.common.css") flatPatterns
35+
mapM_ removeOld cont
36+
when (debug > DebugLevel 0) $ createDirectoryIfMissing True debugPath
37+
writeBlockTree path debugPath rulesTree
38+
writePatterns filteredInfo (path </> "ab2p.common.css") (if debug > DebugLevel 0 then debugPath </> "ab2p.common.css" else "") flatPatterns
3839
removeOld entry' =
3940
let entry = path </> entry'
4041
in do
4142
isDir <- doesDirectoryExist entry
4243
if isDir then when (head entry' /= '.') $ removeDirectoryRecursive entry
4344
else when (takeExtension entry == ".css") $ removeFile entry
44-
-- writeBlockTree :: String -> String -> BlockedRulesTree -> IO ()
45-
-- writeBlockTree normalNodePath debugNodePath (Node name patterns children) =
46-
writeBlockTree :: String -> BlockedRulesTree -> IO ()
47-
writeBlockTree normalNodePath (Node name patterns children) =
45+
writeBlockTree :: String -> String -> BlockedRulesTree -> IO ()
46+
writeBlockTree normalNodePath debugNodePath (Node name patterns children) =
4847
do
4948
createDirectoryIfMissing True normalPath
50-
-- createDirectoryIfMissing True debugPath
51-
-- _ <- sequence (writeBlockTree normalPath debugPath <$> children)
52-
-- writePatterns ["See ab2p.common.css for sources info"] normalFilename debugFilename patterns
53-
_ <- sequence (writeBlockTree normalPath <$> children)
54-
writePatterns ["See ab2p.common.css for sources info"] normalFilename patterns
49+
when (debug > DebugLevel 1) $ createDirectoryIfMissing True debugPath
50+
mapM_ (writeBlockTree normalPath debugPath) children
51+
writePatterns ["See ab2p.common.css for sources info"] normalFilename (if debug > DebugLevel 1 then debugFilename else "") patterns
5552
where
5653
normalPath
5754
| null name = normalNodePath
5855
| otherwise = normalNodePath </> name
59-
-- debugPath
60-
-- | null name = debugNodePath
61-
-- | otherwise = debugNodePath </> name
56+
debugPath
57+
| null name = debugNodePath
58+
| otherwise = debugNodePath </> name
6259
normalFilename = normalPath </> "ab2p.css"
63-
-- debugFilename = debugPath </> "ab2p.css"
64-
writePatterns_with_debug :: [String] -> String -> String -> [Pattern] -> IO ()
65-
writePatterns_with_debug _ _ _ [] = return ()
66-
writePatterns_with_debug info' normalFilename debugFilename patterns =
60+
debugFilename = debugPath </> "ab2p.css"
61+
writePatterns :: [String] -> String -> String -> [Pattern] -> IO ()
62+
writePatterns _ _ _ [] = return ()
63+
writePatterns info' normalFilename debugFilename patterns =
6764
do
6865
writeCssFile normalFilename $ intercalate "\n" ((++ Templates.blockCss) . intercalate "," <$>
6966
splitEvery 4000 patterns)
@@ -75,24 +72,7 @@ elemBlock path info = writeElemBlock . elemBlockData
7572
do outFile <- openFile filename WriteMode
7673
hSetEncoding outFile utf8
7774
hPutStrLn outFile "/*"
78-
_ <- mapM (hPutStrLn outFile) info'
79-
hPutStrLn outFile "*/"
80-
hPutStrLn outFile content
81-
hClose outFile
82-
writePatterns :: [String] -> String -> [Pattern] -> IO ()
83-
writePatterns _ _ [] = return ()
84-
writePatterns info' normalFilename patterns =
85-
do
86-
-- writeCssFile debugFilename $ intercalate "\n" $ (++ Templates.blockCss) <$> patterns
87-
writeCssFile normalFilename $ intercalate "\n" ((++ Templates.blockCss) . intercalate "," <$>
88-
splitEvery 4000 patterns)
89-
where
90-
splitEvery n = takeWhile (not . null) . unfoldr (Just . splitAt n)
91-
writeCssFile filename content =
92-
do outFile <- openFile filename WriteMode
93-
hSetEncoding outFile utf8
94-
hPutStrLn outFile "/*"
95-
_ <- mapM (hPutStrLn outFile) info'
75+
mapM_ (hPutStrLn outFile) info'
9676
hPutStrLn outFile "*/"
9777
hPutStrLn outFile content
9878
hClose outFile

adblock2privoxy/src/ElementBlocker.hs.orig

-104
This file was deleted.

0 commit comments

Comments
 (0)