cells-haml 0.0.3 → 0.0.4

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: afb505222abec10007aa42aba06dc1471e13bd35
4
- data.tar.gz: d6cf9966745815f0831df6b914757f42c91791d1
3
+ metadata.gz: 1cdad224d97c15e3ca642dcea8d9449b2b1298ae
4
+ data.tar.gz: f665747209ac4d5d7cff32d680677b811be68a87
5
5
  SHA512:
6
- metadata.gz: bfdf392451a738e1de7266b25c36f0707463cbc412d61f574da61258d3e89d1b33c2d25ff919796d9dff08ad043f6f51e0f5c4661fd26c1e673cef013aa28ddb
7
- data.tar.gz: 4b2c625bd551d555979a71b632cf0f522343d4c4ebb7c200dc6c644ae9fd8736247451b8c09e4f70e161f386337709de508df655657609bec94f94aac34a2302
6
+ metadata.gz: 6d3d433ac40e0cf825f3bca8a058739faa9bab14ed28f78fa48ff4a35ea38aed4bf7490ec7231367e3ae3135630c1e2f63811c9ef483bdfc87174b82fca5a6ef
7
+ data.tar.gz: 33413f055c224c4157fe835f97820b59d24caec46c4e7fbf2b7be2bcdf7ad0f1687dc49f378e996174f826aa8a3afe3fb888558608a2cb0a0918e074637330ae
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.4
2
+
3
+ * Added `capture` helper to override Rails escaping.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cells::Haml
2
2
 
3
- TODO: Write a gem description
3
+ Haml support for Cells.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,22 +10,27 @@ Add this line to your application's Gemfile:
10
10
  gem 'cells-haml'
11
11
  ```
12
12
 
13
- And then execute:
13
+ This will set `ViewModel.template_engine = :haml.
14
14
 
15
- $ bundle
15
+ And that's all you need to do.
16
16
 
17
- Or install it yourself as:
17
+ ## HTML Escaping
18
18
 
19
- $ gem install cells-haml
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
20
 
21
- ## Usage
21
+ As a first step, try this and see if it helps.
22
22
 
