Skip to content

Commit

Permalink
Fork scriplet support into its own library
Browse files Browse the repository at this point in the history
In github.com/tliron/go-scriptlet
  • Loading branch information
tliron committed Nov 30, 2023
1 parent 37510a9 commit 8a53c97
Show file tree
Hide file tree
Showing 134 changed files with 3,380 additions and 5,841 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dist/
work/

go.work
go.work.sum
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ Prudence

An opinionated lightweight web framework built for scale, featuring integrated
[RESTful](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm) server-side and
client-side caching. Write your code in JavaScript, TypeScript, or Go. Suitable for frontend user
interfaces and backend APIs.
client-side caching. Suitable for frontend user interfaces, backend APIs, and full-stack combos.

Write your code in Go, JavaScript, TypeScript, or a combination of them. Choose the best programming
language per need. Balance performance and productivity.

Prudence is distributed as a Go library, as well as a single, compact, customizable executable file with
no external dependencies.

Prudence is distributed as a single, compact, customizable executable file with no external dependencies.
And it's fun! Through rigorous benchmarks conducted in our good-times laboratory we found Prudence to be
a zillion times more fun than competing products from leading brand names.

Expand All @@ -21,15 +25,15 @@ a zillion times more fun than competing products from leading brand names.
Highlights
----------

* A triple-phase representation process allows for composable, fine-grained, associative control over
server-side and client-side caching. Reap the full benefits of idempotency in RESTful network
architectures.
* Prudence's core is written in compiled Go for reliability and performance but allows for interpreted
JavaScript or TypeScript for your application. This is the right balance between power and productivity.
* Or use [JavaScript Templates (JST)](jst/README.md) to generate HTML by combining design with short
* Structure your code as a routable hierarchy of apps, resources, facets, and representations.
* Maximize efficiency via a triple-phase representation process allowing for composable, fine-grained,
associative control over server-side and client-side caching.
* Rich, embedded support for content negotiation according to format, language, and compression algorithms.
* Ue JavaScript Templates (JST) to generate HTML and other textual formats by combining design with short
code scriptlets. And there's sugar.
* Pluggable server-side cache backends, such as the included Kuberentes-aware distributed memory cache.
* Pluggable server-side cache backends, such as the included Kubernetes-aware distributed memory cache.
Or choose backends for [Memcached](https://memcached.org/), [Redis](https://redis.io/), etc.
Or create a tiered cache combining several backends.
* Schedule jobs using a crontab-like pattern.
* [Extensible](platform/README.md) via the [xprudence tool](xprudence/README.md), which allows you
to create custom builds of Prudence bundled with the plugins and APIs you need. Even when extended in
Expand All @@ -43,7 +47,7 @@ Documentation
* [Caching guide](CACHING.md)
* [Examples](examples/README.md)
* [JavaScript/TypeScript API](https://prudence.threecrickets.com/assets/typescript/prudence/docs/)
* [JavaScript Templates (JST)](jst/README.md)
* [JavaScript Templates (JST)](https://github.com/tliron/go-scriptlet/blob/main/jst/README.md)
* [Renderers](render/README.md)
* [Extension guide](platform/README.md)
* [xprudence](xprudence/README.md)
Expand Down
19 changes: 10 additions & 9 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ To see it in the terminal:
### NCSA

To enable an [NCSA Common log](https://en.wikipedia.org/wiki/Common_Log_Format) run Prudence
with the `--ncsa` flag. You can give it a path to a log file or the special values "stdout"
or "stderr":
with the `--ncsa` flag. You can give it a path to a log file:

prudence run start.js --ncsa=/var/log/ncsa.log -v

Expand All @@ -89,6 +88,8 @@ the `--ncsa` filename:
ncsaLogFilePrefix: 'main-'
}));

Note that if you're logging to `/dev/` (e.g. `/dev/stderr`) then the prefix is ignored.

We have a server running. Now, let's add an application!


Expand Down Expand Up @@ -169,9 +170,9 @@ a.k.a. URL rewriting:
name: 'myapp',
routes: [{
handler: function(context) {
const p = context.path.indexOf('/product/');
const p = context.request.path.indexOf('/product/');
if (p != -1) {
context.redirect('https://supplier.com/?product=' + context.path.substr(p+9), 301);
context.redirect('https://supplier.com/?product=' + context.request.path.substr(p+9), 301);
return true;
} else {
return false;
Expand Down Expand Up @@ -205,9 +206,9 @@ file and "bind" it, like so:
The `rewrite.js` file:

exports.handler = function(context) {
const p = context.path.indexOf('/product/');
const p = context.request.path.indexOf('/product/');
if (p != -1) {
context.redirect('https://supplier.com/?product=' + context.path.substr(p+9), 301);
context.redirect('https://supplier.com/?product=' + context.request.path.substr(p+9), 301);
return true;
} else {
return false;
Expand Down Expand Up @@ -236,11 +237,11 @@ will have have to wait in line to be handled.

Note that you do not have to use "bind" for Prudence's built-in types, such as "Resource" and
"Router". It is only necessary for JavaScript code. Still, it's good practice to use "bind" for all
handlers.
handlers to avoid problems.

One consequence of "bind" is that it creates a new execution environment for the bound code. Bound
code will thus not share the same JavaScript globals as other code. To get around this divide you
can use "prudence.globals", which are truly global.
can use "env.variables", which are truly global.

Writing code for a multi-threaded environment is not trivial. You might need to rely on
synchronization techniques for accessing shared data, for example a mutex created by calling
Expand Down Expand Up @@ -456,7 +457,7 @@ Though not required, it's often a good idea with PUT to return the modified repr
essentially what we see in the next GET. So it might make sense to just call "present". Example:

exports.modify = function(context) {
if (mydb.update(context.variables.name) == 'new') {
if (mydb.update(context.variables.name) === 'new') {
context.created = true;
}
context.done = true;
Expand Down
Loading

0 comments on commit 8a53c97

Please sign in to comment.