rename pollen-source to decoder-source

pull/9/head
Matthew Butterick 10 years ago
parent af2209a0ba
commit f7f5a10694

@ -32,7 +32,7 @@ polcom [filename] (renders individual file)")]
(define (pollen-related-file? file)
(ormap (λ(proc) (proc file)) (list
pollen-source?
decoder-source?
preproc-source?
template-source?
ptree-source?

@ -196,9 +196,9 @@
(any/c . -> . boolean?)
(file-exists? (->preproc-source-path (->path x))))
(define/contract (has-pollen-source? x)
(define/contract (has-decoder-source? x)
(any/c . -> . boolean?)
(file-exists? (->pollen-source-path (->path x))))
(file-exists? (->decoder-source-path (->path x))))
(define/contract (needs-preproc? x)
(any/c . -> . boolean?)
@ -209,7 +209,7 @@
(any/c . -> . boolean?)
; it's a pollen source file
; or a file (e.g., html) that has a pollen source file
(ormap (λ(proc) (proc (->path x))) (list pollen-source? has-pollen-source?)))
(ormap (λ(proc) (proc (->path x))) (list decoder-source? has-decoder-source?)))
(define/contract (ptree-source? x)
@ -222,13 +222,13 @@
(define/contract (pollen-source? x)
(define/contract (decoder-source? x)
(any/c . -> . boolean?)
(has-ext? x DECODER_SOURCE_EXT))
(module+ test
(check-true (pollen-source? "foo.pd"))
(check-false (pollen-source? "foo.p")))
(check-true (decoder-source? "foo.pd"))
(check-false (decoder-source? "foo.p")))
(define/contract (template-source? x)
@ -271,7 +271,7 @@
(define/contract (->output-path x)
(pathish? . -> . path?)
(->path
(if (or (pollen-source? x) (preproc-source? x))
(if (or (decoder-source? x) (preproc-source? x))
(remove-ext x)
x)))
@ -287,17 +287,17 @@
;; does not, however, validate that new path exists
;; todo: should it? I don't think so, sometimes handy to make the name for later use
;; OK to use pollen source as input (comes out the same way)
(define/contract (->pollen-source-path x)
(define/contract (->decoder-source-path x)
(pathish? . -> . path?)
(->path (if (pollen-source? x)
(->path (if (decoder-source? x)
x
(add-ext x DECODER_SOURCE_EXT))))
(module+ test
(check-equal? (->pollen-source-path (->path "foo.pd")) (->path "foo.pd"))
(check-equal? (->pollen-source-path (->path "foo.html")) (->path "foo.html.pd"))
(check-equal? (->pollen-source-path "foo") (->path "foo.pd"))
(check-equal? (->pollen-source-path 'foo) (->path "foo.pd")))
(check-equal? (->decoder-source-path (->path "foo.pd")) (->path "foo.pd"))
(check-equal? (->decoder-source-path (->path "foo.html")) (->path "foo.html.pd"))
(check-equal? (->decoder-source-path "foo") (->path "foo.pd"))
(check-equal? (->decoder-source-path 'foo) (->path "foo.pd")))
(define/contract (project-files-with-ext ext)
(symbol? . -> . (listof complete-path?))

@ -1,7 +1,7 @@
#lang racket/base
(require (only-in scribble/reader make-at-reader)
(only-in "../world.rkt" EXPRESSION_DELIMITER)
(only-in "../file-tools.rkt" preproc-source? unsaved-source?))
(only-in "../file-tools.rkt" decoder-source? ptree-source?))
(provide (rename-out [mb-read read]
[mb-read-syntax read-syntax])
@ -26,8 +26,8 @@
(define i (read-inner path-string p))
(datum->syntax i
;; select pollen dialect based on file type
`(module pollen-lang-module ,(if (or (preproc-source? path-string) (unsaved-source? path-string))
'pollen/main-preproc
'pollen/main)
`(module pollen-lang-module ,(if (or (decoder-source? path-string) (ptree-source? path-string))
'pollen/main
'pollen/main-preproc)
,@i)
i))

@ -212,18 +212,18 @@
;; this becomes the return value
(->boolean (> (len (get-output-string port-for-catching-file-info)) 0)))
(define (complete-pollen-source-path x)
(->complete-path (->pollen-source-path (->path x))))
(define (complete-decoder-source-path x)
(->complete-path (->decoder-source-path (->path x))))
;; apply template
(define/contract (render-with-template x [template-name #f] #:force [force #f])
(((and/c pathish?
(flat-named-contract 'file-exists
(λ(x) (file-exists? (complete-pollen-source-path x))))))
(λ(x) (file-exists? (complete-decoder-source-path x))))))
(path? #:force boolean?) . ->* . void?)
;; set up information about source
(define source-path (complete-pollen-source-path x))
(define source-path (complete-decoder-source-path x))
;; todo: this won't work with source files nested down one level
(define-values (source-dir ignored also-ignored) (split-path source-path))

@ -163,7 +163,7 @@
(define possible-sources
(if (directory-exists? fn)
empty ;; folders don't have source files
(filter file-in-dir? (list (->preproc-source-path filename) (->pollen-source-path filename)))))
(filter file-in-dir? (list (->preproc-source-path filename) (->decoder-source-path filename)))))
(define source (and (not (empty? possible-sources)) (->string (car possible-sources))))
`(tr ,@(map make-link-cell
(append (list

@ -16,8 +16,8 @@
(define/contract (puttable-item? x)
(any/c . -> . boolean?)
(or (tagged-xexpr? x)
(has-pollen-source? x)
(and (pnode->url x) (has-pollen-source? (pnode->url x)))))
(has-decoder-source? x)
(and (pnode->url x) (has-decoder-source? (pnode->url x)))))
(define/contract (query-key? x)
(any/c . -> . boolean?)
@ -28,8 +28,8 @@
(cond
;; Using put has no effect on tagged-xexprs. It's here to make the idiom smooth.
[(tagged-xexpr? x) x]
[(has-pollen-source? x) (dynamic-require (->pollen-source-path x) 'main)]
[(has-pollen-source? (pnode->url x)) (dynamic-require (->pollen-source-path (pnode->url x)) 'main)]))
[(has-decoder-source? x) (dynamic-require (->decoder-source-path x) 'main)]
[(has-decoder-source? (pnode->url x)) (dynamic-require (->decoder-source-path (pnode->url x)) 'main)]))
(module+ test
(check-equal? (put '(foo "bar")) '(foo "bar"))
@ -51,15 +51,15 @@
(define/contract (find-in-metas px key)
(puttable-item? query-key? . -> . (or/c xexpr-elements? false?))
(and (has-pollen-source? px)
(let ([metas (dynamic-require (->pollen-source-path px) 'metas)]
(and (has-decoder-source? px)
(let ([metas (dynamic-require (->decoder-source-path px) 'metas)]
[key (->string key)])
(and (key . in? . metas ) (->list (get metas key))))))
(module+ test
(parameterize ([current-directory "tests/template"])
(check-equal? (find-in-metas "put" "foo") (list "bar"))
(let* ([metas (dynamic-require (->pollen-source-path 'put) 'metas)]
(let* ([metas (dynamic-require (->decoder-source-path 'put) 'metas)]
[here (find-in-metas 'put 'here)])
(check-equal? here (list "tests/template/put")))))

Loading…
Cancel
Save