jadeite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +27 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +100 -0
- data/Rakefile +9 -0
- data/jadeite.gemspec +25 -0
- data/lib/jadeite.rb +6 -0
- data/lib/jadeite/environment.rb +45 -0
- data/lib/jadeite/version.rb +3 -0
- data/lib/nodejs.rb +13 -0
- data/lib/nodejs/README.md +29 -0
- data/lib/nodejs/builtins.rb +21 -0
- data/lib/nodejs/environment.rb +52 -0
- data/lib/nodejs/module.rb +28 -0
- data/package.json +10 -0
- data/spec/fixtures/auxiliary/escapes.html +3 -0
- data/spec/fixtures/auxiliary/layout.jade +6 -0
- data/spec/fixtures/auxiliary/mixins.jade +3 -0
- data/spec/fixtures/auxiliary/smile.html +1 -0
- data/spec/fixtures/form.jade +29 -0
- data/spec/fixtures/include-mixin.jade +11 -0
- data/spec/fixtures/includes.jade +7 -0
- data/spec/jade_spec.rb +79 -0
- data/spec/spec_helper.rb +6 -0
- metadata +131 -0
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
/tmp
|
5
|
+
.DS_Store
|
6
|
+
.rvmrc
|
7
|
+
*~
|
8
|
+
coverage/
|
9
|
+
.idea
|
10
|
+
node_modules
|
11
|
+
npm-debug.log
|
12
|
+
/.sass-cache
|
13
|
+
/log/*
|
14
|
+
.config
|
15
|
+
.yardoc
|
16
|
+
Gemfile.lock
|
17
|
+
InstalledFiles
|
18
|
+
_yardoc
|
19
|
+
coverage
|
20
|
+
doc/
|
21
|
+
lib/bundler/man
|
22
|
+
pkg
|
23
|
+
rdoc
|
24
|
+
spec/reports
|
25
|
+
test/tmp
|
26
|
+
test/version_tmp
|
27
|
+
tmp
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Bengler AS
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
```
|
2
|
+
________ _________ __________
|
3
|
+
______(_)_____ ______ /_______(_)_ /_____
|
4
|
+
_____ /_ __ `/ __ /_ _ \_ /_ __/ _ \
|
5
|
+
____ / / /_/ // /_/ / / __/ / / /_ / __/
|
6
|
+
___ / \__,_/ \__,_/ \___//_/ \__/ \___/
|
7
|
+
/___/ Compile and render Jade templates from Ruby
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
Jadeite lets you compile and render [Jade](http://jade-lang.com) templates from your Ruby code.
|
12
|
+
Under the hood it uses the Jade node module running in
|
13
|
+
[therubyracer's](https://github.com/cowboyd/therubyracer) embedded V8 JavaScript engine.
|
14
|
+
|
15
|
+
It is pretty cool since it means you can easily share templates between the server side and front end.
|
16
|
+
Render with json/javascript data on the client side and ruby objects on the server side.
|
17
|
+
|
18
|
+
## Getting started
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
gem 'jadeite'
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install jadeite
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Render a template string with data
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
env = Jadeite::Environment.new
|
38
|
+
env.render('p Hello #{what}!', {:what =>"world"})
|
39
|
+
#=> "<p>Hello world!</p>"
|
40
|
+
```
|
41
|
+
|
42
|
+
### Compile once, render twice (or more)
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
env = Jadeite::Environment.new
|
46
|
+
compiled = env.compile('p Hello #{what}!')
|
47
|
+
compiled.render :what => "world"
|
48
|
+
#=> "<p>Hello world!</p>"
|
49
|
+
compiled.render :what => "moon"
|
50
|
+
#=> "<p>Hello moon!</p>"
|
51
|
+
```
|
52
|
+
|
53
|
+
### Compile / render a file
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
env = Jadeite::Environment.new
|
57
|
+
|
58
|
+
# compile first
|
59
|
+
compiled = env.compile_file("./hello.jade")
|
60
|
+
compiled.render :what => "world"
|
61
|
+
#=> "<p>Hello world!</p>"
|
62
|
+
|
63
|
+
# or simply
|
64
|
+
env.render_file("./hello.jade", :what => "moon")
|
65
|
+
#=> "<p>Hello moon!</p>"
|
66
|
+
```
|
67
|
+
|
68
|
+
### Output compiled template function (i.e. for serving your front-end views)
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
env = Jadeite::Environment.new
|
72
|
+
env.compile 'p Hello #{what}!', :client => true, :compileDebug => false
|
73
|
+
#=> function anonymous(locals, attrs, escape, rethrow, merge) {
|
74
|
+
# var attrs = jade.attrs, escape = jade.escape, rethrow = jade.rethrow, merge = jade.merge;
|
75
|
+
# var buf = [];
|
76
|
+
# with (locals || {}) {
|
77
|
+
# var interp;
|
78
|
+
# buf.push('<p>Hello ' + escape((interp = what) == null ? '' : interp) + '!</p>');
|
79
|
+
# }
|
80
|
+
# return buf.join("");
|
81
|
+
# }
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
See https://github.com/visionmedia/jade#browser-support for more info.
|
86
|
+
|
87
|
+
### API
|
88
|
+
Instances of Jadeite::Environment has two public methods:
|
89
|
+
|
90
|
+
`compile(template_string, options)` and `render(template_string, data, options)`
|
91
|
+
in where the `options` argument for both of them corresponds to the options argument in
|
92
|
+
[Jade's public api](https://github.com/visionmedia/jade#public-api).
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/jadeite.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jadeite/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Bjørge Næss"]
|
6
|
+
gem.email = ["bjoerge@bengler.no"]
|
7
|
+
gem.description = %q{Compile and render Jade templates from Ruby}
|
8
|
+
gem.summary = %q{Jadeite lets you compile and render Jade templates from your Ruby code. Under the hood it uses the Jade node module running in therubyracer's embedded V8 JavaScript engine.}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "jadeite"
|
15
|
+
gem.rubyforge_project = "jadeite"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Jadeite::VERSION
|
18
|
+
|
19
|
+
gem.extensions = "Rakefile"
|
20
|
+
|
21
|
+
gem.add_dependency "therubyracer"
|
22
|
+
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "simplecov"
|
25
|
+
end
|
data/lib/jadeite.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'v8'
|
2
|
+
require "nodejs"
|
3
|
+
|
4
|
+
module Jadeite
|
5
|
+
class Environment
|
6
|
+
def initialize
|
7
|
+
context = V8::Context.new
|
8
|
+
context.eval("var process = {env: {}}")
|
9
|
+
context.load(File.expand_path(File.join('../../../', 'node_modules/jade/runtime.js'), __FILE__))
|
10
|
+
|
11
|
+
node_env = NodeJS::Environment.new(context, File.expand_path('../../', __FILE__))
|
12
|
+
@jade = node_env.require('jade')
|
13
|
+
end
|
14
|
+
|
15
|
+
def compile(template_str, opts={})
|
16
|
+
Template.new(@jade.compile(template_str.strip, opts))
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(template_str, data={}, opts={})
|
20
|
+
compile(template_str, opts).render(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def compile_file(file, opts = {})
|
24
|
+
opts.merge!(:filename => File.expand_path(file))
|
25
|
+
compile(File.read(file), opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
def render_file(file, data={}, opts = {})
|
29
|
+
compile_file(file, opts).render(data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
class Template
|
35
|
+
def initialize(compiled)
|
36
|
+
@compiled = compiled
|
37
|
+
end
|
38
|
+
def render(data={})
|
39
|
+
@compiled.call data
|
40
|
+
end
|
41
|
+
def to_s
|
42
|
+
@compiled.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/nodejs.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
A Naïve implementation of Node.js require() in [therubyracer](https://github.com/cowboyd/therubyracer).
|
2
|
+
|
3
|
+
Based on [commonjs.rb](https://github.com/cowboyd/commonjs.rb) by Charles Lowell (cowboyd) but has a few notable extra features:
|
4
|
+
|
5
|
+
- If a directory is passed to require(), it will look for dirname/index.js
|
6
|
+
- If a module id is passed to require(), it will look in the node_modules subdirectory for a directory matching the module name,
|
7
|
+
read package.json from that directory and require the main entry javascript file.
|
8
|
+
|
9
|
+
# Disclaimer
|
10
|
+
|
11
|
+
This is by no means a solid implementation of the module loader in NPM. It is written to solve a very
|
12
|
+
specific task: to be able to require the jade npm module in therubyracer. If it works with other libraries,
|
13
|
+
it is most likely out of pure luck.
|
14
|
+
|
15
|
+
# Usage:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
env = NodeJS::Environment.new(V8::Context.new, File.expand_path(__FILE__))
|
20
|
+
|
21
|
+
# Will look for ./node_modules/lalala/package.json and require() the specified main entry file
|
22
|
+
lalala = env.require("lalala")
|
23
|
+
puts lalala.saySomething("arg1", "arg2")
|
24
|
+
|
25
|
+
somejs = env.require("./path/to/some.js")
|
26
|
+
|
27
|
+
puts somejs.doSomething(:test => "hello")
|
28
|
+
|
29
|
+
```
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Quick and dirty implementations of the node.js standard modules as required by Jade
|
2
|
+
module NodeJS
|
3
|
+
|
4
|
+
NodeJS.register_builtin('fs', {
|
5
|
+
:readFileSync => lambda {|this, file, encoding|
|
6
|
+
File.read(file).force_encoding("utf-8")
|
7
|
+
}
|
8
|
+
})
|
9
|
+
|
10
|
+
NodeJS.register_builtin('path', {
|
11
|
+
:dirname => lambda { |this, file|
|
12
|
+
File.dirname(file)
|
13
|
+
},
|
14
|
+
:basename => lambda { |this, *args|
|
15
|
+
File.basename(*args)
|
16
|
+
},
|
17
|
+
:join => lambda { |this, *args|
|
18
|
+
File.join(*args)
|
19
|
+
}
|
20
|
+
})
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
module NodeJS
|
4
|
+
class Environment
|
5
|
+
def initialize(runtime, base_path)
|
6
|
+
@runtime = runtime
|
7
|
+
@base_path = Pathname(base_path)
|
8
|
+
@cache = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_object
|
12
|
+
@runtime['Object'].new
|
13
|
+
end
|
14
|
+
|
15
|
+
def require(module_or_path)
|
16
|
+
# module main or single js file to require
|
17
|
+
|
18
|
+
return NodeJS.builtins[module_or_path] if NodeJS.builtins[module_or_path]
|
19
|
+
|
20
|
+
file = NodeJS.resolve(@base_path.dirname, module_or_path)
|
21
|
+
return @cache[file].exports if @cache[file]
|
22
|
+
|
23
|
+
mod = @cache[file] = Module.new(self, file)
|
24
|
+
|
25
|
+
loader = @runtime.eval("(function(module, require, exports) {#{File.read(file)}});", file.to_s)
|
26
|
+
loader.call(mod, mod.require_function, mod.exports)
|
27
|
+
mod.exports
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.resolve(base_path, module_or_path)
|
32
|
+
NodeJS.send(module_or_path =~ /^(\.|\/)/ ? :resolve_file : :resolve_module, base_path, module_or_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.resolve_file(base_path, path)
|
36
|
+
full_path = base_path.join(path)
|
37
|
+
return NodeJS.resolve_file(base_path, full_path.join("index.js")) if full_path.directory?
|
38
|
+
unless File.exists?(full_path) && full_path.extname =~ /\.js$/
|
39
|
+
full_path = Pathname("#{full_path.to_s}.js")
|
40
|
+
end
|
41
|
+
fail LoadError, "Module '#{full_path}' not found" unless full_path.file?
|
42
|
+
full_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.resolve_module(base_path, module_name)
|
46
|
+
module_dir = base_path.join("node_modules", module_name)
|
47
|
+
package_json = module_dir.join("package.json")
|
48
|
+
fail LoadError, "Module '#{module_name}' not found" unless package_json.file?
|
49
|
+
module_def = JSON.parse(File.read(package_json))
|
50
|
+
module_dir.join(module_def['main'])
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NodeJS
|
2
|
+
class Module
|
3
|
+
attr_accessor :exports
|
4
|
+
def initialize(environmnent, file)
|
5
|
+
@environment = environmnent
|
6
|
+
@file = file
|
7
|
+
@exports = @environment.new_object
|
8
|
+
end
|
9
|
+
|
10
|
+
# Used to require both script files and modules
|
11
|
+
# Script path is relative from base path and defines where the require function will begin looking for
|
12
|
+
# require()'d js-files
|
13
|
+
# script_path is ignored when requiring modules, i.e. require("jade")
|
14
|
+
def require_function
|
15
|
+
lambda do |*args|
|
16
|
+
this, module_id = *args
|
17
|
+
|
18
|
+
module_id ||= this #backwards compatibility with TRR < 0.10
|
19
|
+
|
20
|
+
return @environment.require(module_id) if NodeJS.builtins.keys.include?(module_id)
|
21
|
+
|
22
|
+
#puts "requiring #{module_id} from #{CommonJS.resolve(@file.dirname, module_id).to_s}"
|
23
|
+
@environment.require(NodeJS.resolve(@file.dirname, module_id).to_s)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/package.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<p>:)</p>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
form(method="post")
|
2
|
+
fieldset
|
3
|
+
legend General
|
4
|
+
p
|
5
|
+
label(for="user[name]") Username:
|
6
|
+
input(type="text", name="user[name]", value=user.name)
|
7
|
+
p
|
8
|
+
label(for="user[email]") Email:
|
9
|
+
input(type="text", name="user[email]", value=user.email)
|
10
|
+
.tip.
|
11
|
+
Enter a valid
|
12
|
+
email address
|
13
|
+
such as <em>tj@vision-media.ca</em>.
|
14
|
+
fieldset
|
15
|
+
legend Location
|
16
|
+
p
|
17
|
+
label(for="user[city]") City:
|
18
|
+
input(type="text", name="user[city]", value=user.city)
|
19
|
+
p
|
20
|
+
select(name="user[province]")
|
21
|
+
option(value="") -- Select Province --
|
22
|
+
option(value="AB") Alberta
|
23
|
+
option(value="BC") British Columbia
|
24
|
+
option(value="SK") Saskatchewan
|
25
|
+
option(value="MB") Manitoba
|
26
|
+
option(value="ON") Ontario
|
27
|
+
option(value="QC") Quebec
|
28
|
+
p.buttons
|
29
|
+
input(type="submit", value="Save")
|
data/spec/jade_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'jadeite'
|
3
|
+
|
4
|
+
describe "Jadeite" do
|
5
|
+
let(:template_str) {
|
6
|
+
<<-jade
|
7
|
+
p Hello \#{who}
|
8
|
+
- if (awesome)
|
9
|
+
em Pretty awesome
|
10
|
+
p=a.nested.title
|
11
|
+
p.
|
12
|
+
plain text can have a
|
13
|
+
body inside an element
|
14
|
+
jade
|
15
|
+
}
|
16
|
+
let(:template_data) {
|
17
|
+
{:who => "world", :awesome => true, :a => {:nested => {:title => "This is the nested title"}}}
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:env) {
|
21
|
+
Jadeite::Environment.new
|
22
|
+
}
|
23
|
+
let(:fixtures_path) {"./spec/fixtures"}
|
24
|
+
|
25
|
+
it "renders a jade template with data" do
|
26
|
+
env.render(template_str, template_data).should eql "<p>Hello world<em>Pretty awesome</em><p>This is the nested title</p><p>plain text can have a\nbody inside an element</p></p>"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can reference a compiled template and render it several times with various data" do
|
30
|
+
|
31
|
+
compiled = env.compile(template_str, template_data)
|
32
|
+
|
33
|
+
compiled.render(template_data).should eql "<p>Hello world<em>Pretty awesome</em><p>This is the nested title</p><p>plain text can have a\nbody inside an element</p></p>"
|
34
|
+
|
35
|
+
other_data = {:who => "moon!", :awesome => false, :a => {:nested => {:title => "Have you seen my dark side?"}}}
|
36
|
+
compiled.render(other_data).should eql "<p>Hello moon!<p>Have you seen my dark side?</p><p>plain text can have a\nbody inside an element</p></p>"
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Will fail if reference data is missing" do
|
41
|
+
|
42
|
+
compiled = env.compile(template_str, template_data)
|
43
|
+
|
44
|
+
other_data = {:who => "moon!", :awesome => false, :a => {}}
|
45
|
+
->{ compiled.render(other_data) }.should raise_error(V8::JSError, "Cannot read property 'title' of undefined")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "Can handle a more complex example" do
|
49
|
+
|
50
|
+
compiled = env.compile(File.read("#{fixtures_path}/form.jade"))
|
51
|
+
|
52
|
+
compiled.render(:user => {:name => "Bengel"}).should eq "<form method=\"post\"><fieldset><legend>General</legend><p><label for=\"user[name]\">Username:<input type=\"text\" name=\"user[name]\" value=\"Bengel\"/></label></p><p><label for=\"user[email]\">Email:<input type=\"text\" name=\"user[email]\"/><div class=\"tip\">Enter a valid \nemail address \nsuch as <em>tj@vision-media.ca</em>.</div></label></p></fieldset><fieldset><legend>Location</legend><p><label for=\"user[city]\">City:<input type=\"text\" name=\"user[city]\"/></label></p><p><select name=\"user[province]\"><option value=\"\">-- Select Province --</option><option value=\"AB\">Alberta</option><option value=\"BC\">British Columbia</option><option value=\"SK\">Saskatchewan</option><option value=\"MB\">Manitoba</option><option value=\"ON\">Ontario</option><option value=\"QC\">Quebec</option></select></p></fieldset><p class=\"buttons\"><input type=\"submit\" value=\"Save\"/></p></form>"
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "Handles includes" do
|
57
|
+
|
58
|
+
compiled = env.compile_file("#{fixtures_path}/includes.jade")
|
59
|
+
|
60
|
+
compiled.render.should eq "<p>bar</p><body><p>:)</p><script>\n console.log(\"foo\\nbar\")\n</script></body>"
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
it "Handles includes and mixins" do
|
65
|
+
|
66
|
+
compiled = env.compile_file("#{fixtures_path}/include-mixin.jade")
|
67
|
+
|
68
|
+
compiled.render.should eq "<html><head><title>My Application</title></head><body><h1>The meaning of life</h1><p>Foo bar baz!</p></body></html>"
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
it "Can render a file" do
|
73
|
+
env.render_file("#{fixtures_path}/include-mixin.jade").should eq "<html><head><title>My Application</title></head><body><h1>The meaning of life</h1><p>Foo bar baz!</p></body></html>"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "Returns a string of the compiled template" do
|
77
|
+
env.compile("p", :client => true, :compileDebug => false).to_s.should eq "function anonymous(locals, attrs, escape, rethrow, merge) {\nattrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow || jade.rethrow; merge = merge || jade.merge;\nvar buf = [];\nwith (locals || {}) {\nvar interp;\nbuf.push('<p></p>');\n}\nreturn buf.join(\"\");\n}"
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jadeite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bjørge Næss
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: therubyracer
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Compile and render Jade templates from Ruby
|
63
|
+
email:
|
64
|
+
- bjoerge@bengler.no
|
65
|
+
executables: []
|
66
|
+
extensions:
|
67
|
+
- Rakefile
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- jadeite.gemspec
|
77
|
+
- lib/jadeite.rb
|
78
|
+
- lib/jadeite/environment.rb
|
79
|
+
- lib/jadeite/version.rb
|
80
|
+
- lib/nodejs.rb
|
81
|
+
- lib/nodejs/README.md
|
82
|
+
- lib/nodejs/builtins.rb
|
83
|
+
- lib/nodejs/environment.rb
|
84
|
+
- lib/nodejs/module.rb
|
85
|
+
- package.json
|
86
|
+
- spec/fixtures/auxiliary/escapes.html
|
87
|
+
- spec/fixtures/auxiliary/layout.jade
|
88
|
+
- spec/fixtures/auxiliary/mixins.jade
|
89
|
+
- spec/fixtures/auxiliary/smile.html
|
90
|
+
- spec/fixtures/form.jade
|
91
|
+
- spec/fixtures/include-mixin.jade
|
92
|
+
- spec/fixtures/includes.jade
|
93
|
+
- spec/jade_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project: jadeite
|
115
|
+
rubygems_version: 1.8.19
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Jadeite lets you compile and render Jade templates from your Ruby code. Under
|
119
|
+
the hood it uses the Jade node module running in therubyracer's embedded V8 JavaScript
|
120
|
+
engine.
|
121
|
+
test_files:
|
122
|
+
- spec/fixtures/auxiliary/escapes.html
|
123
|
+
- spec/fixtures/auxiliary/layout.jade
|
124
|
+
- spec/fixtures/auxiliary/mixins.jade
|
125
|
+
- spec/fixtures/auxiliary/smile.html
|
126
|
+
- spec/fixtures/form.jade
|
127
|
+
- spec/fixtures/include-mixin.jade
|
128
|
+
- spec/fixtures/includes.jade
|
129
|
+
- spec/jade_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
has_rdoc:
|