oBloq literate programming tool
oBloq isn't finished. I am working to add support for visually testing layouts and modules, a tool for watching files and rebuilding them as needed, and a server for distributed editing of the oBloq files. It's already handy for creating documentation and extracting the files needed to build an app. Soon it will also support concatenating and compressing the resulting files for production, as well as control over how the files are build (building different production files for editing than for viewers, for instance). Development is progressing quickly and I am currently seeking feedback on the ideas captured in oBloq.
About the name
oBloq was developed around the idea of "card-based programming," which is that most web sites and web applications have roughly modular, often rectangular types of content which can be designed and assembled as components. These are then, "bloqs." Also, it reminds me of the great Dr. Seuss book on web programming, "Bartholemew and the Ooblek."
How to use oBloq
Once you've forked the project and cloned a local copy there are a few things to know to get started.
Most of the magic comes from code blocks in the markdown files. Each code block expects to have the first line in the format:
followed by a blank line, then the contents of the expected file. This line is used for creating files, for triggering post-processing (stylus -> css, markdown -> html). Currently supported extensions are .html, .css, .js, .markdown, .md (same as .markdown), .stylus, .mustache, and .coffee. The filename part is usually the same as the markdown filename that is being processed, but it doesn't have to be. All the markdown files in the .bloqs directory will be processed at once and all the code blocks with the same filename will be concatenated. Code blocks containing markdown files will be processed and concatenated with html content with the same base filename. Likewise .stylus will be processed and concatenated with .css, and .coffee will be processed and concatenated with .js.
Beside Node and NPM, node modules needed are coffee-script, markdown, mustache, stylus, and nib.
File organization and the Extract command
When you run extract it looks for a folder named "bloqs" in the current directory, then searches that folder recursively for markdown files (*.md or *.markdown). Extracted files are put into a "build" directory. HTML files for documentation are built for each markdown file found, and are placed in matching subdirectories (so a bloqs/sub/folder/file.md will end up in build/sub/folder/file.html). Files extracted from code blocks are not organized hierchically, but put in the build directory directly.
Currently you have to edit the index.html document to create links to the generated documents in the build directory (by adding hash tags based on the examples given). At some point it would be nice to autogenerate those.
Code blocks whose file extension is .sketch are preserved and converted in-browser. Other types are formatted in-browser for syntax highlighting, but .sketch blocks are converted to line drawings using Raphael.js and a plugin for Raphael called Sketchy.js. Sketchy lets you draw line which are rough and resemble hand-drawn (and not with a particularly steady hand) and is still in development in parallel with oBloq, but the commands recognized in oBloq at the time of writing this are below. Arguments x, y, w, and h are all assumed to be integers, text is any string following them. Text strings do not have to be quoted. The offset of strings is a little wonky, that's something I'm looking into. Comments are not supported by the sketchy syntax, but #comments below are used to describe the results.
size w h # REQUIRED, sets the size of the canvas to sketch into. I plan to make this calculated from the sketch commands at some point. line x1 y1 x2 y2 # draws a line from the point x1 y2 to the point x2 y2 arrow x1 y1 x2 y2 # like line, but puts an arrowhead at x2 y2 rect x y w h text # draws a rectangle with its upper-left-hand corner at x y and the dimensions w h. The text argument is optional and will be centered in the rectangle. img x y w h # draws a rect with an x across it, to represent an image ellipse x y w h text # draws an ellipse inside the rect described by x y w h, optionally with text centered in the ellipse crossellipse x y w h # draws an ellipse, and a cross inside it. Useful for things like close buttons fatarrowright x y w h # draws an outlined arrow to fit inside the rect defined by x y w h fatarrowleft x y w h fatarrowdown x y w h fatarrowup x y w h triangleright x y w h # draws a triangle pointing right, useful for disclosure triangles triangleleft x y w h triangledown x y w h triangleup x y w h text x y text # draws text centered on x y in the "dadhand" handwriting font ltext x y text # draws text left justified starting at x y rtext x y text # draws text right justified and ending at x y avatar x y w h # draws a rectangle with a very rough sketch of a person. Needs work.
There is no specific support, but oBloq can be used to document Ajax paths, URL patterns, Events generated or listened for, APIs, permissions, reasons for hacks and work-arounds, problems encountered, etc. Essentially, all development-related documentation (and most code) should be able to be fit into readable oBloq documents. I haven't used it for server-side development yet, but see no overwhelming reason not to do so (especially if the server uses Node.js). For any documentation which does not fit into a language that oBloq supports, it can kept in plain Markdown, or oBloq can be extended to support the language
- Allow raw HTML, CSS, JS files to be in bloqs directory?
- Build an editor based on CodeMirror (http://codemirror.net/doc/manual.html)
- Minimized and compress concatenated files for production (side-effect of moving to Grunt)
- Support coffeescript on server-side (side-effect of multiple targets, better specificity)
- More example code
- Comment extracted code to show where it was extracted from, for tracing back to source file
- Code clean up and commenting
- Allow mustache placeholders to be used in markdown for template generation (*.mushdown?)
- Include useful snippets of HTML, CSS, JS to be assembled as standard components (with commentary on use)
- Componentization - use x-tag (http://csuwldcat.github.com/x-tag/) or Enyo (http://enyojs.com/) to help define bloqs?
- Build list of classes used and in which bloqs (need to parse html templates)
- Build list of IDs used and in which bloqs (ditto)
- Build list of events emitted and in which bloqs (need to parse JS: use Escrima?)
- Build list of events listened for and in which bloqs (ditto)
- Build list of functions defined and in which bloqs (ditto)
- Build list of functions called? (ditto)
- Syntax highlighting (stylus was missing)
- Validate / lint / hint all files (side effect of moving to Grunt)
- Build visual tests into the docs, including tools to check with various data (for overflow), state (loggged in?), and block size (for responsive design). Seeing the visual tests update while you're in the oBloq editor would be pretty nifty.
- Fix offset of text in sketchy
- Different units for sketches (grid-based?)
- Convert sketchy to build dom objects for layout where applicable
- Determine sketch size automatically from content (this would avoid the need to give room for sketchy lines to overflow, done manually now
- Reduce the "nudge" factor in small sketches
- Smoothing: keep each point's nudge factor within 2px of last nudge
- Make sketch components clickable links to docs for those items (interpage linking)
- New component: rich text
- New component: text
- New component: tab view
- New component: social noise
- New component: video player
- √ Sketches not showing up
- √ Allow user configuration for which files get concatenated, minimized, and compressed and in what order (side-effect of Grunt)
- √ Generate links to documentation automatically
- √ Have default filename targets
- √ Make client vs. server code explicit rather than a naming convention. Default to both?
- √ Allow alternate filename targets in comments
- √ Convert to be an extension of Grunt (https://github.com/cowboy/grunt) (mainly the code extraction from markdown)
- √ Allow multiple filename targets
- √ Watch command to re-run extraction whenever a source file is changed
- √ Package as a Node module
- √ Gather all extracted *.js and *.css files into concatenated files
- √ Include files global.stylus (deferred: or bloqs/global/*.stylus) when processing other stylus files (for definitions of site-wide variables for things like colours and fonts)
- √ Include files global.markdown (deferred: or bloqs/global/*.markdown) when processing other markdown files (for link definitions)