Skip to content

Commit

Permalink
Merge branch 'fd-structured-change-descriptions'
Browse files Browse the repository at this point in the history
  • Loading branch information
fd committed Feb 25, 2013
2 parents 34f1b37 + 3b5da7c commit ea41ec2
Show file tree
Hide file tree
Showing 62 changed files with 2,938 additions and 5,252 deletions.
41 changes: 24 additions & 17 deletions example/blog.sx
Expand Up @@ -16,27 +16,34 @@ type (
)

var (
posts = make(table[string]Post)
a *api.API
Posts = make(table[int]Post)
ByDate = Posts.sort(publish_date)
LongTitle = Posts.select(long_title)
)

// API Endpoints:
// GET blog/posts
var API *api.API

func init() {
runtime.Void(posts.select(func(p Post) bool {
if len(p.Title) > len("Hello World (10)") {
return true
}
/*panic("hello")*/
return false
}))

//runtime.Dump(posts)

a = api.New(runtime.Env, "blog")
a.RegisterTable(posts)
a.RegisterView(posts.sort(publish_date), "posts")
runtime.Void(LongTitle)

//runtime.Dump(ByDate)

API = api.New(runtime.Env, "blog")
API.RegisterTable(Posts)
API.RegisterView(ByDate, "posts")
}

