Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
coffeescript filter for haml
Browse files Browse the repository at this point in the history
  • Loading branch information
paulnicholson committed Apr 29, 2011
0 parents commit 1f0ad0e
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in coffee-filter.gemspec
gemspec
21 changes: 21 additions & 0 deletions MIT-LICENSE
@@ -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.

35 changes: 35 additions & 0 deletions README.rdoc
@@ -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


2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
23 changes: 23 additions & 0 deletions coffee-filter.gemspec
@@ -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
6 changes: 6 additions & 0 deletions lib/coffee-filter.rb
@@ -0,0 +1,6 @@
require 'coffee-filter/coffeescript'

module Coffee
module Filter
end
end
20 changes: 20 additions & 0 deletions lib/coffee-filter/coffeescript.rb
@@ -0,0 +1,20 @@
module Coffee
module Filter
module Coffeescript
include Haml::Filters::Base

lazy_require 'coffee-script'

def render_with_options(text, options)

This comment has been minimized.

Copy link
@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

5 changes: 5 additions & 0 deletions lib/coffee-filter/version.rb
@@ -0,0 +1,5 @@
module Coffee
module Filter
VERSION = "0.1.0"
end
end

0 comments on commit 1f0ad0e

Please sign in to comment.