graph-common
Version:
Open Graph API core js lib
198 lines (137 loc) • 7.32 kB
HTML
<html>
<head>
<title>gql.litcoffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="bootstrap.html">
bootstrap.litcoffee
</a>
<a class="source" href="configuration_manager.html">
configuration_manager.litcoffee
</a>
<a class="source" href="echo_router.html">
echo_router.litcoffee
</a>
<a class="source" href="gql.html">
gql.litcoffee
</a>
<a class="source" href="graph.html">
graph.litcoffee
</a>
<a class="source" href="index.html">
index.litcoffee
</a>
<a class="source" href="mongodb_storage.html">
mongodb_storage.litcoffee
</a>
<a class="source" href="node_manager.html">
node_manager.litcoffee
</a>
<a class="source" href="node_schema.html">
node_schema.litcoffee
</a>
<a class="source" href="query.html">
query.litcoffee
</a>
<a class="source" href="redirect_router.html">
redirect_router.litcoffee
</a>
<a class="source" href="router_manager.html">
router_manager.litcoffee
</a>
<a class="source" href="router_schema.html">
router_schema.litcoffee
</a>
<a class="source" href="schema_manager.html">
schema_manager.litcoffee
</a>
<a class="source" href="schema_schema.html">
schema_schema.litcoffee
</a>
<a class="source" href="static_router.html">
static_router.litcoffee
</a>
<a class="source" href="storage_manager.html">
storage_manager.litcoffee
</a>
<a class="source" href="storage_router.html">
storage_router.litcoffee
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>gql.litcoffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<p>GQL can read GQL text and parse it to Graph API queries</p>
</div>
<div class="content"><div class='highlight'><pre>Query = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./query'</span>)
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GQL</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">()</span> -></span>
<span class="hljs-property">@parse</span>: <span class="hljs-function"><span class="hljs-params">(script, callback)</span> -></span>
queries = []
lines = script.split(<span class="hljs-string">"\n"</span>)
lines.forEach<span class="hljs-function"><span class="hljs-params">((line) ->
queries.push(GQL.parse_line(line, callback))
)</span>
<span class="hljs-title">return</span> <span class="hljs-title">queries</span>
@<span class="hljs-title">parse_line</span>: <span class="hljs-params">(line, callback)</span> -></span>
query = <span class="hljs-literal">null</span>
node = <span class="hljs-literal">null</span>
GQL.parse_node<span class="hljs-function"><span class="hljs-params">(line, (parsed, rest) ->
node = parsed
line = rest
)</span>
<span class="hljs-title">action</span> = <span class="hljs-title">null</span>
<span class="hljs-title">GQL</span>.<span class="hljs-title">parse_action</span><span class="hljs-params">(line, (parsed, rest) ->
action = parsed
line = rest
)</span>
<span class="hljs-title">data</span> = <span class="hljs-title">line</span>.<span class="hljs-title">trim</span><span class="hljs-params">()</span>
<span class="hljs-title">query</span> = <span class="hljs-title">new</span> <span class="hljs-title">Query</span><span class="hljs-params">(node, action, data)</span>
<span class="hljs-title">callback</span><span class="hljs-params">(query)</span> <span class="hljs-title">if</span> <span class="hljs-title">callback</span>
<span class="hljs-title">return</span> <span class="hljs-title">query</span>
@<span class="hljs-title">parse_node</span>: <span class="hljs-params">(line, callback)</span> -></span>
line.replace(<span class="hljs-regexp">/^\s+/</span>, <span class="hljs-string">''</span>)
splitted = line.split(<span class="hljs-string">' '</span>)
path = splitted.shift()
rest = splitted.join(<span class="hljs-string">' '</span>)
callback(path, rest)
<span class="hljs-keyword">return</span> path
<span class="hljs-property">@parse_action</span>: <span class="hljs-function"><span class="hljs-params">(line, callback)</span> -></span>
line.replace(<span class="hljs-regexp">/^\s+/</span>, <span class="hljs-string">''</span>)
splitted = line.split(<span class="hljs-string">' '</span>)
action = splitted.shift().toLowerCase()
<span class="hljs-keyword">if</span> action <span class="hljs-keyword">in</span> [<span class="hljs-string">'create'</span>, <span class="hljs-string">'read'</span>, <span class="hljs-string">'update'</span>, <span class="hljs-string">'delete'</span>]
rest = splitted.join(<span class="hljs-string">' '</span>)
<span class="hljs-keyword">else</span>
action = <span class="hljs-string">'read'</span>
rest = line
callback(action, rest)
<span class="hljs-keyword">return</span> action
<span class="hljs-built_in">module</span>.<span class="hljs-built_in">exports</span> = GQL</pre></div></div>
</li>
</ul>
</div>
</body>
</html>