walrus-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in walrus-rails.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ # walrus-rails
2
+
3
+ JST style templates with walrus.js via Sprockets
4
+
5
+ ## Summary
6
+
7
+ Write files named `app/assets/javascripts/templates/tmpl.js.wal`
8
+ and use them client-side like this:
9
+
10
+ ``` javascript
11
+ window.walrus_templates["templates/tmpl"].compile(obj)
12
+ ```
13
+
14
+ ## Installation
15
+
16
+ Add `walrus-rails` to your Gemfile
17
+
18
+ ``` ruby
19
+ gem "walrus-rails"
20
+ ```
21
+
22
+ This will register a new template engine in `Sprockets` to handle `.wal` files
23
+
24
+ Make sure to include your templates in your main application.js, for example:
25
+
26
+ ``` javascript
27
+ //= require_tree ./templates
28
+ ```
29
+
30
+ You'll also need [walrus.js](http://github.com/jeremyruppel/walrus)
31
+
32
+ That's it!
33
+
34
+ ## Configuration
35
+
36
+ You can change the namespace `walrus_templates` if you like:
37
+
38
+ ``` ruby
39
+ # In some initialization code
40
+ Sprockets::WalrusTemplate.namespace = 'this.JST'
41
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ require 'action_view/helpers'
2
+
3
+ module Sprockets
4
+ class WalrusTemplate < Tilt::Template
5
+
6
+ def self.default_mime_type
7
+ 'application/javascript'
8
+ end
9
+
10
+ class << self
11
+ attr_accessor :namespace
12
+ end
13
+
14
+ self.namespace = 'this.walrus_templates'
15
+
16
+ def prepare
17
+ @namespace = self.class.namespace
18
+ end
19
+
20
+ attr_reader :namespace
21
+
22
+ def evaluate(scope, locals, &block)
23
+ <<-JST
24
+ (function() {
25
+ #{namespace} || (#{namespace} = {});
26
+ #{namespace}[#{scope.logical_path.inspect}] = #{wrap_in_walrus_parser(data)};
27
+ }).call(this);
28
+ JST
29
+ end
30
+
31
+ protected
32
+
33
+ module JSHelper
34
+ include ActionView::Helpers::JavaScriptHelper
35
+ extend self
36
+ end
37
+
38
+ def wrap_in_walrus_parser(source)
39
+ "Walrus.Parser.parse('%s')" % JSHelper.escape_javascript(source)
40
+ end
41
+ end
42
+
43
+ register_engine '.wal', ::Sprockets::WalrusTemplate
44
+ end
45
+
@@ -0,0 +1,3 @@
1
+ require "tilt"
2
+ require "sprockets"
3
+ require "sprockets/walrus_template"
@@ -0,0 +1,5 @@
1
+ module Walrus
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "walrus/rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "walrus-rails"
7
+ s.version = Walrus::Rails::VERSION
8
+ s.authors = ["Ben Marini"]
9
+ s.email = ["bmarini@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{JST style object for walrus.js templates }
12
+ s.description = %q{JST style object for walrus.js templates }
13
+
14
+ s.rubyforge_project = "walrus-rails"
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"
24
+ s.add_runtime_dependency "sprockets"
25
+ s.add_runtime_dependency "actionpack"
26
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walrus-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Marini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: &70114013418020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70114013418020
25
+ - !ruby/object:Gem::Dependency
26
+ name: sprockets
27
+ requirement: &70114013417520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70114013417520
36
+ - !ruby/object:Gem::Dependency
37
+ name: actionpack
38
+ requirement: &70114013416880 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70114013416880
47
+ description: ! 'JST style object for walrus.js templates '
48
+ email:
49
+ - bmarini@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - lib/sprockets/walrus_template.rb
59
+ - lib/walrus-rails.rb
60
+ - lib/walrus/rails/version.rb
61
+ - walrus-rails.gemspec
62
+ homepage: ''
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project: walrus-rails
82
+ rubygems_version: 1.8.11
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: JST style object for walrus.js templates
86
+ test_files: []
87
+ has_rdoc: