Skip to content

Commit 0ec2f5c

Browse files
committed
the first commit of the haml-sprockets project
0 parents  commit 0ec2f5c

File tree

9 files changed

+752
-0
lines changed

9 files changed

+752
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*swp
2+
*~
3+
*bak
4+
*.gem
5+
.bundle
6+
Gemfile.lock
7+
pkg/*

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "http://rubygems.org"
2+
3+
# Specify your gem's dependencies in haml-sprockets.gemspec
4+
gemspec

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Using HAML-JS with Sprockets and Rails 3.1
2+
3+
Rails 3.1 uses sprockets for its asset pipeline. Rails 3.1 has shown considerable love for SCSS and SASS but has left [HAML] out. We at [Dharana Software Innovations][] are die hard HAML fans. We beleive that it is the best templating language around. So we would like to have it as a part of our client side toolkit as well. The [haml-js] project does exactly that. It was written for Node.js but works well with the browser too.
4+
5+
The gem includes [haml-js]. You would not have to download it separately. To use this gem, you need to do the following.
6+
7+
In the `Gemfile`, add the following line.
8+
9+
gem "haml-sprockets"
10+
11+
In `app/assets/javascripts/application.js` add the following line before `//= require_tree .`
12+
13+
//=require haml
14+
15+
Now, you can create hamljs files under `app/assets/javascripts/templates` folder. You can create the templates folder, if it does not already exist.
16+
17+
// code for app/assets/javascripts/templates/hello.jst.hamljs
18+
%h1 Hello HAML
19+
20+
You can now access the template anywhere in your javascript or coffeescript code.
21+
22+
JST["templates/hello"]()
23+
24+
This should give you back the string `"<h1>Hello HAML</h1>"`.
25+
26+
27+
[HAML]: http://haml-lang.com/
28+
[haml-js]: https://github.com/creationix/haml-js
29+
[Dharana Software Innovations]: http://www.dharanasoft.com/

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

haml-sprockets.gemspec

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path("../lib", __FILE__)
3+
require "haml-sprockets/version"
4+
5+
Gem::Specification.new do |s|
6+
s.name = "haml-sprockets"
7+
s.version = Haml::Sprockets::VERSION
8+
s.authors = ["vagmi"]
9+
s.email = ["[email protected]"]
10+
s.homepage = "https://github.com/dharanasoft/haml-sprockets"
11+
s.summary = %q{Use the awesome haml-js javascript templating lib in Ruby}
12+
s.description = %q{Use the JST processor and have haml code read in and appended to application.js}
13+
14+
s.rubyforge_project = "haml-sprockets"
15+
16+
s.files = `git ls-files`.split("\n")
17+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19+
s.require_paths = ["lib"]
20+
21+
# specify any dependencies here; for example:
22+
# s.add_development_dependency "rspec"
23+
s.add_runtime_dependency "tilt", "~> 1.3"
24+
s.add_runtime_dependency "sprockets", "~> 2.0.0"
25+
end

lib/haml-sprockets.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require "haml-sprockets/version"
2+
require 'tilt'
3+
module Haml
4+
module Sprockets
5+
class Template < ::Tilt::Template
6+
def self.engine_initialized?
7+
true
8+
end
9+
def initialize_engine
10+
end
11+
def prepare
12+
end
13+
def evaluate(scope,locals,&block)
14+
haml_code = data.dup
15+
haml_code = haml_code.gsub(/\\/,"\\\\").gsub(/\'/,"\\'").gsub(/\n/,"\\n")
16+
"Haml('#{haml_code}')"
17+
end
18+
end
19+
end
20+
end
21+
require "haml-sprockets/engine" if defined?(Rails)

lib/haml-sprockets/engine.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Haml
2+
module Sprockets
3+
class Engine < ::Rails::Engine
4+
config.after_initialize do
5+
Rails.application.assets.register_engine '.hamljs', Haml::Sprockets::Template
6+
end
7+
end
8+
end
9+
end

lib/haml-sprockets/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Haml
2+
module Sprockets
3+
VERSION = "0.0.1"
4+
end
5+
end

0 commit comments

Comments
 (0)