jadeite 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,18 +27,18 @@ module Jadeite
27
27
  node_env = NodeJS::Environment.new(@context, File.expand_path('../../', __FILE__))
28
28
  @context['jade'] = node_env.require('jade-runtime').runtime
29
29
  @jade = node_env.require('jade')
30
+
31
+ # Create a new object in V8 that will keep a cached copy of compiled templates
32
+ @cache = @context['Object'].new
30
33
  end
31
34
 
32
35
  def compile(template_str, opts={})
33
36
  opts = compile_options.merge(opts)
34
37
  compiled = if cache?
35
- cached = cached_read(template_str, opts) do
36
- @jade.compile(template_str, opts.merge(client: true))
37
- end
38
- @context.eval(cached)
39
- else
40
- @jade.compile(template_str.strip, compile_options.merge(opts))
41
- end
38
+ cached_read(template_str, opts) { @jade.compile(template_str, opts) }
39
+ else
40
+ @jade.compile(template_str.strip, compile_options.merge(opts))
41
+ end
42
42
  Template.new(compiled)
43
43
  end
44
44
 
@@ -69,16 +69,9 @@ module Jadeite
69
69
  private
70
70
 
71
71
  def cached_read(template_str, opts, &blk)
72
- cache_file = File.join(cache_dir, "#{Digest::MD5.hexdigest("#{template_str}#{opts.inspect}")}.jade.js")
73
- if File.exists?(cache_file)
74
- File.read(cache_file)
75
- else
76
- File.open(cache_file, "w") do |f|
77
- cached = "(#{blk.call});"
78
- f.write(cached)
79
- cached
80
- end
81
- end
72
+ key = Digest::MD5.hexdigest("#{template_str}#{opts.inspect}")
73
+ @cache[key] = blk.call unless @cache[key]
74
+ @cache[key]
82
75
  end
83
76
  end
84
77
 
@@ -1,3 +1,3 @@
1
1
  module Jadeite
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -14,6 +14,9 @@ module NodeJS
14
14
  :basename => lambda { |this, *args|
15
15
  File.basename(*args)
16
16
  },
17
+ :extname => lambda { |this, *args|
18
+ File.extname(*args)
19
+ },
17
20
  :join => lambda { |this, *args|
18
21
  File.join(*args)
19
22
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jadeite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: therubyracer
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project: jadeite
124
- rubygems_version: 1.8.19
124
+ rubygems_version: 1.8.24
125
125
  signing_key:
126
126
  specification_version: 3
127
127
  summary: Jadeite lets you compile and render Jade templates from your Ruby code. Under