coffee-haml-filter 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ ## PROJECT::GENERAL
2
+ coverage
3
+ rdoc
4
+ pkg
5
+
6
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,71 @@
1
+ = CoffeeHamlFilter
2
+
3
+ * http://github.com/aussiegeek/coffee-haml-filter
4
+
5
+ == Description:
6
+
7
+ CoffeeHamlFilter is custom filter for rendering {CoffeeScript}[http://jashkenas.github.com/coffee-script/]
8
+ inside your {Haml}[http://github.com/nex3/haml] templates.
9
+
10
+ == Install:
11
+
12
+ Install the gem, on rails 3 just add to your Gemfile
13
+
14
+ == Requirements:
15
+
16
+ Requires the CoffeeScript command line utility (which, in turn requires node.js). See the {CoffeeScript}[http://github.com/jashkenas/coffee-script] documentation for installation instructions.
17
+
18
+ == Example:
19
+
20
+ :coffee
21
+ window.cl: s =>
22
+ if typeof(console) != 'undefined' then console.log(s) else s
23
+
24
+ will render:
25
+
26
+ <script type='text/javascript'>
27
+ //<![CDATA[
28
+ (function(){
29
+ window.cl = function cl(s) {
30
+ return typeof (console) !== 'undefined' ? console.log(s) : s;
31
+ };
32
+ })();
33
+ //]]>
34
+ </script>
35
+
36
+ == Coffee Not in Path
37
+
38
+ If you need to specify the path to coffee you can, eg. coffee installed with homebrew:
39
+
40
+ Haml::Filters::Coffee.coffee_path = "/usr/local/bin/node /usr/local/bin/coffee"
41
+
42
+ == Also:
43
+
44
+ See {bistro}[http://github.com/sutto/barista] for automatic Coffee script generation on Rails 3
45
+
46
+ == License:
47
+
48
+ (The MIT License)
49
+
50
+ Copyright (c) 2010 Alan Harper
51
+ Copyright (c) 2050 Ivan Nemytchenko
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71
+
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "coffee-haml-filter"
8
+ gem.summary = %Q{Haml filter for inline coffeescript}
9
+ gem.description = %Q{Haml filter for inline coffeescript}
10
+ gem.email = "alan@aussiegeek.net"
11
+ gem.homepage = "http://github.com/aussiegeek/coffee-haml-filter"
12
+ gem.authors = ["Alan Harper"]
13
+ gem.add_dependency "haml"
14
+ gem.add_development_dependency "rspec", ">= 1.3.0"
15
+ gem.add_development_dependency "yard", ">= 0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ begin
40
+ require 'yard'
41
+ YARD::Rake::YardocTask.new
42
+ rescue LoadError
43
+ task :yardoc do
44
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
45
+ end
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{coffee-haml-filter}
8
+ s.version = "0.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alan Harper"]
12
+ s.date = %q{2010-05-22}
13
+ s.description = %q{Haml filter for inline coffeescript}
14
+ s.email = %q{alan@aussiegeek.net}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "coffee-haml-filter.gemspec",
24
+ "init.rb",
25
+ "install.rb",
26
+ "lib/coffee-haml-filter.rb",
27
+ "lib/haml/filters/coffee.rb",
28
+ "spec/coffee-haml-filter_spec.rb",
29
+ "spec/fixtures/invalid.haml",
30
+ "spec/fixtures/win.haml",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "uninstall.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/aussiegeek/coffee-haml-filter}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Haml filter for inline coffeescript}
40
+ s.test_files = [
41
+ "spec/coffee-haml-filter_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
52
+ s.add_development_dependency(%q<yard>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<haml>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
56
+ s.add_dependency(%q<yard>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<haml>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
61
+ s.add_dependency(%q<yard>, [">= 0"])
62
+ end
63
+ end
64
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'lib/coffee-haml-filter'
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1 @@
1
+ require 'haml/filters/coffee'
@@ -0,0 +1,37 @@
1
+ module Haml::Filters::Coffee
2
+ attr_accessor :coffee_path
3
+ include Haml::Filters::Base
4
+
5
+ lazy_require 'open3'
6
+
7
+ def coffee_path
8
+ @coffee_path || "coffee"
9
+ end
10
+
11
+ def popen_args
12
+ bin, args = coffee_path.split(' ')
13
+ if args
14
+ args << " -sc"
15
+ else
16
+ args = "-sc"
17
+ end
18
+
19
+ [bin, args]
20
+ end
21
+ def render_with_options(text, options)
22
+ bin, path = popen_args
23
+ js, error = Open3.popen3(bin, path) do |i,o,e|
24
+ i << text
25
+ i.close
26
+ [o.read, e.read]
27
+ end
28
+ raise SyntaxError, error unless error.blank?
29
+ <<END
30
+ <script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
31
+ //<![CDATA[
32
+ #{js}
33
+ //]]>
34
+ </script>
35
+ END
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CoffeeHamlFilter" do
4
+ it "should render valid coffeescript" do
5
+ template = read_fixture('win.haml')
6
+ engine = Haml::Engine.new(template)
7
+ rendered = engine.render
8
+ rendered.should == "<script type='text/javascript'>\n //<![CDATA[\n (function(){\n alert('Win!');\n})();\n\n //]]>\n</script>\n"
9
+ end
10
+
11
+ it "should show errors for invalid coffee script" do
12
+ template = read_fixture('invalid.haml')
13
+ lambda { Haml::Engine.new(template) }.should raise_error(SyntaxError)
14
+ end
15
+
16
+ describe "setup" do
17
+ describe "default path" do
18
+ it "should have the correct path" do
19
+ Haml::Filters::Coffee.coffee_path.should == "coffee"
20
+ end
21
+
22
+ it "should generate popen args" do
23
+ Haml::Filters::Coffee.popen_args.should == ["coffee", "-sc"]
24
+ end
25
+ end
26
+
27
+ describe "should change the path if requested" do
28
+ before do
29
+ Haml::Filters::Coffee.coffee_path = "/usr/local/bin/node /usr/local/bin/coffee"
30
+ end
31
+ it "should update coffee path" do
32
+ Haml::Filters::Coffee.coffee_path.should == "/usr/local/bin/node /usr/local/bin/coffee"
33
+ end
34
+
35
+ it "should generate popen args" do
36
+ Haml::Filters::Coffee.popen_args.should == ["/usr/local/bin/node", "/usr/local/bin/coffee -sc"]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ :coffee
2
+ invalid.
@@ -0,0 +1,2 @@
1
+ :coffee
2
+ alert 'Win!'
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'haml'
4
+ require 'haml/filters/coffee'
5
+
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
12
+
13
+ def read_fixture(filename)
14
+ File.read(File.join(File.dirname(__FILE__), 'fixtures', filename))
15
+ end
16
+
17
+ #hack around haml dependency on String#blank? method
18
+ class String
19
+ def blank?
20
+ self == ""
21
+ end
22
+ end
File without changes
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee-haml-filter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
+ platform: ruby
11
+ authors:
12
+ - Alan Harper
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-22 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: haml
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 3
42
+ - 0
43
+ version: 1.3.0
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: Haml filter for inline coffeescript
59
+ email: alan@aussiegeek.net
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README.rdoc
66
+ files:
67
+ - .gitignore
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - coffee-haml-filter.gemspec
72
+ - init.rb
73
+ - install.rb
74
+ - lib/coffee-haml-filter.rb
75
+ - lib/haml/filters/coffee.rb
76
+ - spec/coffee-haml-filter_spec.rb
77
+ - spec/fixtures/invalid.haml
78
+ - spec/fixtures/win.haml
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ - uninstall.rb
82
+ has_rdoc: true
83
+ homepage: http://github.com/aussiegeek/coffee-haml-filter
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --charset=UTF-8
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.6
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Haml filter for inline coffeescript
112
+ test_files:
113
+ - spec/coffee-haml-filter_spec.rb
114
+ - spec/spec_helper.rb