Encoding fun...
What happens if someone puts in a URL? The framework should translate the special characters, but it is the blog software itself that should translate it into a clickable link.
Of course, that doesn't mean I can't make a function to turn URLs into links automatically (and do other post-entry formatting of blog post text) and include it in Rockets...
http://arstechnica.com/science/2012/09/curiosity-rolls-on-as-instrument-checkout-continues-on-mars/
Views: 6588
Today's function turned out to be well suited for a macro. (create-record) takes a couple of arguments. The first is a string which holds the name of the table you are updating. The rest is kind of cool. You put in a bunch of variable names--any number is fine--and what you do is make the variable name the same as the FIELD name in your table. Then the macro takes the names and values of these variables and constructs a valid SQL statement (after filtering each value for SQL injection issues)
So, for example, to add a post in this blog, I just have to write:(create-record "Posts" Id PosterId PostDate PostSubject PostContent)
and it generates a valid SQLite query to insert the values into the field names that are the variables Id, PosterId, etc.
The magic comes from newLISPs (sym) function, which converts a string into a valid symbol, and the (args) feature of newLISP macros, which allow a dynamic number of arguments to be passed to the macro.
Here's the code that converts the variable names into symbols:
(dolist (s (rest (args)))
(set 'temp-index-num (string 'idx)) ; we need to number the symbols to keep them in the correct order
(if (= (length temp-index-num) 1) (set 'temp-index-num (string "0" temp-index-num))) ; leading 0 keeps the max at 100.
(sym (string temp-index-num s) 'DB))
Views: 5558
Wow, this is kind of historic! This is the very first post on the newLISP on Rockets blog. Right now Rockets is barely functional (version 0.04!) but it's just enough to host itself and handle input to forms and connect to a SQLite 3 database.
It's nothing earth-shattering so far, but I want to start "eating my own dogfood" as it were, so this blog will be running on Rockets from the very beginning. As I add features, I'll post about them in the blog.
Views: 5275