snidely_whiplash 1.0.1 → 1.0.2

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.
data/README.md CHANGED
@@ -99,7 +99,27 @@ data = {
99
99
  var user = ich.user_template(data);
100
100
  ```
101
101
 
102
- The `SnidelyWhiplash` constructor can take one argument which can be used to specify the parent path for properties. For example, if you had used `SnidelyWhiplash.new('user')` in the examples above, the mustache outputs would have all been in the form `user.full_name`, `user.address`, and `user.email`. Your path can contain dots for those cases when your data is very deeply nested (for example: `SnidelyWhiplash.new('result.user')` would cause output like `{{result.user.full_name}}`, etc).
102
+ There is only one method call that SnidelyWhiplash treats as a special case and that is `html_safe`. If any of your outputs contain `html_safe`, SnidelyWhiplash will render `{{{prop}}}` which will cause mustache to disable html escaping. For example:
103
+
104
+ ```erb
105
+ <span><%= user.build_menu.html_safe %></span>
106
+ ```
107
+
108
+ or
109
+
110
+ ```haml
111
+ %span= user.build_menu.html_safe
112
+ ```
113
+
114
+ will output:
115
+
116
+ ```html
117
+ <span>{{{build_menu}}}</span>
118
+ ```
119
+
120
+ The `SnidelyWhiplash` constructor can take an argument which can be used to specify the parent path for properties. For example, if you had used `SnidelyWhiplash.new('user')` in the examples above, the mustache outputs would have all been in the form `user.full_name`, `user.address`, and `user.email`. Your path can contain dots for those cases when your data is very deeply nested (for example: `SnidelyWhiplash.new('result.user')` would cause output like `{{result.user.full_name}}`, etc). The default value for this argument is `nil`.
121
+
122
+ You may specify a second argument to the `SnidelyWhiplash` constructor: true to enable html escaping in mustache (this is the default), or false to disable html escaping for all outputs! You probably don't want to use this though... you're probably better off just using `html_safe` for the values that need to have html escaping disabled.
103
123
 
104
124
  ## Contributing
105
125
 
@@ -1,3 +1,3 @@
1
1
  class SnidelyWhiplash
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -2,16 +2,21 @@ require "snidely_whiplash/version"
2
2
 
3
3
  class SnidelyWhiplash
4
4
 
5
- def initialize(path=nil)
5
+ def initialize(path=nil, html_escape=true)
6
6
  @path = path
7
+ @html_escape = html_escape
7
8
  end
8
9
 
9
10
  def to_s
10
- "{{#{@path || ''}}}"
11
+ @html_escape ? "{{#{@path || ''}}}" : "{{{#{@path || ''}}}}"
11
12
  end
12
13
 
13
14
  def method_missing(method_sym, *args, &block)
14
- SnidelyWhiplash.new(@path.nil? ? method_sym.to_s : "#{@path}.#{method_sym.to_s}")
15
+ if method_sym == :html_safe
16
+ SnidelyWhiplash.new(@path, false)
17
+ else
18
+ SnidelyWhiplash.new(@path.nil? ? method_sym.to_s : "#{@path}.#{method_sym.to_s}", @html_escape)
19
+ end
15
20
  end
16
21
 
17
22
  def respond_to?(method_sym, include_private=false)
@@ -14,6 +14,12 @@ describe SnidelyWhiplash do
14
14
  obj.nested.example.to_s.should eql '{{nested.example}}'
15
15
  end
16
16
 
17
+ it "should return a mustache-escaped string with html escaping disabled if the method calls include .html_safe" do
18
+ obj = SnidelyWhiplash.new
19
+ obj.example.html_safe.to_s.should eql '{{{example}}}'
20
+ obj.nested.example.html_safe.to_s.should eql '{{{nested.example}}}'
21
+ end
22
+
17
23
  it "should allow the caller to specify a parent path" do
18
24
  obj = SnidelyWhiplash.new 'parent'
19
25
  obj.example.to_s.should eql '{{parent.example}}'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snidely_whiplash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core