cells-erb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/README.md +17 -0
- data/cells-erb.gemspec +1 -2
- data/gemfiles/rails_3.2-tilt-1.4.gemfile +16 -0
- data/gemfiles/rails_4.2-tilt-1.4.gemfile +1 -1
- data/gemfiles/rails_4.2-tilt-2.0.gemfile +2 -2
- data/gemfiles/rails_4.2-tilt-3.0.gemfile +1 -1
- data/lib/cell/erb/template.rb +39 -16
- data/lib/cell/erb/version.rb +1 -1
- data/test/dummy/app/cells/song/with_form_tag_and_content_tag.erb +22 -0
- data/test/dummy/app/cells/song_cell.rb +9 -1
- data/test/erb_test.rb +22 -28
- metadata +6 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 005beea2b9096c5a67fb46b5ca628b0311b18914
|
4
|
+
data.tar.gz: c06f9882697cf8817093305196e5e151d4726636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f208dccb628772160dd64132d4c981c59bf4a8cfbb8d06e9cadf7797d2b531ba80f0ce1b4fff3ca9a71df809b8ee870617e024100c06e2b299392ab291c2190b
|
7
|
+
data.tar.gz: 9bc78f5239748dcaa02bc90a6d70df1f772687a7185004ea451fcce4ecf9679682225b4d3561d897c044851577479fa32a38926ad1e85c836713baf2a4099f2b
|
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -14,6 +14,23 @@ This will register the `Erbse::Template` engine with Tilt for `.erb` files.
|
|
14
14
|
|
15
15
|
And that's all you need to do.
|
16
16
|
|
17
|
+
## HTML Escaping
|
18
|
+
|
19
|
+
Cells doesn't escape except when you tell it to do. However, you may run into problems when using Rails helpers. Internally, those helpers often blindly escape. This is not Cells' fault but a design flaw in Rails.
|
20
|
+
|
21
|
+
As a first step, try this and see if it helps.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class SongCell < Cell::ViewModel
|
25
|
+
include ActionView::Helpers::FormHelper
|
26
|
+
include Cell::Erb # include Erb _after_ AV helpers.
|
27
|
+
|
28
|
+
# ..
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
If that doesn't work, [read the docs](http://trailblazerb.org/cells/gems/cells4.html#escaping).
|
33
|
+
|
17
34
|
## Dependencies
|
18
35
|
|
19
36
|
This gem works with Tilt 1.4 and 2.0, and hence allows you to use it from Rails 3.2 upwards.
|
data/cells-erb.gemspec
CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "cells", "~> 4.0.0.
|
22
|
-
spec.add_runtime_dependency "tilt", ">= 1.4", "< 3"
|
21
|
+
spec.add_runtime_dependency "cells", "~> 4.0.0.beta3"
|
23
22
|
spec.add_runtime_dependency "erbse", ">= 0.0.2"
|
24
23
|
|
25
24
|
spec.add_development_dependency "bundler"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# gem "cells", :github => "apotonick/cells"
|
6
|
+
#gem "cells", path: "../../cells"
|
7
|
+
gem "appraisal"
|
8
|
+
gem "railties", "~> 3.2.0"
|
9
|
+
gem "activemodel"
|
10
|
+
gem "minitest", "~> 4.6"
|
11
|
+
gem "tilt", "~> 1.4"
|
12
|
+
gem "tzinfo"
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
15
|
+
|
16
|
+
# gem "erbse", path: "../../erbse"
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "cells", :github => "apotonick/cells"
|
6
|
-
#gem "cells", path: "../../cells"
|
5
|
+
#gem "cells", :github => "apotonick/cells"
|
6
|
+
# gem "cells", path: "../../cells"
|
7
7
|
gem "appraisal"
|
8
8
|
gem "railties", "~> 4.2.0"
|
9
9
|
gem "activemodel"
|
data/lib/cell/erb/template.rb
CHANGED
@@ -1,27 +1,50 @@
|
|
1
1
|
require "erbse"
|
2
2
|
|
3
|
-
module Cell
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Cell
|
4
|
+
# Erb contains helpers that are messed up in Rails and do escaping.
|
5
|
+
module Erb
|
6
|
+
# this is capture copied from AV:::CaptureHelper without doing escaping.
|
7
|
+
# TODO: re-implement capture and return content instead of the OB rubbish.
|
8
|
+
def capture(*args)
|
9
|
+
value = nil
|
10
|
+
buffer = with_output_buffer { value = yield(*args) }
|
11
|
+
if string = buffer.presence || value and string.is_a?(String)
|
12
|
+
string
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
|
-
def
|
11
|
-
|
16
|
+
def form_tag_with_body(html_options, content)
|
17
|
+
"#{form_tag_html(html_options)}" << content.to_s << "</form>"
|
12
18
|
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def prepare
|
18
|
-
engine_class = options.delete(:engine_class)
|
19
|
-
# engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
|
20
|
-
@template = (engine_class || ::Erbse::Template).new(data, options)
|
20
|
+
def form_tag_html(html_options)
|
21
|
+
extra_tags = extra_tags_for_form(html_options)
|
22
|
+
"#{tag(:form, html_options, true) + extra_tags}"
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
|
26
|
+
# Erbse-Tilt binding. This should be bundled with tilt. # 1.4. OR should be tilt-erbse.
|
27
|
+
class Template < Tilt::Template
|
28
|
+
def self.engine_initialized?
|
29
|
+
defined? ::Erbse::Template
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize_engine
|
33
|
+
require_template_library 'erbse'
|
34
|
+
end
|
35
|
+
|
36
|
+
# :engine_class can be passed via
|
37
|
+
#
|
38
|
+
# Tilt.new("#{base}/#{prefix}/#{view}", engine_class: Erbse::Eruby)
|
39
|
+
def prepare
|
40
|
+
engine_class = options.delete(:engine_class)
|
41
|
+
# engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
|
42
|
+
@template = (engine_class || ::Erbse::Template).new(data, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def precompiled_template(locals)
|
46
|
+
@template.call
|
47
|
+
end
|
25
48
|
end
|
26
49
|
end
|
27
50
|
end
|
data/lib/cell/erb/version.rb
CHANGED
@@ -10,3 +10,25 @@ Word.
|
|
10
10
|
<% end %>
|
11
11
|
|
12
12
|
<% end %>
|
13
|
+
|
14
|
+
<%- answer = "<script>oui!</script>" %>
|
15
|
+
|
16
|
+
<%- content = capture do %>
|
17
|
+
Bonjour!
|
18
|
+
<%= link_to "Coffee?", "/coffee" %>
|
19
|
+
<b>Yes please!</b>
|
20
|
+
<%= answer.html_safe %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
Weiter!
|
24
|
+
|
25
|
+
<%= content %>
|
26
|
+
|
27
|
+
<%- breadcrumbs = capture do %>
|
28
|
+
<%- [link_to("1", "/1"), link_to("2", "/2")].join("+") %>
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
<%= breadcrumbs %>
|
32
|
+
|
33
|
+
<%= current_page %>
|
34
|
+
<%= form_tag_with_body( {url: "/rails/escapes/too/much"}, %{<input type="button"/>}).html_safe %>
|
@@ -2,6 +2,7 @@ class SongCell < Cell::ViewModel
|
|
2
2
|
self.view_paths = ["test/dummy/app/cells"]
|
3
3
|
|
4
4
|
include ActionView::Helpers::FormHelper
|
5
|
+
include Cell::Erb
|
5
6
|
|
6
7
|
def with_form_tag_and_content_tag
|
7
8
|
render
|
@@ -35,8 +36,15 @@ class SongCell < Cell::ViewModel
|
|
35
36
|
render
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
+
private
|
39
40
|
def cap
|
40
41
|
"yay, #{with_output_buffer { yield } }"
|
41
42
|
end
|
43
|
+
|
44
|
+
def current_page
|
45
|
+
capture do
|
46
|
+
#[link_to("1", "/1"), link_to("2", "/2")].join("+") # this breaks, too!
|
47
|
+
"<b>No current page!<b>"
|
48
|
+
end
|
49
|
+
end
|
42
50
|
end
|
data/test/erb_test.rb
CHANGED
@@ -20,10 +20,14 @@ class ErbTest < MiniTest::Spec
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# form_tag { content_tag { } }
|
23
|
-
it
|
23
|
+
it do
|
24
24
|
form_tag = "<form action=\"/erubis/is/horribly/outdated\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" />"
|
25
25
|
form_tag = "<form accept-charset=\"UTF-8\" action=\"/erubis/is/horribly/outdated\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div>" if ActionPack::VERSION::MAJOR == 3
|
26
26
|
|
27
|
+
form_with_body_tag = "<form url=\"/rails/escapes/too/much\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /><input type=\"button\"/></form>"
|
28
|
+
form_with_body_tag = "<form method=\"post\" url=\"/rails/escapes/too/much\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /></div><input type=\"button\"/></form>" if ActionPack::VERSION::MAJOR == 3
|
29
|
+
|
30
|
+
|
27
31
|
song_cell.(:with_form_tag_and_content_tag).must_equal %{Word.
|
28
32
|
|
29
33
|
#{form_tag}
|
@@ -33,33 +37,23 @@ class ErbTest < MiniTest::Spec
|
|
33
37
|
<ul>
|
34
38
|
Hallo
|
35
39
|
</ul>
|
36
|
-
</form>
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# it { cellule.with_block.must_equal "Nice!\nyay, <b>yeah</b>\n" }
|
54
|
-
#
|
55
|
-
# # capture
|
56
|
-
# it { cellule.with_capture.must_equal "Nice!\n<b>Great!</b>\n" }
|
57
|
-
#
|
58
|
-
# # there's again escaping happening where it shouldn't be in link_to and rails <= 3.2.
|
59
|
-
# if Cell.rails_version >= Gem::Version.new('4.0')
|
60
|
-
# # link_to with block and img_tag
|
61
|
-
# it { cellule.with_link_to.must_equal "<a href=\"/songs\"><img alt=\"All\" src=\"/images/all.png\" />\n</a>\n" }
|
62
|
-
# end
|
40
|
+
</form>
|
41
|
+
|
42
|
+
|
43
|
+
Weiter!
|
44
|
+
|
45
|
+
Bonjour!
|
46
|
+
<a href=\"/coffee\">Coffee?</a>
|
47
|
+
<b>Yes please!</b>
|
48
|
+
<script>oui!</script>
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
<a href=\"/1\">1</a>+<a href=\"/2\">2</a>
|
53
|
+
|
54
|
+
<b>No current page!<b>
|
55
|
+
#{form_with_body_tag}}
|
56
|
+
end
|
63
57
|
end
|
64
58
|
|
65
59
|
# start with content_tag and block (or capture) and find out how sinatra handles that. goal is NOT to use those hacks in haml's action_view_extensions.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells-erb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cells
|
@@ -17,34 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 4.0.0.
|
20
|
+
version: 4.0.0.beta3
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 4.0.0.
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: tilt
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '1.4'
|
35
|
-
- - "<"
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '3'
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
requirements:
|
42
|
-
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '1.4'
|
45
|
-
- - "<"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3'
|
27
|
+
version: 4.0.0.beta3
|
48
28
|
- !ruby/object:Gem::Dependency
|
49
29
|
name: erbse
|
50
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,11 +79,13 @@ files:
|
|
99
79
|
- ".gitignore"
|
100
80
|
- ".travis.yml"
|
101
81
|
- Appraisals
|
82
|
+
- CHANGES.md
|
102
83
|
- Gemfile
|
103
84
|
- LICENSE.txt
|
104
85
|
- README.md
|
105
86
|
- Rakefile
|
106
87
|
- cells-erb.gemspec
|
88
|
+
- gemfiles/rails_3.2-tilt-1.4.gemfile
|
107
89
|
- gemfiles/rails_4.2-tilt-1.4.gemfile
|
108
90
|
- gemfiles/rails_4.2-tilt-2.0.gemfile
|
109
91
|
- gemfiles/rails_4.2-tilt-3.0.gemfile
|