haml_assets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@handlebars_assets
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in haml_assets.gemspec
4
+ gemspec
@@ -0,0 +1,71 @@
1
+ # Use haml to write your Javascript templates
2
+
3
+ *ALPHA*
4
+
5
+ Writing Javascript templates for Backbone.js (or other frameworks) in your app? Would you like to use haml and the asset pipeline?
6
+
7
+ This gem adds haml templating support to the Rails 3.1 asset pipeline. This gem works with the EJS gem and JST asset engine to make your haml available as a compiled Javascript template.
8
+
9
+ ## Installing
10
+
11
+ Add this to your `Gemfile`
12
+
13
+ gem haml_assets
14
+ gem ejs
15
+
16
+ # Using haml for your Javascript templates
17
+
18
+
19
+ ## Templates directory
20
+
21
+ You should located your templates under `app/assets`; we suggest `app/assets/templates`. In your Javascript manifest file (for example `application.js`), use `require_tree`
22
+
23
+ //= require_tree ../templates
24
+
25
+ ## The template file
26
+
27
+ Inside your templates directory, add your template file. The file should be named as follows
28
+
29
+ your_template_name.jst.ejs.haml
30
+
31
+ The asset pipeline will then generate the actual Javascript asset
32
+
33
+ 1. Convert your haml to HTML
34
+ 1. Compile the HTML to an EJS Javascript template
35
+ 1. Add the template to the JST global under the templates name
36
+
37
+ **Important!** The asset pipeline is not invoking a controller to generate the templates. If you are using existing view templates, you may have to edit templates to remove some references to controller helpers.
38
+
39
+ ## EJS
40
+
41
+ In your template file you can use the EJS delimiters as you would normally. If you want to use them in attributes mark the attribute html_safe.
42
+
43
+ = f.text_field :email, class: 'text', value: '<%= email %>'.html_safe
44
+
45
+ ### Helpers
46
+
47
+ All the ActionView and route helpers are available in your template. If you use `form_for` and the related helpers, you should use the *new* object form, even if you are writing an *edit* form, for example
48
+
49
+ = form_for :contact, url: "javascript_not_working", html: {:class => :edit_contact, :method => :put} do |f|
50
+ %p
51
+ = f.label :name, "Name"
52
+ = f.text_field :name, class: 'text required', autofocus: true, value: '<%= name %>'.html_safe
53
+
54
+ # TODO
55
+
56
+ Make `render` available, so you can render a partial.
57
+
58
+ # Contributing
59
+
60
+ Once you've made your great commits:
61
+
62
+ 1. Fork
63
+ 1. Create a topic branch - git checkout -b my_branch
64
+ 1. Push to your branch - git push origin my_branch
65
+ 1. Create a Pull Request from your branch
66
+ 1. That's it!
67
+
68
+ # Authors
69
+
70
+ Les Hill : @leshill
71
+ Wes Gibbs : @wgibbs
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "haml_assets/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "haml_assets"
7
+ s.version = HamlAssets::VERSION
8
+ s.authors = ["Les Hill", "Wes Gibbs"]
9
+ s.email = ["les@infbio.com", "wes@infbio.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Use Haml with Rails helpers in the asset pipeline}
12
+ s.description = %q{Use Haml with Rails helpers in the asset pipeline}
13
+
14
+ s.rubyforge_project = "haml_assets"
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
+ s.add_runtime_dependency "haml"
22
+ s.add_runtime_dependency "tilt"
23
+ end
@@ -0,0 +1,6 @@
1
+ require "haml_assets/version"
2
+ require "haml_assets/engine"
3
+
4
+ module HamlAssets
5
+ autoload :HamlSprocketsEngine, "haml_assets/haml_sprockets_engine"
6
+ end
@@ -0,0 +1,7 @@
1
+ module HamlAssets
2
+ class Engine < ::Rails::Engine
3
+ initializer "sprockets.haml", after: "sprockets.environment" do |app|
4
+ app.assets.register_engine('.haml', HamlSprocketsEngine)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ require 'haml'
2
+ require 'tilt'
3
+
4
+ module HamlAssets
5
+ class HamlSprocketsEngine < Tilt::Template
6
+ attr_accessor :locals
7
+
8
+ def self.default_mime_type
9
+ 'application/javascript'
10
+ end
11
+
12
+ class ViewContext
13
+ include Rails.application.routes.url_helpers
14
+ include Rails.application.routes.mounted_helpers
15
+ include ActionView::Helpers
16
+
17
+ attr_accessor :output_buffer
18
+
19
+ def protect_against_forgery?
20
+ false
21
+ end
22
+ end
23
+
24
+ def evaluate(scope, locals, &block)
25
+ self.locals = locals
26
+
27
+ begin
28
+ "" + render_haml
29
+ rescue Exception => e
30
+ Rails.logger.debug "ERROR: compiling #{file} RAISED #{e}"
31
+ Rails.logger.debug "Backtrace: #{e.backtrace.join("\n")}"
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def prepare; end
38
+
39
+ def render_haml
40
+ Haml::Engine.new(data, Haml::Template.options.merge(escape_attrs: false)).render(scope, locals)
41
+ end
42
+
43
+ def scope
44
+ @scope ||= ViewContext.new
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module HamlAssets
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haml_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Les Hill
9
+ - Wes Gibbs
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-08-25 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: haml
17
+ requirement: &70096504992300 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70096504992300
26
+ - !ruby/object:Gem::Dependency
27
+ name: tilt
28
+ requirement: &70096504991880 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70096504991880
37
+ description: Use Haml with Rails helpers in the asset pipeline
38
+ email:
39
+ - les@infbio.com
40
+ - wes@infbio.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - haml_assets.gemspec
51
+ - lib/haml_assets.rb
52
+ - lib/haml_assets/engine.rb
53
+ - lib/haml_assets/haml_sprockets_engine.rb
54
+ - lib/haml_assets/version.rb
55
+ homepage: ''
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project: haml_assets
75
+ rubygems_version: 1.8.6
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Use Haml with Rails helpers in the asset pipeline
79
+ test_files: []