23
- TODO: Write usage instructions here
23
+ ```ruby
24
+ class SongCell < Cell::ViewModel
25
+ include ActionView::Helpers::FormHelper
26
+ include Cell::Haml # include Haml _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).
24
33
 
25
- ## Contributing
34
+ ## Dependencies
26
35
 
27
- 1. Fork it ( https://github.com/trailblazer/cells-haml/fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
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-haml.gemspec CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'cells', '~> 4.0.0.beta'
21
- spec.add_runtime_dependency 'haml', '~> 4.0'
20
+ spec.add_dependency 'cells', '~> 4.0.0.beta3'
21
+ spec.add_dependency 'haml', '~> 4.0'
22
22
  spec.add_development_dependency 'bundler'
23
23
  spec.add_development_dependency 'rake'
24
24
  end
@@ -3,8 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  #gem "cells", :github => "apotonick/cells"
6
- gem "cells", path: "../../cells"
7
- gem "appraisal"
6
+ # gem "cells", path: "../../cells"
8
7
  gem "railties", "~> 3.2.0"
9
8
  gem "activemodel"
10
9
  gem "minitest", "~> 4.0"
@@ -12,5 +11,3 @@ gem "tilt", "~> 1.4"
12
11
  gem "tzinfo"
13
12
 
14
13
  gemspec :path => "../"
15
-
16
- # gem "erbse", path: "../../erbse"
@@ -0,0 +1,12 @@
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 "railties", "~> 4.0.0"
8
+ gem "activemodel"
9
+ gem "minitest", "~> 4.0"
10
+ gem "tilt", "~> 1.4"
11
+
12
+ gemspec :path => "../"
@@ -2,14 +2,11 @@
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
- gem "appraisal"
8
7
  gem "railties", "~> 4.2.0"
9
8
  gem "activemodel"
10
9
  gem "minitest", "~> 5.2"
11
10
  gem "tilt", "~> 1.4"
12
11
 
13
12
  gemspec :path => "../"
14
-
15
- # gem "erbse", path: "../../erbse"
@@ -0,0 +1,14 @@
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", "~> 4.2.0"
9
+ gem "activemodel"
10
+ gem "minitest", "~> 5.2"
11
+ gem "tilt", "~> 2.0"
12
+ gem "haml-rails", "~> 0.9.0"
13
+
14
+ gemspec :path => "../"
@@ -3,8 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  # gem "cells", :github => "apotonick/cells"
6
- gem "cells", path: "../../cells"
7
- gem "appraisal"
6
+ # gem "cells", path: "../../cells"
8
7
  gem "railties", "~> 4.2.0"
9
8
  gem "activemodel"
10
9
  gem "minitest", "~> 5.2"
@@ -2,9 +2,8 @@
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
- gem "appraisal"
8
7
  gem "railties", "~> 4.2.0"
9
8
  gem "activemodel"
10
9
  gem "minitest", "~> 5.2"
@@ -1,5 +1,5 @@
1
1
  module Cell
2
2
  module Haml
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
data/lib/cell/haml.rb CHANGED
@@ -2,87 +2,21 @@ require 'tilt/haml'
2
2
 
3
3
  module Cell
4
4
  module Haml
5
- # def output_buffer_with_haml
6
- # return haml_buffer.buffer if is_haml?
7
- # output_buffer_without_haml
8
- # end
9
-
10
- # def set_output_buffer_with_haml(new_buffer)
11
- # if is_haml?
12
- # if ::Haml::Util.rails_xss_safe? && new_buffer.is_a?(ActiveSupport::SafeBuffer)
13
- # new_buffer = String.new(new_buffer)
14
- # end
15
- # haml_buffer.buffer = new_buffer
16
- # else
17
- # set_output_buffer_without_haml new_buffer
18
- # end
19
- # end
20
-
21
-
22
- # def self.included(base)
23
- # base.class_eval do
24
- # alias_method :output_buffer_without_haml, :output_buffer
25
- # alias_method :output_buffer, :output_buffer_with_haml
26
-
27
- # alias_method :set_output_buffer_without_haml, :output_buffer=
28
- # alias_method :output_buffer=, :set_output_buffer_with_haml
29
- # end
30
- # end
31
-
32
- # # TODO: remove the concept of output buffers and just return block's result!
33
- # class OutputBuffer < String
34
- # end
35
-
36
-
37
- # def with_output_buffer(buf = nil)
38
- # unless buf
39
- # buf = OutputBuffer.new
40
- # end
41
- # self.output_buffer, old_buffer = buf, output_buffer
42
- # yield
43
- # output_buffer
44
- # ensure
45
- # self.output_buffer = old_buffer
46
- # end
47
-
48
-
49
- # # generic ERB HAML HELPERS>>>>>>
50
- # def capture(*args,&block)
51
- # value = nil
52
- # buffer = with_output_buffer() { value = yield(*args) }
53
- # if string = buffer.presence || value and string.is_a?(String)
54
- # return string
55
- # end
56
- # end
57
-
58
- # # From FormTagHelper. why do they escape every possible string? why?
59
- # def form_tag_in_block(html_options, &block)
60
- # content = capture(&block)
61
- # form_tag_with_body(html_options, content)
62
- # end
63
-
64
- # def form_tag_with_body(html_options, content)
65
- # "#{form_tag_html(html_options)}" << content.to_s << "</form>"
66
- # end
67
-
68
- # def form_tag_html(html_options)
69
- # extra_tags = extra_tags_for_form(html_options)
70
- # "#{tag(:form, html_options, true) + extra_tags}"
71
- # end
72
-
73
- # # Rails 4.0, TagHelper.
74
- # def tag_option(key, value, escape)
75
- # super(key, value, false)
76
- # end
77
-
78
- # def content_tag_string(name, content, options, escape=true)
79
- # super(name, content, options, false)
80
- # end
5
+ # From FormTagHelper. why do they escape every possible string? why?
6
+ def form_tag_in_block(html_options, &block)
7
+ content = capture(&block)
8
+ form_tag_with_body(html_options, content)
9
+ end
10
+
11
+ def form_tag_with_body(html_options, content)
12
+ "#{form_tag_html(html_options)}" << content.to_s << "</form>"
13
+ end
14
+
15
+ def form_tag_html(html_options)
16
+ extra_tags = extra_tags_for_form(html_options)
17
+ "#{tag(:form, html_options, true) + extra_tags}"
18
+ end
81
19
  end
82
20
 
83
- # ViewModel.class_eval do
84
- # include Haml
85
- # end
86
-
87
21
  ViewModel.template_engine = :haml
88
22
  end
@@ -4,12 +4,26 @@ Word.
4
4
  = link_to "/rails/sucks" do
5
5
  hallo
6
6
 
7
- = content_tag( :ul) do
7
+ = content_tag(:ul) do
8
8
  Hallo
9
9
 
10
+ - answer = "<script>oui!</script>"
11
+
12
+ -# test content rendering in capture.
10
13
  - content = capture do
11
14
  Bonjour!
15
+ = link_to "Coffee?", "/coffee"
16
+ <b>Yes please!</b>
17
+ = answer
12
18
 
13
19
  Weiter!
14
20
 
15
- = content
21
+ = content
22
+
23
+ - breadcrumbs = capture do
24
+ - [link_to("1", "/1"), link_to("2", "/2")].join("+")
25
+
26
+ = breadcrumbs
27
+
28
+ = current_page
29
+ = form_tag_with_body( {url: "/rails/escapes/too/much"}, %{<input type="button"/>})
@@ -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::Haml
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 # FIXME: this escapes!
46
+ #[link_to("1", "/1"), link_to("2", "/2")].join("+") # this breaks, too!
47
+ "<b>No current page!<b>".html_safe
48
+ end
49
+ end
42
50
  end
data/test/haml_test.rb CHANGED
@@ -27,6 +27,9 @@ class HamlTest < MiniTest::Spec
27
27
  form_tag = "<form action=\"/erubis/is/horribly/outdated\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" />"
28
28
  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
29
29
 
30
+ form_with_body_tag = "<form url=\"/rails/escapes/too/much\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"button\"/></form>"
31
+ 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
+
30
33
  song_cell.(:with_form_tag_and_content_tag).must_equal %{Word.
31
34
  #{form_tag}
32
35
  <a href=\"/rails/sucks\">hallo
@@ -36,7 +39,13 @@ class HamlTest < MiniTest::Spec
36
39
  </form>
37
40
  Weiter!
38
41
  Bonjour!
42
+ <a href=\"/coffee\">Coffee?</a>
43
+ <b>Yes please!</b>
44
+ <script>oui!</script>
45
+ <a href=\"/1\">1</a>+<a href=\"/2\">2</a>
46
+ <b>No current page!<b>
47
+ #{form_with_body_tag}
39
48
  }
40
- end
49
+ end
41
50
 
42
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells-haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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,14 +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
27
+ version: 4.0.0.beta3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: haml
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -77,13 +77,16 @@ extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
79
  - ".travis.yml"
80
+ - CHANGES.md
80
81
  - Gemfile
81
82
  - LICENSE.txt
82
83
  - README.md
83
84
  - Rakefile
84
85
  - cells-haml.gemspec
85
86
  - gemfiles/rails_3.2-tilt-1.4.gemfile
87
+ - gemfiles/rails_4.0-tilt-1.4.gemfile
86
88
  - gemfiles/rails_4.2-tilt-1.4.gemfile
89
+ - gemfiles/rails_4.2-tilt-2.0-rails-haml-0.9.gemfile
87
90
  - gemfiles/rails_4.2-tilt-2.0.gemfile
88
91
  - gemfiles/rails_4.2-tilt-3.0.gemfile
89
92
  - lib/cell/haml.rb