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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15a81cb8e550deade32a9dd5311062296927e306
4
- data.tar.gz: ecbea4577de1b3059769b6d56cae6ded988eebfb
3
+ metadata.gz: 005beea2b9096c5a67fb46b5ca628b0311b18914
4
+ data.tar.gz: c06f9882697cf8817093305196e5e151d4726636
5
5
  SHA512:
6
- metadata.gz: 553a21f3119347d5be6e0e18fd7e30d8b7cc8344cfe5f22c2ded2a9d21b86ebbfd536567d8384627997d9915b422c3b3b2515f52851b4998da57f92956144efa
7
- data.tar.gz: 15322a3fe3e5dcc825723fc06806577d591f1657972117cc09053b06a1d002963dd47ac77b4c06b294899499d48d881861a4d34d835c3dc0ea5c242e84dd399a
6
+ metadata.gz: f208dccb628772160dd64132d4c981c59bf4a8cfbb8d06e9cadf7797d2b531ba80f0ce1b4fff3ca9a71df809b8ee870617e024100c06e2b299392ab291c2190b
7
+ data.tar.gz: 9bc78f5239748dcaa02bc90a6d70df1f772687a7185004ea451fcce4ecf9679682225b4d3561d897c044851577479fa32a38926ad1e85c836713baf2a4099f2b
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.3
2
+
3
+ * Added `#capture` helper that doesn't do escaping, in `Cell::Erb`.
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.beta"
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,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "cells", :github => "apotonick/cells"
5
+ # gem "cells", :github => "apotonick/cells"
6
6
  #gem "cells", path: "../../cells"
7
7
  gem "appraisal"
8
8
  gem "railties", "~> 4.2.0"
@@ -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"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "cells", :github => "apotonick/cells"
5
+ # gem "cells", :github => "apotonick/cells"
6
6
  #gem "cells", path: "../../cells"
7
7
  gem "appraisal"
8
8
  gem "railties", "~> 4.2.0"
@@ -1,27 +1,50 @@
1
1
  require "erbse"
2
2
 
3
- module Cell::Erb
4
- # Erbse-Tilt binding. This should be bundled with tilt. # 1.4. OR should be tilt-erbse.
5
- class Template < Tilt::Template
6
- def self.engine_initialized?
7
- defined? ::Erbse::Template
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 initialize_engine
11
- require_template_library 'erbse'
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
- # :engine_class can be passed via
15
- #
16
- # Tilt.new("#{base}/#{prefix}/#{view}", engine_class: Erbse::Eruby)
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
- def precompiled_template(locals)
24
- @template.call
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
@@ -1,5 +1,5 @@
1
1
  module Cell
2
2
  module Erb
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -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
- private
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( "xxx") do
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=\"&#x2713;\" />"
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=\"&#x2713;\" /></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=\"&#x2713;\" /><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=\"&#x2713;\" /></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
- end
38
- # song_cell.(:with_form_tag_and_content_tag).must_equal_xml_structure "<form><div><input/></div><label/><input/><ul><li/></ul></form>" }
39
-
40
-
41
-
42
- #
43
- # # form_tag with block in block work.
44
- # it { cellule.edit.must_equal "<form><div><input/></div><label/><input/><ul><li/></ul></form>" }
45
- #
46
- # # form_tag, no block
47
- # it { cellule.with_form_tag.must_equal "<form><div><input/></div><span/></form>" }
48
- #
49
- # # form_for with block in ERB.
50
- # it { cellule.with_form_for_block.must_equal "<form><div><input/></div><input/></form>" }
51
- #
52
- # # when using yield, haml breaks it (but doesn't escape HTML)
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.2
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-25 00:00:00.000000000 Z
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.beta
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.beta
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