help.html: I give up with the article name escaping. Just compute a SHA1 hash and use that as the file name. Fixes #309

db4
Slava Pestov 2011-10-29 15:26:52 -07:00
parent 914a4aee09
commit 99b4752c57
2 changed files with 29 additions and 35 deletions

View File

@ -1,9 +1,26 @@
USING: help.html tools.test help.topics kernel sequences vocabs ;
USING: help.html help.vocabs tools.test help.topics kernel sequences vocabs
math ;
IN: help.html.tests
[ ] [ "xml" >link help>html drop ] unit-test
[ "article-foobar.html" ] [ "foobar" >link topic>filename ] unit-test
[ ] [ "foobar" >link topic>filename drop ] unit-test
[ ] [ { "foo" "bar" } >link topic>filename drop ] unit-test
[ ] [ \ + topic>filename drop ] unit-test
[ ] [ \ + >link topic>filename drop ] unit-test
[ ] [ "doesnotexist" >vocab-link topic>filename drop ] unit-test
[ ] [ "kernel" lookup-vocab topic>filename drop ] unit-test
[ ] [ "io" <vocab-tag> topic>filename drop ] unit-test
[ ] [ "Steve Jobs" <vocab-author> topic>filename drop ] unit-test
[ ] [ f topic>filename drop ] unit-test
[ t ] [ all-vocabs-really [ vocab-spec? ] all? ] unit-test

View File

@ -1,38 +1,16 @@
! Copyright (C) 2008, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings.utf8 io.encodings.binary io.files
io.files.temp io.directories html.streams help help.home kernel
assocs sequences make words accessors arrays help.topics vocabs
vocabs.hierarchy help.vocabs namespaces prettyprint io
vocabs.loader serialize fry memoize unicode.case math.order
sorting debugger html xml.syntax xml.writer math.parser
sets hashtables ;
USING: checksums checksums.sha io.encodings.utf8
io.encodings.binary io.encodings.string io.files io.files.temp
io.directories html.streams help help.home kernel assocs
sequences make words accessors arrays help.topics vocabs
vocabs.hierarchy help.vocabs namespaces io vocabs.loader
serialize fry memoize unicode.case math.order sorting debugger
html xml.syntax xml.writer math.parser sets hashtables ;
FROM: io.encodings.ascii => ascii ;
FROM: ascii => ascii? ;
IN: help.html
: escape-char ( ch -- )
dup ascii? [
dup H{
{ CHAR: " "__quo__" }
{ CHAR: * "__star__" }
{ CHAR: : "__colon__" }
{ CHAR: < "__lt__" }
{ CHAR: > "__gt__" }
{ CHAR: ? "__que__" }
{ CHAR: \\ "__back__" }
{ CHAR: | "__pipe__" }
{ CHAR: / "__slash__" }
{ CHAR: , "__comma__" }
{ CHAR: @ "__at__" }
{ CHAR: # "__hash__" }
{ CHAR: % "__percent__" }
} at [ % ] [ , ] ?if
] [ number>string "__" "__" surround % ] if ;
: escape-filename ( string -- filename )
[ [ escape-char ] each ] "" make ;
GENERIC: topic>filename* ( topic -- name prefix )
M: word topic>filename*
@ -51,10 +29,9 @@ M: f topic>filename* drop \ f topic>filename* ;
topic>filename* dup [
[
% "-" %
dup array?
[ [ escape-filename ] map "," join ]
[ escape-filename ]
if % ".html" %
dup array? [ "," join ] when
utf8 encode sha1 checksum-bytes hex-string
% ".html" %
] "" make
] [ 2drop f ] if ;