mustache 0.99.5 → 0.99.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -23
- data/Rakefile +1 -1
- data/bin/mustache +30 -12
- data/lib/mustache.rb +4 -11
- data/lib/mustache/blah.rb +116 -0
- data/lib/mustache/context.rb +28 -15
- data/lib/mustache/enumerable.rb +3 -0
- data/lib/mustache/generator.rb +16 -11
- data/lib/mustache/parser.rb +83 -33
- data/lib/mustache/sinatra.rb +1 -1
- data/lib/mustache/template.rb +52 -0
- data/lib/mustache/version.rb +1 -1
- data/man/mustache.1 +4 -4
- data/man/mustache.1.html +6 -6
- data/man/mustache.1.ron +3 -3
- data/man/mustache.5 +8 -8
- data/man/mustache.5.html +11 -9
- data/man/mustache.5.ron +9 -7
- data/test/fixtures/liberal.mustache +1 -0
- data/test/fixtures/liberal.rb +22 -0
- data/test/fixtures/simply_complicated.mustache +25 -0
- data/test/mustache_test.rb +67 -2
- data/test/parser_test.rb +15 -0
- data/test/partial_test.rb +1 -1
- data/test/spec_test.rb +6 -2
- data/test/template_test.rb +33 -0
- metadata +87 -11
@@ -0,0 +1 @@
|
|
1
|
+
{{first-name}} {{middle_name!}} {{lastName?}}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'mustache'
|
3
|
+
|
4
|
+
class Liberal < Mustache
|
5
|
+
self.path = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
def first_name
|
8
|
+
"kevin"
|
9
|
+
end
|
10
|
+
|
11
|
+
def middle_name!
|
12
|
+
'j'
|
13
|
+
end
|
14
|
+
|
15
|
+
def lastName?
|
16
|
+
'sheurs'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if $0 == __FILE__
|
21
|
+
puts Liberal.to_html
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Hi there {{yourname}}. Your home directory is {{HOME}}.
|
2
|
+
|
3
|
+
{{#friend}}
|
4
|
+
Your friend is named {{name}}
|
5
|
+
{{#morr}}
|
6
|
+
Hey {{word}} {{up}} {{{awesomesauce}}}.
|
7
|
+
{{/morr}}
|
8
|
+
{{^morr}}
|
9
|
+
Booooo. {{hiss}}
|
10
|
+
{{/morr}}
|
11
|
+
{{notinmorr}}
|
12
|
+
{{> partial1}}
|
13
|
+
{{/friend}}
|
14
|
+
{{^friend}}
|
15
|
+
You have no friends, {{person}}. You suck.
|
16
|
+
{{/friend}}
|
17
|
+
|
18
|
+
{{> partial2}}
|
19
|
+
{{! comments are awesome }}
|
20
|
+
|
21
|
+
{{={% %}=}}
|
22
|
+
|
23
|
+
{%love%}
|
24
|
+
{%={{ }}=%}
|
25
|
+
{{{triplestash}}}
|
data/test/mustache_test.rb
CHANGED
@@ -344,6 +344,63 @@ data
|
|
344
344
|
assert_equal ' <li>1234</li> ', instance.render
|
345
345
|
end
|
346
346
|
|
347
|
+
def test_enumerable_sections_enumerate_mustache_enumerables
|
348
|
+
person = Struct.new(:name, :age)
|
349
|
+
people_array = []
|
350
|
+
people_array << person.new('Juliet', 13)
|
351
|
+
people_array << person.new('Romeo', 16)
|
352
|
+
people = Class.new do
|
353
|
+
include Enumerable
|
354
|
+
include Mustache::Enumerable
|
355
|
+
|
356
|
+
def initialize array
|
357
|
+
@people = array
|
358
|
+
end
|
359
|
+
|
360
|
+
def each *args, &block
|
361
|
+
@people.each *args, &block
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
view = Mustache.new
|
366
|
+
view[:people] = people.new(people_array)
|
367
|
+
view.template = <<-TEMPLATE
|
368
|
+
{{#people}}
|
369
|
+
{{name}} is {{age}}
|
370
|
+
{{/people}}
|
371
|
+
TEMPLATE
|
372
|
+
assert_equal <<-EXPECTED, view.render
|
373
|
+
Juliet is 13
|
374
|
+
Romeo is 16
|
375
|
+
EXPECTED
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_enumerable_sections_do_not_enumerate_untagged_enumerables
|
379
|
+
people = Struct.new(:first, :second, :third)
|
380
|
+
person = Struct.new(:name, :age)
|
381
|
+
|
382
|
+
view = Mustache.new
|
383
|
+
view[:people] = people.new(person.new("Mercutio", 17), person.new("Tybalt", 20), person.new("Benvolio", 15))
|
384
|
+
view.template = <<-TEMPLATE
|
385
|
+
{{#people}}
|
386
|
+
{{#first}}
|
387
|
+
{{name}} is {{age}}
|
388
|
+
{{/first}}
|
389
|
+
{{#second}}
|
390
|
+
{{name}} is {{age}}
|
391
|
+
{{/second}}
|
392
|
+
{{#third}}
|
393
|
+
{{name}} is {{age}}
|
394
|
+
{{/third}}
|
395
|
+
{{/people}}
|
396
|
+
TEMPLATE
|
397
|
+
assert_equal <<-EXPECTED, view.render
|
398
|
+
Mercutio is 17
|
399
|
+
Tybalt is 20
|
400
|
+
Benvolio is 15
|
401
|
+
EXPECTED
|
402
|
+
end
|
403
|
+
|
347
404
|
def test_not_found_in_context_renders_empty_string
|
348
405
|
instance = Mustache.new
|
349
406
|
instance.template = '{{#list}} <li>{{item}}</li> {{/list}}'
|
@@ -454,6 +511,12 @@ data
|
|
454
511
|
assert_equal "chris j strath", Mustache.render(template, hash)
|
455
512
|
end
|
456
513
|
|
514
|
+
def test_liberal_tag_names_in_class
|
515
|
+
assert_equal <<-end_liberal, Liberal.render
|
516
|
+
kevin j sheurs
|
517
|
+
end_liberal
|
518
|
+
end
|
519
|
+
|
457
520
|
def test_nested_sections_same_names
|
458
521
|
template = <<template
|
459
522
|
{{#items}}
|
@@ -614,7 +677,8 @@ text
|
|
614
677
|
assert_equal value, tmpl.send(attr)
|
615
678
|
end
|
616
679
|
end
|
617
|
-
|
680
|
+
|
681
|
+
def test_array_of_arrays
|
618
682
|
template = <<template
|
619
683
|
{{#items}}
|
620
684
|
start
|
@@ -651,7 +715,8 @@ start
|
|
651
715
|
end
|
652
716
|
expected
|
653
717
|
end
|
654
|
-
|
718
|
+
|
719
|
+
def test_indentation_again
|
655
720
|
template = <<template
|
656
721
|
SELECT
|
657
722
|
{{#cols}}
|
data/test/parser_test.rb
CHANGED
@@ -2,6 +2,21 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
|
|
2
2
|
require 'helper'
|
3
3
|
|
4
4
|
class ParserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_parser_extension
|
7
|
+
parser = Mustache::Parser.new
|
8
|
+
parser.instance_variable_set :@result, 'zomg'
|
9
|
+
Mustache::Parser.add_type(:'@', :'$') do |*args|
|
10
|
+
[:mustache, :at_sign, @result, *args]
|
11
|
+
end
|
12
|
+
assert_match Mustache::Parser.valid_types, '@'
|
13
|
+
assert_match Mustache::Parser.valid_types, '$'
|
14
|
+
assert_equal [:mustache, :at_sign, 'zomg', 1, 2, 3],
|
15
|
+
parser.send('scan_tag_@', 1, 2, 3)
|
16
|
+
assert_equal [:mustache, :at_sign, 'zomg', 1, 2, 3],
|
17
|
+
parser.send('scan_tag_$', 1, 2, 3)
|
18
|
+
end
|
19
|
+
|
5
20
|
def test_parser
|
6
21
|
lexer = Mustache::Parser.new
|
7
22
|
tokens = lexer.compile(<<-EOF)
|
data/test/partial_test.rb
CHANGED
data/test/spec_test.rb
CHANGED
@@ -3,8 +3,12 @@ require 'tmpdir'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'test/unit'
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# Calls appropriate method on YAML. See: https://gist.github.com/tenderlove/958999ab4240b93bd3cd
|
7
|
+
if RUBY_VERSION > "1.8"
|
8
|
+
YAML.add_domain_type(nil, 'code') { |_, val| eval(val['ruby']) }
|
9
|
+
else
|
10
|
+
YAML.add_builtin_type('code') { |_, val| eval(val['ruby']) }
|
11
|
+
end
|
8
12
|
|
9
13
|
# A simple base class for Mustache specs.
|
10
14
|
# Creates a partials directory, then points a (dynamic) subclass of Mustache at
|
data/test/template_test.rb
CHANGED
@@ -18,3 +18,36 @@ class TemplateTest < Test::Unit::TestCase
|
|
18
18
|
assert_equal [:multi, [:static, "bar"]], Mustache::Template.new("foo").tokens("bar")
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
class TemplateTest2 < Test::Unit::TestCase
|
23
|
+
def setup
|
24
|
+
@@template_text ||= File.read(File.dirname(__FILE__) + "/fixtures/simply_complicated.mustache")
|
25
|
+
@template = Mustache::Template.new(@@template_text)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tags
|
29
|
+
assert_equal [
|
30
|
+
"yourname",
|
31
|
+
"HOME",
|
32
|
+
"friend.name",
|
33
|
+
"friend.morr.word",
|
34
|
+
"friend.morr.up",
|
35
|
+
"friend.morr.awesomesauce",
|
36
|
+
"friend.morr.hiss",
|
37
|
+
"friend.notinmorr",
|
38
|
+
"friend.person",
|
39
|
+
"love",
|
40
|
+
"triplestash"
|
41
|
+
], @template.tags
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_partials
|
45
|
+
assert_equal ["partial1", "partial2"], @template.partials
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_sections
|
49
|
+
assert_equal ["friend", "friend.morr"], @template.sections
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.99.
|
4
|
+
version: 0.99.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -10,8 +10,78 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
14
|
-
dependencies:
|
13
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.6'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '10.3'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.3'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rdoc
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '4.1'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '4.1'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: ronn
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.7'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.7'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: turn
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.9'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0.9'
|
15
85
|
description: |
|
16
86
|
Inspired by ctemplate, Mustache is a framework-agnostic way to render
|
17
87
|
logic-free views.
|
@@ -30,21 +100,23 @@ executables:
|
|
30
100
|
extensions: []
|
31
101
|
extra_rdoc_files: []
|
32
102
|
files:
|
103
|
+
- LICENSE
|
33
104
|
- README.md
|
34
105
|
- Rakefile
|
35
|
-
-
|
106
|
+
- bin/mustache
|
107
|
+
- lib/mustache.rb
|
108
|
+
- lib/mustache/blah.rb
|
36
109
|
- lib/mustache/context.rb
|
110
|
+
- lib/mustache/enumerable.rb
|
37
111
|
- lib/mustache/generator.rb
|
38
112
|
- lib/mustache/parser.rb
|
39
113
|
- lib/mustache/settings.rb
|
40
114
|
- lib/mustache/sinatra.rb
|
41
115
|
- lib/mustache/template.rb
|
42
116
|
- lib/mustache/version.rb
|
43
|
-
- lib/
|
117
|
+
- lib/rack/bug/panels/mustache_panel.rb
|
44
118
|
- lib/rack/bug/panels/mustache_panel/mustache_extension.rb
|
45
119
|
- lib/rack/bug/panels/mustache_panel/view.mustache
|
46
|
-
- lib/rack/bug/panels/mustache_panel.rb
|
47
|
-
- bin/mustache
|
48
120
|
- man/mustache.1
|
49
121
|
- man/mustache.1.html
|
50
122
|
- man/mustache.1.ron
|
@@ -72,6 +144,8 @@ files:
|
|
72
144
|
- test/fixtures/inverted_section.rb
|
73
145
|
- test/fixtures/lambda.mustache
|
74
146
|
- test/fixtures/lambda.rb
|
147
|
+
- test/fixtures/liberal.mustache
|
148
|
+
- test/fixtures/liberal.rb
|
75
149
|
- test/fixtures/method_missing.rb
|
76
150
|
- test/fixtures/namespaced.mustache
|
77
151
|
- test/fixtures/namespaced.rb
|
@@ -86,6 +160,7 @@ files:
|
|
86
160
|
- test/fixtures/recursive.rb
|
87
161
|
- test/fixtures/simple.mustache
|
88
162
|
- test/fixtures/simple.rb
|
163
|
+
- test/fixtures/simply_complicated.mustache
|
89
164
|
- test/fixtures/template_partial.mustache
|
90
165
|
- test/fixtures/template_partial.rb
|
91
166
|
- test/fixtures/template_partial.txt
|
@@ -100,7 +175,8 @@ files:
|
|
100
175
|
- test/spec_test.rb
|
101
176
|
- test/template_test.rb
|
102
177
|
homepage: http://github.com/defunkt/mustache
|
103
|
-
licenses:
|
178
|
+
licenses:
|
179
|
+
- MIT
|
104
180
|
metadata: {}
|
105
181
|
post_install_message:
|
106
182
|
rdoc_options: []
|
@@ -108,17 +184,17 @@ require_paths:
|
|
108
184
|
- lib
|
109
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
186
|
requirements:
|
111
|
-
- -
|
187
|
+
- - ">="
|
112
188
|
- !ruby/object:Gem::Version
|
113
189
|
version: '0'
|
114
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
191
|
requirements:
|
116
|
-
- -
|
192
|
+
- - ">="
|
117
193
|
- !ruby/object:Gem::Version
|
118
194
|
version: '0'
|
119
195
|
requirements: []
|
120
196
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.2.2
|
122
198
|
signing_key:
|
123
199
|
specification_version: 4
|
124
200
|
summary: Mustache is a framework-agnostic way to render logic-free views.
|