Permalink
Browse files

the first commit of the haml-sprockets project

  • Loading branch information...
0 parents commit 0ec2f5cb95dba0ded63fa343f28b75399aafe900 @vagmi vagmi committed Sep 9, 2011
Showing with 752 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +4 −0 Gemfile
  3. +29 −0 README.md
  4. +1 −0 Rakefile
  5. +25 −0 haml-sprockets.gemspec
  6. +21 −0 lib/haml-sprockets.rb
  7. +9 −0 lib/haml-sprockets/engine.rb
  8. +5 −0 lib/haml-sprockets/version.rb
  9. +651 −0 vendor/assets/javascripts/haml.js
@@ -0,0 +1,7 @@
+*swp
+*~
+*bak
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in haml-sprockets.gemspec
+gemspec
@@ -0,0 +1,29 @@
+# Using HAML-JS with Sprockets and Rails 3.1
+
+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.
+
+The gem includes [haml-js]. You would not have to download it separately. To use this gem, you need to do the following.
+
+In the `Gemfile`, add the following line.
+
+ gem "haml-sprockets"
+
+In `app/assets/javascripts/application.js` add the following line before `//= require_tree .`
+
+ //=require haml
+
+Now, you can create hamljs files under `app/assets/javascripts/templates` folder. You can create the templates folder, if it does not already exist.
+
+ // code for app/assets/javascripts/templates/hello.jst.hamljs
+ %h1 Hello HAML
+
+You can now access the template anywhere in your javascript or coffeescript code.
+
+ JST["templates/hello"]()
+
+This should give you back the string `"<h1>Hello HAML</h1>"`.
+
+
+[HAML]: http://haml-lang.com/
+[haml-js]: https://github.com/creationix/haml-js
+[Dharana Software Innovations]: http://www.dharanasoft.com/
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "haml-sprockets/version"
+
+Gem::Specification.new do |s|
+ s.name = "haml-sprockets"
+ s.version = Haml::Sprockets::VERSION
+ s.authors = ["vagmi"]
+ s.email = ["vagmi.mudumbai@gmail.com"]
+ s.homepage = "https://github.com/dharanasoft/haml-sprockets"
+ s.summary = %q{Use the awesome haml-js javascript templating lib in Ruby}
+ s.description = %q{Use the JST processor and have haml code read in and appended to application.js}
+
+ s.rubyforge_project = "haml-sprockets"
+
+ 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"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ s.add_runtime_dependency "tilt", "~> 1.3"
+ s.add_runtime_dependency "sprockets", "~> 2.0.0"
+end
@@ -0,0 +1,21 @@
+require "haml-sprockets/version"
+require 'tilt'
+module Haml
+ module Sprockets
+ class Template < ::Tilt::Template
+ def self.engine_initialized?
+ true
+ end
+ def initialize_engine
+ end
+ def prepare
+ end
+ def evaluate(scope,locals,&block)
+ haml_code = data.dup
+ haml_code = haml_code.gsub(/\\/,"\\\\").gsub(/\'/,"\\'").gsub(/\n/,"\\n")
+ "Haml('#{haml_code}')"
+ end
+ end
+ end
+end
+require "haml-sprockets/engine" if defined?(Rails)
@@ -0,0 +1,9 @@
+module Haml
+ module Sprockets
+ class Engine < ::Rails::Engine
+ config.after_initialize do
+ Rails.application.assets.register_engine '.hamljs', Haml::Sprockets::Template
+ end
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Haml
+ module Sprockets
+ VERSION = "0.0.1"
+ end
+end
Oops, something went wrong.

0 comments on commit 0ec2f5c

Please sign in to comment.