Skip to content

Commit

Permalink
Made a Resource object
Browse files Browse the repository at this point in the history
  • Loading branch information
LeifW committed May 29, 2010
1 parent 634b6a5 commit 4becd8c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Expand Up @@ -3,7 +3,7 @@
project.name=musicpath
project.organization=org.musicpath
sbt.version=0.7.4
project.version=0.1
project.version=0.2
def.scala.version=2.7.7
build.scala.versions=2.7.7
project.initialize=false
39 changes: 38 additions & 1 deletion src/main/scala/org/musicpath/MusicPath.scala
Expand Up @@ -13,6 +13,42 @@ import Scene._ // Predicates in musicpath ontolo
// This class mostly defines routes. A couple view helpers are factored out into the "View" object.
class MusicPath extends Step {

def ref(thing:Res):String = thing.jResource.getLocalName
def instruments(stint:Node) = for (instr <- stint/plays) yield <instr ref={ref(instr asRes)}>{instr/(RDFS^"label")}</instr>

val people = new Resource("person", "people", FOAF.Person, person=>
<person ref={ref(person)}>
<name>{person/FOAF.givenname}</name>
<plays>{
for (stint <- person/performs) yield
<stint>
<in ref={ref(stint/in/asRes)}>{stint/in/FOAF.name}</in>
{instruments(stint)}
</stint>
}</plays>
</person>)

val bands = new Resource("band", MO.MusicGroup, band=>
<band ref={ref(band)}>
<name>{band/FOAF.name}</name>
<members>{
for (stint <- band/position) yield
<member ref={ref(stint/by/asRes)}>
<name>{stint/by/FOAF.givenname}</name>
{instruments(stint)}
</member>
}</members>
</band>)

//val resources = List(people, bands)

for (res <- List(people)) {
get("/"+res.plural+"/?")(<root title={res.plural}>{allOf(res.rdfType) map res.view}</root>)
get("/"+res.plural+"/:id")(res view Res(res.plural+"/"+params(":id")))
}



// Blank string return value for null params
// override protected def params = super.params withDefaultValue ""

Expand Down Expand Up @@ -110,13 +146,14 @@ class MusicPath extends Step {
/* -- People URL's -- */

// Display all the people in the system.
get("/people/?") { template(
/* get("/people/?") { template(
<people title="People">{ allOf(FOAF.Person) map View.person }</people>
)}
get("/people/:person") { template(
View person Res("people/"+params(":person"))
)}
*/

get("/people/:person/xml") {
View person Res("people/"+params(":person"))
Expand Down
22 changes: 22 additions & 0 deletions src/main/scala/org/musicpath/Resource.scala
@@ -0,0 +1,22 @@
package org.musicpath

import net.croz.scardf.Res // Jena wrapper
import scala.xml.Node

class Resource(val singular:String, val plural:String, val rdfType:Res, val view:(Res)=>Node) {

def this(singular:String, rdfType:Res, view:(Res)=>Node) = this(singular, singular+"s", rdfType, view)
/*
def viewAll
def view
if res/RDF.Type isEmpty
edit
def edit
private def appearance
*/
}

// vim: set ts=4 sw=4 et:

0 comments on commit 4becd8c

Please sign in to comment.