Skip to content

Instantly share code, notes, and snippets.

@kareemk
Created July 24, 2011 19:31
Show Gist options
  • Save kareemk/1102990 to your computer and use it in GitHub Desktop.
Save kareemk/1102990 to your computer and use it in GitHub Desktop.
Stitch-rb Config
class StitchApplication < Stitch::Server
def initialize
settings = YAML.load_file("config/stitch.yml")
super(:paths => settings["paths"], :dependencies => settings["dependencies"])
end
def call(env)
if Rails.env == "production"
[200, {"Content-Type" => "text/javascript"}, [Uglifier.compile(@package.compile)]]
else
super
end
end
end
class TmplCompiler < Stitch::Compiler
# List of supported extensions
extensions :tmpl
# A compile method which takes a file path,
# and returns a compiled string
def compile(path)
content = File.read(path)
%{
var template = jQuery.template(#{content.to_json});
module.exports = (function(data){ return jQuery.tmpl(template, data); });
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment