Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 876b1a8d8e3ef5b132dd788a6e9488db74622a32 @MSNexploder committed Aug 13, 2011
6 .gitignore
@@ -0,0 +1,6 @@
+.DS_Store
+.npm
+node_modules/
+build/
+html/
+lib/
3 CHANGELOG.md
@@ -0,0 +1,3 @@
+## 0.1.0 (13th August, 2011)
+
+ * Initial release
189 Cakefile
@@ -0,0 +1,189 @@
+# shamelessly taken from Zombie
+
+fs = require("fs")
+path = require("path")
+{spawn, exec} = require("child_process")
+stdout = process.stdout
+
+# Use executables installed with npm bundle.
+process.env["PATH"] = "node_modules/.bin:#{process.env["PATH"]}"
+
+# ANSI Terminal Colors.
+bold = "\033[0;1m"
+red = "\033[0;31m"
+green = "\033[0;32m"
+reset = "\033[0m"
+
+# Log a message with a color.
+log = (message, color, explanation) ->
+ console.log color + message + reset + ' ' + (explanation or '')
+
+# Handle error and kill the process.
+onerror = (err) ->
+ if err
+ process.stdout.write "#{red}#{err.stack}#{reset}\n"
+ process.exit -1
+
+
+## Setup ##
+
+# Setup development dependencies, not part of runtime dependencies.
+task "setup", "Install development dependencies", ->
+ fs.readFile "package.json", "utf8", (err, package) ->
+ #log "Need runtime dependencies, installing into node_modules ...", green
+ #exec "npm bundle", onerror
+
+ log "Need development dependencies, installing ...", green
+ for name, version of JSON.parse(package).devDependencies
+ log "Installing #{name} #{version}", green
+ exec "npm bundle install \"#{name}@#{version}\"", onerror
+
+task "install", "Install coffee-conf in your local repository", ->
+ build (err) ->
+ onerror err
+ generateMan (err) ->
+ onerror err
+ log "Installing coffee-conf ...", green
+ exec "npm install", (err, stdout, stderr) ->
+ process.stdout.write stderr
+ onerror err
+
+
+## Building ##
+
+build = (callback) ->
+ log "Compiling CoffeeScript to JavaScript ...", green
+ exec "rm -rf lib && coffee -c -l -b -o lib src", callback
+task "build", "Compile CoffeeScript to JavaScript", -> build onerror
+
+task "watch", "Continously compile CoffeeScript to JavaScript", ->
+ cmd = spawn("coffee", ["-c", "-l", "-b", "-w", "-o", "lib", "src"])
+ cmd.stdout.on "data", (data) -> process.stdout.write green + data + reset
+ cmd.on "error", onerror
+
+
+clean = (callback) ->
+ exec "rm -rf html lib docs", callback
+task "clean", "Remove temporary files and such", -> clean onerror
+
+
+## Testing ##
+
+runTests = (callback) ->
+ log "Running test suite ...", green
+ exec "find spec -name '*-spec.coffee' -print | xargs vows", (err, stdout, stderr) ->
+ process.stdout.write stdout
+ process.binding('stdio').writeError stderr
+ callback err if callback
+task "test", "Run all tests", ->
+ runTests (err) ->
+ process.stdout.on "drain", -> process.exit -1 if err
+
+
+## Documentation ##
+
+# Markdown to HTML.
+#toHTML = (source, callback) ->
+# target = "html/#{path.basename(source, ".md").toLowerCase()}.html"
+# fs.readFile "doc/layout/main.html", "utf8", (err, layout) ->
+# onerror err
+# fs.readFile source, "utf8", (err, text) ->
+# onerror err
+# log "Creating #{target}", green
+# exec "ronn --html #{source}", (err, stdout, stderr) ->
+# onerror err
+# [name, title] = stdout.match(/<h1>(.*)<\/h1>/)[1].split(" -- ")
+# name = name.replace(/\(\d\)/, "")
+# body = stdout.replace(/<h1>.*<\/h1>/, "")
+# html = layout.replace("{{body}}", body).replace(/{{title}}/g, title)
+# fs.writeFile target, html, "utf8", (err) ->
+# callback err, target
+
+#documentPages = (callback) ->
+# files = fs.readdirSync(".").filter((file) -> path.extname(file) == ".md").
+# concat(fs.readdirSync("doc").filter((file) -> path.extname(file) == ".md").map((file) -> "doc/#{file}"))
+# fs.mkdir "html", 0777, ->
+# convert = ->
+# if file = files.pop()
+# toHTML file, (err) ->
+# onerror err
+# convert()
+# else
+# process.stdout.write "\n"
+# fs.readFile "html/readme.html", "utf8", (err, html) ->
+# html = html.replace(/<h1>(.*)<\/h1>/, "<h1>coffee-conf.js</h1><b>$1</b>")
+# fs.writeFile "html/index.html", html, "utf8", onerror
+# fs.unlink "html/readme.html", onerror
+# exec "cp -fr doc/css doc/images html/", callback
+# convert()
+
+documentSource = (callback) ->
+ log "Documenting source files ...", green
+ exec "docco src/coffee-conf/*.coffee", (err, stdout, stderr) ->
+ log stdout, green
+ onerror err
+ callback()
+ #log "Copying to html/source", green
+ #exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs", callback
+
+generateDocs = (callback) ->
+ log "Generating documentation ...", green
+ #documentPages (err) ->
+ # onerror err
+ # documentSource callback
+ documentSource callback
+
+#task "doc:pages", "Generate documentation for main pages", -> documentPages onerror
+task "doc:source", "Generate documentation from source files", -> documentSource onerror
+task "doc", "Generate all documentation", -> generateDocs onerror
+
+## Publishing ##
+
+#publishDocs = (callback) ->
+# log "Uploading documentation ...", green
+# exec "rsync -chr --del --stats html/ labnotes.org:/var/www/zombie/", (err, stdout, stderr) ->
+# log stdout, green
+# callback err
+#task "doc:publish", "Publish documentation to site", ->
+# documentPages (err) ->
+# onerror err
+# documentSource (err) ->
+# onerror err
+# generatePDF (err) ->
+# onerror err
+# publishDocs onerror
+
+task "publish", "Publish new version (Git, NPM, site)", ->
+ # Run tests, don't publish unless tests pass.
+ runTests (err) ->
+ onerror err
+ # Clean up temporary files and such, want to create everything from
+ # scratch, don't want generated files we no longer use, etc.
+ clean (err) ->
+ onerror err
+ exec "git push", (err) ->
+ onerror err
+ fs.readFile "package.json", "utf8", (err, package) ->
+ package = JSON.parse(package)
+
+ # Publish documentation, need these first to generate man pages,
+ # inclusion on NPM package.
+ generateDocs (err) ->
+ onerror err
+
+ log "Publishing to NPM ...", green
+ build (err) ->
+ onerror err
+ exec "npm publish", (err, stdout, stderr) ->
+ log stdout, green
+ onerror err
+
+ # Create a tag for this version and push changes to Github.
+ log "Tagging v#{package.version} ...", green
+ exec "git tag v#{package.version}", (err, stdout, stderr) ->
+ log stdout, green
+ exec "git push --tags origin master", (err, stdout, stderr) ->
+ log stdout, green
+
+ # We can do this in parallel.
+ #publishDocs onerror
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Stefan Huber
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 README.md
@@ -0,0 +1,37 @@
+## Install
+
+ npm install coffee-conf
+
+## Documentation
+
+[Documentation](http://msnexploder.github.com/coffee-conf)
+
+## Usage
+
+ config.runFile 'config.coffee'
+ # given file is executed using default locals and context.
+
+ config.runFile 'config.coffee', { foo: => bar }
+ # given file is executed using given locals.
+
+ config.runFile 'config.coffee', {}, { foo: => bar }
+ # given file is executed using given locals and context.
+
+## Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Commit, do not mess with cakefile, package.json, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+## License
+
+(The MIT License)
+
+Copyright © 2011 Stefan Huber
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 docs/config.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html> <html> <head> <title>config.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="config.html"> config.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="version.html"> version.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> config.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s1">&#39;fs&#39;</span>
+<span class="nv">path = </span><span class="nx">require</span> <span class="s1">&#39;path&#39;</span>
+<span class="nv">coffee = </span><span class="nx">require</span> <span class="s1">&#39;coffee-script&#39;</span>
+
+<span class="k">class</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Config</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Creates new config reader.
+Given locals and context are passed down to the executed code.</p>
+
+<p>locals are available as top-level objects.
+The context is available as <code>this</code>.
+Basic top-level objects like <code>require</code>, <code>process</code> or <code>console</code> are passed in automatically.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">constructor: </span><span class="nf">(@locals = {}, @context = {}) -&gt;</span>
+ <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="nx">default_locals</span>
+ <span class="nx">@locals</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">value</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Executes file at given path
+Returns result of executed coffee code.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">runFile: </span><span class="nf">(file) -&gt;</span>
+ <span class="vi">@locals.__filename = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">(),</span> <span class="nx">file</span><span class="p">)</span>
+ <span class="vi">@locals.__dirname = </span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()</span>
+ <span class="vi">@locals.module.filename = </span><span class="nx">@locals</span><span class="p">.</span><span class="nx">__filename</span>
+ <span class="nv">code = </span><span class="nx">@readAndCompile</span> <span class="nx">file</span>
+ <span class="nx">@run</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Executes given code.
+Returns result of executed coffee code.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">run: </span><span class="nf">(code) -&gt;</span> <span class="nx">@defineWith</span> <span class="nx">code</span>
+
+ <span class="nv">readAndCompile: </span><span class="nf">(file) -&gt;</span>
+ <span class="nv">code = </span><span class="nx">@read</span> <span class="nx">file</span>
+ <span class="nx">coffee</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span>
+
+ <span class="nv">read: </span><span class="nf">(file) -&gt;</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">file</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span>
+
+ <span class="nv">defineWith: </span><span class="nf">(code) -&gt;</span>
+ <span class="nx">@scoped</span><span class="p">(</span><span class="nx">code</span><span class="p">)(</span><span class="nx">@context</span><span class="p">,</span> <span class="nx">@locals</span><span class="p">)</span>
+
+ <span class="nv">scoped: </span><span class="nf">(code) -&gt;</span>
+ <span class="nv">code = </span><span class="nb">String</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span>
+ <span class="nv">code = </span><span class="s2">&quot;function () {#{code}}&quot;</span> <span class="nx">unless</span> <span class="nx">code</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="o">is</span> <span class="mi">0</span>
+ <span class="nv">code = </span><span class="s2">&quot;#{coffeescript_support} with(locals) {return (#{code}).apply(context, args);}&quot;</span>
+ <span class="k">new</span> <span class="nb">Function</span><span class="p">(</span><span class="s1">&#39;context&#39;</span><span class="p">,</span> <span class="s1">&#39;locals&#39;</span><span class="p">,</span> <span class="s1">&#39;args&#39;</span><span class="p">,</span> <span class="nx">code</span><span class="p">)</span>
+
+<span class="nv">coffeescript_support = </span><span class="s2">&quot;&quot;&quot;</span>
+<span class="s2"> var __slice = Array.prototype.slice;</span>
+<span class="s2"> var __hasProp = Object.prototype.hasOwnProperty;</span>
+<span class="s2"> var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };</span>
+<span class="s2"> var __extends = function(child, parent) {</span>
+<span class="s2"> for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }</span>
+<span class="s2"> function ctor() { this.constructor = child; }</span>
+<span class="s2"> ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;</span>
+<span class="s2"> return child;</span>
+<span class="s2"> };</span>
+<span class="s2"> var __indexOf = Array.prototype.indexOf || function(item) {</span>
+<span class="s2"> for (var i = 0, l = this.length; i &lt; l; i++) {</span>
+<span class="s2"> if (this[i] === item) return i;</span>
+<span class="s2"> }</span>
+<span class="s2"> return -1;</span>
+<span class="s2"> };</span>
+<span class="s2">&quot;&quot;&quot;</span>
+
+<span class="nv">default_locals = </span><span class="p">{</span>
+ <span class="nv">require: </span><span class="nx">require</span>
+ <span class="nv">global: </span><span class="nx">global</span>
+ <span class="nv">process: </span><span class="nx">process</span>
+ <span class="nv">module: </span><span class="nx">module</span>
+ <span class="nv">console: </span><span class="nx">console</span>
+<span class="p">}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
186 docs/docco.css
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
37 docs/index.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html> <html> <head> <title>index.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="config.html"> config.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="version.html"> version.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> index.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>version information</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">version = </span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./version&#39;</span><span class="p">)</span>
+<span class="nv">exports.package = </span><span class="nx">version</span><span class="p">.</span><span class="nx">package</span>
+<span class="nv">exports.version = </span><span class="nx">version</span><span class="p">.</span><span class="nx">version</span>
+
+<span class="nv">exports.Config = </span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./config&#39;</span><span class="p">).</span><span class="nx">Config</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>convenience methods</p>
+
+<p>Executes file at given path.
+Optional specified locals and context are passed down into the executed code.
+Returns result of executed coffee code.</p>
+
+<h3>Examples</h3>
+
+<pre><code>config.runFile 'config.coffee'
+# given file is executed using default locals and context.
+config.runFile 'config.coffee', { foo: =&gt; bar }
+# given file is executed using given locals.
+config.runFile 'config.coffee', {}, { foo: =&gt; bar }
+# given file is executed using given locals and context.
+</code></pre> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.runFile = </span><span class="nf">(filename, locals = {}, context = {}) -&gt;</span>
+ <span class="nv">config = </span><span class="k">new</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Config</span><span class="p">(</span><span class="nx">locals</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span>
+ <span class="nx">config</span><span class="p">.</span><span class="nx">runFile</span> <span class="nx">filename</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Executes given code.
+Optional specified locals and context are passed down into the executed code.
+Returns result of executed coffee code.</p>
+
+<h3>Examples</h3>
+
+<pre><code>config.run 'return 1 + 1'
+# given code is executed using default locals and context.
+config.run 'foo()', { foo: =&gt; bar }
+# given code is executed using given locals.
+config.run 'this.foo()', {}, { foo: =&gt; bar }
+# given code is executed using given locals and context.
+</code></pre> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="nf">(code, locals = {}, context = {}) -&gt;</span>
+ <span class="nv">config = </span><span class="k">new</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Config</span><span class="p">(</span><span class="nx">locals</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span>
+ <span class="nx">config</span><span class="p">.</span><span class="nx">run</span> <span class="nx">code</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
4 docs/version.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html> <html> <head> <title>version.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="config.html"> config.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="version.html"> version.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> version.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>version information</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.package = </span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">require</span><span class="p">(</span><span class="s2">&quot;fs&quot;</span><span class="p">).</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s2">&quot;/../../package.json&quot;</span><span class="p">))</span>
+<span class="nv">exports.version = </span><span class="nx">exports</span><span class="p">.</span><span class="nx">package</span><span class="p">.</span><span class="nx">version</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
46 package.json
@@ -0,0 +1,46 @@
+{
+ "name": "coffee-conf",
+ "description": "Write your config files in coffee-script.",
+ "keywords": ["coffee-script", "config", "loading", "application"],
+ "version": "0.1.0",
+ "author": "Stefan Huber <MSNexploder@gmail.com>",
+ "homepage": "http://msnexploder.github.com/coffee-conf",
+ "main": "lib/coffee-conf",
+ "files": [
+ "Cakefile",
+ "CHANGELOG.md",
+ "doc",
+ "lib",
+ "LICENSE",
+ "README.md",
+ "spec",
+ "src"
+ ],
+ "scripts": {
+ "test": "cake test"
+ },
+ "directories": {
+ "doc":"./doc",
+ "lib":"./lib"
+ },
+ "engines": {
+ "node": ">= 0.4.x <= 0.5.3"
+ },
+ "dependencies": {
+ "coffee-script": ">= 1.1.2 < 2.0.0"
+ },
+ "devDependencies": {
+ "docco": ">= 0.3.0 < 0.4.0",
+ "vows": ">= 0.5.9 < 0.6.0"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/MSNexploder/coffee-conf.git"
+ },
+ "bugs": { "url": "https://github.com/MSNexploder/coffee-conf/issues" },
+ "licenses": [
+ { "type": "MIT",
+ "url": "https://github.com/MSNexploder/coffee-conf/raw/master/LICENSE"
+ }
+ ]
+}
88 spec/coffee-conf-spec.coffee
@@ -0,0 +1,88 @@
+conf = require('../src/coffee-conf')
+
+path = require('path')
+vows = require('vows')
+assert = require('assert')
+
+vows.describe('Coffee-conf').addBatch(
+ 'sets default locals': ->
+ config = new conf.Config
+ config.run "require\nglobal\nprocess\nmodule\nconsole"
+
+ assert.ok
+
+ 'uses given locals': ->
+ a = 0
+ locals = {
+ foo: => a++
+ }
+ config = new conf.Config(locals)
+ config.run "foo()"
+
+ assert.equal a, 1
+
+
+ 'added default locals to given locals': ->
+ locals = {
+ foo: => ""
+ }
+ config = new conf.Config(locals)
+ config.run "require\nglobal\nprocess\nmodule\nconsole\nfoo"
+
+ assert.ok
+
+ 'does not override given locals with default locals': ->
+ a = 0
+ locals = {
+ require: => a++
+ }
+ config = new conf.Config(locals)
+ config.run "require()"
+
+ assert.equal a, 1
+
+ 'returns result of given code': ->
+ config = new conf.Config
+ assert.equal config.run("return 1 + 1"), 2
+
+ 'uses given context': ->
+ a = 0
+ context = {
+ foo: => a++
+ }
+
+ config = new conf.Config({}, context)
+ config.run "this.foo()"
+
+ assert.equal a, 1
+
+ 'loads config from file': ->
+ a = 0
+ locals = {
+ foo: => a++
+ }
+ config = new conf.Config(locals)
+ config.runFile path.join(__dirname, 'test-config.coffee')
+
+ assert.equal a, 1
+
+ 'provides convenience method for running code': ->
+ a = 0
+ locals = {
+ foo: => a++
+ }
+ conf.run "foo()", locals
+
+ assert.equal a, 1
+
+ 'provides convenience method for executing file': ->
+ 'uses given context': ->
+ a = 0
+ context = {
+ foo: => a++
+ }
+ conf.runFile path.join(__dirname, 'test-config-this.coffee'), {}, context
+
+ assert.equal a, 1
+
+).export(module)
1 spec/test-config-this.coffee
@@ -0,0 +1 @@
+this.foo()
1 spec/test-config.coffee
@@ -0,0 +1 @@
+foo()
69 src/coffee-conf/config.coffee
@@ -0,0 +1,69 @@
+fs = require 'fs'
+path = require 'path'
+coffee = require 'coffee-script'
+
+class exports.Config
+
+ # Creates new config reader.
+ # Given locals and context are passed down to the executed code.
+ #
+ # locals are available as top-level objects.
+ # The context is available as `this`.
+ # Basic top-level objects like `require`, `process` or `console` are passed in automatically.
+ constructor: (@locals = {}, @context = {}) ->
+ for key, value of default_locals
+ @locals[key] ?= value
+
+ # Executes file at given path
+ # Returns result of executed coffee code.
+ runFile: (file) ->
+ @locals.__filename = path.join(process.cwd(), file)
+ @locals.__dirname = process.cwd()
+ @locals.module.filename = @locals.__filename
+ code = @readAndCompile file
+ @run code
+
+ # Executes given code.
+ # Returns result of executed coffee code.
+ run: (code) -> @defineWith code
+
+ readAndCompile: (file) ->
+ code = @read file
+ coffee.compile code
+
+ read: (file) -> fs.readFileSync file, 'utf8'
+
+ defineWith: (code) ->
+ @scoped(code)(@context, @locals)
+
+ scoped: (code) ->
+ code = String(code)
+ code = "function () {#{code}}" unless code.indexOf('function') is 0
+ code = "#{coffeescript_support} with(locals) {return (#{code}).apply(context, args);}"
+ new Function('context', 'locals', 'args', code)
+
+coffeescript_support = """
+ var __slice = Array.prototype.slice;
+ var __hasProp = Object.prototype.hasOwnProperty;
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ var __extends = function(child, parent) {
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
+ function ctor() { this.constructor = child; }
+ ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;
+ return child;
+ };
+ var __indexOf = Array.prototype.indexOf || function(item) {
+ for (var i = 0, l = this.length; i < l; i++) {
+ if (this[i] === item) return i;
+ }
+ return -1;
+ };
+"""
+
+default_locals = {
+ require: require
+ global: global
+ process: process
+ module: module
+ console: console
+}
38 src/coffee-conf/index.coffee
@@ -0,0 +1,38 @@
+# version information
+version = require('./version')
+exports.package = version.package
+exports.version = version.version
+
+exports.Config = require('./config').Config
+
+# convenience methods
+#
+# Executes file at given path.
+# Optional specified locals and context are passed down into the executed code.
+# Returns result of executed coffee code.
+#
+# ### Examples
+# config.runFile 'config.coffee'
+# # given file is executed using default locals and context.
+# config.runFile 'config.coffee', { foo: => bar }
+# # given file is executed using given locals.
+# config.runFile 'config.coffee', {}, { foo: => bar }
+# # given file is executed using given locals and context.
+exports.runFile = (filename, locals = {}, context = {}) ->
+ config = new exports.Config(locals, context)
+ config.runFile filename
+
+ # Executes given code.
+ # Optional specified locals and context are passed down into the executed code.
+ # Returns result of executed coffee code.
+ #
+ # ### Examples
+ # config.run 'return 1 + 1'
+ # # given code is executed using default locals and context.
+ # config.run 'foo()', { foo: => bar }
+ # # given code is executed using given locals.
+ # config.run 'this.foo()', {}, { foo: => bar }
+ # # given code is executed using given locals and context.
+exports.run = (code, locals = {}, context = {}) ->
+ config = new exports.Config(locals, context)
+ config.run code
3 src/coffee-conf/version.coffee
@@ -0,0 +1,3 @@
+# version information
+exports.package = JSON.parse(require("fs").readFileSync(__dirname + "/../../package.json"))
+exports.version = exports.package.version
1 src/index.coffee
@@ -0,0 +1 @@
+module.exports = require("./coffee-conf")

0 comments on commit 876b1a8

Please sign in to comment.
Something went wrong with that request. Please try again.