Permalink
Browse files

coffeescript filter for haml

  • Loading branch information...
0 parents commit 1f0ad0e93c0689911601f5d62ef5b4284af23bc5 @paulnicholson committed Apr 29, 2011
Showing with 120 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +21 −0 MIT-LICENSE
  4. +35 −0 README.rdoc
  5. +2 −0 Rakefile
  6. +23 −0 coffee-filter.gemspec
  7. +6 −0 lib/coffee-filter.rb
  8. +20 −0 lib/coffee-filter/coffeescript.rb
  9. +5 −0 lib/coffee-filter/version.rb
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in coffee-filter.gemspec
+gemspec
@@ -0,0 +1,21 @@
+Copyright (c) 2011 Paul Nicholson
+
+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.
+
@@ -0,0 +1,35 @@
+=== What is coffee-filter?
+Coffee-filter provides a custom haml filter allowing you to inline coffeescript in your haml templates.
+It was inspired by Ivan Nemytchenko's coffee-haml-filter but I wanted an installable gem and "coffeescript" as the filter name.
+
+=== Example
+Haml:
+
+ %div
+ stuff
+ :coffeescript
+ alert 'here'
+
+Html:
+
+ <div>
+ stuff
+ <script type='text/javascript'>
+ //<![CDATA[
+ (function() {
+ alert('here');
+ }).call(this);
+
+ //]]>
+ </script>
+ </div>
+
+=== Installation
+Add the following to your Gemfile:
+
+ gem 'coffee-filter'
+
+
+Copyright (c) 2011 Paul Nicholson, released under the MIT license
+
+
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "coffee-filter/version"
+
+Gem::Specification.new do |s|
+ s.name = "coffee-filter"
+ s.version = Coffee::Filter::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Paul Nicholson"]
+ s.email = ["paul@webpowerdesign.net"]
+ s.homepage = "http://github.com/paulnicholson/coffee-filter"
+ s.summary = %q{CoffeeFilter is a custom haml filter for rendering coffeescript.}
+ s.description = %q{CoffeeFilter is a custom haml filter for rendering coffeescript inside your haml templates. It was inspired by Ivan Nemytchenko's coffee-haml-filter but I wanted an installable gem and coffeescript as the filter name.}
+
+ s.rubyforge_project = "coffee-filter"
+ s.add_dependency('haml', '>= 3.0.18')
+ s.add_dependency('coffee-script', '>= 2.2.0')
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
@@ -0,0 +1,6 @@
+require 'coffee-filter/coffeescript'
+
+module Coffee
+ module Filter
+ end
+end
@@ -0,0 +1,20 @@
+module Coffee
+ module Filter
+ module Coffeescript
+ include Haml::Filters::Base
+
+ lazy_require 'coffee-script'
+
+ def render_with_options(text, options)
@texastoland
texastoland Sep 23, 2011

I'm not a Ruby guy but could you forward the compiled text and options to the JavaScript filter? Besides indenting differently nex3/haml@bc4977f modified the behaviour of type attributes.

+ <<END
+<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
+ //<![CDATA[
+ #{CoffeeScript.compile(text)}
+ //]]>
+</script>
+END
+ end
+ end
+ end
+end
+
@@ -0,0 +1,5 @@
+module Coffee
+ module Filter
+ VERSION = "0.1.0"
+ end
+end

0 comments on commit 1f0ad0e

Please sign in to comment.