0.0.179 • Published 5 months ago

study-lenses v0.0.179

Weekly downloads
271
License
MIT
Repository
github
Last release
5 months ago

Study Lenses

a tool to add new perspectives and layers of interactivity on top of existing code. Explore a live demo right here, learn more about the ideas behind Study Lenses right here


Getting Started

To Explore the Test Content

  1. $ npm install
  2. $ npm run test-content

To Explore Anything on your Computer

If you would like to this server with files from your computer that are not in /test-content you will need to install it as a global dependency.

  1. git clone the repo
  2. cd study-lenses into repo
  3. npm install -g .
    • installing this repository as a global dependency will let you test your changes in realtime
  4. npm run test-content

If everything looks good, and you see study-lenses running on your browser, you are good to go!

One last check: stop the tool by pressing Ctrl+C on the terminal. Now visit any other folder through your terminal (e.g. cd to another folder) and run either the study or lenses global command and check whether the study-lenses loads the current directory's content in the browser.


UPI

This tool has a URL Parameter Interface, the student controls how they view and study their code by modifying the URL parameters when requesting a resource. At it's base, this is just a static server. requesting a path inside the folder you have studyed will send the raw content. however ...

URL params can be used to modify the resource before it is sent. once you have a directory open in your browser using $ study, navigate to a file and add ?hello-world to the end of the URL and refreshing. You can find the source code for this lens in ./src/lenses/hello-world. (This is a Lens. There is another type of URL parameter called an Option that will be covered in more detail later.)

To see lenses in action, open the /test-content ($ npm run test-content) directory as indicated in Getting Started and try pasting in these url extensions and refreshing:

  • /README.md
    • /README.md - no lens, the markdown source is returned as-is
    • /README.md?hello-world - the markdown will be rendered into a textarea in an HTML file
    • /README.md?hello-world=1234 - the markdown will be rendered into a textarea in an HTML file, with the value 1234 passed as a query
    • /README.md?render - the markdown will be rendered to HTML using marked, it will now be a web page
    • /README.md?render&hello-world - like the previous hello-world, but with the rendered HTML code instead of the raw markdown
  • /messy-code/file.css
    • /messy-code/file.css
    • /messy-code/file.css?highlight
    • /messy-code/file.css?format
    • /messy-code/file.css?format&highlight
    • /messy-code/file.css?hello-world
    • /messy-code/file.css?format&hello-world
  • /languages/file.js
    • /languages/file.js?highlight
    • /languages/file.js?flowchart
    • /languages/file.js?review
    • /languages/file.js?study

There are a lot of different lenses, and they sometimes will compose in unhelpful or unexpected ways. it's also not very student-friendly to be adjusting params all the time. so ...

The server comes with a default lenses ?hyf that opens a directory as a navigable folder structure. Each subdirectory and file is a link that opens with a sane default lens so students won't need to understand how to use params or read lens guides to get started. Here are a few of the defaults:

  • .html files will open without a lens, as a live website (study is just an augmented static server. import/export, local fetch calls, it all works! )
  • .js files open up in a monaco editor with configurable study options.
  • .json files open as colored and collapsible data
  • ...

--help

Adding --help anywhere in your query (ie. /path/file.js?hyf&--help) will send a guide to how you can use this tool including:

  • the general idea
  • a list of all lenses and links to their user guides
  • a list of all options and links to their user guides

Plugins

There are two types of plugins, head over to DOCS for full details. here's a quick summary:

Lenses

lenses are functions that process the requested resource before the final HTTP response is generated. They exist to change the way a student sees or interacts with a given resource while in the browser. Lenses can be composed to create a variety of study experiences, some examples:

  • /file.js will send the raw js code
  • /file.js?format will format the code before sending it (in case the source file is messy)
  • /file.js?format&highlight will format the code, then render it into an HTML file using Prism (or other) for highlighted code in the browser

The most basic lens could just be a function that reverses the text stored in the file.

Options

Options are inspired by cli conventions. Option arguments are passed the same way as lenses: as a URL parameter. They are similar to lenses but fall "outside" the normal control flow, they are filtered out of the params and evaluated before the resource is processed by lenses.

In contrast to lenses, an option can end the request/response cycle early if indicated in their return value, ie. --help will send user documentation regardless of where it is placed in the URL, what other lenses were requested, or what the resource path is.

Options can also return hooks that are called at different points in the lens pipeline process. Hooks cannot modify the content or HTTP response without immediately ending the cycle. For example, the --debug option return hooks that log each stage of the lens pipeline for diagnosis without modifying the behavior of the pipeline (useful for lens developers and especially curious students). More on this in the DOCS


Deploying

besides local studying, this module should be equipped for deployment. it should probably support at least these ways:

  • normal deployment on a server. (not a problem, should work as-is)
  • deployment on a service like netlify functions or aws lambdas, configurable with github actions and npm scripts (i think this is possible because the server is stateless and just reads/modifies files from directory)

Source Walk-Through

also, the docs

Head over to ./bin/index.js and follow the comments for a guided walk-through of the code base. Some files will contain a comment at the bottom indicating which files to read next. If nothing is mentioned, you can take abstractions at face value unless you're the curious type.

If you're a little curious, but not too curious, there's this:

|- bin
| |- index.js -- entry point for the global cli
|
|- config -- global configuration files
|
|- lenses
| |- index.js -- parses and loads the lenses
| |- lens-name -- each lens is stored in it's own folder
|   |- static -- (optional) for own static assets if the lens renders a web page
|   |- index.js -- entry point to the lens
|   |- README.md -- describe your lens, including specs for other lens authors to compose
|   |- user-guide.md -- a student-friendly guide, dynamically included by the `--lenses` option
|
|- options
|  |- index.js -- parses and loads the options
|  |- --option-name -- each option is stored in it's own folder
|    |- static -- (optional) for own static assets if the option renders a web page
|    |- index.js -- entry point to the option
|    |- README.md -- describe your option, including specs
|    |- user-guide.md -- a student-friendly guide, dynamically included by the `--options` option
|
|- server
| |- index.js -- entry point for the server, uses /handle-request
| |- handle-request
|   |- lib
|   |- index.js -- reads the requested resource, executes options, pipes the resource+lenses and responds
|   |- (go there to see the rest in detail)
|
|- static -- shared static resources (monaco editor, parsons library, mermaid, prism, ...)
|
|- test-content -- a whole bunch of code and markdown for testing out lenses

Known Bugs

0.0.179

5 months ago

0.0.177

6 months ago

0.0.176

6 months ago

0.0.175

9 months ago

0.0.174

10 months ago

0.0.173

10 months ago

0.0.172

10 months ago

0.0.171

11 months ago

0.0.159

1 year ago

0.0.169

1 year ago

0.0.164

1 year ago

0.0.163

1 year ago

0.0.162

1 year ago

0.0.161

1 year ago

0.0.168

1 year ago

0.0.167

1 year ago

0.0.166

1 year ago

0.0.165

1 year ago

0.0.160

1 year ago

0.0.170

1 year ago

0.0.158

1 year ago

0.0.157

2 years ago

0.0.156

2 years ago

0.0.155

2 years ago

0.0.154

2 years ago

0.0.153

2 years ago

0.0.152

2 years ago

0.0.151

2 years ago

0.0.150

2 years ago

0.0.149

2 years ago

0.0.148

2 years ago

0.0.147

2 years ago

0.0.146

2 years ago

0.0.142

2 years ago

0.0.145

2 years ago

0.0.144

2 years ago

0.0.143

2 years ago

0.0.141

2 years ago

0.0.128

2 years ago

0.0.125

2 years ago

0.0.129

2 years ago

0.0.120

2 years ago

0.0.123

2 years ago

0.0.122

2 years ago

0.0.121

2 years ago

0.0.139

2 years ago

0.0.138

2 years ago

0.0.137

2 years ago

0.0.136

2 years ago

0.0.131

2 years ago

0.0.130

2 years ago

0.0.134

2 years ago

0.0.133

2 years ago

0.0.132

2 years ago

0.0.140

2 years ago

0.0.117

2 years ago

0.0.116

2 years ago

0.0.119

2 years ago

0.0.118

2 years ago

0.0.115

2 years ago

0.0.114

3 years ago

0.0.113

3 years ago

0.0.112

3 years ago

0.0.111

3 years ago

0.0.109

3 years ago

0.0.110

3 years ago

0.0.108

3 years ago

0.0.107

3 years ago

0.0.106

3 years ago

0.0.105

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.100

3 years ago

0.0.99

3 years ago

0.0.98

3 years ago

0.0.97

3 years ago

0.0.95

3 years ago

0.0.96

3 years ago

0.0.92

3 years ago

0.0.93

3 years ago

0.0.94

3 years ago

0.0.84

3 years ago

0.0.85

3 years ago

0.0.86

3 years ago

0.0.87

3 years ago

0.0.88

3 years ago

0.0.89

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.83

3 years ago

0.0.90

3 years ago

0.0.91

3 years ago

0.0.80

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.75

3 years ago

0.0.74

3 years ago

0.0.73

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.70

3 years ago

0.0.69

3 years ago

0.0.64

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.63

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

3 years ago

0.0.58

3 years ago

0.0.57

3 years ago

0.0.56

3 years ago

0.0.55

3 years ago

0.0.54

3 years ago

0.0.53

3 years ago

0.0.52

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.47

3 years ago

0.0.48

3 years ago

0.0.44

3 years ago

0.0.45

3 years ago

0.0.46

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.40

3 years ago

0.0.38

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.35

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.32

3 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago