mustache 0.99.4 → 1.1.3

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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +183 -183
  3. data/Rakefile +6 -14
  4. data/bin/mustache +28 -14
  5. data/lib/mustache/context.rb +98 -46
  6. data/lib/mustache/context_miss.rb +55 -0
  7. data/lib/mustache/enumerable.rb +3 -0
  8. data/lib/mustache/generator.rb +63 -42
  9. data/lib/mustache/parser.rb +173 -65
  10. data/lib/mustache/settings.rb +84 -24
  11. data/lib/mustache/template.rb +74 -4
  12. data/lib/mustache/utils.rb +31 -0
  13. data/lib/mustache/version.rb +1 -1
  14. data/lib/mustache.rb +116 -96
  15. data/man/mustache.1 +25 -40
  16. data/man/mustache.1.html +90 -81
  17. data/man/mustache.1.ron +6 -6
  18. data/man/mustache.5 +338 -298
  19. data/man/mustache.5.html +400 -115
  20. data/man/mustache.5.ron +292 -32
  21. data/test/autoloading_test.rb +7 -3
  22. data/test/fixtures/comments.rb +0 -1
  23. data/test/fixtures/complex_view.rb +0 -1
  24. data/test/fixtures/crazy_recursive.rb +0 -1
  25. data/test/fixtures/delimiters.rb +0 -1
  26. data/test/fixtures/dot_notation.rb +0 -1
  27. data/test/fixtures/double_section.rb +0 -1
  28. data/test/fixtures/inverted_section.rb +0 -1
  29. data/test/fixtures/lambda.rb +0 -1
  30. data/test/fixtures/liberal.mustache +1 -0
  31. data/test/fixtures/liberal.rb +25 -0
  32. data/test/fixtures/method_missing.rb +0 -1
  33. data/test/fixtures/namespaced.rb +0 -1
  34. data/test/fixtures/nested_objects.rb +0 -1
  35. data/test/fixtures/override/passenger.conf +6 -0
  36. data/test/fixtures/partial_with_module.rb +0 -1
  37. data/test/fixtures/passenger.rb +0 -1
  38. data/test/fixtures/recursive.rb +0 -1
  39. data/test/fixtures/simple.rb +0 -1
  40. data/test/fixtures/simply_complicated.mustache +25 -0
  41. data/test/fixtures/template_partial.rb +0 -1
  42. data/test/fixtures/unescaped.rb +0 -1
  43. data/test/helper.rb +5 -2
  44. data/test/mustache_test.rb +210 -25
  45. data/test/parser_test.rb +90 -7
  46. data/test/partial_test.rb +16 -4
  47. data/test/path_test.rb +49 -0
  48. data/test/spec_test.rb +5 -5
  49. data/test/template_test.rb +35 -3
  50. metadata +37 -59
  51. data/lib/mustache/sinatra.rb +0 -186
  52. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +0 -27
  53. data/lib/rack/bug/panels/mustache_panel/view.mustache +0 -46
  54. data/lib/rack/bug/panels/mustache_panel.rb +0 -81
metadata CHANGED
@@ -1,62 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mustache
3
- version: !ruby/object:Gem::Version
4
- hash: 411
5
- prerelease:
6
- segments:
7
- - 0
8
- - 99
9
- - 4
10
- version: 0.99.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Chris Wanstrath
14
8
  - Magnus Holm
15
9
  - Pieter van de Bruggen
16
- autorequire:
10
+ - Ricardo Mendes
17
11
  bindir: bin
18
12
  cert_chain: []
19
-
20
- date: 2011-05-26 00:00:00 -07:00
21
- default_executable:
13
+ date: 2026-08-20 00:00:00.000000000 Z
22
14
  dependencies: []
23
-
24
15
  description: |
25
16
  Inspired by ctemplate, Mustache is a framework-agnostic way to render
26
17
  logic-free views.
27
-
18
+
28
19
  As ctemplates says, "It emphasizes separating logic from presentation:
29
20
  it is impossible to embed application logic in this template
30
21
  language.
31
-
22
+
32
23
  Think of Mustache as a replacement for your views. Instead of views
33
24
  consisting of ERB or HAML with random helpers and arbitrary logic,
34
25
  your views are broken into two parts: a Ruby class and an HTML
35
26
  template.
36
-
37
- email: chris@ozmm.org
38
- executables:
27
+ email: rokusu@gmail.com
28
+ executables:
39
29
  - mustache
40
30
  extensions: []
41
-
42
31
  extra_rdoc_files: []
43
-
44
- files:
32
+ files:
33
+ - LICENSE
45
34
  - README.md
46
35
  - Rakefile
47
- - LICENSE
36
+ - bin/mustache
37
+ - lib/mustache.rb
48
38
  - lib/mustache/context.rb
39
+ - lib/mustache/context_miss.rb
40
+ - lib/mustache/enumerable.rb
49
41
  - lib/mustache/generator.rb
50
42
  - lib/mustache/parser.rb
51
43
  - lib/mustache/settings.rb
52
- - lib/mustache/sinatra.rb
53
44
  - lib/mustache/template.rb
45
+ - lib/mustache/utils.rb
54
46
  - lib/mustache/version.rb
55
- - lib/mustache.rb
56
- - lib/rack/bug/panels/mustache_panel/mustache_extension.rb
57
- - lib/rack/bug/panels/mustache_panel/view.mustache
58
- - lib/rack/bug/panels/mustache_panel.rb
59
- - bin/mustache
60
47
  - man/mustache.1
61
48
  - man/mustache.1.html
62
49
  - man/mustache.1.ron
@@ -84,12 +71,15 @@ files:
84
71
  - test/fixtures/inverted_section.rb
85
72
  - test/fixtures/lambda.mustache
86
73
  - test/fixtures/lambda.rb
74
+ - test/fixtures/liberal.mustache
75
+ - test/fixtures/liberal.rb
87
76
  - test/fixtures/method_missing.rb
88
77
  - test/fixtures/namespaced.mustache
89
78
  - test/fixtures/namespaced.rb
90
79
  - test/fixtures/nested_objects.mustache
91
80
  - test/fixtures/nested_objects.rb
92
81
  - test/fixtures/node.mustache
82
+ - test/fixtures/override/passenger.conf
93
83
  - test/fixtures/partial_with_module.mustache
94
84
  - test/fixtures/partial_with_module.rb
95
85
  - test/fixtures/passenger.conf
@@ -98,6 +88,7 @@ files:
98
88
  - test/fixtures/recursive.rb
99
89
  - test/fixtures/simple.mustache
100
90
  - test/fixtures/simple.rb
91
+ - test/fixtures/simply_complicated.mustache
101
92
  - test/fixtures/template_partial.mustache
102
93
  - test/fixtures/template_partial.rb
103
94
  - test/fixtures/template_partial.txt
@@ -109,41 +100,28 @@ files:
109
100
  - test/mustache_test.rb
110
101
  - test/parser_test.rb
111
102
  - test/partial_test.rb
103
+ - test/path_test.rb
112
104
  - test/spec_test.rb
113
105
  - test/template_test.rb
114
- has_rdoc: true
115
- homepage: http://github.com/defunkt/mustache
116
- licenses: []
117
-
118
- post_install_message:
106
+ homepage: https://github.com/mustache/mustache
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
119
110
  rdoc_options: []
120
-
121
- require_paths:
111
+ require_paths:
122
112
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
- requirements:
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
126
115
  - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
132
- required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
- requirements:
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
135
120
  - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
- version: "0"
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
141
123
  requirements: []
142
-
143
- rubyforge_project:
144
- rubygems_version: 1.5.2
145
- signing_key:
146
- specification_version: 3
124
+ rubygems_version: 3.6.9
125
+ specification_version: 4
147
126
  summary: Mustache is a framework-agnostic way to render logic-free views.
148
127
  test_files: []
149
-
@@ -1,186 +0,0 @@
1
- require 'sinatra/base'
2
- require 'mustache'
3
-
4
- class Mustache
5
- # Support for Mustache in your Sinatra app.
6
- #
7
- # require 'mustache/sinatra'
8
- #
9
- # class Hurl < Sinatra::Base
10
- # register Mustache::Sinatra
11
- #
12
- # set :mustache, {
13
- # # Should be the path to your .mustache template files.
14
- # :templates => "path/to/mustache/templates",
15
- #
16
- # # Should be the path to your .rb Mustache view files.
17
- # :views => "path/to/mustache/views",
18
- #
19
- # # This tells Mustache where to look for the Views module,
20
- # # under which your View classes should live. By default it's
21
- # # the class of your app - in this case `Hurl`. That is, for an :index
22
- # # view Mustache will expect Hurl::Views::Index by default.
23
- # # If our Sinatra::Base subclass was instead Hurl::App,
24
- # # we'd want to do `set :namespace, Hurl::App`
25
- # :namespace => Hurl
26
- # }
27
- #
28
- # get '/stats' do
29
- # mustache :stats
30
- # end
31
- # end
32
- #
33
- # As noted above, Mustache will look for `Hurl::Views::Index` when
34
- # `mustache :index` is called.
35
- #
36
- # If no `Views::Stats` class exists Mustache will render the template
37
- # file directly.
38
- #
39
- # You can indeed use layouts with this library. Where you'd normally
40
- # <%= yield %> you instead {{{yield}}} - the body of the subview is
41
- # set to the `yield` variable and made available to you.
42
- module Sinatra
43
- module Helpers
44
- # Call this in your Sinatra routes.
45
- def mustache(template, options={}, locals={})
46
- # Locals can be passed as options under the :locals key.
47
- locals.update(options.delete(:locals) || {})
48
-
49
- # Grab any user-defined settings.
50
- if settings.respond_to?(:mustache)
51
- options = settings.send(:mustache).merge(options)
52
- end
53
-
54
- # If they aren't explicitly disabling layouts, try to find
55
- # one.
56
- if options[:layout] != false
57
- # Let the user pass in a layout name.
58
- layout_name = options[:layout]
59
-
60
- # If all they said was `true` (or nothing), default to :layout.
61
- layout_name = :layout if layout_name == true || !layout_name
62
-
63
- # If they passed a layout name use that.
64
- layout = mustache_class(layout_name, options)
65
-
66
- # If it's just an anonymous subclass then don't bother, otherwise
67
- # give us a layout instance.
68
- if layout.name && layout.name.empty?
69
- layout = nil
70
- else
71
- layout = layout.new
72
- end
73
- end
74
-
75
- # Find and cache the view class we want. This ensures the
76
- # compiled template is cached, too - no looking up and
77
- # compiling templates on each page load.
78
- klass = mustache_class(template, options)
79
-
80
- # Does the view subclass the layout? If so we'll use the
81
- # view to render the layout so you can override layout
82
- # methods in your view - tricky.
83
- view_subclasses_layout = klass < layout.class if layout
84
-
85
- # Create a new instance for playing with.
86
- instance = klass.new
87
-
88
- # Copy instance variables set in Sinatra to the view
89
- instance_variables.each do |name|
90
- instance.instance_variable_set(name, instance_variable_get(name))
91
- end
92
-
93
- # Render with locals.
94
- rendered = instance.render(instance.template, locals)
95
-
96
- # Now render the layout with the view we just rendered, if we
97
- # need to.
98
- if layout && view_subclasses_layout
99
- rendered = instance.render(layout.template, :yield => rendered)
100
- elsif layout
101
- rendered = layout.render(layout.template, :yield => rendered)
102
- end
103
-
104
- # That's it.
105
- rendered
106
- end
107
-
108
- # Returns a View class for a given template name.
109
- def mustache_class(template, options = {})
110
- @template_cache.fetch(:mustache, template) do
111
- compile_mustache(template, options)
112
- end
113
- end
114
-
115
- # Given a view name and settings, finds and prepares an
116
- # appropriate view class for this view.
117
- def compile_mustache(view, options = {})
118
- options[:templates] ||= settings.views if settings.respond_to?(:views)
119
- options[:namespace] ||= self.class
120
-
121
- unless options[:namespace].to_s.include? 'Views'
122
- options[:namespace] = options[:namespace].const_get(:Views)
123
- end
124
-
125
- factory = Class.new(Mustache) do
126
- self.view_namespace = options[:namespace]
127
- self.view_path = options[:views]
128
- end
129
-
130
- # If we were handed :"positions.atom" or some such as the
131
- # template name, we need to remember the extension.
132
- if view.to_s.include?('.')
133
- view, ext = view.to_s.split('.')
134
- end
135
-
136
- # Try to find the view class for a given view, e.g.
137
- # :view => Hurl::Views::Index.
138
- klass = factory.view_class(view)
139
- klass.view_namespace = options[:namespace]
140
- klass.view_path = options[:views]
141
-
142
- # If there is no view class, issue a warning and use the one
143
- # we just generated to cache the compiled template.
144
- if klass == Mustache
145
- warn "No view class found for #{view} in #{factory.view_path}"
146
- klass = factory
147
-
148
- # If this is a generic view class make sure we set the
149
- # template name as it was given. That is, an anonymous
150
- # subclass of Mustache won't know how to find the
151
- # "index.mustache" template unless we tell it to.
152
- klass.template_name = view.to_s
153
- elsif ext
154
- # We got an ext (like "atom"), so look for an "Atom" class
155
- # under the current View's namespace.
156
- #
157
- # So if our template was "positions.atom", try to find
158
- # Positions::Atom.
159
- if klass.const_defined?(ext_class = ext.capitalize)
160
- # Found Positions::Atom - set it
161
- klass = klass.const_get(ext_class)
162
- else
163
- # Didn't find Positions::Atom - create it by creating an
164
- # anonymous subclass of Positions and setting that to
165
- # Positions::Atom.
166
- new_class = Class.new(klass)
167
- new_class.template_name = "#{view}.#{ext}"
168
- klass.const_set(ext_class, new_class)
169
- klass = new_class
170
- end
171
- end
172
-
173
- # Set the template path and return our class.
174
- klass.template_path = options[:templates] if options[:templates]
175
- klass
176
- end
177
- end
178
-
179
- # Called when you `register Mustache::Sinatra` in your Sinatra app.
180
- def self.registered(app)
181
- app.helpers Mustache::Sinatra::Helpers
182
- end
183
- end
184
- end
185
-
186
- Sinatra.register Mustache::Sinatra
@@ -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
-
@@ -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.inject(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