Skip to content

Commit

Permalink
frog.rkt not .frogrc
Browse files Browse the repository at this point in the history
User configures using a frog.rkt file.

For existing projects, do a one-time creation of frog.rkt based on
existing .frogrc.

Also:

- Move most modules under frog/private/, so that it's clearer what
  someone may require in their frog.rkt.

- Start to use scribble/srcdoc to create some of the doc.

- Add .dir-locals.el for better indent of xexprs and at-exps.

- Bump to v0.27.
  • Loading branch information
Greg Hendershott committed May 12, 2017
1 parent 26f5b92 commit 005833f
Show file tree
Hide file tree
Showing 49 changed files with 1,471 additions and 1,219 deletions.
13 changes: 13 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
((nil
(indent-tabs-mode . nil)
(require-final-newline . t)
(show-trailing-whitespace . t))
(prog-mode
(comment-column . 40)
(fill-column . 70))
(makefile-mode
(indent-tabs-mode . t))
(racket-mode
;; Better indentation for quoted xexprs and for at-exprs:
(racket-indent-sequence-depth . 3)
(racket-indent-curly-as-sequence . t)))
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ test:
# Unique to Frog:
TEST-PROJECT=test-blog
create-build-example:
mkdir $(TEST-PROJECT) && \
cd $(TEST-PROJECT) && \
raco frog --init && \
raco frog -b && \
cd .. && \
rm -rf $(TEST-PROJECT)
mkdir $(TEST-PROJECT) && \
cd $(TEST-PROJECT) && \
raco frog --init && \
raco frog --verbose --build && \
raco frog --new-markdown "Blah Blah" && \
raco frog --new-scribble "Blah Blah" && \
raco frog --verbose --build && \
cd .. && \
rm -rf $(TEST-PROJECT)
25 changes: 25 additions & 0 deletions example/frog.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#lang frog/config

;; Called early when Frog launches. Use this to set parameters defined
;; in frog/params.
(define/contract (init)
(-> any)
(current-scheme/host "http://www.example.com")
(current-title "My Blog")
(current-author "The Unknown Author"))

;; Called once per post and non-post page, on the contents.
(define/contract (enhance-body xs)
(-> (listof xexpr/c) (listof xexpr/c))
;; Here we pass the xexprs through a series of functions.
(~> xs
(syntax-highlight #:python-executable "python"
#:line-numbers? #t
#:css-class "source")
(auto-embed-tweets #:parents? #t)
(add-racket-doc-links #:code? #t #:prose? #f)))

;; Called from `raco frog --clean`.
(define/contract (clean)
(-> any)
(void))
9 changes: 0 additions & 9 deletions frog/.dir-locals.el

This file was deleted.

15 changes: 15 additions & 0 deletions frog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Public

`.rkt` files in this directory `provide` things a user may `require`
in their blog project files:

- `frog.rkt`
- templates
- `page-template.html`
- `post-template.html`
- `index-template.html`
- `.scrbl` format sources

Everything else should go under the `private` directory.

When in doubt, err on the side of making things private!
90 changes: 0 additions & 90 deletions frog/config.rkt

This file was deleted.

2 changes: 2 additions & 0 deletions frog/config/lang/reader.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang s-exp syntax/module-reader
frog/config/main
56 changes: 56 additions & 0 deletions frog/config/main.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#lang at-exp racket/base

(require (for-syntax racket/base
racket/function
racket/match
racket/syntax
syntax/parse)
reprovide/reprovide
"private/load.rkt")

(provide (except-out (all-from-out racket/base)
#%module-begin
#%provide
provide)
(rename-out [our-#%module-begin #%module-begin]))

(reprovide racket/contract/base
racket/contract/region
rackjure/threading
xml/xexpr
"../params.rkt"
"../paths.rkt"
"../enhance-body.rkt")

(define-syntax (our-#%module-begin stx)
(syntax-parse stx
[(_ forms ...)
(with-syntax ([(provides ...) (map (curry format-id stx "~a") provide-syms)])
;; If we didn't care about error messages, this could simply be:
;;
;; #'(#%module-begin forms ... (provide provides ...))
;;
;; But if the user has failed to define one of the mandatory functions
;; we want to supply a helpful error message that specifically
;; identifies it. And of course preserve their frog.rkt stx srcloc.
;;
;; So we local-expand their forms, catch the appropriate syntax errors,
;; and re-raise them in a more-helpful form.
(define (fail-sym exn)
(match (exn:fail:syntax-exprs exn)
[(cons stx _) (syntax-e stx)]
[_ #f]))
(with-handlers
([(λ (e)
(and (exn:fail:syntax? e)
(regexp-match? #rx"provided identifier not defined or imported"
(exn-message e))
(memq (fail-sym e) provide-syms)))
(λ (e)
(raise-syntax-error
'frog/config
(format "You must define a function named \"~a\"" (fail-sym e))
stx))])
(local-expand (syntax/loc #'(forms ...)
(#%module-begin forms ... (provide provides ...)))
'module-begin '())))]))
44 changes: 44 additions & 0 deletions frog/config/private/load.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#lang racket/base

(require (for-syntax racket/base
racket/function
racket/syntax))

(begin-for-syntax
(define provide-syms '(init
enhance-body
clean))
(provide provide-syms))

(define-syntax (define-the-things stx)
(with-syntax ([(id ...) (map (curry format-id stx "~a") provide-syms)]
[load (format-id stx "load")])
#'(begin
(define id
(λ _ (error 'id "not yet dynamic-required from frog.rkt"))) ...
(provide id ...)

(define (load top)
(define frog.rkt (build-path top "frog.rkt"))
(let ([fn (dynamic-require frog.rkt 'id)])
(when fn (set! id fn))) ...)
(provide load))))

(define-the-things)

(module+ test
(require rackunit
racket/runtime-path)
(test-case "before loading example/frog.rkt"
(check-exn #rx"init: not yet dynamic-required from frog.rkt"
(λ () (init)))
(check-exn #rx"enhance-body: not yet dynamic-required from frog.rkt"
(λ () (enhance-body '((p () "hi")))))
(check-exn #rx"clean: not yet dynamic-required from frog.rkt"
(λ () (clean))))
(define-runtime-path example "../../../example/")
(test-case "after loading example/frog.rkt"
(load example)
(check-not-exn (λ () (init)))
(check-not-exn (λ () (enhance-body '((p () "hi")))))
(check-not-exn (λ () (clean)))))
36 changes: 36 additions & 0 deletions frog/config/private/test.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#lang racket/base

(module+ test
(require rackunit)

(module m frog/config/main
(define init #f)
(define enhance-body #f)
(define clean #f))

(check-not-exn (λ () (eval '(module m frog/config/main
(define init #f)
(define enhance-body #f)
(define clean #f))
(make-base-namespace))))

(check-exn #rx"frog/config: You must define a function named \"init\""
(λ () (eval '(module m frog/config/main
#;(define init #f)
(define enhance-body #f)
(define clean #f))
(make-base-namespace))))

(check-exn #rx"frog/config: You must define a function named \"enhance-body\""
(λ () (eval '(module m frog/config/main
(define init #f)
#;(define enhance-body #f)
(define clean #f))
(make-base-namespace))))

(check-exn #rx"frog/config: You must define a function named \"clean\""
(λ () (eval '(module m frog/config/main
(define init #f)
(define enhance-body #f)
#;(define clean #f))
(make-base-namespace)))))
Loading

0 comments on commit 005833f

Please sign in to comment.