Compare commits
282 Commits
dev-stylis
...
master
@ -0,0 +1 @@
|
||||
custom: https://mbtype.com
|
@ -0,0 +1,43 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
name: "Build using Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
racket-version: ["6.6", "6.7", "6.8", "6.9", "6.10.1", "6.11", "6.12", "7.0", "7.1", "7.2", "7.3", "7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "current"]
|
||||
racket-variant: ["BC", "CS"]
|
||||
# CS builds are only provided for versions 7.4 and up so avoid
|
||||
# running the job for prior versions.
|
||||
exclude:
|
||||
- {racket-version: "6.6", racket-variant: "CS"}
|
||||
- {racket-version: "6.7", racket-variant: "CS"}
|
||||
- {racket-version: "6.8", racket-variant: "CS"}
|
||||
- {racket-version: "6.9", racket-variant: "CS"}
|
||||
- {racket-version: "6.10.1", racket-variant: "CS"}
|
||||
- {racket-version: "6.11", racket-variant: "CS"}
|
||||
- {racket-version: "6.12", racket-variant: "CS"}
|
||||
- {racket-version: "7.0", racket-variant: "CS"}
|
||||
- {racket-version: "7.1", racket-variant: "CS"}
|
||||
- {racket-version: "7.2", racket-variant: "CS"}
|
||||
- {racket-version: "7.3", racket-variant: "CS"}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
|
||||
- uses: Bogdanp/setup-racket@v0.11
|
||||
with:
|
||||
distribution: 'full'
|
||||
version: ${{ matrix.racket-version }}
|
||||
variant: ${{ matrix.racket-variant }}
|
||||
|
||||
- name: Install Pollen and its dependencies
|
||||
run: raco pkg install --auto --batch
|
||||
|
||||
- name: Run the tests
|
||||
run: xvfb-run raco test -j 4 -p pollen
|
@ -1,47 +0,0 @@
|
||||
# adapted from
|
||||
# https://github.com/greghendershott/travis-racket/blob/master/.travis.yml
|
||||
# Thanks Greg!
|
||||
|
||||
language: c
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
global:
|
||||
- RACKET_DIR=~/racket
|
||||
matrix:
|
||||
- RACKET_VERSION=6.0
|
||||
- RACKET_VERSION=6.1
|
||||
- RACKET_VERSION=6.2
|
||||
- RACKET_VERSION=6.3
|
||||
- RACKET_VERSION=6.4
|
||||
- RACKET_VERSION=6.5
|
||||
- RACKET_VERSION=6.6
|
||||
- RACKET_VERSION=6.7
|
||||
- RACKET_VERSION=6.8
|
||||
- RACKET_VERSION=6.9
|
||||
- RACKET_VERSION=6.10
|
||||
- RACKET_VERSION=6.11
|
||||
- RACKET_VERSION=6.12
|
||||
- RACKET_VERSION=HEAD
|
||||
|
||||
# You may want to test against certain versions of Racket, without
|
||||
# having them count against the overall success/failure.
|
||||
matrix:
|
||||
allow_failures:
|
||||
# - env: RACKET_VERSION=HEAD
|
||||
# Fast finish: Overall build result is determined as soon as any of
|
||||
# its rows have failed, or, all of its rows that aren't allowed to
|
||||
# fail have succeeded.
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- "export DISPLAY=:99.0" # needed for testing with `racket/gui`
|
||||
- "sh -e /etc/init.d/xvfb start" # needed for testing with `racket/gui`
|
||||
- git clone https://github.com/mbutterick/travis-racket.git
|
||||
- cat travis-racket/install-racket.sh | bash # pipe to bash not sh!
|
||||
- export PATH="${RACKET_DIR}/bin:${PATH}" #install-racket.sh can't set for us
|
||||
|
||||
script:
|
||||
- cd .. # Travis did a cd into the dir. Back up, for the next:
|
||||
- travis_retry raco pkg install --deps search-auto --link pollen
|
||||
- raco test -p pollen
|
@ -0,0 +1,134 @@
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
mb@mbtype.com (= Matthew Butterick).
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
||||
at [https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
|
@ -1,165 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
@ -0,0 +1,9 @@
|
||||
MIT License for Pollen
|
||||
|
||||
© 2013-2019 Matthew Butterick
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -0,0 +1,23 @@
|
||||
#lang racket/base
|
||||
(provide (prefix-out pollen- (all-defined-out)))
|
||||
(define main-export 'doc) ; don't forget to change fallback template too
|
||||
(define meta-export 'metas)
|
||||
(define meta-tag-name 'meta)
|
||||
(define define-meta-name 'define-meta)
|
||||
(define preproc-source-ext 'pp)
|
||||
(define markup-source-ext 'pm)
|
||||
(define markdown-source-ext 'pmd)
|
||||
(define null-source-ext 'p)
|
||||
(define pagetree-source-ext 'ptree)
|
||||
(define template-source-ext 'pt)
|
||||
(define scribble-source-ext 'scrbl)
|
||||
(define poly-source-ext 'poly) ; extension that signals source can be used for multiple output targets
|
||||
(define cache-dir-name "compiled")
|
||||
(define cache-subdir-name "pollen")
|
||||
(define template-prefix "template")
|
||||
(define fallback-template-prefix "fallback")
|
||||
(define template-meta-key "template")
|
||||
(define old-cache-names '("pollen.cache" "pollen-cache"))
|
||||
(define splicing-tag '@)
|
||||
(define here-path-key 'here-path)
|
||||
(define extension-escape-char #\_)
|
@ -1,78 +0,0 @@
|
||||
#lang racket/base
|
||||
(require (for-syntax racket/base racket/syntax))
|
||||
(require racket/date racket/string)
|
||||
(require sugar/debug sugar/define)
|
||||
|
||||
(provide (all-from-out sugar/debug))
|
||||
|
||||
; todo: contracts, tests, docs
|
||||
|
||||
|
||||
; debug utilities
|
||||
(define months (list "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
|
||||
|
||||
(define last-message-time #f)
|
||||
(define (seconds-since-last-message)
|
||||
(define now (current-seconds))
|
||||
(define then last-message-time)
|
||||
(set! last-message-time now)
|
||||
(if then
|
||||
(- now then)
|
||||
"0"))
|
||||
|
||||
(define (zero-fill str count)
|
||||
(set! str (format "~a" str))
|
||||
(if (> (string-length str) count)
|
||||
str
|
||||
(string-append (make-string (- count (string-length str)) #\0) str)))
|
||||
|
||||
(define+provide (make-datestamp)
|
||||
(define date (current-date))
|
||||
(define date-fields (map (λ (x) (zero-fill x 2))
|
||||
(list
|
||||
(date-day date)
|
||||
(list-ref months (sub1 (date-month date)))
|
||||
(date-year date)
|
||||
)))
|
||||
(string-join date-fields "-"))
|
||||
|
||||
(define+provide (make-timestamp)
|
||||
(define date (current-date))
|
||||
(define time-fields (map (λ (x) (zero-fill x 2))
|
||||
(list
|
||||
; (date-day date)
|
||||
; (list-ref months (sub1 (date-month date)))
|
||||
(if (<= (date-hour date) 12)
|
||||
(date-hour date) ; am hours + noon hour
|
||||
(modulo (date-hour date) 12)) ; pm hours after noon hour
|
||||
(date-minute date)
|
||||
(date-second date))))
|
||||
(string-append (string-join time-fields ":") (if (< (date-hour date) 12) "am" "pm")))
|
||||
|
||||
(define (make-debug-timestamp)
|
||||
(format "[~a ∆~as]" (make-timestamp) (seconds-since-last-message)))
|
||||
|
||||
;; creates pollen-logger and associated functions:
|
||||
;; log-pollen-fatal, log-pollen-error, log-pollen-warning,
|
||||
;; log-pollen-info, and log-pollen-debug
|
||||
(define-logger pollen)
|
||||
|
||||
|
||||
(define-syntax (make-message-logger-functions stx)
|
||||
(syntax-case stx ()
|
||||
[(_ stem)
|
||||
(with-syntax ([message-stem (format-id stx "message-~a" #'stem)]
|
||||
[log-pollen-stem (format-id stx "log-pollen-~a" #'stem)])
|
||||
#'(begin
|
||||
;; does file have particular extension
|
||||
(define+provide (message-stem . items)
|
||||
(log-pollen-stem (string-join `(,(make-debug-timestamp) ,@(map (λ (x)(if (string? x) x (format "~v" x))) items)))))))]))
|
||||
|
||||
(make-message-logger-functions fatal)
|
||||
(make-message-logger-functions error)
|
||||
(make-message-logger-functions warning)
|
||||
(make-message-logger-functions info)
|
||||
(make-message-logger-functions debug)
|
||||
|
||||
(define+provide (message . items)
|
||||
(displayln (string-join `(,@(map (λ (x)(if (string? x) x (format "~v" x))) items)))))
|
@ -0,0 +1,34 @@
|
||||
#lang racket/base
|
||||
(require (for-syntax racket/base
|
||||
racket/list
|
||||
syntax/parse)
|
||||
(only-in scribble/text/syntax-utils include/text)
|
||||
(only-in "output.rkt" output)
|
||||
racket/match
|
||||
racket/port)
|
||||
|
||||
(provide include-template)
|
||||
|
||||
;; Adaptation of function in web-server/templates library
|
||||
;; to check for binary result and pass it through.
|
||||
;; Actually patches underlying bug in `output`.
|
||||
|
||||
(define (finish result)
|
||||
(match result
|
||||
[(? bytes? bs) bs]
|
||||
;; list of expressions with byte string in last place.
|
||||
;; infer that user is trying to return a binary as the last value in a template,
|
||||
;; and treat it as a single binary value.
|
||||
[(list _ ... (? bytes? bs)) bs]
|
||||
[_ (with-output-to-string (λ () (output result)))]))
|
||||
|
||||
(define-syntax (include-template stx)
|
||||
(syntax-parse stx
|
||||
[(_ (~optional (~seq #:command-char command-char:expr)) src:expr)
|
||||
(quasisyntax/loc stx
|
||||
(finish (include/text #,@(if (attribute command-char)
|
||||
(list #'#:command-char #'command-char)
|
||||
empty)
|
||||
src)))]))
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
#lang info
|
||||
|
||||
;; 210309
|
||||
;; for unknown reason "mode-indentation.rkt"
|
||||
;; started causing CI failures since 210215
|
||||
;; consistently on 6.7, 6.8, 6.9, 7.7CS, 7.8CS, 7.9CS
|
||||
;; I assume it has something to do with the fact that
|
||||
;; it imports `framework` and `racket/gui`,
|
||||
;; OTOH why does it fail in these?
|
||||
(define test-omit-paths '("mode-indentation.rkt"))
|
@ -0,0 +1,69 @@
|
||||
#lang racket/base
|
||||
|
||||
;; 190303: Needed for compatibility with Rackets < 6.7.
|
||||
;; #:logger argument not introduced until 6.7
|
||||
|
||||
(require racket/contract/base)
|
||||
|
||||
(provide log-level/c)
|
||||
|
||||
(define log-level/c (or/c 'none 'fatal 'error 'warning 'info 'debug))
|
||||
(define log-spec? (listof (or/c symbol? #f)))
|
||||
(define log-event? (vector-immutable/c log-level/c string? any/c (or/c symbol? #f)))
|
||||
|
||||
(provide/contract [with-intercepted-logging
|
||||
(->* ((-> log-event? any)
|
||||
(-> any)
|
||||
log-level/c)
|
||||
(#:logger logger?)
|
||||
#:rest log-spec?
|
||||
any)]
|
||||
[with-logging-to-port
|
||||
(->* (output-port? (-> any) log-level/c)
|
||||
(#:logger logger?)
|
||||
#:rest log-spec?
|
||||
any)])
|
||||
|
||||
(define (receiver-thread receiver stop-chan intercept)
|
||||
(thread
|
||||
(lambda ()
|
||||
(define (clear-events)
|
||||
(let ([l (sync/timeout 0 receiver)])
|
||||
(when l ; still something to read
|
||||
(intercept l) ; interceptor gets the whole vector
|
||||
(clear-events))))
|
||||
(let loop ()
|
||||
(let ([l (sync receiver stop-chan)])
|
||||
(cond [(eq? l 'stop)
|
||||
;; we received all the events we were supposed
|
||||
;; to get, read them all (w/o waiting), then
|
||||
;; stop
|
||||
(clear-events)]
|
||||
[else ; keep going
|
||||
(intercept l)
|
||||
(loop)]))))))
|
||||
|
||||
(define (with-intercepted-logging interceptor proc #:logger [logger #f]
|
||||
. log-spec)
|
||||
(let* ([orig-logger (current-logger)]
|
||||
;; Unless we're provided with an explicit logger to monitor we
|
||||
;; use a local logger to avoid getting messages that didn't
|
||||
;; originate from proc. Since it's a child of the original logger,
|
||||
;; the rest of the program still sees the log entries.
|
||||
[logger (or logger (make-logger #f orig-logger))]
|
||||
[receiver (apply make-log-receiver logger log-spec)]
|
||||
[stop-chan (make-channel)]
|
||||
[t (receiver-thread receiver stop-chan interceptor)])
|
||||
(begin0
|
||||
(parameterize ([current-logger logger])
|
||||
(proc))
|
||||
(channel-put stop-chan 'stop) ; stop the receiver thread
|
||||
(thread-wait t))))
|
||||
|
||||
(define (with-logging-to-port port proc #:logger [logger #f] . log-spec)
|
||||
(apply with-intercepted-logging
|
||||
#:logger logger
|
||||
(lambda (l) (displayln (vector-ref l 1) ; actual message
|
||||
port))
|
||||
proc
|
||||
log-spec))
|
@ -0,0 +1,153 @@
|
||||
# This allows us to launch Python and pygments once, and pipe to it
|
||||
# continuously.
|
||||
#
|
||||
# There are four options:
|
||||
# 1. Language (used to determine the lexer)
|
||||
# 2. Line numbers to highlight
|
||||
# 3. Encoding to use for the output
|
||||
# 4. HTML Class to use for the output
|
||||
#
|
||||
# These can be specified as arguments when this script is first invoked, or on a
|
||||
# per invocation.
|
||||
#
|
||||
# To set the options for each invocation, the format is:
|
||||
#
|
||||
# __LANG__ <lexer-name>
|
||||
# __LINENOS__ <true|false>
|
||||
# __LINES__ <list-of-highlighted-lines>
|
||||
# __CSS__ <CSS-class>
|
||||
# __ENC__ <encoding>
|
||||
# <code>
|
||||
# ...
|
||||
# __END__
|
||||
#
|
||||
# OR
|
||||
#
|
||||
# __EXIT__
|
||||
#
|
||||
# Output format is:
|
||||
#
|
||||
# <html>
|
||||
# ...
|
||||
# __END__
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
from pygments import highlight
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.util import ClassNotFound
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
def get_lexer(lang):
|
||||
if not lang:
|
||||
get_lexer_by_name("text", encoding="guess")
|
||||
|
||||
try:
|
||||
return get_lexer_by_name(lang, encoding="guess")
|
||||
except ClassNotFound:
|
||||
print("No lexer was found for the given language. Using plain text instead.", file=sys.stderr)
|
||||
return get_lexer_by_name("text", encoding="guess")
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--linenos', action="store_true", dest="linenos")
|
||||
parser.add_option('--cssclass', default="source", dest="cssclass")
|
||||
parser.add_option('--encoding', default="utf-8", dest="encoding")
|
||||
parser.add_option('--language', dest="language")
|
||||
(options, _) = parser.parse_args()
|
||||
|
||||
# Set initial options
|
||||
config = {
|
||||
'linenos': options.linenos,
|
||||
'cssclass': options.cssclass,
|
||||
'encoding': options.encoding,
|
||||
'hl_lines': []
|
||||
}
|
||||
lexer = get_lexer(options.language)
|
||||
code = ""
|
||||
|
||||
py_version = sys.version_info.major
|
||||
sys.stdout.write("ready\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
while 1:
|
||||
line_raw = sys.stdin.readline()
|
||||
if not line_raw:
|
||||
break
|
||||
# Without trailing space, \n, or \n
|
||||
line = line_raw.rstrip()
|
||||
|
||||
if line == '__EXIT__':
|
||||
break
|
||||
elif line == '__END__':
|
||||
# Lex input finished. Lex it.
|
||||
formatter = HtmlFormatter(linenos=config['linenos'],
|
||||
cssclass=config['cssclass'],
|
||||
encoding=config['encoding'],
|
||||
hl_lines=config['hl_lines'])
|
||||
if py_version >= 3:
|
||||
sys.stdout.write(highlight(code, lexer, formatter).decode("utf-8"))
|
||||
else:
|
||||
sys.stdout.write(highlight(code, lexer, formatter))
|
||||
sys.stdout.write('\n__END__\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
# Reset the configuration for the next invocation. Most options are
|
||||
# actually persisted between runs, except for the code itself and the
|
||||
# lines to be highlighted.
|
||||
code = ""
|
||||
config['hl_lines'] = []
|
||||
|
||||
elif code == "":
|
||||
# Only check for new options at the beginning of a a fresh invocation
|
||||
if line.startswith("__LANG__"):
|
||||
# Use the provided language to find the appropriate lexer.
|
||||
try:
|
||||
lang = line.split()[1]
|
||||
lexer = get_lexer(lang)
|
||||
except IndexError:
|
||||
print("No lexer was found for the given language. Using plain text instead.", file=sys.stderr)
|
||||
lexer = get_lexer_by_name("text", encoding="guess")
|
||||
|
||||
elif line.startswith("__LINENOS__"):
|
||||
try:
|
||||
option = line.split()[1]
|
||||
if option.lower() == "true":
|
||||
config['linenos'] = True
|
||||
elif option.lower() == "false":
|
||||
config['linenos'] = False
|
||||
else:
|
||||
pass
|
||||
except IndexError:
|
||||
print("__LINENOS__ option must be given a `true` or `false` value",
|
||||
file=sys.stderr)
|
||||
|
||||
elif line.startswith("__LINES__"):
|
||||
# The list of lines to highlight is formatted as string of
|
||||
# whitespace-separated integers
|
||||
lines = line.split()[1:]
|
||||
config['hl_lines'] = [int(str) for str in lines]
|
||||
|
||||
elif line.startswith("__CSS__"):
|
||||
try:
|
||||
config['cssclass'] = line.split[1]
|
||||
except IndexError:
|
||||
print("Could not parse CSS class line.", file=sys.stderr)
|
||||
|
||||
elif line.startswith("__ENC__"):
|
||||
try:
|
||||
config['encoding'] = line.split[1]
|
||||
except IndexError:
|
||||
print("Could not parse encoding line.", file=sys.stderr)
|
||||
else:
|
||||
# Done with configuration for this invocation, start accumulating
|
||||
# code. Use `line_raw` because we want trailing space, \n, \r
|
||||
code += line_raw
|
||||
|
||||
else:
|
||||
# Accumulate more code
|
||||
# Use `line_raw`: Do want trailing space, \n, \r
|
||||
code += line_raw
|
||||
|
||||
exit(0)
|
@ -1,33 +0,0 @@
|
||||
#lang racket/base
|
||||
(require (only-in scribble/text/syntax-utils include/text)
|
||||
(only-in "output.rkt" output)
|
||||
racket/list
|
||||
(for-syntax racket/base
|
||||
racket/list
|
||||
syntax/parse)
|
||||
racket/port)
|
||||
|
||||
;; Adaptation of function in web-server/templates library
|
||||
;; to check for binary result and pass it through.
|
||||
;; Actually patches underlying bug in `output`.
|
||||
(define-syntax (include-template stx)
|
||||
(syntax-parse stx
|
||||
[(_ (~optional (~seq #:command-char command-char:expr)) p:expr)
|
||||
(quasisyntax/loc stx
|
||||
(let ([result (include/text #,@(if (attribute command-char)
|
||||
(list #'#:command-char #'command-char)
|
||||
empty)
|
||||
p)])
|
||||
|
||||
(let ([result (cond
|
||||
[(bytes? result) result]
|
||||
;; list of expressions with byte string in last place.
|
||||
;; infer that user is trying to return a binary as the last value in a template,
|
||||
;; and treat it as a single binary value.
|
||||
[(and (list? result) (bytes? (last result))) (last result)]
|
||||
[else result])])
|
||||
(if (bytes? result)
|
||||
(with-output-to-bytes (λ () (write-bytes result)))
|
||||
(with-output-to-string (λ () (output result)))))))]))
|
||||
|
||||
(provide include-template)
|
@ -0,0 +1,17 @@
|
||||
#lang racket/base
|
||||
(require racket/format
|
||||
racket/string
|
||||
"external/logging.rkt")
|
||||
|
||||
(provide (all-defined-out) (all-from-out "external/logging.rkt"))
|
||||
|
||||
;; creates `pollen-logger` and associated functions:
|
||||
;; log-pollen-fatal, log-pollen-error, log-pollen-warning,
|
||||
;; log-pollen-info, and log-pollen-debug
|
||||
(define-logger pollen)
|
||||
|
||||
(define (message . items)
|
||||
(log-pollen-info (string-join (map ~a items) " ")))
|
||||
|
||||
(define (message-debug . items)
|
||||
(log-pollen-debug (string-join (map ~a items) " ")))
|
@ -1,65 +0,0 @@
|
||||
#lang racket/base
|
||||
(require (for-syntax racket/base
|
||||
syntax/parse)
|
||||
version/utils
|
||||
scribble/base
|
||||
scribble/core
|
||||
scribble/private/manual-sprop
|
||||
scribble/private/manual-ex
|
||||
scribble/private/manual-style)
|
||||
|
||||
#|
|
||||
Need this to make pollen docs buildable on v6.0.
|
||||
`history` not added to scribble/manul till v6.1.
|
||||
|#
|
||||
|
||||
(provide pollen-history)
|
||||
|
||||
(struct history-entry (what vers vers-stx expl))
|
||||
|
||||
(begin-for-syntax
|
||||
(define-splicing-syntax-class clause
|
||||
#:attributes (e)
|
||||
[pattern (~seq #:added vers)
|
||||
#:attr e #'(history-entry "Added" vers (quote-syntax vers) '("."))]
|
||||
[pattern (~seq #:changed vers content)
|
||||
#:attr e #'(history-entry "Changed" vers (quote-syntax vers)
|
||||
(list ": " content))]))
|
||||
|
||||
(define-syntax (pollen-history stx)
|
||||
(syntax-parse stx
|
||||
[(_ c:clause ...)
|
||||
#'(make-history (list c.e ...))]))
|
||||
|
||||
(define (make-history es)
|
||||
(for ([e (in-list es)])
|
||||
(define vers (history-entry-vers e))
|
||||
(unless (valid-version? vers)
|
||||
(raise-syntax-error 'history
|
||||
(format "not a valid version: ~e"
|
||||
vers)
|
||||
(history-entry-vers-stx e))))
|
||||
(delayed-block
|
||||
(lambda (renderer p ri)
|
||||
(define pkg
|
||||
(let ([from (resolve-get/tentative p ri '(exporting-packages #f))])
|
||||
(and from
|
||||
(pair? from)
|
||||
(car from))))
|
||||
(para
|
||||
#:style (style "SHistory" (list scheme-properties))
|
||||
(for/list ([e (in-list (sort es (lambda (a b) (version<? a b))
|
||||
#:key history-entry-vers))]
|
||||
[i (in-naturals)])
|
||||
(define vers (history-entry-vers e))
|
||||
(list (if (zero? i)
|
||||
null
|
||||
(list null ; needed to avoid " " dropped as whitespace
|
||||
" "))
|
||||
(history-entry-what e)
|
||||
" in version "
|
||||
vers
|
||||
(if (and pkg (zero? i))
|
||||
(list " of package " (tt pkg))
|
||||
null)
|
||||
(history-entry-expl e)))))))
|
@ -1,76 +0,0 @@
|
||||
# This allows us to launch Python and pygments once, and pipe to it
|
||||
# continuously. Input format is:
|
||||
#
|
||||
# <lexer-name>
|
||||
# <list-of-highlighted-lines>
|
||||
# <code>
|
||||
# ...
|
||||
# __END__
|
||||
#
|
||||
# OR
|
||||
#
|
||||
# __EXIT__
|
||||
#
|
||||
# Output format is:
|
||||
#
|
||||
# <html>
|
||||
# ...
|
||||
# __END__
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
from pygments import highlight
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.util import ClassNotFound
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--linenos', action="store_true", dest="linenos")
|
||||
parser.add_option('--cssclass', default="source", dest="cssclass")
|
||||
(options, _) = parser.parse_args()
|
||||
|
||||
lexer = ""
|
||||
code = ""
|
||||
lines_to_highlight = ""
|
||||
py_version = sys.version_info.major
|
||||
sys.stdout.write("ready\n")
|
||||
sys.stdout.flush()
|
||||
while 1:
|
||||
line_raw = sys.stdin.readline()
|
||||
if not line_raw:
|
||||
break
|
||||
# Without trailing space, \n, or \n
|
||||
line = line_raw.rstrip()
|
||||
if line == '__EXIT__':
|
||||
break
|
||||
elif line == '__END__':
|
||||
# Lex input finished. Lex it.
|
||||
formatter = HtmlFormatter(linenos=options.linenos,
|
||||
cssclass=options.cssclass,
|
||||
encoding="utf-8",
|
||||
hl_lines=lines_to_highlight)
|
||||
if py_version >= 3:
|
||||
sys.stdout.write(highlight(code, lexer, formatter).decode("utf-8"))
|
||||
else:
|
||||
sys.stdout.write(highlight(code, lexer, formatter))
|
||||
sys.stdout.write('\n__END__\n')
|
||||
sys.stdout.flush()
|
||||
lexer = ""
|
||||
code = ""
|
||||
lines_to_highlight = ""
|
||||
elif lexer == "":
|
||||
# Starting another lex. First line is the lexer name.
|
||||
try:
|
||||
lexer = get_lexer_by_name(line, encoding="guess")
|
||||
except ClassNotFound:
|
||||
lexer = get_lexer_by_name("text", encoding="guess")
|
||||
elif lines_to_highlight == "":
|
||||
# Starting another lex. Second line is list of lines to highlight,
|
||||
# formatted as string of whitespace-separated integers
|
||||
lines_to_highlight = [int(str) for str in line.split()]
|
||||
else:
|
||||
# Accumulate more code
|
||||
# Use `line_raw`: Do want trailing space, \n, \r
|
||||
code += line_raw
|
||||
|
||||
exit(0)
|
@ -1,55 +1,80 @@
|
||||
#lang racket/base
|
||||
(require "file-utils.rkt" racket/file "cache-utils.rkt" "debug.rkt" racket/path racket/place sugar/list)
|
||||
(require racket/file
|
||||
racket/path
|
||||
racket/place
|
||||
racket/match
|
||||
racket/format
|
||||
"file-utils.rkt"
|
||||
"cache-utils.rkt"
|
||||
"log.rkt")
|
||||
(provide preheat-cache)
|
||||
|
||||
(define (preheat-cache starting-dir)
|
||||
(define (path-cached? path)
|
||||
;; #true = already cached; #false = not cached
|
||||
;; seems like it would be slow to load cache.rktd but it's not.
|
||||
(define-values (_ private-cache-dir) (make-cache-dirs path))
|
||||
(define cache-db-file (build-path private-cache-dir "cache.rktd"))
|
||||
(and (file-exists? cache-db-file)
|
||||
(hash-has-key? (file->value cache-db-file) (paths->key 'source path))))
|
||||
|
||||
(define (preheat-cache starting-dir [wants-parallel-setup? #false] [wants-dry-run? #false])
|
||||
(unless (and (path-string? starting-dir) (directory-exists? starting-dir))
|
||||
(error 'preheat-cache (format "~a is not a directory" starting-dir)))
|
||||
|
||||
(define max-places (processor-count)) ; number of parallel processes to spawn at a time
|
||||
|
||||
(define paths-that-should-be-cached (for/list ([path (in-directory starting-dir)]
|
||||
#:when (for/or ([proc (in-list (list preproc-source?
|
||||
markup-source?
|
||||
markdown-source?
|
||||
pagetree-source?))])
|
||||
(proc path)))
|
||||
path))
|
||||
(raise-argument-error 'preheat-cache "directory" starting-dir))
|
||||
|
||||
;; if a file is already in the cache, no need to hit it again.
|
||||
;; this allows partially completed preheat jobs to resume.
|
||||
(define uncached-paths (filter
|
||||
(λ (path)
|
||||
;; #t = not cached; #f = already cached
|
||||
;; seems like it would be slow to load cache.rktd but it's not.
|
||||
(define-values (_ private-cache-dir) (make-cache-dirs path))
|
||||
(define cache-db-file (build-path private-cache-dir "cache.rktd"))
|
||||
(cond
|
||||
[(not (file-exists? cache-db-file)) #t]
|
||||
[else (define cache-db (file->value cache-db-file))
|
||||
(not (hash-has-key? cache-db (paths->key path)))])) paths-that-should-be-cached))
|
||||
|
||||
;; compile a path inside a place (= parallel processing)
|
||||
(define (path-into-place path)
|
||||
(message (format "caching: ~a" (find-relative-path starting-dir path)))
|
||||
(define p (place ch
|
||||
(define path (place-channel-get ch))
|
||||
(define-values (path-dir path-name _) (split-path path))
|
||||
(message (format "compiling: ~a" path))
|
||||
;; use #f to signal compile error. Otherwise allow errors to pass.
|
||||
(define result (with-handlers ([exn:fail? (λ _ (message (format "compile failed: ~a" path-name)) #f)])
|
||||
(path->hash path)))
|
||||
(place-channel-put ch result)))
|
||||
(place-channel-put p path)
|
||||
p)
|
||||
(define uncached-paths
|
||||
(for/list ([path (in-directory starting-dir (λ (p) (not (special-path? p))))]
|
||||
#:when (for/or ([proc (in-list (list preproc-source?
|
||||
markup-source?
|
||||
markdown-source?
|
||||
pagetree-source?))])
|
||||
(proc path))
|
||||
#:unless (path-cached? path))
|
||||
(simple-form-path path)))
|
||||
|
||||
(cond
|
||||
[wants-dry-run? (for-each message uncached-paths)]
|
||||
[(null? uncached-paths) (message "all cached files are up to date")]
|
||||
[wants-parallel-setup?
|
||||
|
||||
(define job-count
|
||||
(min
|
||||
(length uncached-paths)
|
||||
(match wants-parallel-setup?
|
||||
[#true (processor-count)]
|
||||
[(? exact-positive-integer? count) count]
|
||||
[_ (raise-argument-error 'preheat-cache "exact positive integer" wants-parallel-setup?)])))
|
||||
|
||||
(define worker-evts
|
||||
(for/list ([wpidx (in-range job-count)])
|
||||
(define wp
|
||||
(place ch
|
||||
(let loop ()
|
||||
(define path (place-channel-put/get ch (list 'want-job)))
|
||||
(place-channel-put ch (list 'job-finished path
|
||||
(with-handlers ([exn:fail? (λ (e) (cons #false (exn-message e)))])
|
||||
(path->hash path))))
|
||||
(loop))))
|
||||
(handle-evt wp (λ (val) (list* wpidx wp val)))))
|
||||
|
||||
;; compile the paths in groups, so they can be incrementally saved.
|
||||
;; that way, if there's a failure, the progress is preserved.
|
||||
;; but the slowest file in a group will prevent further progress.
|
||||
(for ([path-group (in-list (slice-at uncached-paths max-places))])
|
||||
(define path-places (map path-into-place path-group))
|
||||
(for ([path (in-list path-group)]
|
||||
[ppl (in-list path-places)])
|
||||
(define result (place-channel-get ppl))
|
||||
(when result ; #f is used to signal compile error
|
||||
(cache-ref! (paths->key path) (λ _ result))))))
|
||||
(let loop ([paths uncached-paths][actives null])
|
||||
(unless (and (null? paths) (null? actives))
|
||||
(match (apply sync worker-evts)
|
||||
[(list wpidx wp 'want-job)
|
||||
(match paths
|
||||
[(? null?) (loop null actives)]
|
||||
[(cons path rest)
|
||||
(place-channel-put wp path)
|
||||
(message (format "caching @ job ~a: ~a" (~r (add1 wpidx) #:min-width (string-length (~r job-count)) #:pad-string " ") (find-relative-path starting-dir path)))
|
||||
(loop rest (cons wpidx actives))])]
|
||||
[(list wpidx wp 'job-finished path result)
|
||||
(match result
|
||||
[(cons #false exn-msg) (message (format "caching failed on job ~a: ~a\n because ~a" (add1 wpidx) (find-relative-path starting-dir path) exn-msg))]
|
||||
[_ (cache-ref! (paths->key 'source path) (λ () result))])
|
||||
(loop paths (remq wpidx actives))])))]
|
||||
[else (for ([path (in-list uncached-paths)])
|
||||
(message (format "caching: ~a" (find-relative-path starting-dir path)))
|
||||
(match (with-handlers ([exn:fail? (λ (e) (cons #false (exn-message e)))]) (path->hash path))
|
||||
[(cons #false exn-msg) (message (format "caching failed: ~a\n because ~a" (find-relative-path starting-dir path) exn-msg))]
|
||||
[result (cache-ref! (paths->key 'source path) (λ () result))]))]))
|
@ -1,41 +1,78 @@
|
||||
#lang web-server/base
|
||||
|
||||
(require racket/list
|
||||
web-server/servlet-env
|
||||
web-server/dispatch)
|
||||
(require "project-server-routes.rkt"
|
||||
"debug.rkt"
|
||||
#lang racket/base
|
||||
(require racket/async-channel
|
||||
racket/runtime-path
|
||||
web-server/dispatch
|
||||
web-server/web-server
|
||||
web-server/servlet-dispatch
|
||||
web-server/private/mime-types
|
||||
(prefix-in files: web-server/dispatchers/dispatch-files)
|
||||
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
||||
web-server/dispatchers/filesystem-map
|
||||
net/sendurl
|
||||
"project-server-routes.rkt"
|
||||
"log.rkt"
|
||||
"../setup.rkt"
|
||||
"../file.rkt"
|
||||
"../cache.rkt"
|
||||
"version.rkt")
|
||||
|
||||
(provide start-server)
|
||||
|
||||
(define (start-server servlet-path [open-browser-window? #f])
|
||||
(define-values (pollen-servlet _)
|
||||
(dispatch-rules
|
||||
[((string-arg) ... (? (λ (x) (equal? "" x)))) route-index] ; last element of a "/"-terminated url is ""
|
||||
[((string-arg) ... (? pagetree-source?)) route-dashboard]
|
||||
[((string-arg) ... "in" (string-arg) ...) route-in]
|
||||
[((string-arg) ... "out" (string-arg) ...) route-out]
|
||||
[else route-default]))
|
||||
|
||||
(message (format "Welcome to Pollen ~a" pollen:version) (format "(Racket ~a)" (version)))
|
||||
(message (format "Project root is ~a" (current-project-root)))
|
||||
(define-runtime-path mime-types "server-extras/mime.types")
|
||||
|
||||
(define (make-static-dispatcher-sequence . pths)
|
||||
(apply sequencer:make
|
||||
(for/list ([pth (in-list pths)])
|
||||
(files:make
|
||||
#:path->mime-type (make-path->mime-type mime-types)
|
||||
#:url->path (make-url->path (path->string pth))))))
|
||||
|
||||
(define-values (pollen-servlet _)
|
||||
(dispatch-rules
|
||||
;; last element of a "/"-terminated url is ""
|
||||
[((string-arg) ... "") route-index]
|
||||
[((string-arg) ... (? pagetree-source?)) route-dashboard]
|
||||
[((string-arg) ... "in" (string-arg) ...) route-in]
|
||||
[((string-arg) ... "out" (string-arg) ...) route-out]
|
||||
[else route-default]))
|
||||
|
||||
(define (start-server servlet-path [open-browser-window? #false] #:return [return? #false])
|
||||
|
||||
(define server-name (format "http://localhost:~a" (current-server-port)))
|
||||
(message (format "Project server is ~a" server-name) "(Ctrl+C to exit)")
|
||||
(message (format "Project dashboard is ~a/~a" server-name (setup:main-pagetree)))
|
||||
(message "Ready to rock")
|
||||
|
||||
(parameterize ([error-print-width 1000])
|
||||
(serve/servlet pollen-servlet
|
||||
#:launch-browser? open-browser-window?
|
||||
#:servlet-path servlet-path
|
||||
#:port (current-server-port)
|
||||
#:listen-ip (current-server-listen-ip)
|
||||
#:servlet-regexp #rx"" ; respond to top level
|
||||
#:command-line? #t
|
||||
#:file-not-found-responder route-404
|
||||
#:extra-files-paths (list (current-server-extras-path) (current-project-root)))))
|
||||
|
||||
(message (format "welcome to Pollen ~a (Racket ~a)" pollen:version (version)))
|
||||
(message (format "project root is ~a" (current-project-root)))
|
||||
(message (format "project server is ~a (Ctrl+C to exit)" server-name))
|
||||
(message (format "project dashboard is ~a/~a" server-name (setup:main-pagetree)))
|
||||
(message (let ([clsi (current-server-listen-ip)])
|
||||
(if clsi
|
||||
(format "project server permitting access only to ~a"
|
||||
(case clsi
|
||||
[("127.0.0.1") "localhost"]
|
||||
[else clsi]))
|
||||
"project server permitting access to all clients")))
|
||||
(define ch (make-async-channel))
|
||||
(define stop-func
|
||||
(parameterize ([error-print-width 1000])
|
||||
(serve
|
||||
#:confirmation-channel ch
|
||||
#:dispatch (sequencer:make
|
||||
(dispatch/servlet pollen-servlet)
|
||||
(make-static-dispatcher-sequence
|
||||
(current-project-root)
|
||||
(current-server-extras-path))
|
||||
(dispatch/servlet route-404))
|
||||
#:listen-ip (current-server-listen-ip)
|
||||
#:port (current-server-port))))
|
||||
(define exn-or-port
|
||||
(sync ch))
|
||||
(when (exn? exn-or-port)
|
||||
(message "project server failed to start")
|
||||
(sync (system-idle-evt))
|
||||
(exit 1))
|
||||
(message "ready to rock")
|
||||
(when open-browser-window?
|
||||
(send-url (string-append server-name servlet-path)))
|
||||
(if return?
|
||||
stop-func
|
||||
(with-handlers ([exn:break? (λ (e) (stop-func) (message "project server stopped"))])
|
||||
(do-not-return))))
|
||||
|
@ -0,0 +1,53 @@
|
||||
#lang racket/base
|
||||
(require (for-syntax racket/base
|
||||
syntax/strip-context
|
||||
"project.rkt"
|
||||
"../setup.rkt")
|
||||
racket/stxparam
|
||||
racket/splicing
|
||||
"external/include-template.rkt"
|
||||
"../cache.rkt"
|
||||
"../pagetree.rkt"
|
||||
"../core.rkt"
|
||||
"../setup.rkt"
|
||||
"../template.rkt"
|
||||
"../top.rkt")
|
||||
|
||||
(provide (rename-out [mb #%module-begin])
|
||||
(except-out (all-from-out racket/base) #%module-begin))
|
||||
|
||||
(define-syntax-parameter doc (λ (stx) (error 'doc-not-parameterized)))
|
||||
(define-syntax-parameter metas (λ (stx) (error 'metas-not-parameterized)))
|
||||
(define-syntax-parameter result (λ (stx) (error 'result-not-parameterized)))
|
||||
|
||||
(define-syntax (mb stx)
|
||||
(syntax-case stx ()
|
||||
;; markup / markdown branch
|
||||
[(_ #:source SOURCE-PATH-STRING
|
||||
#:template TEMPLATE-PATH-STRING
|
||||
#:result-id RESULT-ID)
|
||||
(let ([source-path (syntax->datum #'SOURCE-PATH-STRING)])
|
||||
(with-syntax ([DIRECTORY-REQUIRE-FILES
|
||||
(replace-context #'here (require-directory-require-files source-path))]
|
||||
[DOC-ID pollen-main-export]
|
||||
[METAS-ID pollen-meta-export]
|
||||
[COMMAND-CHAR (setup:command-char source-path)])
|
||||
#'(#%module-begin
|
||||
DIRECTORY-REQUIRE-FILES
|
||||
(splicing-syntax-parameterize
|
||||
([doc (make-rename-transformer #'DOC-ID)]
|
||||
[metas (make-rename-transformer #'METAS-ID)]
|
||||
[result (make-rename-transformer #'RESULT-ID)])
|
||||
(define result
|
||||
(parameterize ([current-pagetree (make-project-pagetree (current-project-root))]
|
||||
[current-metas (cached-metas SOURCE-PATH-STRING)])
|
||||
(define doc (cached-doc SOURCE-PATH-STRING))
|
||||
(define metas (current-metas))
|
||||
(define here (path->pagenode
|
||||
(or (select-from-metas pollen-here-path-key metas) 'unknown)))
|
||||
(if (bytes? doc) ; if main export is binary, just pass it through
|
||||
doc
|
||||
;; allows `require` in a template
|
||||
(splicing-let-syntax ([require (make-rename-transformer #'local-require)])
|
||||
(include-template #:command-char COMMAND-CHAR (file TEMPLATE-PATH-STRING))))))
|
||||
(provide result)))))]))
|
@ -1,35 +1,43 @@
|
||||
#lang racket/base
|
||||
(require pollen/setup scribble/reader racket/pretty version/utils racket/port racket/string)
|
||||
(provide (all-defined-out))
|
||||
(require pollen/setup
|
||||
scribble/reader
|
||||
racket/pretty
|
||||
version/utils
|
||||
racket/port
|
||||
racket/string
|
||||
txexpr/base)
|
||||
|
||||
(provide show configure current-top-path)
|
||||
|
||||
(define current-top-path (make-parameter #f))
|
||||
|
||||
(define (my-pretty-print x)
|
||||
;; #:newline option for `pretty-print` was introduced in 6.6.0.3
|
||||
(if (version<? (version) "6.7")
|
||||
;; so trim trailing newline manually in earlier versions
|
||||
(display (string-trim #:left? #f (with-output-to-string (λ () (pretty-print x))) "\n"))
|
||||
(pretty-print #:newline? #f x)))
|
||||
|
||||
(define (my-error-handler exn)
|
||||
(error '|pollen markup error| (string-join (cdr (string-split (exn-message exn) ": ")) ": ")))
|
||||
|
||||
(define (show doc parser-mode here-path)
|
||||
;; we only want the top doc to print in the runtime environment
|
||||
;; otherwise if a Pollen source imports others, they will all print their docs in sequence.
|
||||
;; so only print if the current here-path is the top path, which is stored in the `current-top-path` parameter.
|
||||
(let ([ctp (current-top-path)])
|
||||
(when (and ctp (equal? here-path ctp))
|
||||
(if (memq parser-mode (list default-mode-preproc default-mode-template))
|
||||
(display doc)
|
||||
;; #:newline option for `pretty-print` was introduced in 6.6.0.3,
|
||||
;; so trim trailing newline manually
|
||||
(let ([pretty-print-proc (if (version<? (version) "6.7")
|
||||
(λ (x) (display (string-trim #:left? #f (with-output-to-string (λ () (pretty-print x))) "\n")))
|
||||
(λ (x) (pretty-print #:newline? #f x)))])
|
||||
;; OK to use dynamic-require because runtime-config itself is dynamic-required
|
||||
(pretty-print-proc (with-handlers ([exn:fail? (λ (exn) ((error '|pollen markup error|
|
||||
((dynamic-require 'racket/string 'string-join) (cdr ((dynamic-require 'racket/string 'string-split) (exn-message exn) ": ")) ": "))))])
|
||||
((dynamic-require 'txexpr/base 'validate-txexpr) doc))))))))
|
||||
(when (equal? here-path (current-top-path))
|
||||
(if (memq parser-mode (list default-mode-preproc default-mode-template))
|
||||
(display doc)
|
||||
(with-handlers ([exn:fail? my-error-handler])
|
||||
(my-pretty-print (validate-txexpr doc))))))
|
||||
|
||||
(define (configure top-here-path)
|
||||
(current-top-path top-here-path) ;; puts `show` into the right mode
|
||||
|
||||
;; wrap REPL interactions with pollen expression support
|
||||
(current-top-path top-here-path) ; puts `show` into the right mode
|
||||
(define old-read (current-read-interaction))
|
||||
(define pollen-readtable (make-at-readtable #:command-char (setup:command-char)))
|
||||
(define (new-read src in)
|
||||
(define (pollen-repl-read src in)
|
||||
;; wrap repl interactions with pollen expression support
|
||||
(define pollen-readtable (make-at-readtable #:command-char (setup:command-char)))
|
||||
(parameterize ([current-readtable pollen-readtable])
|
||||
(old-read src in)))
|
||||
(current-read-interaction new-read))
|
||||
(current-read-interaction pollen-repl-read))
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,32 @@
|
||||
#lang racket/base
|
||||
(require racket/match
|
||||
racket/list)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (split-metas x meta-key)
|
||||
(define (split-metas x [meta-key 'define-meta])
|
||||
(apply hasheq
|
||||
(let loop ([x (if (syntax? x) (syntax->datum x) x)])
|
||||
(cond
|
||||
[(list? x) (cond
|
||||
[(and (= (length x) 3) (eq? (car x) meta-key))
|
||||
(unless (symbol? (cadr x))
|
||||
(raise-argument-error 'define-meta "valid meta key" (cadr x)))
|
||||
(cdr x)] ; list with meta key and meta value
|
||||
[else (apply append (map loop x))])]
|
||||
[else null]))))
|
||||
|
||||
(let loop ([x ((if (syntax? x) syntax->datum values) x)])
|
||||
(match x
|
||||
[(list (== meta-key eq?) kvs ...)
|
||||
(unless (>= (length kvs) 2)
|
||||
(raise-argument-error meta-key "at least one key-value pair" kvs))
|
||||
(unless (even? (length kvs))
|
||||
(raise-argument-error meta-key "equal number of keys and values" kvs))
|
||||
(for ([(key idx) (in-indexed kvs)]
|
||||
#:when (even? idx))
|
||||
(unless (symbol? key)
|
||||
(raise-argument-error meta-key "valid meta key" key)))
|
||||
kvs]
|
||||
[(? list? xs) (append-map loop xs)]
|
||||
[_ null]))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (split-metas 'root 'define-meta) (hasheq))
|
||||
(check-equal? (split-metas '(root) 'define-meta) (hasheq))
|
||||
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta 42 "bar")) 'define-meta)))
|
||||
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo "bar") "hi") "zim" (define-meta foo "boing") "zam") 'define-meta) '#hasheq((foo . "boing")))
|
||||
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo 'bar) "hi") "zim" (define-meta foo 'boing) "zam") 'define-meta) '#hasheq((foo . 'boing)))
|
||||
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (define-meta dog "Lex")) 'define-meta) '#hasheq((dog . "Lex")))
|
||||
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (div (define-meta dog "Lex"))) 'define-meta) '#hasheq((dog . "Lex"))))
|
||||
(check-equal? (split-metas 'root) (hasheq))
|
||||
(check-equal? (split-metas '(root)) (hasheq))
|
||||
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta 42 "bar")))))
|
||||
(check-exn exn:fail:contract? (λ () (split-metas '(root (define-meta foo "bar" zim)))))
|
||||
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo "bar") "hi") "zim" (define-meta foo "boing") "zam")) '#hasheq((foo . "boing")))
|
||||
(check-equal? (split-metas '(root (div #:kw #f (define-meta foo 'bar) "hi") "zim" (define-meta foo 'boing) "zam")) '#hasheq((foo . 'boing)))
|
||||
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (define-meta dog "Lex"))) '#hasheq((dog . "Lex")))
|
||||
(check-equal? (split-metas #'(root (define-meta dog "Roxy") (div (define-meta dog "Lex")))) '#hasheq((dog . "Lex"))))
|
@ -1 +1 @@
|
||||
1537996006
|
||||
1710316839
|
||||
|
@ -1,10 +0,0 @@
|
||||
#lang racket/base
|
||||
(require racket/runtime-path racket/file pollen/private/version)
|
||||
|
||||
(define-runtime-path info-file "../../info.rkt")
|
||||
|
||||
(module+ main
|
||||
(define str (file->string info-file))
|
||||
(define newstr
|
||||
(regexp-replace #rx"\\(define version .*?\\)" str (format "(define version ~v)" pollen:version-strict)))
|
||||
(display-to-file newstr info-file #:exists 'replace))
|
@ -1,34 +1,29 @@
|
||||
#lang racket/base
|
||||
(require racket/match)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (whitespace-base x #:nbsp-is-white? nbsp-white?)
|
||||
(define pat (pregexp (format "^[\\s~a]+$" (if nbsp-white? #\u00A0 ""))))
|
||||
(and (let loop ([x x])
|
||||
(cond
|
||||
[(string? x) (or (zero? (string-length x)) (regexp-match pat x))] ; empty string is deemed whitespace
|
||||
[(symbol? x) (loop (symbol->string x))]
|
||||
[(pair? x) (andmap loop x)]
|
||||
[(vector? x) (loop (vector->list x))]
|
||||
[else #f]))
|
||||
#t))
|
||||
(define white-pat (pregexp (format "^[\\s~a]+$" (if nbsp-white? #\u00A0 ""))))
|
||||
(let loop ([x x])
|
||||
(match x
|
||||
["" #true] ; empty string is deemed whitespace
|
||||
[(pregexp white-pat) #true]
|
||||
[(? symbol?) (loop (symbol->string x))]
|
||||
[(? pair?) (andmap loop x)]
|
||||
[(? vector?) (loop (vector->list x))]
|
||||
[_ #false])))
|
||||
|
||||
(define (whitespace? x) (whitespace-base x #:nbsp-is-white? #f))
|
||||
|
||||
(define (whitespace? x)
|
||||
(whitespace-base x #:nbsp-is-white? #f))
|
||||
|
||||
|
||||
(define not-whitespace? (λ (x) (not (whitespace? x))))
|
||||
|
||||
|
||||
(define (whitespace/nbsp? x)
|
||||
(whitespace-base x #:nbsp-is-white? #t))
|
||||
(define (not-whitespace? x) (not (whitespace? x)))
|
||||
|
||||
(define (whitespace/nbsp? x) (whitespace-base x #:nbsp-is-white? #t))
|
||||
|
||||
(module+ test
|
||||
(require rackunit racket/format)
|
||||
(check-true (whitespace? " "))
|
||||
(check-false (whitespace? (~a #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (~a #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (vector (~a #\u00A0))))
|
||||
(check-false (whitespace? (format " ~a " #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (format " ~a " #\u00A0))))
|
||||
(require rackunit racket/format)
|
||||
(check-true (whitespace? " "))
|
||||
(check-false (whitespace? (~a #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (~a #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (vector (~a #\u00A0))))
|
||||
(check-false (whitespace? (format " ~a " #\u00A0)))
|
||||
(check-true (whitespace/nbsp? (format " ~a " #\u00A0))))
|
@ -0,0 +1,20 @@
|
||||
\newcommand{\terminal}[1]{#1}
|
||||
\newcommand{\browser}[1]{#1}
|
||||
\newcommand{\foreignCode}[1]{#1}
|
||||
|
||||
\newenvironment{fileblock}{}{}
|
||||
|
||||
\definecolor{fileboxborder}{gray}{0.5}
|
||||
\definecolor{fileboxbackground}{gray}{0.9}
|
||||
\definecolor{noskipbackground}{gray}{0.5}
|
||||
\definecolor{noskipforeground}{gray}{1}
|
||||
|
||||
\newcommand{\fileblockFiletitle}[1]{\fcolorbox{fileboxborder}{fileboxbackground}{\makebox[\textwidth][r]{#1}}}
|
||||
\newcommand{\fileblockFilename}[1]{#1}
|
||||
|
||||
\newenvironment{fileblockFilecontent}{}{}
|
||||
|
||||
\newenvironment{noskip}{}{}
|
||||
|
||||
% pdflatex chokes on emoji. Use ∇ in place of the guitar in setup.scrbl
|
||||
\DeclareUnicodeCharacter{1F3B8}{$\nabla$}
|
@ -1,44 +0,0 @@
|
||||
#lang scribble/manual
|
||||
|
||||
@title{Getting more help}
|
||||
|
||||
|
||||
@section{Bugs and feature requests}
|
||||
|
||||
Can be submitted as @link["https://github.com/mbutterick/pollen/issues"]{GitHub issues}.
|
||||
|
||||
@section{Mailing list}
|
||||
|
||||
For general tips and how-to questions, use the @link["https://groups.google.com/forum/#!forum/pollenpub"]{Pollen discussion group} at @link["mailto:pollenpub@googlegroups.com"]{pollenpub@"@"googlegroups.com}. I'll also use that list to post major changes and new features.
|
||||
|
||||
@section{Utilities & libraries}
|
||||
|
||||
@link["https://github.com/malcolmstill/pollen-count"]{pollen-count}: enumeration and cross-referencing library by Malcolm Still
|
||||
|
||||
@link["https://github.com/lijunsong/pollen-mode"]{pollen-mode}: Emacs mode for Pollen by Junsong Li
|
||||
|
||||
@link["https://github.com/basus/pollen-mode"]{Pollen mode}: Emacs mode for Pollen by Shrutarshi Basu
|
||||
|
||||
@link["https://docs.racket-lang.org/pollen-component/"]{Pollen Component}: Component-based development for Pollen by Leandro Facchinetti
|
||||
|
||||
@link["https://docs.racket-lang.org/css-expr/"]{CSS-expressions}: S-expression-based CSS by Leandro Facchinetti
|
||||
|
||||
@link["https://github.com/lijunsong/pollen-rock"]{Pollen Rock}: rendering server and an in-browser editor for Pollen
|
||||
|
||||
|
||||
@section{Can I see the source for Practical Typography or Typography for Lawyers?}
|
||||
|
||||
Yes, the source for @link["http://typographyforlawyers.com/"]{Typography for Lawyers} is available. In terms of content, TFL was originally the basis of Practical Typography. But in terms of code, this new TFL website is essentially a clone of Practical Typography, but rewritten to be clearer and more instructive, with extensive source comments. [@link["https://github.com/mbutterick/pollen-tfl"]{source}]
|
||||
|
||||
@section{More projects & guides}
|
||||
|
||||
|
||||
@link["http://mstill.io"]{mstill.io blog} by Malcolm Still [@link["https://github.com/malcolmstill/mstill.io"]{source}]
|
||||
|
||||
@link["https://thelocalyarn.com/excursus/secretary"]{Secretary of Foreign Relations} by Joel Dueck [@link["https://github.com/otherjoel/try-pollen"]{source}]
|
||||
|
||||
@link["https://github.com/fasiha/pollen-guide"]{A Poor Guide to Pollen} by Ahmed Fasih
|
||||
|
||||
@link["https://youtu.be/20GGVNBykaw"]{The World's Most Dangerous Racket Programmer} and @link["https://youtu.be/IMz09jYOgoc"]{Like a Blind Squirrel in a Ferrari}: short talks about Pollen that I gave at RacketCons 2013 and 2014, respectively.
|
||||
|
||||
@link["https://www.leafac.com/"]{Leandro Facchinetti's personal website} [@link["https://github.com/leafac/www.leafac.com/tree/pollen"]{source}]
|
@ -1,170 +0,0 @@
|
||||
// Common functionality for PLT documentation pages
|
||||
|
||||
// Page Parameters ------------------------------------------------------------
|
||||
|
||||
var page_query_string = location.search.substring(1);
|
||||
|
||||
var page_args =
|
||||
((function(){
|
||||
if (!page_query_string) return [];
|
||||
var args = page_query_string.split(/[&;]/);
|
||||
for (var i=0; i<args.length; i++) {
|
||||
var a = args[i];
|
||||
var p = a.indexOf('=');
|
||||
if (p >= 0) args[i] = [a.substring(0,p), a.substring(p+1)];
|
||||
else args[i] = [a, false];
|
||||
}
|
||||
return args;
|
||||
})());
|
||||
|
||||
function GetPageArg(key, def) {
|
||||
for (var i=0; i<page_args.length; i++)
|
||||
if (page_args[i][0] == key) return decodeURIComponent(page_args[i][1]);
|
||||
return def;
|
||||
}
|
||||
|
||||
function MergePageArgsIntoLink(a) {
|
||||
if (page_args.length == 0 ||
|
||||
(!a.attributes["data-pltdoc"]) || (a.attributes["data-pltdoc"].value == ""))
|
||||
return;
|
||||
a.href = MergePageArgsIntoUrl(a.href);
|
||||
}
|
||||
|
||||
function MergePageArgsIntoUrl(href) {
|
||||
var mtch = href.match(/^([^?#]*)(?:\?([^#]*))?(#.*)?$/);
|
||||
if (mtch == undefined) { // I think this never happens
|
||||
return "?" + page_query_string;
|
||||
}
|
||||
if (!mtch[2]) {
|
||||
return mtch[1] + "?" + page_query_string + (mtch[3] || "");
|
||||
}
|
||||
// need to merge here, precedence to arguments that exist in `a'
|
||||
var i, j;
|
||||
var prefix = mtch[1], str = mtch[2] || "", suffix = mtch[3] || "";
|
||||
var args = str.split(/[&;]/);
|
||||
for (i=0; i<args.length; i++) {
|
||||
j = args[i].indexOf('=');
|
||||
if (j) args[i] = args[i].substring(0,j);
|
||||
}
|
||||
var additions = "";
|
||||
for (i=0; i<page_args.length; i++) {
|
||||
var exists = false;
|
||||
for (j=0; j<args.length; j++)
|
||||
if (args[j] == page_args[i][0]) { exists = true; break; }
|
||||
if (!exists) str += "&" + page_args[i][0] + "=" + page_args[i][1];
|
||||
}
|
||||
return prefix + "?" + str + suffix;
|
||||
}
|
||||
|
||||
// Cookies --------------------------------------------------------------------
|
||||
|
||||
// Actually, try localStorage (a la HTML 5), first.
|
||||
|
||||
function GetCookie(key, def) {
|
||||
try {
|
||||
var v = localStorage[key];
|
||||
if (!v) v = def;
|
||||
return v;
|
||||
} catch (e) {
|
||||
var i, cookiestrs;
|
||||
try {
|
||||
if (document.cookie.length <= 0) return def;
|
||||
cookiestrs = document.cookie.split(/; */);
|
||||
} catch (e) { return def; }
|
||||
for (i = 0; i < cookiestrs.length; i++) {
|
||||
var cur = cookiestrs[i];
|
||||
var eql = cur.indexOf('=');
|
||||
if (eql >= 0 && cur.substring(0,eql) == key)
|
||||
return unescape(cur.substring(eql+1));
|
||||
}
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
function SetCookie(key, val) {
|
||||
try {
|
||||
localStorage[key] = val;
|
||||
} catch(e) {
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime()+(365*24*60*60*1000));
|
||||
try {
|
||||
document.cookie =
|
||||
key + "=" + escape(val) + "; expires="+ d.toGMTString() + "; path=/";
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
// note that this always stores a directory name, ending with a "/"
|
||||
function SetPLTRoot(ver, relative) {
|
||||
var root = location.protocol + "//" + location.host
|
||||
+ NormalizePath(location.pathname.replace(/[^\/]*$/, relative));
|
||||
SetCookie("PLT_Root."+ver, root);
|
||||
}
|
||||
|
||||
// adding index.html works because of the above
|
||||
function GotoPLTRoot(ver, relative) {
|
||||
var u = GetCookie("PLT_Root."+ver, null);
|
||||
if (u == null) return true; // no cookie: use plain up link
|
||||
// the relative path is optional, default goes to the toplevel start page
|
||||
if (!relative) relative = "index.html";
|
||||
location = u + relative;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Utilities ------------------------------------------------------------------
|
||||
|
||||
var normalize_rxs = [/\/\/+/g, /\/\.(\/|$)/, /\/[^\/]*\/\.\.(\/|$)/];
|
||||
function NormalizePath(path) {
|
||||
var tmp, i;
|
||||
for (i = 0; i < normalize_rxs.length; i++)
|
||||
while ((tmp = path.replace(normalize_rxs[i], "/")) != path) path = tmp;
|
||||
return path;
|
||||
}
|
||||
|
||||
// `noscript' is problematic in some browsers (always renders as a
|
||||
// block), use this hack instead (does not always work!)
|
||||
// document.write("<style>mynoscript { display:none; }</style>");
|
||||
|
||||
// Interactions ---------------------------------------------------------------
|
||||
|
||||
function DoSearchKey(event, field, ver, top_path) {
|
||||
var val = field.value;
|
||||
if (event && event.keyCode == 13) {
|
||||
var u = GetCookie("PLT_Root."+ver, null);
|
||||
if (u == null) u = top_path; // default: go to the top path
|
||||
u += "search/index.html?q=" + encodeURIComponent(val);
|
||||
u = MergePageArgsIntoUrl(u);
|
||||
location = u;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function TocviewToggle(glyph, id) {
|
||||
var s = document.getElementById(id).style;
|
||||
var expand = s.display == "none";
|
||||
s.display = expand ? "block" : "none";
|
||||
glyph.innerHTML = expand ? "▼" : "►";
|
||||
}
|
||||
|
||||
// Page Init ------------------------------------------------------------------
|
||||
|
||||
// Note: could make a function that inspects and uses window.onload to chain to
|
||||
// a previous one, but this file needs to be required first anyway, since it
|
||||
// contains utilities for all other files.
|
||||
var on_load_funcs = [];
|
||||
function AddOnLoad(fun) { on_load_funcs.push(fun); }
|
||||
window.onload = function() {
|
||||
for (var i=0; i<on_load_funcs.length; i++) on_load_funcs[i]();
|
||||
};
|
||||
|
||||
AddOnLoad(function(){
|
||||
var links = document.getElementsByTagName("a");
|
||||
for (var i=0; i<links.length; i++) MergePageArgsIntoLink(links[i]);
|
||||
var label = GetPageArg("ctxtname",false);
|
||||
if (!label) return;
|
||||
var indicator = document.getElementById("contextindicator");
|
||||
if (!indicator) return;
|
||||
indicator.innerHTML = label;
|
||||
indicator.style.display = "block";
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
#lang pollen
|
||||
|
||||
this is bar
|
@ -0,0 +1,3 @@
|
||||
#lang pollen
|
||||
|
||||
this is foo
|
@ -0,0 +1,4 @@
|
||||
#lang pollen/ptree
|
||||
|
||||
foo.txt
|
||||
bar.txt
|
Binary file not shown.
After Width: | Height: | Size: 95 B |
@ -0,0 +1 @@
|
||||
◊doc
|
@ -0,0 +1,3 @@
|
||||
#lang pollen
|
||||
◊(require racket/file)
|
||||
◊(file->bytes "pixel.png")
|
@ -0,0 +1,5 @@
|
||||
#lang racket/base
|
||||
|
||||
(module setup racket/base
|
||||
(provide poly-targets)
|
||||
(define poly-targets '(html txt)))
|
@ -0,0 +1,3 @@
|
||||
#lang pollen
|
||||
|
||||
hello world
|
@ -1,2 +1,2 @@
|
||||
◊(local-require racket/list)
|
||||
◊(require racket/list)
|
||||
◊(apply string-append (filter string? (flatten doc)))
|
@ -0,0 +1,3 @@
|
||||
#lang pollen
|
||||
|
||||
Hello!
|
@ -0,0 +1,6 @@
|
||||
#lang racket/base
|
||||
|
||||
(module setup racket/base
|
||||
(provide (all-defined-out))
|
||||
(define project-server-port
|
||||
9876))
|
@ -1,2 +1,2 @@
|
||||
◊(local-require racket/list)
|
||||
◊(require racket/list)
|
||||
◊(apply string-append (filter string? (flatten doc)))
|
@ -0,0 +1,7 @@
|
||||
#lang racket/base
|
||||
(require pollen/setup)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(module setup racket/base
|
||||
(provide (all-defined-out))
|
||||
(define trim-whitespace? #false))
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue