mustache 0.99.8 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +53 -67
- data/Rakefile +4 -12
- data/lib/mustache.rb +67 -73
- data/lib/mustache/context.rb +57 -48
- data/lib/mustache/context_miss.rb +14 -0
- data/lib/mustache/generator.rb +5 -1
- data/lib/mustache/parser.rb +39 -14
- data/lib/mustache/settings.rb +1 -2
- data/lib/mustache/template.rb +37 -18
- data/lib/mustache/version.rb +1 -1
- data/test/autoloading_test.rb +2 -3
- data/test/fixtures/comments.rb +0 -1
- data/test/fixtures/complex_view.rb +0 -1
- data/test/fixtures/crazy_recursive.rb +0 -1
- data/test/fixtures/delimiters.rb +0 -1
- data/test/fixtures/dot_notation.rb +0 -1
- data/test/fixtures/double_section.rb +0 -1
- data/test/fixtures/inverted_section.rb +0 -1
- data/test/fixtures/lambda.rb +0 -1
- data/test/fixtures/liberal.rb +0 -1
- data/test/fixtures/method_missing.rb +0 -1
- data/test/fixtures/namespaced.rb +0 -1
- data/test/fixtures/nested_objects.rb +0 -1
- data/test/fixtures/partial_with_module.rb +0 -1
- data/test/fixtures/passenger.rb +0 -1
- data/test/fixtures/recursive.rb +0 -1
- data/test/fixtures/simple.rb +0 -1
- data/test/fixtures/template_partial.rb +0 -1
- data/test/fixtures/unescaped.rb +0 -1
- data/test/helper.rb +3 -2
- data/test/mustache_test.rb +13 -13
- data/test/parser_test.rb +2 -3
- data/test/partial_test.rb +2 -3
- data/test/spec_test.rb +2 -2
- data/test/template_test.rb +3 -4
- metadata +17 -19
- data/lib/mustache/sinatra.rb +0 -205
- data/lib/rack/bug/panels/mustache_panel.rb +0 -81
- data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +0 -27
- data/lib/rack/bug/panels/mustache_panel/view.mustache +0 -46
@@ -1,81 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
module Bug
|
3
|
-
# MustachePanel is a Rack::Bug panel which tracks the time spent rendering
|
4
|
-
# Mustache views as well as all the variables accessed during view
|
5
|
-
# rendering.
|
6
|
-
#
|
7
|
-
# It can be used to track down slow partials and ensure you're only
|
8
|
-
# generating data you need.
|
9
|
-
#
|
10
|
-
# Also, it's fun.
|
11
|
-
class MustachePanel < Panel
|
12
|
-
require "rack/bug/panels/mustache_panel/mustache_extension"
|
13
|
-
|
14
|
-
# The view is responsible for rendering our panel. While Rack::Bug
|
15
|
-
# takes care of the nav, the content rendered by View is used for
|
16
|
-
# the panel itself.
|
17
|
-
class View < Mustache
|
18
|
-
self.path = ::File.dirname(__FILE__) + '/mustache_panel'
|
19
|
-
|
20
|
-
# We track the render times of all the Mustache views on this
|
21
|
-
# page load.
|
22
|
-
def times
|
23
|
-
MustachePanel.times.map do |key, value|
|
24
|
-
{ :key => key, :value => value }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Any variables used in this page load are collected and displayed.
|
29
|
-
def variables
|
30
|
-
vars = MustachePanel.variables.sort_by { |key, _| key.to_s }
|
31
|
-
vars.map do |key, value|
|
32
|
-
# Arrays can get too huge. Just show the first 10 to give you
|
33
|
-
# some idea.
|
34
|
-
if value.is_a?(Array) && value.size > 10
|
35
|
-
size = value.size
|
36
|
-
value = value.first(10)
|
37
|
-
value << "...and #{size - 10} more"
|
38
|
-
end
|
39
|
-
|
40
|
-
{ :key => key, :value => value.inspect }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Clear out our page load-specific variables.
|
46
|
-
def self.reset
|
47
|
-
Thread.current["rack.bug.mustache.times"] = {}
|
48
|
-
Thread.current["rack.bug.mustache.vars"] = {}
|
49
|
-
end
|
50
|
-
|
51
|
-
# The view render times for this page load
|
52
|
-
def self.times
|
53
|
-
Thread.current["rack.bug.mustache.times"] ||= {}
|
54
|
-
end
|
55
|
-
|
56
|
-
# The variables used on this page load
|
57
|
-
def self.variables
|
58
|
-
Thread.current["rack.bug.mustache.vars"] ||= {}
|
59
|
-
end
|
60
|
-
|
61
|
-
# The name of this Rack::Bug panel
|
62
|
-
def name
|
63
|
-
"mustache"
|
64
|
-
end
|
65
|
-
|
66
|
-
# The string used for our tab in Rack::Bug's navigation bar
|
67
|
-
def heading
|
68
|
-
"{{%.2fms}}" % self.class.times.values.reduce(0.0) do |sum, obj|
|
69
|
-
sum + obj
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
# The content of our Rack::Bug panel
|
74
|
-
def content
|
75
|
-
View.render
|
76
|
-
ensure
|
77
|
-
self.class.reset
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
if defined? Mustache
|
2
|
-
require 'benchmark'
|
3
|
-
|
4
|
-
Mustache.class_eval do
|
5
|
-
alias_method :real_render, :render
|
6
|
-
|
7
|
-
def render(*args, &block)
|
8
|
-
out = ''
|
9
|
-
Rack::Bug::MustachePanel.times[self.class.name] = Benchmark.realtime do
|
10
|
-
out = real_render(*args, &block)
|
11
|
-
end
|
12
|
-
out
|
13
|
-
end
|
14
|
-
|
15
|
-
alias_method :to_html, :render
|
16
|
-
alias_method :to_text, :render
|
17
|
-
end
|
18
|
-
|
19
|
-
Mustache::Context.class_eval do
|
20
|
-
alias_method :real_get, :[]
|
21
|
-
|
22
|
-
def [](name)
|
23
|
-
return real_get(name) if name == :yield || !@mustache.respond_to?(name)
|
24
|
-
Rack::Bug::MustachePanel.variables[name] = real_get(name)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
<script type="text/javascript">
|
2
|
-
$(function() {
|
3
|
-
$('#mustache_variables .variable').each(function() {
|
4
|
-
var el = $(this)
|
5
|
-
if (el.text().length > 500) {
|
6
|
-
var txt = el.text()
|
7
|
-
el.click(function() {
|
8
|
-
$(this).text(txt)
|
9
|
-
}).text( el.text().slice(0, 500) + '...' )
|
10
|
-
}
|
11
|
-
})
|
12
|
-
});
|
13
|
-
</script>
|
14
|
-
|
15
|
-
<h3>Render Times</h3>
|
16
|
-
|
17
|
-
<table>
|
18
|
-
<tr>
|
19
|
-
<th>View</th>
|
20
|
-
<th>Render Time</th>
|
21
|
-
</tr>
|
22
|
-
|
23
|
-
{{# times }}
|
24
|
-
<tr>
|
25
|
-
<td>{{ key }}</td>
|
26
|
-
<td>{{ value }}</td>
|
27
|
-
</tr>
|
28
|
-
{{/ times }}
|
29
|
-
</table>
|
30
|
-
|
31
|
-
<h3>Variables</h3>
|
32
|
-
|
33
|
-
<table id="mustache_variables">
|
34
|
-
<tr>
|
35
|
-
<th>Name</th>
|
36
|
-
<th>Value</th>
|
37
|
-
</tr>
|
38
|
-
|
39
|
-
{{# variables }}
|
40
|
-
<tr>
|
41
|
-
<td>{{ key }}</td>
|
42
|
-
<td class="variable">{{ value }}</td>
|
43
|
-
</tr>
|
44
|
-
{{/ variables }}
|
45
|
-
</table>
|
46
|
-
|