func publish_date(m Post) int64 {
func publish_date(m Post) uint64 {
i := m.PublishedAt.Unix()
return 9223372036854775807 - i
return 18446744073709551615 - (uint64(9223372036854775808) + uint64(i))
}

func long_title(p Post) bool {
if len(p.Title) > len("Hello World (10)") {
return true
}
/*panic("hello")*/
return false
}
51 changes: 51 additions & 0 deletions example/cms_posts.sx.html
@@ -0,0 +1,51 @@

document PostIndex(posts view[]Post) {
route: /blog

<ul>
{{# posts.collect(frag(post Post)<<) }}
<li data-id={{ post.Id }}>
<a href="/blog/posts/show/{{ post.Id }}">{{ post.Title }}</a>
</li>
{{/ collect }}
</ul>
}

document PostShow(post Post) {
route: blog/{{ post.Id }}
route: /blog/{{ UrlFormattedDate(post.PublishedAt) }}/{{ Slug(post.Title) }}
route: ://example.com/blog-post-{{ Slug(post.Title) }}
X-Feed-Published: {{ post.PublishedAt }}

{{# Layout("Blog - " + post.Title, frag()<<) }}

<h1>{{ post.Title }}</h1>
<em class="meta">{{ post.Author }}</em>
{{ post.Body }}

{{# if post.AcceptsComments }}
{{ PostComments(CommentsForPosts[post.Id].select(accepted_comment)) }}
{{/ if }}

{{/ end }}
}

frag PostComments(comments view[]Comment) {
<ul>
{{# comments.collect(frag(c Comment)<<) }}
<li>
<h2>{{ c.Title }}</h2>
{{ c.Body }}
</li>
{{/ end }}
</ul>
}

frag Layout(title string, content frag()) {
<html>
<head>
<title>{{ title }}</title>
</head>
<body>{{ content() }}</body>
</html>
}
42 changes: 0 additions & 42 deletions example/example.sx

This file was deleted.

18 changes: 11 additions & 7 deletions example/main.sx
Expand Up @@ -2,23 +2,27 @@ package main

import (
"fmt"
"os"
"simplex.sh/cas/redis"
"simplex.sh/net/http"
"simplex.sh/runtime"
"time"
)

func init() {
}

func main() {
fmt.Printf("Version: %s\n", SxVersion)

// add redis store
runtime.Env.Store = redis.New("", 0, "")
{ // add redis store
addr := ""
if port := os.Getenv("BOXEN_REDIS_PORT"); port != "" {
addr = "tcp:localhost:" + port
}
runtime.Env.Store = redis.New(addr, 0, "")
}

// register blog api
h := http.New(":3000")
h.Handle("/blog/", a)
h.Handle("/blog/", API)
runtime.Env.RegisterService(h)

go func() {
Expand All @@ -27,7 +31,7 @@ func main() {
txn := runtime.NewTransaction(runtime.Env)
now := time.Now()
for i := 0; i < 5000; i++ {
txn.Set(posts, i, Post{
txn.Set(Posts, i, Post{
Title: fmt.Sprintf("Hello world (%d)", i),
PublishedAt: now,
})
Expand Down
28 changes: 28 additions & 0 deletions lang/ast/ast.go
Expand Up @@ -991,3 +991,31 @@ type Package struct {

func (p *Package) Pos() token.Pos { return token.NoPos }
func (p *Package) End() token.Pos { return token.NoPos }

// ----------------------------------------------------------------------------
// Simplex Views and Tables

type (

// A ViewType node represents a view type.
ViewType struct {
View token.Pos // position of "view" keyword
Key Expr // primary key type or nil
Value Expr
}

// A TableType node represents a table type.
TableType struct {
Table token.Pos // position of "table" keyword
Key Expr // primary key type
Value Expr
}
)

func (x *ViewType) Pos() token.Pos { return x.View }
func (x *ViewType) End() token.Pos { return x.Value.End() }
func (*ViewType) exprNode() {}

func (x *TableType) Pos() token.Pos { return x.Table }
func (x *TableType) End() token.Pos { return x.Value.End() }
func (*TableType) exprNode() {}
32 changes: 0 additions & 32 deletions lang/ast/ast_sx.go

This file was deleted.

17 changes: 15 additions & 2 deletions lang/ast/filter.go
Expand Up @@ -123,7 +123,6 @@ func filterParamList(fields *FieldList, filter Filter, export bool) bool {
return b
}

/*Simplex
func filterType(typ Expr, f Filter, export bool) bool {
switch t := typ.(type) {
case *Ident:
Expand Down Expand Up @@ -152,10 +151,24 @@ func filterType(typ Expr, f Filter, export bool) bool {
return b1 || b2
case *ChanType:
return filterType(t.Value, f, export)

//=== start Simplex
case *ViewType:
if t.Key == nil {
return filterType(t.Value, f, export)
}
b1 := filterType(t.Key, f, export)
b2 := filterType(t.Value, f, export)
return b1 || b2
case *TableType:
b1 := filterType(t.Key, f, export)
b2 := filterType(t.Value, f, export)
return b1 || b2
//=== end Simplex

}
return false
}
*/

func filterSpec(spec Spec, f Filter, export bool) bool {
switch s := spec.(type) {
Expand Down
49 changes: 0 additions & 49 deletions lang/ast/filter_sx.go

This file was deleted.

9 changes: 2 additions & 7 deletions lang/cmd/sxdoc/appinit.go
Expand Up @@ -17,12 +17,9 @@ import (
)

func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path!
w.WriteHeader(http.StatusNotFound)
servePage(w, Page{
Title: "File " + relpath,
Subtitle: relpath,
Body: applyTemplate(errorHTML, "errorHTML", err), // err may contain an absolute path!
})
servePage(w, relpath, "File "+relpath, "", "", contents)
}

func init() {
Expand All @@ -37,7 +34,6 @@ func init() {
*indexFiles = indexFilenames
*maxResults = 100 // reduce latency by limiting the number of fulltext search results
*indexThrottle = 0.3 // in case *indexFiles is empty (and thus the indexer is run)
*showPlayground = true

// read .zip file and set up file systems
const zipfile = zipFilename
Expand All @@ -52,7 +48,6 @@ func init() {
readTemplates()
initHandlers()
registerPublicHandlers(http.DefaultServeMux)
registerPlaygroundHandlers(http.DefaultServeMux)

// initialize default directory tree with corresponding timestamp.
initFSTree()
Expand Down
13 changes: 4 additions & 9 deletions lang/cmd/sxdoc/codewalk.go
Expand Up @@ -68,11 +68,8 @@ func codewalk(w http.ResponseWriter, r *http.Request) {
return
}

servePage(w, Page{
Title: "Codewalk: " + cw.Title,
Tabtitle: cw.Title,
Body: applyTemplate(codewalkHTML, "codewalk", cw),
})
b := applyTemplate(codewalkHTML, "codewalk", cw)
servePage(w, cw.Title, "Codewalk: "+cw.Title, "", "", b)
}

// A Codewalk represents a single codewalk read from an XML file.
Expand Down Expand Up @@ -202,10 +199,8 @@ func codewalkDir(w http.ResponseWriter, r *http.Request, relpath, abspath string
}
}

servePage(w, Page{
Title: "Codewalks",
Body: applyTemplate(codewalkdirHTML, "codewalkdir", v),
})
b := applyTemplate(codewalkdirHTML, "codewalkdir", v)
servePage(w, "", "Codewalks", "", "", b)
}

// codewalkFileprint serves requests with ?fileprint=f&lo=lo&hi=hi.
Expand Down

0 comments on commit ea41ec2

Please sign in to comment.