Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 213d748be11c477a0f1b70f10fa890a8b9a82187 @jfirebaugh committed May 29, 2012
Showing with 98 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +2 −0 Gemfile
  3. +22 −0 LICENSE
  4. +3 −0 README.md
  5. +2 −0 Rakefile
  6. +32 −0 lib/sprockets/html_template.rb
  7. +1 −0 lib/sprockets_html_template.rb
  8. +19 −0 sprockets_html_template.gemspec
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
2 Gemfile
@@ -0,0 +1,2 @@
+source 'https://rubygems.org'
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 John Firebaugh
+
+MIT License
+
+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.
3 README.md
@@ -0,0 +1,3 @@
+# Sprockets::HtmlTemplate
+
+Adds Sprockets support for static templates with the extension `.jst.html`.
2 Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
32 lib/sprockets/html_template.rb
@@ -0,0 +1,32 @@
+require "sprockets"
+
+module Sprockets
+ class HtmlTemplate < Tilt::Template
+ def prepare
+ end
+
+ def evaluate(scope, locals, &block)
+ source = data.dup
+
+ escape_quotes!(source)
+ escape_whitespace!(source)
+
+ "function () { return '#{source}'; }"
+ end
+
+ private
+ def escape_quotes!(source)
+ source.gsub!(/\\/) { '\\\\' }
+ source.gsub!(/'/) { "\\'" }
+ end
+
+ def escape_whitespace!(source)
+ source.gsub!(/\r/, '\\r')
+ source.gsub!(/\n/, '\\n')
+ source.gsub!(/\t/, '\\t')
+ end
+ end
+end
+
+Sprockets::Engines # force autoload
+Sprockets.register_engine ".html", Sprockets::HtmlTemplate
1 lib/sprockets_html_template.rb
@@ -0,0 +1 @@
+require "sprockets/html_template"
19 sprockets_html_template.gemspec
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |gem|
+ gem.authors = ["John Firebaugh"]
+ gem.email = ["john.firebaugh@gmail.com"]
+ gem.description = %q{Adds Sprockets support for static templates with the extension .jst.html}
+ gem.summary = %q{Adds Sprockets support for static templates with the extension .jst.html}
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "sprockets_html_template"
+ gem.require_paths = ["lib"]
+ gem.version = "0.0.1"
+
+ gem.add_dependency "sprockets"
+ gem.add_dependency "tilt"
+end

0 comments on commit 213d748

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