gara 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,8 +22,8 @@ class GaraTest < ActiveSupport::TestCase
22
22
 
23
23
  class TestEmitter
24
24
  module DelegatedMethods
25
- def component1 ; @gara_delegate.component1 ; yield if block_given? ; end
26
- def component2 ; @gara_delegate.component2 ; yield if block_given? ; end
25
+ def component1 ; @delegate.component1 ; yield if block_given? ; end
26
+ def component2 ; @delegate.component2 ; yield if block_given? ; end
27
27
  end
28
28
 
29
29
  def initialize
@@ -32,8 +32,9 @@ class GaraTest < ActiveSupport::TestCase
32
32
  def component1 ; @doc << "stuff " ; end
33
33
  def component2 ; @doc << "and more stuff" ; end
34
34
 
35
- def registered_methods
36
- return DelegatedMethods
35
+ def add_methods_to(context)
36
+ context.instance_variable_set(:@delegate, self)
37
+ context.extend(DelegatedMethods)
37
38
  end
38
39
  def emit
39
40
  @doc
@@ -5,6 +5,7 @@ class HandlerTest < ActiveSupport::TestCase
5
5
  GARAHandler = Gara::Template::Handler.new
6
6
 
7
7
  DEFAULT_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
8
+ A_LINK = %Q(<a href="#">link</a>)
8
9
 
9
10
  class LookupContext
10
11
  def disable_cache
@@ -26,6 +27,10 @@ class HandlerTest < ActiveSupport::TestCase
26
27
  def lookup_context
27
28
  @lookup_context ||= LookupContext.new
28
29
  end
30
+
31
+ def link_helper
32
+ A_LINK
33
+ end
29
34
  end
30
35
 
31
36
  def new_template(body = " h1 'Hello' ", details = { format: :html })
@@ -73,7 +78,7 @@ class HandlerTest < ActiveSupport::TestCase
73
78
 
74
79
  test "real document has doctype and newline" do
75
80
  @template = new_template("html { body { h1 \"hello\" } }")
76
- assert_equal with_doctype("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <body>\n <h1>hello</h1>\n </body>\n</html>\n"), render
81
+ assert_equal with_doctype("<html><body><h1>hello</h1></body></html>\n"), render
77
82
  end
78
83
 
79
84
  test "locals work" do
@@ -82,4 +87,21 @@ class HandlerTest < ActiveSupport::TestCase
82
87
  assert_equal "<h1>Foo</h1>", render(title: 'Foo')
83
88
  end
84
89
 
90
+ test "string in block works" do
91
+ @template = new_template "h1 { 'foo' } "
92
+ assert_equal "<h1>foo</h1>", render
93
+ end
94
+
95
+ test "helpers returning html when alone in a block" do
96
+ @template = new_template("li { link_helper } ")
97
+ assert_equal "<li>#{A_LINK}</li>", render
98
+ end
99
+
100
+ test "helpers returning html work in sequence within a block" do
101
+ @template = new_template("li { link_helper ; link_helper } ")
102
+ without_self = render
103
+ assert_equal "<li>\n#{A_LINK}#{A_LINK}\n</li>", render
104
+ end
105
+
106
+
85
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith