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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +53 -67
  3. data/Rakefile +4 -12
  4. data/lib/mustache.rb +67 -73
  5. data/lib/mustache/context.rb +57 -48
  6. data/lib/mustache/context_miss.rb +14 -0
  7. data/lib/mustache/generator.rb +5 -1
  8. data/lib/mustache/parser.rb +39 -14
  9. data/lib/mustache/settings.rb +1 -2
  10. data/lib/mustache/template.rb +37 -18
  11. data/lib/mustache/version.rb +1 -1
  12. data/test/autoloading_test.rb +2 -3
  13. data/test/fixtures/comments.rb +0 -1
  14. data/test/fixtures/complex_view.rb +0 -1
  15. data/test/fixtures/crazy_recursive.rb +0 -1
  16. data/test/fixtures/delimiters.rb +0 -1
  17. data/test/fixtures/dot_notation.rb +0 -1
  18. data/test/fixtures/double_section.rb +0 -1
  19. data/test/fixtures/inverted_section.rb +0 -1
  20. data/test/fixtures/lambda.rb +0 -1
  21. data/test/fixtures/liberal.rb +0 -1
  22. data/test/fixtures/method_missing.rb +0 -1
  23. data/test/fixtures/namespaced.rb +0 -1
  24. data/test/fixtures/nested_objects.rb +0 -1
  25. data/test/fixtures/partial_with_module.rb +0 -1
  26. data/test/fixtures/passenger.rb +0 -1
  27. data/test/fixtures/recursive.rb +0 -1
  28. data/test/fixtures/simple.rb +0 -1
  29. data/test/fixtures/template_partial.rb +0 -1
  30. data/test/fixtures/unescaped.rb +0 -1
  31. data/test/helper.rb +3 -2
  32. data/test/mustache_test.rb +13 -13
  33. data/test/parser_test.rb +2 -3
  34. data/test/partial_test.rb +2 -3
  35. data/test/spec_test.rb +2 -2
  36. data/test/template_test.rb +3 -4
  37. metadata +17 -19
  38. data/lib/mustache/sinatra.rb +0 -205
  39. data/lib/rack/bug/panels/mustache_panel.rb +0 -81
  40. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +0 -27
  41. data/lib/rack/bug/panels/mustache_panel/view.mustache +0 -46
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class CrazyRecursive < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Delimiters < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class DotNotation < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class DoubleSection < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class InvertedSection < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Lambda < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Liberal < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class MethodMissing < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  module TestViews
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
  require 'ostruct'
4
3
 
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  module SimpleView
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Passenger < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Recursive < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Simple < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class TemplatePartial < Mustache
@@ -1,4 +1,3 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
1
  require 'mustache'
3
2
 
4
3
  class Unescaped < Mustache
@@ -1,6 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
 
3
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/fixtures'
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
4
5
 
5
6
  Dir[File.dirname(__FILE__) + '/fixtures/*.rb'].each do |f|
6
7
  require f
@@ -1,8 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- $LOAD_PATH.unshift File.dirname(__FILE__)
3
- require 'helper'
2
+ require_relative 'helper'
4
3
 
5
- class MustacheTest < Test::Unit::TestCase
4
+ class MustacheTest < Minitest::Test
6
5
  def test_instance_render
7
6
  klass = Class.new(Mustache)
8
7
  klass.template = "Hi {{thing}}!"
@@ -15,7 +14,7 @@ end_simple
15
14
  end
16
15
 
17
16
  def test_passenger
18
- assert_equal <<-end_passenger, Passenger.to_text
17
+ assert_equal <<-end_passenger, Passenger.render
19
18
  <VirtualHost *>
20
19
  ServerName example.com
21
20
  DocumentRoot /var/www/example.com
@@ -429,7 +428,7 @@ Benvolio is 15
429
428
  def test_knows_when_its_been_compiled_when_set_with_string
430
429
  klass = Class.new(Mustache)
431
430
 
432
- assert ! klass.compiled?
431
+ refute klass.compiled?
433
432
  klass.template = 'Hi, {{person}}!'
434
433
  assert klass.compiled?
435
434
  end
@@ -438,28 +437,29 @@ Benvolio is 15
438
437
  klass = Class.new(Simple)
439
438
  klass.template_file = File.dirname(__FILE__) + '/fixtures/simple.mustache'
440
439
 
441
- assert ! klass.compiled?
440
+ refute klass.compiled?
442
441
  klass.render
443
442
  assert klass.compiled?
444
443
  end
445
444
 
446
445
  def test_an_instance_knows_when_its_class_is_compiled
447
- instance = Simple.new
446
+ klass = Class.new(Simple)
447
+ instance = klass.new
448
448
 
449
- assert ! Simple.compiled?
450
- assert ! instance.compiled?
449
+ refute klass.compiled?, "Simple was already compiled (from class)."
450
+ refute instance.compiled?, "Simple was already compiled (from instance)."
451
451
 
452
- Simple.render
452
+ klass.render
453
453
 
454
- assert Simple.compiled?
455
- assert instance.compiled?
454
+ assert klass.compiled?, "Simple was not compiled (from class)."
455
+ assert instance.compiled?, "Simple was not compiled (from instance)."
456
456
  end
457
457
 
458
458
  def test_knows_when_its_been_compiled_at_the_instance_level
459
459
  klass = Class.new(Mustache)
460
460
  instance = klass.new
461
461
 
462
- assert ! instance.compiled?
462
+ refute instance.compiled?
463
463
  instance.template = 'Hi, {{person}}!'
464
464
  assert instance.compiled?
465
465
  end
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
3
2
 
4
- class ParserTest < Test::Unit::TestCase
3
+ class ParserTest < Minitest::Test
5
4
 
6
5
  def test_parser_extension
7
6
  parser = Mustache::Parser.new
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
3
2
 
4
- class PartialTest < Test::Unit::TestCase
3
+ class PartialTest < Minitest::Test
5
4
  def test_view_partial
6
5
  assert_equal <<-end_partial.strip, PartialWithModule.render
7
6
  <h1>Welcome</h1>
@@ -1,7 +1,7 @@
1
1
  require 'mustache'
2
2
  require 'tmpdir'
3
3
  require 'yaml'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
6
  # Calls appropriate method on YAML. See: https://gist.github.com/tenderlove/958999ab4240b93bd3cd
7
7
  YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
@@ -10,7 +10,7 @@ YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
10
10
  # Creates a partials directory, then points a (dynamic) subclass of Mustache at
11
11
  # that directory before each test; the partials directory is destroyed after
12
12
  # each test is run.
13
- class MustacheSpec < Test::Unit::TestCase
13
+ class MustacheSpec < Minitest::Test
14
14
  def setup
15
15
  @partials = File.join(File.dirname(__FILE__), 'partials')
16
16
  Dir.mkdir(@partials)
@@ -1,7 +1,6 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'helper'
1
+ require_relative 'helper'
3
2
 
4
- class TemplateTest < Test::Unit::TestCase
3
+ class TemplateTest < Minitest::Test
5
4
  def test_compile
6
5
  assert_equal %("foo"), Mustache::Template.new("foo").compile
7
6
  end
@@ -19,7 +18,7 @@ class TemplateTest < Test::Unit::TestCase
19
18
  end
20
19
  end
21
20
 
22
- class TemplateTest2 < Test::Unit::TestCase
21
+ class TemplateTest2 < Minitest::Test
23
22
  def setup
24
23
  @@template_text ||= File.read(File.dirname(__FILE__) + "/fixtures/simply_complicated.mustache")
25
24
  @template = Mustache::Template.new(@@template_text)
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
8
8
  - Magnus Holm
9
9
  - Pieter van de Bruggen
10
+ - Ricardo Mendes
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2014-12-01 00:00:00.000000000 Z
14
+ date: 2015-01-11 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -41,47 +42,47 @@ dependencies:
41
42
  - !ruby/object:Gem::Version
42
43
  version: '10.3'
43
44
  - !ruby/object:Gem::Dependency
44
- name: rdoc
45
+ name: minitest
45
46
  requirement: !ruby/object:Gem::Requirement
46
47
  requirements:
47
48
  - - "~>"
48
49
  - !ruby/object:Gem::Version
49
- version: '4.1'
50
+ version: '5.4'
50
51
  type: :development
51
52
  prerelease: false
52
53
  version_requirements: !ruby/object:Gem::Requirement
53
54
  requirements:
54
55
  - - "~>"
55
56
  - !ruby/object:Gem::Version
56
- version: '4.1'
57
+ version: '5.4'
57
58
  - !ruby/object:Gem::Dependency
58
- name: ronn
59
+ name: rdoc
59
60
  requirement: !ruby/object:Gem::Requirement
60
61
  requirements:
61
62
  - - "~>"
62
63
  - !ruby/object:Gem::Version
63
- version: '0.7'
64
+ version: '4.1'
64
65
  type: :development
65
66
  prerelease: false
66
67
  version_requirements: !ruby/object:Gem::Requirement
67
68
  requirements:
68
69
  - - "~>"
69
70
  - !ruby/object:Gem::Version
70
- version: '0.7'
71
+ version: '4.1'
71
72
  - !ruby/object:Gem::Dependency
72
- name: turn
73
+ name: ronn
73
74
  requirement: !ruby/object:Gem::Requirement
74
75
  requirements:
75
76
  - - "~>"
76
77
  - !ruby/object:Gem::Version
77
- version: '0.9'
78
+ version: '0.7'
78
79
  type: :development
79
80
  prerelease: false
80
81
  version_requirements: !ruby/object:Gem::Requirement
81
82
  requirements:
82
83
  - - "~>"
83
84
  - !ruby/object:Gem::Version
84
- version: '0.9'
85
+ version: '0.7'
85
86
  description: |
86
87
  Inspired by ctemplate, Mustache is a framework-agnostic way to render
87
88
  logic-free views.
@@ -94,7 +95,7 @@ description: |
94
95
  consisting of ERB or HAML with random helpers and arbitrary logic,
95
96
  your views are broken into two parts: a Ruby class and an HTML
96
97
  template.
97
- email: chris@ozmm.org
98
+ email: rokusu@gmail.com
98
99
  executables:
99
100
  - mustache
100
101
  extensions: []
@@ -106,16 +107,13 @@ files:
106
107
  - bin/mustache
107
108
  - lib/mustache.rb
108
109
  - lib/mustache/context.rb
110
+ - lib/mustache/context_miss.rb
109
111
  - lib/mustache/enumerable.rb
110
112
  - lib/mustache/generator.rb
111
113
  - lib/mustache/parser.rb
112
114
  - lib/mustache/settings.rb
113
- - lib/mustache/sinatra.rb
114
115
  - lib/mustache/template.rb
115
116
  - lib/mustache/version.rb
116
- - lib/rack/bug/panels/mustache_panel.rb
117
- - lib/rack/bug/panels/mustache_panel/mustache_extension.rb
118
- - lib/rack/bug/panels/mustache_panel/view.mustache
119
117
  - man/mustache.1
120
118
  - man/mustache.1.html
121
119
  - man/mustache.1.ron
@@ -173,7 +171,7 @@ files:
173
171
  - test/partial_test.rb
174
172
  - test/spec_test.rb
175
173
  - test/template_test.rb
176
- homepage: http://github.com/mustache/mustache
174
+ homepage: https://github.com/mustache/mustache
177
175
  licenses:
178
176
  - MIT
179
177
  metadata: {}
@@ -183,9 +181,9 @@ require_paths:
183
181
  - lib
184
182
  required_ruby_version: !ruby/object:Gem::Requirement
185
183
  requirements:
186
- - - ">="
184
+ - - "~>"
187
185
  - !ruby/object:Gem::Version
188
- version: 1.9.3
186
+ version: '2.0'
189
187
  required_rubygems_version: !ruby/object:Gem::Requirement
190
188
  requirements:
191
189
  - - ">="
@@ -1,205 +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
- #
43
- # If you don't want the Sinatra extension to look up your view class,
44
- # maybe because you've already loaded it or you're pulling it in from
45
- # a gem, you can hand the `mustache` helper a Mustache subclass directly:
46
- #
47
- # # Assuming `class Omnigollum::Login < Mustache`
48
- # get '/login' do
49
- # @title = "Log In"
50
- # require 'lib/omnigollum/views/login'
51
- # mustache Omnigollum::Login
52
- # end
53
- #
54
- module Sinatra
55
- module Helpers
56
- # Call this in your Sinatra routes.
57
- def mustache(template, options={}, locals={})
58
- # Locals can be passed as options under the :locals key.
59
- locals.update(options.delete(:locals) || {})
60
-
61
- # Grab any user-defined settings.
62
- if settings.respond_to?(:mustache)
63
- options = settings.send(:mustache).merge(options)
64
- end
65
-
66
- # If they aren't explicitly disabling layouts, try to find
67
- # one.
68
- if options[:layout] != false
69
- # Let the user pass in a layout name.
70
- layout_name = options[:layout]
71
-
72
- # If all they said was `true` (or nothing), default to :layout.
73
- layout_name = :layout if layout_name == true || !layout_name
74
-
75
- # If they passed a layout name use that.
76
- layout = mustache_class(layout_name, options)
77
-
78
- # If it's just an anonymous subclass then don't bother, otherwise
79
- # give us a layout instance.
80
- if layout.name && layout.name.empty?
81
- layout = nil
82
- else
83
- layout = layout.new
84
- end
85
- end
86
-
87
- # If instead of a symbol they gave us a Mustache class,
88
- # use that for rendering.
89
- klass = template if template.is_a?(Class) && template < Mustache
90
-
91
- # Find and cache the view class we want if we don't have
92
- # one yet. This ensures the compiled template is cached,
93
- # too - no looking up and compiling templates on each page
94
- # load.
95
- if klass.nil?
96
- klass = mustache_class(template, options)
97
- end
98
-
99
- # Does the view subclass the layout? If so we'll use the
100
- # view to render the layout so you can override layout
101
- # methods in your view - tricky.
102
- view_subclasses_layout = klass < layout.class if layout
103
-
104
- # Create a new instance for playing with.
105
- instance = klass.new
106
-
107
- # Copy instance variables set in Sinatra to the view
108
- instance_variables.each do |name|
109
- instance.instance_variable_set(name, instance_variable_get(name))
110
- end
111
-
112
- # Render with locals.
113
- rendered = instance.render(instance.template, locals)
114
-
115
- # Now render the layout with the view we just rendered, if we
116
- # need to.
117
- if layout && view_subclasses_layout
118
- rendered = instance.render(layout.template, :yield => rendered)
119
- elsif layout
120
- rendered = layout.render(layout.template, :yield => rendered)
121
- end
122
-
123
- # That's it.
124
- rendered
125
- end
126
-
127
- # Returns a View class for a given template name.
128
- def mustache_class(template, options = {})
129
- @template_cache.fetch(:mustache, template) do
130
- compile_mustache(template, options)
131
- end
132
- end
133
-
134
- # Given a view name and settings, finds and prepares an
135
- # appropriate view class for this view.
136
- def compile_mustache(view, options = {})
137
- options[:templates] ||= settings.views if settings.respond_to?(:views)
138
- options[:namespace] ||= self.class
139
-
140
- unless options[:namespace].to_s.include? 'Views'
141
- options[:namespace] = options[:namespace].const_get(:Views) rescue Object
142
- end
143
-
144
- factory = Class.new(Mustache) do
145
- self.view_namespace = options[:namespace]
146
- self.view_path = options[:views]
147
- end
148
-
149
- # If we were handed :"positions.atom" or some such as the
150
- # template name, we need to remember the extension.
151
- if view.to_s.include?('.')
152
- view, ext = view.to_s.split('.')
153
- end
154
-
155
- # Try to find the view class for a given view, e.g.
156
- # :view => Hurl::Views::Index.
157
- klass = factory.view_class(view)
158
- klass.view_namespace = options[:namespace]
159
- klass.view_path = options[:views]
160
-
161
- # If there is no view class, issue a warning and use the one
162
- # we just generated to cache the compiled template.
163
- if klass == Mustache
164
- warn "No view class found for #{view} in #{factory.view_path}"
165
- klass = factory
166
-
167
- # If this is a generic view class make sure we set the
168
- # template name as it was given. That is, an anonymous
169
- # subclass of Mustache won't know how to find the
170
- # "index.mustache" template unless we tell it to.
171
- klass.template_name = view.to_s
172
- elsif ext
173
- # We got an ext (like "atom"), so look for an "Atom" class
174
- # under the current View's namespace.
175
- #
176
- # So if our template was "positions.atom", try to find
177
- # Positions::Atom.
178
- if klass.const_defined?(ext_class = ext.capitalize)
179
- # Found Positions::Atom - set it
180
- klass = klass.const_get(ext_class)
181
- else
182
- # Didn't find Positions::Atom - create it by creating an
183
- # anonymous subclass of Positions and setting that to
184
- # Positions::Atom.
185
- new_class = Class.new(klass)
186
- new_class.template_name = "#{view}.#{ext}"
187
- klass.const_set(ext_class, new_class)
188
- klass = new_class
189
- end
190
- end
191
-
192
- # Set the template path and return our class.
193
- klass.template_path = options[:templates] if options[:templates]
194
- klass
195
- end
196
- end
197
-
198
- # Called when you `register Mustache::Sinatra` in your Sinatra app.
199
- def self.registered(app)
200
- app.helpers Mustache::Sinatra::Helpers
201
- end
202
- end
203
- end
204
-
205
- Sinatra.register Mustache::Sinatra