mustache-bibanon 0.99.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +409 -0
  3. data/Rakefile +89 -0
  4. data/bin/mustache +94 -0
  5. data/lib/mustache.rb +304 -0
  6. data/lib/mustache/context.rb +142 -0
  7. data/lib/mustache/generator.rb +195 -0
  8. data/lib/mustache/parser.rb +263 -0
  9. data/lib/mustache/settings.rb +226 -0
  10. data/lib/mustache/sinatra.rb +205 -0
  11. data/lib/mustache/template.rb +58 -0
  12. data/lib/mustache/version.rb +3 -0
  13. data/lib/rack/bug/panels/mustache_panel.rb +81 -0
  14. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +27 -0
  15. data/lib/rack/bug/panels/mustache_panel/view.mustache +46 -0
  16. data/man/mustache.1 +165 -0
  17. data/man/mustache.1.html +213 -0
  18. data/man/mustache.1.ron +127 -0
  19. data/man/mustache.5 +539 -0
  20. data/man/mustache.5.html +422 -0
  21. data/man/mustache.5.ron +324 -0
  22. data/test/autoloading_test.rb +56 -0
  23. data/test/fixtures/comments.mustache +1 -0
  24. data/test/fixtures/comments.rb +14 -0
  25. data/test/fixtures/complex_view.mustache +17 -0
  26. data/test/fixtures/complex_view.rb +34 -0
  27. data/test/fixtures/crazy_recursive.mustache +9 -0
  28. data/test/fixtures/crazy_recursive.rb +31 -0
  29. data/test/fixtures/delimiters.mustache +8 -0
  30. data/test/fixtures/delimiters.rb +23 -0
  31. data/test/fixtures/dot_notation.mustache +10 -0
  32. data/test/fixtures/dot_notation.rb +25 -0
  33. data/test/fixtures/double_section.mustache +7 -0
  34. data/test/fixtures/double_section.rb +14 -0
  35. data/test/fixtures/escaped.mustache +1 -0
  36. data/test/fixtures/escaped.rb +14 -0
  37. data/test/fixtures/inner_partial.mustache +1 -0
  38. data/test/fixtures/inner_partial.txt +1 -0
  39. data/test/fixtures/inverted_section.mustache +7 -0
  40. data/test/fixtures/inverted_section.rb +14 -0
  41. data/test/fixtures/lambda.mustache +7 -0
  42. data/test/fixtures/lambda.rb +31 -0
  43. data/test/fixtures/method_missing.rb +19 -0
  44. data/test/fixtures/namespaced.mustache +1 -0
  45. data/test/fixtures/namespaced.rb +25 -0
  46. data/test/fixtures/nested_objects.mustache +17 -0
  47. data/test/fixtures/nested_objects.rb +35 -0
  48. data/test/fixtures/node.mustache +8 -0
  49. data/test/fixtures/partial_with_module.mustache +4 -0
  50. data/test/fixtures/partial_with_module.rb +37 -0
  51. data/test/fixtures/passenger.conf +5 -0
  52. data/test/fixtures/passenger.rb +27 -0
  53. data/test/fixtures/recursive.mustache +4 -0
  54. data/test/fixtures/recursive.rb +14 -0
  55. data/test/fixtures/simple.mustache +5 -0
  56. data/test/fixtures/simple.rb +26 -0
  57. data/test/fixtures/template_partial.mustache +2 -0
  58. data/test/fixtures/template_partial.rb +18 -0
  59. data/test/fixtures/template_partial.txt +4 -0
  60. data/test/fixtures/unescaped.mustache +1 -0
  61. data/test/fixtures/unescaped.rb +14 -0
  62. data/test/fixtures/utf8.mustache +3 -0
  63. data/test/fixtures/utf8_partial.mustache +1 -0
  64. data/test/helper.rb +7 -0
  65. data/test/mustache_test.rb +677 -0
  66. data/test/parser_test.rb +78 -0
  67. data/test/partial_test.rb +168 -0
  68. data/test/spec_test.rb +68 -0
  69. data/test/template_test.rb +20 -0
  70. metadata +147 -0
@@ -0,0 +1,78 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'helper'
3
+
4
+ class ParserTest < Test::Unit::TestCase
5
+ def test_parser
6
+ lexer = Mustache::Parser.new
7
+ tokens = lexer.compile(<<-EOF)
8
+ <h1>{{header}}</h1>
9
+ {{#items}}
10
+ {{#first}}
11
+ <li><strong>{{name}}</strong></li>
12
+ {{/first}}
13
+ {{#link}}
14
+ <li><a href="{{url}}">{{name}}</a></li>
15
+ {{/link}}
16
+ {{/items}}
17
+
18
+ {{#empty}}
19
+ <p>The list is empty.</p>
20
+ {{/empty}}
21
+ EOF
22
+
23
+ expected = [:multi,
24
+ [:static, "<h1>"],
25
+ [:mustache, :etag, [:mustache, :fetch, ["header"]]],
26
+ [:static, "</h1>\n"],
27
+ [:mustache,
28
+ :section,
29
+ [:mustache, :fetch, ["items"]],
30
+ [:multi,
31
+ [:mustache,
32
+ :section,
33
+ [:mustache, :fetch, ["first"]],
34
+ [:multi,
35
+ [:static, " <li><strong>"],
36
+ [:mustache, :etag, [:mustache, :fetch, ["name"]]],
37
+ [:static, "</strong></li>\n"]],
38
+ %Q' <li><strong>{{name}}</strong></li>\n',
39
+ %w[{{ }}]],
40
+ [:mustache,
41
+ :section,
42
+ [:mustache, :fetch, ["link"]],
43
+ [:multi,
44
+ [:static, " <li><a href=\""],
45
+ [:mustache, :etag, [:mustache, :fetch, ["url"]]],
46
+ [:static, "\">"],
47
+ [:mustache, :etag, [:mustache, :fetch, ["name"]]],
48
+ [:static, "</a></li>\n"]],
49
+ %Q' <li><a href="{{url}}">{{name}}</a></li>\n',
50
+ %w[{{ }}]]],
51
+ %Q'{{#first}}\n <li><strong>{{name}}</strong></li>\n{{/first}}\n{{#link}}\n <li><a href="{{url}}">{{name}}</a></li>\n{{/link}}\n',
52
+ %w[{{ }}]],
53
+ [:static, "\n"],
54
+ [:mustache,
55
+ :section,
56
+ [:mustache, :fetch, ["empty"]],
57
+ [:multi, [:static, "<p>The list is empty.</p>\n"]],
58
+ %Q'<p>The list is empty.</p>\n',
59
+ %w[{{ }}]]]
60
+
61
+ assert_equal expected, tokens
62
+ end
63
+
64
+ def test_raw_content_and_whitespace
65
+ lexer = Mustache::Parser.new
66
+ tokens = lexer.compile("{{#list}}\t{{/list}}")
67
+
68
+ expected = [:multi,
69
+ [:mustache,
70
+ :section,
71
+ [:mustache, :fetch, ["list"]],
72
+ [:multi, [:static, "\t"]],
73
+ "\t",
74
+ %w[{{ }}]]]
75
+
76
+ assert_equal expected, tokens
77
+ end
78
+ end
@@ -0,0 +1,168 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'helper'
3
+
4
+ class PartialTest < Test::Unit::TestCase
5
+ def test_view_partial
6
+ assert_equal <<-end_partial.strip, PartialWithModule.render
7
+ <h1>Welcome</h1>
8
+ Hello Bob
9
+ You have just won $100000!
10
+
11
+ <h3>Fair enough, right?</h3>
12
+ end_partial
13
+ end
14
+
15
+ def test_partial_with_slashes
16
+ klass = Class.new(Mustache)
17
+ klass.template = '{{> test/fixtures/inner_partial}}'
18
+ view = klass.new
19
+ view[:title] = 'success'
20
+
21
+ assert_equal "Again, success!", view.render
22
+ end
23
+
24
+ def test_view_partial_inherits_context
25
+ klass = Class.new(TemplatePartial)
26
+ view = klass.new
27
+ view.template_path = File.dirname(__FILE__) + '/fixtures'
28
+ view[:titles] = [{:title => :One}, {:title => :Two}]
29
+ view.template = <<-end_template
30
+ <h1>Context Test</h1>
31
+ <ul>
32
+ {{#titles}}
33
+ <li>{{>inner_partial}}</li>
34
+ {{/titles}}
35
+ </ul>
36
+ end_template
37
+ assert_equal <<-end_partial, view.render
38
+ <h1>Context Test</h1>
39
+ <ul>
40
+ <li>Again, One!</li>
41
+ <li>Again, Two!</li>
42
+ </ul>
43
+ end_partial
44
+ end
45
+
46
+ def test_view_partial_inherits_context_of_class_methods
47
+ klass = Class.new(TemplatePartial)
48
+ klass.template_path = File.dirname(__FILE__) + '/fixtures'
49
+ klass.send(:define_method, :titles) do
50
+ [{:title => :One}, {:title => :Two}]
51
+ end
52
+ view = klass.new
53
+ view.template = <<-end_template
54
+ <h1>Context Test</h1>
55
+ <ul>
56
+ {{#titles}}
57
+ <li>{{>inner_partial}}</li>
58
+ {{/titles}}
59
+ </ul>
60
+ end_template
61
+ assert_equal <<-end_partial, view.render
62
+ <h1>Context Test</h1>
63
+ <ul>
64
+ <li>Again, One!</li>
65
+ <li>Again, Two!</li>
66
+ </ul>
67
+ end_partial
68
+ end
69
+
70
+ def test_template_partial
71
+ assert_equal <<-end_partial.strip, TemplatePartial.render
72
+ <h1>Welcome</h1>
73
+ Again, Welcome!
74
+ end_partial
75
+ end
76
+
77
+ def test_template_partial_with_custom_extension
78
+ partial = Class.new(TemplatePartial)
79
+ partial.template_extension = 'txt'
80
+ partial.template_path = File.dirname(__FILE__) + '/fixtures'
81
+
82
+ assert_equal <<-end_partial.strip, partial.render.strip
83
+ Welcome
84
+ -------
85
+
86
+ ## Again, Welcome! ##
87
+ end_partial
88
+ end
89
+
90
+ def test_recursive_paritals
91
+ assert_equal <<-end_partial, Recursive.render
92
+ It works!
93
+ end_partial
94
+ end
95
+
96
+ def test_crazy_recursive_partials
97
+ assert_equal <<-end_partial.strip, CrazyRecursive.render
98
+ <html>
99
+ <body>
100
+ <ul>
101
+ <li>
102
+ 1
103
+ <ul>
104
+ <li>
105
+ 2
106
+ <ul>
107
+ <li>
108
+ 3
109
+ <ul>
110
+ </ul>
111
+ </li>
112
+ </ul>
113
+ </li>
114
+ <li>
115
+ 4
116
+ <ul>
117
+ <li>
118
+ 5
119
+ <ul>
120
+ <li>
121
+ 6
122
+ <ul>
123
+ </ul>
124
+ </li>
125
+ </ul>
126
+ </li>
127
+ </ul>
128
+ </li>
129
+ </ul>
130
+ </li>
131
+ </ul>
132
+ </body>
133
+ </html>
134
+ end_partial
135
+ end
136
+
137
+ def test_partials_use_proper_context
138
+ assert_equal "OuterThing OuterThing", OuterThing.render('{{name}} {{> p}}')
139
+
140
+ assert_equal "InnerThing InnerThing", InnerThing.render('{{name}} {{> p}}')
141
+
142
+ assert_equal "OuterThing InnerThing InnerThing",
143
+ OuterThing.render('{{name}} {{#inner}}{{name}} {{> p}}{{/inner}}')
144
+ end
145
+
146
+ def test_partials_render_returned_strings
147
+ assert_equal "ok", MiddleThing.render('{{> some_partial }}')
148
+ end
149
+ end
150
+
151
+ class InnerThing < Mustache
152
+ def partial(p) self.class end
153
+ def name; self.class end
154
+ end
155
+
156
+ class OuterThing < Mustache
157
+ def inner
158
+ InnerThing.new
159
+ end
160
+
161
+ def partial(p) self.class end
162
+ def name; self.class end
163
+ end
164
+
165
+ class MiddleThing < Mustache
166
+ def partial(name) "{{#{name}}}" end
167
+ def some_partial; "ok" end
168
+ end
@@ -0,0 +1,68 @@
1
+ require 'mustache'
2
+ require 'tmpdir'
3
+ require 'yaml'
4
+ require 'test/unit'
5
+
6
+ # Automatically process !code types into Proc objects
7
+ YAML::add_builtin_type('code') { |_, val| eval(val['ruby']) }
8
+
9
+ # A simple base class for Mustache specs.
10
+ # Creates a partials directory, then points a (dynamic) subclass of Mustache at
11
+ # that directory before each test; the partials directory is destroyed after
12
+ # each test is run.
13
+ class MustacheSpec < Test::Unit::TestCase
14
+ def setup
15
+ @partials = File.join(File.dirname(__FILE__), 'partials')
16
+ Dir.mkdir(@partials)
17
+
18
+ @Mustache = Class.new(Mustache)
19
+ @Mustache.template_path = @partials
20
+ end
21
+
22
+ def teardown
23
+ Dir[File.join(@partials, '*')].each { |file| File.delete(file) }
24
+ Dir.rmdir(@partials)
25
+ end
26
+
27
+ # Extracts the partials from the test, and dumps them into the partials
28
+ # directory for inclusion.
29
+ def setup_partials(test)
30
+ (test['partials'] || {}).each do |name, content|
31
+ File.open(File.join(@partials, "#{name}.mustache"), 'w') do |f|
32
+ f.print(content)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Asserts equality between the rendered template and the expected value,
38
+ # printing additional context data on failure.
39
+ def assert_mustache_spec(test)
40
+ actual = @Mustache.render(test['template'], test['data'])
41
+
42
+ assert_equal test['expected'], actual, "" <<
43
+ "#{ test['desc'] }\n" <<
44
+ "Data: #{ test['data'].inspect }\n" <<
45
+ "Template: #{ test['template'].inspect }\n" <<
46
+ "Partials: #{ (test['partials'] || {}).inspect }\n"
47
+ end
48
+
49
+ def test_noop; assert(true); end
50
+ end
51
+
52
+ spec_files = File.join(File.dirname(__FILE__), '..', 'ext', 'spec', 'specs', '*.yml')
53
+ Dir[spec_files].each do |file|
54
+ spec = YAML.load_file(file)
55
+
56
+ klass_name = "Test" + File.basename(file, ".yml").sub(/~/, '').capitalize
57
+ instance_eval "class ::#{klass_name} < MustacheSpec; end"
58
+ test_suite = Kernel.const_get(klass_name)
59
+
60
+ test_suite.class_eval do
61
+ spec['tests'].each do |test|
62
+ define_method :"test - #{test['name']}" do
63
+ setup_partials(test)
64
+ assert_mustache_spec(test)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'helper'
3
+
4
+ class TemplateTest < Test::Unit::TestCase
5
+ def test_compile
6
+ assert_equal %("foo"), Mustache::Template.new("foo").compile
7
+ end
8
+
9
+ def test_compile_with_source
10
+ assert_equal %("bar"), Mustache::Template.new("foo").compile("bar")
11
+ end
12
+
13
+ def test_token
14
+ assert_equal [:multi, [:static, "foo"]], Mustache::Template.new("foo").tokens
15
+ end
16
+
17
+ def test_token_with_source
18
+ assert_equal [:multi, [:static, "bar"]], Mustache::Template.new("foo").tokens("bar")
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mustache-bibanon
3
+ version: !ruby/object:Gem::Version
4
+ hash: 409
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 99
9
+ - 5
10
+ version: 0.99.5
11
+ platform: ruby
12
+ authors:
13
+ - Chris Wanstrath
14
+ - Magnus Holm
15
+ - Pieter van de Bruggen
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2012-02-05 00:00:00 Z
21
+ dependencies: []
22
+
23
+ description: |
24
+ Inspired by ctemplate, Mustache is a framework-agnostic way to render
25
+ logic-free views.
26
+
27
+ As ctemplates says, "It emphasizes separating logic from presentation:
28
+ it is impossible to embed application logic in this template
29
+ language.
30
+
31
+ Think of Mustache as a replacement for your views. Instead of views
32
+ consisting of ERB or HAML with random helpers and arbitrary logic,
33
+ your views are broken into two parts: a Ruby class and an HTML
34
+ template.
35
+
36
+ email: chris@ozmm.org
37
+ executables:
38
+ - mustache
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - README.md
45
+ - Rakefile
46
+ - LICENSE
47
+ - lib/rack/bug/panels/mustache_panel.rb
48
+ - lib/rack/bug/panels/mustache_panel/mustache_extension.rb
49
+ - lib/rack/bug/panels/mustache_panel/view.mustache
50
+ - lib/mustache/settings.rb
51
+ - lib/mustache/template.rb
52
+ - lib/mustache/sinatra.rb
53
+ - lib/mustache/parser.rb
54
+ - lib/mustache/generator.rb
55
+ - lib/mustache/version.rb
56
+ - lib/mustache/context.rb
57
+ - lib/mustache.rb
58
+ - bin/mustache
59
+ - man/mustache.5.html
60
+ - man/mustache.1.ron
61
+ - man/mustache.1
62
+ - man/mustache.5.ron
63
+ - man/mustache.5
64
+ - man/mustache.1.html
65
+ - test/template_test.rb
66
+ - test/mustache_test.rb
67
+ - test/fixtures/crazy_recursive.mustache
68
+ - test/fixtures/crazy_recursive.rb
69
+ - test/fixtures/nested_objects.mustache
70
+ - test/fixtures/utf8_partial.mustache
71
+ - test/fixtures/simple.rb
72
+ - test/fixtures/partial_with_module.mustache
73
+ - test/fixtures/partial_with_module.rb
74
+ - test/fixtures/namespaced.rb
75
+ - test/fixtures/delimiters.mustache
76
+ - test/fixtures/inverted_section.rb
77
+ - test/fixtures/recursive.rb
78
+ - test/fixtures/inverted_section.mustache
79
+ - test/fixtures/passenger.rb
80
+ - test/fixtures/complex_view.mustache
81
+ - test/fixtures/unescaped.mustache
82
+ - test/fixtures/complex_view.rb
83
+ - test/fixtures/unescaped.rb
84
+ - test/fixtures/comments.rb
85
+ - test/fixtures/node.mustache
86
+ - test/fixtures/template_partial.rb
87
+ - test/fixtures/dot_notation.rb
88
+ - test/fixtures/utf8.mustache
89
+ - test/fixtures/template_partial.txt
90
+ - test/fixtures/nested_objects.rb
91
+ - test/fixtures/passenger.conf
92
+ - test/fixtures/namespaced.mustache
93
+ - test/fixtures/escaped.rb
94
+ - test/fixtures/inner_partial.txt
95
+ - test/fixtures/simple.mustache
96
+ - test/fixtures/inner_partial.mustache
97
+ - test/fixtures/recursive.mustache
98
+ - test/fixtures/double_section.rb
99
+ - test/fixtures/dot_notation.mustache
100
+ - test/fixtures/template_partial.mustache
101
+ - test/fixtures/lambda.rb
102
+ - test/fixtures/method_missing.rb
103
+ - test/fixtures/delimiters.rb
104
+ - test/fixtures/lambda.mustache
105
+ - test/fixtures/comments.mustache
106
+ - test/fixtures/double_section.mustache
107
+ - test/fixtures/escaped.mustache
108
+ - test/parser_test.rb
109
+ - test/helper.rb
110
+ - test/autoloading_test.rb
111
+ - test/partial_test.rb
112
+ - test/spec_test.rb
113
+ homepage: http://github.com/defunkt/mustache
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.11
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Mustache is a framework-agnostic way to render logic-free views.
146
+ test_files: []
147
+