File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ module Phlex::Helpers
18
18
# tokens(
19
19
# active?: { then: "active", else: "inactive" }
20
20
# )
21
- def tokens ( *tokens , **conditional_tokens )
21
+ def tokens ( *tokens , class : nil , **conditional_tokens )
22
22
conditional_tokens . each do |condition , token |
23
23
truthy = case condition
24
24
when Symbol then send ( condition )
@@ -38,6 +38,13 @@ def tokens(*tokens, **conditional_tokens)
38
38
end
39
39
end
40
40
41
+ case binding . local_variable_get ( :class )
42
+ when Class
43
+ raise ArgumentError , "Implicit class binding is not supported. Use the class: keyword argument."
44
+ else
45
+ tokens . append binding . local_variable_get ( :class )
46
+ end
47
+
41
48
tokens = tokens . select ( &:itself ) . join ( " " )
42
49
tokens . strip!
43
50
tokens . gsub! ( /\s +/ , " " )
Original file line number Diff line number Diff line change 3
3
describe Phlex ::HTML do
4
4
extend ViewHelper
5
5
6
+ with "implicit class binding" do
7
+ with "class: keyword argument" do
8
+ view do
9
+ def view_template
10
+ red ( class : "buzz" )
11
+ end
12
+
13
+ def red ( class :)
14
+ div ( class : tokens ( "fizz" , class :) )
15
+ end
16
+ end
17
+
18
+ it "implicitly binds class: keyword argument" do
19
+ expect ( output ) . to be == %(<div class="fizz buzz"></div>)
20
+ end
21
+ end
22
+
23
+ with "endless argumens (...)" do
24
+ view do
25
+ def view_template
26
+ red ( class : "buzz" )
27
+ end
28
+
29
+ def red ( ...)
30
+ div ( class : tokens ( "fizz" , class :) )
31
+ end
32
+ end
33
+
34
+ it "raises error" do
35
+ expect { output } . to raise_exception ArgumentError ,
36
+ message : be == "Implicit class binding is not supported. Use the class: keyword argument."
37
+ end
38
+ end
39
+ end
40
+
6
41
with "conditional classes" do
7
42
with "symbol conditionals" do
8
43
view do
You can’t perform that action at this time.
0 commit comments