! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-
USING: accessors alien arrays assocs byte-arrays calendar
classes classes.error combinators combinators.short-circuit
-continuations hashtables help.markup interpolate io
+continuations eval hashtables help.markup interpolate io
io.directories io.encodings.utf8 io.files io.pathnames
io.streams.string kernel math math.parser namespaces prettyprint
-quotations sequences sets sorting splitting strings system
-timers unicode urls vocabs vocabs.loader vocabs.metadata words
-words.symbol ;
+quotations sequences sequences.extras sets sorting splitting
+strings system timers unicode urls vocabs vocabs.loader
+vocabs.metadata words words.symbol ;
IN: tools.scaffold
SYMBOL: developer-name
: scaffold-directory ( vocab-root vocab -- )
vocab-root/vocab>path
- dup exists? [ directory-exists ] [ make-directories ] if ;
+ dup file-exists? [ directory-exists ] [ make-directories ] if ;
: not-scaffolding ( path -- path )
"Not creating scaffolding for " write dup <pathname> . ;
"Creating scaffolding for " write dup <pathname> . ;
: scaffolding? ( path -- path ? )
- dup exists? [ not-scaffolding f ] [ scaffolding t ] if ;
+ dup file-exists? [ not-scaffolding f ] [ scaffolding t ] if ;
: scaffold-copyright ( -- )
"! Copyright (C) " write now year>> number>string write
{ "vocab-root" "a vocabulary root string" }
{ "c-ptr" c-ptr }
{ "sequence" sequence }
+ { "slice" slice }
+ { "from" integer }
+ { "to" integer }
+ { "i" integer }
+ { "n" integer }
{ "seq" sequence }
{ "exemplar" object }
{ "assoc" assoc }
[ unparse write bl ]
[ [ pprint ] [ add-using ] bi ] bi*
] [
- drop unparse write bl null pprint
- null add-using
+ drop unparse write bl object pprint
+ object add-using
] if
" }" write
] interleave
[ HS{ } clone using ] dip with-variable ; inline
: link-vocab ( vocab -- )
+ ".private" ?tail drop
check-vocab
"Edit documentation: " write
"-docs.factor" vocab/suffix>path <pathname> . ;
SYMBOL: nested-examples
: example-using ( using -- )
- unwords "example-using" [
+ join-words "example-using" [
nested-examples get 4 0 ? CHAR: \s <string> "example-indent" [
"${example-indent}\"Example:\"
${example-indent}{ $example \"USING: ${example-using} ;\"
[ "Click to edit: " write <pathname> . ] bi ;
: scaffold-rc ( path -- )
- [ home ] dip append-path scaffold-file ;
+ home prepend-path scaffold-file ;
: scaffold-factor-boot-rc ( -- )
".factor-boot-rc" scaffold-rc ;
: scaffold-factor-roots ( -- )
".factor-roots" scaffold-rc ;
+: make-unit-test ( answer code -- str )
+ [
+ prepend-lines-with-spaces
+ "{\n" "\n}" surround
+ ] [
+ prepend-lines-with-spaces
+ "[\n" "\n] unit-test\n" surround
+ ] bi* " " glue ;
+
+: scaffold-unit-test ( -- str/f )
+ read-contents dup "" = [
+ drop f
+ ] [
+ [ eval( -- x ) unparse ] keep make-unit-test
+ ] if ;
+
+: scaffold-unit-tests ( -- str )
+ [ scaffold-unit-test ] loop>array "\n\n" join ;
+
HOOK: scaffold-emacs os ( -- )
M: unix scaffold-emacs ".emacs" scaffold-rc ;