Skip to content

Instantly share code, notes, and snippets.

@honewatson
Last active October 8, 2016 11:15
Show Gist options
  • Select an option

  • Save honewatson/d1341011767707e60fd655ae313fab43 to your computer and use it in GitHub Desktop.

Select an option

Save honewatson/d1341011767707e60fd655ae313fab43 to your computer and use it in GitHub Desktop.
Basic Moon App
lapis = require "lapis"
db = require "lapis.db"
html = require "lapis.html"
queries = require "queries"
config = require("lapis.config").get!
import get_redis from require "lapis.redis"
import notNil from require "utils"
main = require "components.main"
get_set_redis = (widget) =>
key = widget.key @req
content = @redis\get key
unless notNil content
@query = widget.query
@view = widget.html
content = @view @query!
@redis\set key, content
return content
class App extends lapis.Application
@before_filter =>
@redis = get_redis!
@get_set_redis = get_set_redis
@db = db
[index: "/"]: =>
content = @get_set_redis main
{
layout: false,
content
}
queries = require "queries"
html = require "lapis.html"
import render_html from require "lapis.html"
import notNil from require "utils"
key = () =>
@req.parsed_url.path
query = () =>
@mainResults = db.query(query(queries.main, @blog_id), 0, 40)
html = () =>
render_html ->
div class: "body", ->
for post in *@mainResults
div ->
h2 post.post_title
h3 post.post_excerpt
post.post_read_more
export { :key, :query, :html }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment