cells-erb 0.0.9 → 0.1.0

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: dfcfcbf248e2459af3f2a141706c37ef174bea50
4
- data.tar.gz: 2b929671c430d62bbf14bde528fd590802249d9a
3
+ metadata.gz: 129f1072e84921e3942d70ffdc5c7c941d9ea9b1
4
+ data.tar.gz: 67181a81d3d94dd675e5bb998f05937972ce593a
5
5
  SHA512:
6
- metadata.gz: 53abfa93101530caf77ea1c7ada5b79f7897622cf36eb17e1aac5f49cd4dc1b1bab022a9e9fbd89497b072c4da46dfcfb0795bbebdba579094dcd46b348c73f0
7
- data.tar.gz: 89974701d08f46cb4a28c92e9dbee52818ecf884c93f314783acf61f5e8af8f4b79a556a6838f48f794963fb67ae9eb0008dfbbbbd865c0cec3679604d6c9c05
6
+ metadata.gz: 039a26afbef0c6d0ae9b3931a28e3bbe69d6f83554c69469641808a257f39d3d57a2325f690e033a56670112de19046401cd9a8c80f032657af809a27055e9d5
7
+ data.tar.gz: 1c69b28d6fdc9fde537bcaee91c89553f1c5f49c2cc2b3cde494b66b942efc13cf6edf82775c6a10e02295b2f8c6ecd9646cf3a8e6c8a23586a51cc3c85b266f
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.3.0
4
+ - 2.3.1
5
5
  gemfile:
6
6
  - gemfiles/rails_4.2-tilt-1.4.gemfile
7
7
  - gemfiles/rails_4.2-tilt-2.0.gemfile
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.0
2
+
3
+ * The `concat` helper is not supported, anymore. Concatenate to a local string instead.
4
+
1
5
  # 0.0.9
2
6
 
3
7
  * Limit to erbse-0.0.x.
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ gemspec
5
5
 
6
6
  gem "railties", "~> 4.2.0"
7
7
  gem "activemodel"
8
- gem "minitest", "~> 5.2"
9
- gem "tilt", "~> 2.0"
10
- gem "cells", path: "../cells"
8
+ # gem "cells", path: "../cells"
9
+ # gem "erbse", path: "../erbse"
10
+ gem "minitest-line"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cells::Erb
2
2
 
3
- Proper ERB support for Cells using [Erbse](https://github.com/apotonick/erbse).
3
+ ERB support for Cells using [Erbse](https://github.com/apotonick/erbse).
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,10 +10,60 @@ Add this line to your application's Gemfile:
10
10
  gem 'cells-erb'
11
11
  ```
12
12
 
13
- This will register the `Erbse::Template` engine with Tilt for `.erb` files.
13
+ This will register `Erbse::Engine` with Tilt for `.erb` files.
14
14
 
15
15
  And that's all you need to do.
16
16
 
17
+ ## Erbse
18
+
19
+ [Erbse](https://github.com/apotonick/erbse) is the next-generation implementation of ERB that comes with some nice new semantics and explicit code. It does not use instance variables for output buffering.
20
+
21
+ You should read its docs to learn what you can and can't do with Erbse.
22
+
23
+ ## Concat
24
+
25
+ The global `#concat` helper is not supported in Cells-ERB. Erbse uses local variables as output buffers, hence this global state helper does not work. Please use explicit string concatenation instead.
26
+
27
+ Instead of
28
+
29
+ ```ruby
30
+ concat content_tag(:p, "Good")
31
+ concat "Morning!"
32
+ ```
33
+
34
+ you can do
35
+
36
+ ```ruby
37
+ content_tag(:p, "Good") + "Morning!"
38
+ ```
39
+
40
+ ## Block Yielding
41
+
42
+ With Erbse, you can actually [capture blocks](https://github.com/apotonick/erbse#block-yielding), pass them to other cells and `yield` them. This will simply return whatever the block returns, no weird buffer magic will be happening in the background.
43
+
44
+ ## Capture
45
+
46
+ The `capture` implementation in Cells-ERB is literally a `yield`.
47
+
48
+ ```ruby
49
+ def capture(&block)
50
+ yield
51
+ end
52
+ ```
53
+
54
+ If you want to capture a block of code without outputting it, you need to use Erbse's `<%@ %>` tag.
55
+
56
+ ```erb
57
+ <%@ content = capture do %>
58
+ <h1>Hi!</h1>
59
+ It's <%= Time.new %>'o clock.
60
+ <% end %>
61
+ ```
62
+
63
+ The `content` variable will now contain the string `<h1>Hi!</h1>\nIt's 23:37'o clock.`.
64
+
65
+ Use `c@pture` as a mnemonic for the correct tag, should you need this mechanic. `capture` is usually a smell of bad view design and should be avoided.
66
+
17
67
  ## HTML Escaping
18
68
 
19
69
  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.
@@ -33,4 +83,4 @@ If that doesn't work, [read the docs](http://trailblazerb.org/gems/cells/cells4.
33
83
 
34
84
  ## Dependencies
35
85
 
36
- This gem works with Tilt 1.4 and 2.0, and hence allows you to use it from Rails 3.2 upwards.
86
+ This gem works with Tilt 1.4 and 2.0, and hence allows you to use it from Rails 3.2 upwards.
@@ -1,7 +1,6 @@
1
1
  lib = File.expand_path('../lib/', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
-
5
4
  require 'cell/erb/version'
6
5
 
7
6
  Gem::Specification.new do |spec|
@@ -19,7 +18,7 @@ Gem::Specification.new do |spec|
19
18
  spec.require_paths = ['lib']
20
19
 
21
20
  spec.add_dependency "cells", "~> 4.0"
22
- spec.add_dependency "erbse", ">= 0.0.2", "< 0.1.0"
21
+ spec.add_dependency "erbse", ">= 0.1.1"
23
22
 
24
23
  spec.add_development_dependency "bundler"
25
24
  spec.add_development_dependency "rake"
@@ -3,15 +3,6 @@ require "erbse"
3
3
  module Cell
4
4
  # Erb contains helpers that are messed up in Rails and do escaping.
5
5
  module Erb
6
- # This is to prevent multiple renders to share the same output_buffer.
7
- # I am still trying to find a way to avoid output buffers.
8
- def render_template(*)
9
- old_output_buffer = @output_buffer
10
- super
11
- ensure
12
- @output_buffer = old_output_buffer
13
- end
14
-
15
6
  def template_options_for(options)
16
7
  {
17
8
  template_class: ::Cell::Erb::Template,
@@ -19,21 +10,8 @@ module Cell
19
10
  }
20
11
  end
21
12
 
22
- # this is capture copied from AV:::CaptureHelper without doing escaping.
23
13
  def capture(*args)
24
- value = nil
25
- buffer = with_output_buffer { value = yield(*args) }
26
-
27
- return buffer.to_s if buffer.size > 0
28
- value # this applies for "Beachparty" string-only statements.
29
- end
30
-
31
- def with_output_buffer(block_buffer=ViewModel::OutputBuffer.new)
32
- @output_buffer, old_buffer = block_buffer, @output_buffer
33
- yield
34
- @output_buffer = old_buffer
35
-
36
- block_buffer
14
+ yield(*args)
37
15
  end
38
16
 
39
17
  # Below:
@@ -59,29 +37,29 @@ module Cell
59
37
  end
60
38
 
61
39
  def concat(string)
62
- @output_buffer << string
40
+ raise "[Cells-ERB] The #concat helper uses global state and is not supported anymore.
41
+ Please change your code to simple `+` String concatenation or tell the gem authors to remove #concat usage."
63
42
  end
64
43
 
65
44
 
66
45
  # Erbse-Tilt binding. This should be bundled with tilt. # 1.4. OR should be tilt-erbse.
67
46
  class Template < Tilt::Template
68
47
  def self.engine_initialized?
69
- defined? ::Erbse::Template
48
+ defined? ::Erbse::Engine
70
49
  end
71
50
 
72
51
  def initialize_engine
73
- require_template_library 'erbse'
52
+ require_template_library "erbse"
74
53
  end
75
54
 
76
- # Tilt.new("#{base}/#{prefix}/#{view}", engine_class: Erbse::Eruby)
77
55
  def prepare
78
- @template = ::Erbse::Template.new(data, options)
56
+ @template = ::Erbse::Engine.new # we also have #options here.
79
57
  end
80
58
 
81
59
  def precompiled_template(locals)
82
- # puts "@@@@@ #{@template.().inspect}"
83
- @template.call
60
+ # puts @template.call(data)
61
+ @template.call(data)
84
62
  end
85
63
  end
86
64
  end
87
- end
65
+ end
@@ -1,5 +1,5 @@
1
1
  module Cell
2
2
  module Erb
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ bla
2
+ <h1>Welcome!</h1>
3
+
4
+ <%= self.class %>
5
+ <% invoke = true %>
6
+ <% if invoke %>
7
+ invoke!
8
+ <% else %>
9
+ no invoke at all!
10
+ <% end %>
11
+ <% unless invoke %>
12
+ !unless invoke!
13
+ <% else %>
14
+ !unless invoke, #not!
15
+ <% end %>
16
+
17
+ <%= form do %>
18
+ captured
19
+ <% end %>
20
+ line
21
+ <%= render_block %>
@@ -0,0 +1,13 @@
1
+ class ErbseCell < Cell::ViewModel
2
+ include Cell::Erb
3
+ self.view_paths = ["test/dummy/app/cells"]
4
+
5
+ def form(&block)
6
+ @block = block
7
+ nil
8
+ end
9
+
10
+ def render_block
11
+ @block.call
12
+ end
13
+ end
@@ -14,9 +14,9 @@ Word.
14
14
 
15
15
  <% end %>
16
16
 
17
- <%- answer = "<script>oui!</script>" %>
17
+ <% answer = "<script>oui!</script>" %>
18
18
 
19
- <%- content = capture do %>
19
+ <%@ content = capture do %>
20
20
  Bonjour!
21
21
  <%= link_to "Coffee?", "/coffee" %>
22
22
  <b>Yes please!</b>
@@ -27,8 +27,8 @@ Weiter!
27
27
 
28
28
  <%= content %>
29
29
 
30
- <%- breadcrumbs = capture do %>
31
- <%- [link_to("1", "/1"), link_to("2", "/2")].join("+") %>
30
+ <%@ breadcrumbs = capture do %>
31
+ <%= [link_to("1", "/1"), link_to("2", "/2")].join("+") %>
32
32
  <% end %>
33
33
 
34
34
  <%= breadcrumbs %>
@@ -40,4 +40,4 @@ Weiter!
40
40
  <%= f.text_field :id %>
41
41
  <% end %>
42
42
 
43
- <%= concatting %>
43
+ <%= concatting %>
@@ -57,8 +57,10 @@ private
57
57
 
58
58
  def concatting
59
59
  content_tag :div do
60
- concat content_tag :p, "Concat!"
61
- concat "Whoo"
60
+ # concat content_tag :p, "Concat!"
61
+ # concat "Whoo"
62
+ content_tag(:p, "Concat!") +
63
+ "Whoo"
62
64
  end
63
65
  end
64
- end
66
+ end
@@ -15,13 +15,22 @@ class ErbTest < MiniTest::Spec
15
15
  it { song_cell.(:with_content_tag).must_equal "<div>Beachparty</div>" }
16
16
 
17
17
  # content_tag { content_tag { } }
18
- it do song_cell.(:with_content_tag_and_content_tag).must_equal %{<span>
19
- Title:
20
- <div>
21
- Still Knee Deep
22
- </div></span>}
18
+ it do song_cell.(:with_content_tag_and_content_tag).must_equal %{<span> Title:
19
+ <div> Still Knee Deep
20
+ </div></span>}
23
21
  end
24
22
 
23
+ # describe "benchmarking" do
24
+ # it do
25
+ # require "benchmark"
26
+ # t = Benchmark.measure do
27
+ # 10000.times { |i| song_cell.(:with_content_tag_and_content_tag) }
28
+ # end
29
+
30
+ # puts "@@@@@ #{t}"
31
+ # end
32
+ # end
33
+
25
34
  # form_tag { content_tag { } }
26
35
  it do
27
36
  form_tag = "<form action=\"/erubis/is/horribly/outdated\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" />"
@@ -30,45 +39,36 @@ class ErbTest < MiniTest::Spec
30
39
  form_with_body_tag = "<form url=\"/rails/escapes/too/much\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"button\"/></form>"
31
40
  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
32
41
 
33
- form_for_tag = "<form class=\"new_open\" id=\"new_open\" action=\"/\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" />
34
- <input type=\"text\" name=\"open[id]\" id=\"open_id\" />
35
- </form>"
42
+ form_for_tag = "<form class=\"new_open\" id=\"new_open\" action=\"/\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"text\" name=\"open[id]\" id=\"open_id\" /></form>"
36
43
  form_for_tag = "<form accept-charset=\"UTF-8\" action=\"/\" class=\"new_open\" id=\"new_open\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div>
37
44
  <input id=\"open_id\" name=\"open[id]\" size=\"30\" type=\"text\" />
38
45
  </form>" if ActionPack::VERSION::MAJOR == 3
39
46
 
40
47
  song_cell.(:with_form_tag_and_content_tag).must_equal %{Word.
41
48
 
42
- #{form_tag}
43
- <a href=\"/rails/sucks\">
44
- hallo
49
+ #{form_tag}<a href=\"/rails/sucks\"> hallo
45
50
  <div class="row">
46
51
  Cool
47
52
  </div>
48
- </a>
49
- <ul data-x="{&quot;a&quot;:&quot;1&quot;}">
50
- Hallo
51
- </ul>
52
- </form>
53
-
54
-
55
- Weiter!
53
+ </a><ul data-x="{&quot;a&quot;:&quot;1&quot;}"> Hallo
54
+ </ul></form>Weiter!
56
55
 
57
56
  Bonjour!
58
- <a href=\"/coffee\">Coffee?</a>
59
- <b>Yes please!</b>
60
- <script>oui!</script>
61
-
62
-
63
-
64
- <a href=\"/1\">1</a>+<a href=\"/2\">2</a>
65
-
66
- <b>No current page!<b>
67
- #{form_with_body_tag}
57
+ <a href=\"/coffee\">Coffee?</a> <b>Yes please!</b>
58
+ <script>oui!</script><a href=\"/1\">1</a>+<a href=\"/2\">2</a><b>No current page!<b>#{form_with_body_tag}#{form_for_tag}<div><p>Concat!</p>Whoo</div>}
59
+ end
68
60
 
69
- #{form_for_tag}
70
- <div><p>Concat!</p>Whoo</div>}
61
+ it do
62
+ # puts ErbseCell.new.()
63
+ ErbseCell.new.().must_equal %{bla
64
+ <h1>Welcome!</h1>
65
+
66
+ ErbseCell invoke!
67
+ !unless invoke, #not!
68
+ line
69
+ captured
70
+ }
71
71
  end
72
72
  end
73
73
 
74
- # 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.
74
+ # 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.9
4
+ version: 0.1.0
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: 2016-10-05 00:00:00.000000000 Z
12
+ date: 2016-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cells
@@ -31,20 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.0.2
35
- - - "<"
36
- - !ruby/object:Gem::Version
37
- version: 0.1.0
34
+ version: 0.1.1
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
38
  requirements:
42
39
  - - ">="
43
40
  - !ruby/object:Gem::Version
44
- version: 0.0.2
45
- - - "<"
46
- - !ruby/object:Gem::Version
47
- version: 0.1.0
41
+ version: 0.1.1
48
42
  - !ruby/object:Gem::Dependency
49
43
  name: bundler
50
44
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +92,8 @@ files:
98
92
  - lib/cell/erb/version.rb
99
93
  - lib/cells-erb.rb
100
94
  - test/dummy/Rakefile
95
+ - test/dummy/app/cells/erbse/show.erb
96
+ - test/dummy/app/cells/erbse_cell.rb
101
97
  - test/dummy/app/cells/song/render_in_render.erb
102
98
  - test/dummy/app/cells/song/render_in_render_2.erb
103
99
  - test/dummy/app/cells/song/with_content_tag.erb
@@ -135,12 +131,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
131
  version: '0'
136
132
  requirements: []
137
133
  rubyforge_project:
138
- rubygems_version: 2.5.1
134
+ rubygems_version: 2.6.3
139
135
  signing_key:
140
136
  specification_version: 4
141
137
  summary: Tilt binding for Erbse.
142
138
  test_files:
143
139
  - test/dummy/Rakefile
140
+ - test/dummy/app/cells/erbse/show.erb
141
+ - test/dummy/app/cells/erbse_cell.rb
144
142
  - test/dummy/app/cells/song/render_in_render.erb
145
143
  - test/dummy/app/cells/song/render_in_render_2.erb
146
144
  - test/dummy/app/cells/song/with_content_tag.erb