Skip to content

Commit

Permalink
initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Aug 7, 2012
1 parent 8a362eb commit 38fb3d0
Show file tree
Hide file tree
Showing 133 changed files with 1,551 additions and 2 deletions.
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The MIT License

Copyright (c) 2009 Chris Wanstrath (Ruby)
Copyright (c) 2010 Jan Lehnardt (JavaScript)

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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## What is this?

A special build of mustache.js (by @janl) which works within the security policies defined by
A special build of [mustache.js](https://github.com/janl/mustache.js) (by [@janl](https://github.com/janl)) which works within the security policies defined by
the Google Chrome Apps/Extensions [Content Security Policy](http://code.google.com/chrome/extensions/contentSecurityPolicy.html).

In CSP, inline JavaScript as well as potentially harmful string-to-JS methods such as `eval` are not executed. Whilst great for security, this also means that it can be a challenge finding a popular templating engine which doesn't use features disabled by the CSP.
In CSP, inline JavaScript as well as potentially harmful string-to-JS methods such as `eval` are not executed. Whilst great for security, this also means that it can be a challenge finding a popular templating engine which doesn't use features disabled by the policy.

This version of mustache works fine under the CSP and has been used with frameworks such as Backbone.js within Chrome Apps without any issues.

Expand Down
62 changes: 62 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'rake'
require 'rake/clean'

task :default => :spec

desc "Run all specs"
task :spec do
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
#t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.pattern = 'spec/*_spec.rb'
end
end

def version
File.read("mustache.js").match('version: "([^\"]+)",$')[1]
end

# Creates a rule that uses the .tmpl.{pre,post} stuff to make a final,
# wrapped, output file. There is some extra complexity because Dojo and YUI3
# use different template files and final locations.
def templated_build(name, opts={})
short = name.downcase
source = File.join("wrappers", short)
dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*")
target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js"

CLEAN.include(opts[:location] ? opts[:location] : target_js)

desc "Package for #{name}"
task short.to_sym => dependencies do
puts "Packaging for #{name}"

mkdir_p opts[:location] if opts[:location]

sh "cat #{source}/#{target_js}.tpl.pre mustache.js \
#{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}"

# extra
if opts[:extra]
sh "sed -e 's/{{version}}/#{version}/' #{source}/#{opts[:extra]} \
> #{opts[:location]}/#{opts[:extra]}"
end

puts "Done, see #{opts[:location] || '.'}/#{target_js}"
end
end

templated_build "CommonJS", :location => "lib", :extra => "package.json"
templated_build "jQuery"
templated_build "Dojo", :location => "dojox/string"
templated_build "YUI3", :location => "yui3/mustache"
templated_build "RequireJS"
templated_build "qooxdoo"

task :minify do
# npm install uglify-js
mmjs = "mustache.min.js"
`echo "/*! Version: 0.4.2 */" > #{mmjs}`
`uglifyjs mustache.js >> #{mmjs}`
puts "Created #{mmjs}"
end
75 changes: 75 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## Running the mustache.js Test Suite

Notice: the tests are only expected to run on unixoid systems.

The mustache.js test suite uses the [RSpec](http://rspec.info/) testing
framework. In order to run the tests you'll need to install [Ruby](http://ruby-lang.org/)
as well as the `rake`, `rspec` (>=2), and `json` [RubyGems](http://rubygems.org/).

### How to install Ruby and the required gems from source

Make sure you have the required tools to compile it:

$ apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev

Download and extract the Ruby source, and install it:

$ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz
$ tar xvzf stable-snapshot.tar.gz
$ cd ruby
$ ./configure && make && make install

Download and extract RubyGems, and install it:

$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.12.tgz
$ tar xzvf rubygems-1.8.12.tgz
$ cd rubygems-1.8.12
$ ruby setup.rb

If you want to update RubyGems:

$ gem update --system

Install the required gems:

$ gem install rake rspec json

That's it!

### How to install node.js from source

$ git clone https://github.com/joyent/node.git
$ cd node
$ # select the version to install, master is unstable;
$ # latest stable version is advertised on http://nodejs.org
$ git checkout v0.6.11
$ ./configure
$ make
$ sudo make install

### How to run the tests

The mustache.js test suite currently uses 4 different JavaScript runtime engines
to maximize portability across platforms and browsers. They are:

* node
* SpiderMonkey (Mozilla, Firefox)
* JavaScriptCore (WebKit, Safari)
* Rhino (Mozilla, Java)

When the test suite runs it will automatically determine which platforms are
available on your machine and run on all of them. The suite must run on at least
one platform in order to succeed.

Once you have at least one JavaScript platform installed, you can run the test
suite with the following command:

$ rake

### How to create a test

All test files live in the spec/_files directory. To create a new test:

* Create a template file `somename.mustache`
* Create a javascript file with data and functions `somename.js`
* Create a file the expected result `somename.txt`
Loading

0 comments on commit 38fb3d0

Please sign in to comment.