Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow methods such as to_a, to_json on hash objects #259

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: ruby
rvm:
- 2.1.0
- 2.4.0
- 2.4
- 2.6
before_install:
- gem install bundler
addons:
code_climate:
repo_token: 197d6b3eb448e97f94a63414e2f6b6a96d0bf0d44514cf57100be14483302d12
Expand Down
1 change: 1 addition & 0 deletions lib/mustache/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def find_in_hash(obj, key, default)
return obj[key] if obj.has_key?(key)
return obj[key.to_s] if obj.has_key?(key.to_s)
return obj[key] if obj.respond_to?(:default_proc) && obj.default_proc && obj[key]
return obj.send(key) if obj.respond_to?(key) # eg. to_a, to_json

# If default is :__missing then we are from #fetch which is hunting through the stack
# If default is nil then we are reducing dot notation
Expand Down
2 changes: 1 addition & 1 deletion mustache.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ desc

s.required_ruby_version = '>= 2.0'

s.add_development_dependency 'bundler', '~> 1.6'
s.add_development_dependency 'bundler', '~> 2.1'
s.add_development_dependency 'rake', '~> 10.3'
s.add_development_dependency 'minitest', '~> 5.4'
s.add_development_dependency 'benchmark-ips'
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/dot_notation.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* {{#person}}{{hometown.city}}, {{hometown.state}}{{/person}}
* {{#person}}{{#hometown}}{{city}}, {{state}}{{/hometown}}{{/person}}
* {{#person.hometown}}{{city}}, {{state}}{{/person.hometown}}
* {{#person}}{{#hometown.to_a}}{{first}}.{{last}};{{/hometown.to_a}}{{/person}}
* {{#person.hometown.to_a}}{{first}}.{{last}};{{/person.hometown.to_a}}
* {{normal}}

* {{{person.name.first}}} {{&person.name.last}}
Expand Down
2 changes: 2 additions & 0 deletions test/mustache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ def test_dot_notation
* Cincinnati, OH
* Cincinnati, OH
* Cincinnati, OH
* city.Cincinnati;state.OH;
* city.Cincinnati;state.OH;
* Normal

* Chris Firescythe
Expand Down