Permalink
Browse files

initial commit.

  • Loading branch information...
addyosmani committed Aug 7, 2012
1 parent 8a362eb commit 38fb3d0b34cc423a2140b9863f7c9acfcdda1c0a
Showing with 1,551 additions and 2 deletions.
  1. +23 −0 LICENSE
  2. +2 −2 README.md
  3. +62 −0 Rakefile
  4. +75 −0 TESTING.md
  5. +436 −0 mustache.js
  6. +6 −0 mustache.min.js
  7. +3 −0 spec/_files/ampersand_escape.js
  8. +1 −0 spec/_files/ampersand_escape.mustache
  9. +1 −0 spec/_files/ampersand_escape.txt
  10. +1 −0 spec/_files/apostrophe.js
  11. +1 −0 spec/_files/apostrophe.mustache
  12. +1 −0 spec/_files/apostrophe.txt
  13. +1 −0 spec/_files/array_of_partials_implicit_partial.2.mustache
  14. +3 −0 spec/_files/array_of_partials_implicit_partial.js
  15. +4 −0 spec/_files/array_of_partials_implicit_partial.mustache
  16. +5 −0 spec/_files/array_of_partials_implicit_partial.txt
  17. +1 −0 spec/_files/array_of_partials_partial.2.mustache
  18. +3 −0 spec/_files/array_of_partials_partial.js
  19. +4 −0 spec/_files/array_of_partials_partial.mustache
  20. +5 −0 spec/_files/array_of_partials_partial.txt
  21. +1 −0 spec/_files/array_of_strings.js
  22. +1 −0 spec/_files/array_of_strings.mustache
  23. +1 −0 spec/_files/array_of_strings.txt
  24. +1 −0 spec/_files/array_of_strings_options.js
  25. +2 −0 spec/_files/array_of_strings_options.mustache
  26. +1 −0 spec/_files/array_of_strings_options.txt
  27. +4 −0 spec/_files/array_partial.2.mustache
  28. +5 −0 spec/_files/array_partial.js
  29. +1 −0 spec/_files/array_partial.mustache
  30. +6 −0 spec/_files/array_partial.txt
  31. +3 −0 spec/_files/bug_11_eating_whitespace.js
  32. +1 −0 spec/_files/bug_11_eating_whitespace.mustache
  33. +1 −0 spec/_files/bug_11_eating_whitespace.txt
  34. +5 −0 spec/_files/comments.js
  35. +1 −0 spec/_files/comments.mustache
  36. +1 −0 spec/_files/comments.txt
  37. +19 −0 spec/_files/complex.js
  38. +16 −0 spec/_files/complex.mustache
  39. +6 −0 spec/_files/complex.txt
  40. +6 −0 spec/_files/delimiters.js
  41. +7 −0 spec/_files/delimiters.mustache
  42. +5 −0 spec/_files/delimiters.txt
  43. +23 −0 spec/_files/dot_notation.js
  44. +9 −0 spec/_files/dot_notation.mustache
  45. +9 −0 spec/_files/dot_notation.txt
  46. +5 −0 spec/_files/double_render.js
  47. +1 −0 spec/_files/double_render.mustache
  48. +1 −0 spec/_files/double_render.txt
  49. +1 −0 spec/_files/empty_partial.2.mustache
  50. +3 −0 spec/_files/empty_partial.js
  51. +2 −0 spec/_files/empty_partial.mustache
  52. +2 −0 spec/_files/empty_partial.txt
  53. +1 −0 spec/_files/empty_sections.js
  54. +1 −0 spec/_files/empty_sections.mustache
  55. +1 −0 spec/_files/empty_sections.txt
  56. +1 −0 spec/_files/empty_template.js
  57. +1 −0 spec/_files/empty_template.mustache
  58. +1 −0 spec/_files/empty_template.txt
  59. +1 −0 spec/_files/error_not_found.js
  60. +1 −0 spec/_files/error_not_found.mustache
  61. +1 −0 spec/_files/error_not_found.txt
  62. +7 −0 spec/_files/escaped.js
  63. +3 −0 spec/_files/escaped.mustache
  64. +3 −0 spec/_files/escaped.txt
  65. +9 −0 spec/_files/higher_order_sections.js
  66. +1 −0 spec/_files/higher_order_sections.mustache
  67. +1 −0 spec/_files/higher_order_sections.txt
  68. +3 −0 spec/_files/inverted_section.js
  69. +2 −0 spec/_files/inverted_section.mustache
  70. +1 −0 spec/_files/inverted_section.txt
  71. +5 −0 spec/_files/keys_with_questionmarks.js
  72. +3 −0 spec/_files/keys_with_questionmarks.mustache
  73. +1 −0 spec/_files/keys_with_questionmarks.txt
  74. +7 −0 spec/_files/nesting.js
  75. +5 −0 spec/_files/nesting.mustache
  76. +4 −0 spec/_files/nesting.txt
  77. +9 −0 spec/_files/null_string.js
  78. +5 −0 spec/_files/null_string.mustache
  79. +5 −0 spec/_files/null_string.txt
  80. +4 −0 spec/_files/partial_recursion.2.mustache
  81. +11 −0 spec/_files/partial_recursion.js
  82. +4 −0 spec/_files/partial_recursion.mustache
  83. +3 −0 spec/_files/partial_recursion.txt
  84. +8 −0 spec/_files/recursion_with_same_names.js
  85. +7 −0 spec/_files/recursion_with_same_names.mustache
  86. +6 −0 spec/_files/recursion_with_same_names.txt
  87. +6 −0 spec/_files/reuse_of_enumerables.js
  88. +8 −0 spec/_files/reuse_of_enumerables.mustache
  89. +8 −0 spec/_files/reuse_of_enumerables.txt
  90. +7 −0 spec/_files/section_as_context.js
  91. +9 −0 spec/_files/section_as_context.mustache
  92. +6 −0 spec/_files/section_as_context.txt
  93. +8 −0 spec/_files/simple.js
  94. +5 −0 spec/_files/simple.mustache
  95. +3 −0 spec/_files/simple.txt
  96. +1 −0 spec/_files/template_partial.2.mustache
  97. +8 −0 spec/_files/template_partial.js
  98. +2 −0 spec/_files/template_partial.mustache
  99. +2 −0 spec/_files/template_partial.txt
  100. +4 −0 spec/_files/two_in_a_row.js
  101. +1 −0 spec/_files/two_in_a_row.mustache
  102. +1 −0 spec/_files/two_in_a_row.txt
  103. +1 −0 spec/_files/two_sections.js
  104. +4 −0 spec/_files/two_sections.mustache
  105. +1 −0 spec/_files/two_sections.txt
  106. +5 −0 spec/_files/unescaped.js
  107. +1 −0 spec/_files/unescaped.mustache
  108. +1 −0 spec/_files/unescaped.txt
  109. +1 −0 spec/_files/unknown_pragma.js
  110. +1 −0 spec/_files/unknown_pragma.mustache
  111. +1 −0 spec/_files/unknown_pragma.txt
  112. +5 −0 spec/_files/view_partial.2.mustache
  113. +19 −0 spec/_files/view_partial.js
  114. +3 −0 spec/_files/view_partial.mustache
  115. +6 −0 spec/_files/view_partial.txt
  116. +5 −0 spec/_files/whitespace_partial.2.mustache
  117. +19 −0 spec/_files/whitespace_partial.js
  118. +3 −0 spec/_files/whitespace_partial.mustache
  119. +6 −0 spec/_files/whitespace_partial.txt
  120. +276 −0 spec/mustache_spec.rb
  121. +8 −0 wrappers/commonjs/mustache.js.tpl.post
  122. +6 −0 wrappers/commonjs/mustache.js.tpl.pre
  123. +8 −0 wrappers/commonjs/package.json
  124. +4 −0 wrappers/dojo/mustache.js.tpl.post
  125. +9 −0 wrappers/dojo/mustache.js.tpl.pre
  126. +6 −0 wrappers/jquery/jquery.mustache.js.tpl.post
  127. +9 −0 wrappers/jquery/jquery.mustache.js.tpl.pre
  128. +9 −0 wrappers/qooxdoo/qooxdoo.mustache.js.tpl.post
  129. +127 −0 wrappers/qooxdoo/qooxdoo.mustache.js.tpl.pre
  130. +3 −0 wrappers/requirejs/requirejs.mustache.js.tpl.post
  131. +6 −0 wrappers/requirejs/requirejs.mustache.js.tpl.pre
  132. +4 −0 wrappers/yui3/mustache.js.tpl.post
  133. +1 −0 wrappers/yui3/mustache.js.tpl.pre
View
23 LICENSE
@@ -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.
View
@@ -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.
View
@@ -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
View
@@ -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`
Oops, something went wrong.

0 comments on commit 38fb3d0

Please sign in to comment.