lapillus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/changelog.txt CHANGED
@@ -1,3 +1,9 @@
1
+ Changes Lapillus 0.0.3 --> 0.0.4
2
+ - Added MonkeyPatch for Ruby 1.8.6 REXML bug
3
+ See: http://www.intertwingly.net/blog/2007/11/02/MonkeyPatch-for-Ruby-1-8-6
4
+ - Added fix and tests for MultiView component
5
+ - Added fix and test for ListView component
6
+
1
7
  Changes Lapillus 0.0.2 --> 0.0.3
2
8
  - Refactoring: Component identifiers have become Symbols instead of Strings
3
9
  - Refactoring: use named parameters in Component constructor to set options (like :visible=false)
@@ -5,7 +11,7 @@ Changes Lapillus 0.0.2 --> 0.0.3
5
11
  - Refactoring: Lapillus now works with ruby 1.8.6 (version contains some changes in the REXML API)
6
12
  - Refactoring: HTML rendering is now done using the visitor pattern instead of recursion
7
13
  - First version of the Lapillus website (Thanks to Joris van Zundert)
8
- URL: http://hi3.huygensinstituut.nl:2000/
14
+ URL: http://lapi.llus.org
9
15
 
10
16
 
11
17
  Changes Lapillus 0.0.1 --> 0.0.2
data/lib/lapillus/base.rb CHANGED
@@ -46,7 +46,7 @@ module Lapillus
46
46
  result_dom = visitor.container_output.root
47
47
  element = REXML::XPath.first( result_dom, "//*[@id=\"#{path}\"]" )
48
48
  if element == nil
49
- message = "Identifier "+path+" not found! in "+doc.to_s
49
+ message = "Identifier "+path+" not found! in "+result_dom.to_s
50
50
  raise message
51
51
  end
52
52
  formatter = REXML::Formatters::Default.new
@@ -91,6 +91,7 @@ module Lapillus
91
91
  visitor.current_container = container
92
92
  container.render_children(visitor, listview_element)
93
93
  }
94
+ visitor.current_container = self.parent
94
95
  end
95
96
  end
96
97
 
@@ -1,3 +1,19 @@
1
+ # FIX FOR REXML BUG IN RUBY 1.8.6
2
+ # See: http://www.intertwingly.net/blog/2007/11/02/MonkeyPatch-for-Ruby-1-8-6
3
+
4
+ require 'rexml/document'
5
+ doc = REXML::Document.new '<doc xmlns="ns"><item name="foo"/></doc>'
6
+ if not doc.root.elements["item[@name='foo']"]
7
+ class REXML::Element
8
+ def attribute( name, namespace=nil )
9
+ prefix = nil
10
+ prefix = namespaces.index(namespace) if namespace
11
+ prefix = nil if prefix == 'xmlns'
12
+ attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
13
+ end
14
+ end
15
+ end
16
+
1
17
  module Lapillus
2
18
  class NullComponent < RenderableComponent
3
19
  #TODO: move to standard container class?
@@ -25,10 +41,10 @@ module Lapillus
25
41
 
26
42
  def visit_element(element)
27
43
  return if element.name=="fragment"
28
- #puts "rendering: #{element.name}"
29
44
  component_id = element.attributes['lapillus:id']
30
45
  if !component_id.nil?
31
46
  child_component = current_container[component_id]
47
+ #puts "rendering: #{element.name} with #{component_id} -> #{child_component.class} from #{current_container.class}"
32
48
  else
33
49
  child_component = NullComponent.new
34
50
  end
@@ -15,19 +15,18 @@ class MultiView < Lapillus::Component
15
15
  @mode=views[0].identifier
16
16
  end
17
17
 
18
- def current_view(id=mode)
18
+ def current_view
19
19
  @views.each do |v|
20
- return v if v.identifier == id
20
+ return v if v.identifier == mode
21
21
  end
22
22
  raise "view with identifier #{id} not found!"
23
23
  nil
24
24
  end
25
25
 
26
- def render_container(html)
26
+ def render_children(visitor, html)
27
27
  singleview = current_view
28
- result = singleview.render_container(html)
29
- render_behaviours(result)
30
- return result
28
+ visitor.current_container = singleview
29
+ singleview.render_children(visitor, html)
31
30
  end
32
31
 
33
32
  # TODO: add test
@@ -81,6 +81,17 @@ class TC_containers < Test::Unit::TestCase
81
81
  label :text, :model => text
82
82
  end
83
83
  end
84
+
85
+ class TestWebpage2 < Webpage
86
+ attr_accessor :values
87
+ listview :listview, :model => :values do |text|
88
+ label :text, :model => text
89
+ end
90
+ attr_accessor :values2
91
+ listview :listview2, :model => :values2 do |text|
92
+ label :text, :model => text
93
+ end
94
+ end
84
95
 
85
96
  def test_listview_components
86
97
  test = TestWebpage.new
@@ -113,6 +124,26 @@ class TC_containers < Test::Unit::TestCase
113
124
  assert_equal(expected, result)
114
125
  end
115
126
 
127
+ def test_listview_rendering_with_two_lists
128
+ html = html_template('<span lapillus:id="listview">'+
129
+ '<p><span lapillus:id="text">Comment text goes here.</span>'+
130
+ '</p></span>'+
131
+ '<span lapillus:id="listview2">'+
132
+ '<p><span lapillus:id="text">Comment text goes here.</span>'+
133
+ '</p></span>')
134
+ expected = expected_html('<span lapillus:id="listview">'+
135
+ '<p><span lapillus:id="text">first</span>'+
136
+ '</p></span>'+
137
+ '<span lapillus:id="listview2">'+
138
+ '<p><span lapillus:id="text">second</span>'+
139
+ '</p></span>')
140
+ testpanel = TestWebpage2.new
141
+ testpanel.values = ["first"]
142
+ testpanel.values2 = ["second"]
143
+ result = testpanel.render(html)
144
+ assert_equal(expected, result)
145
+ end
146
+
116
147
  def test_listview_set_value
117
148
  test = TestWebpage.new
118
149
  test.values = ["first","second"]
data/test/tc_multiview.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
- require 'lapillus/multiview'
2
+ require 'lapillus'
3
+
4
+ include Lapillus
3
5
 
4
6
  class TC_MultiView < Test::Unit::TestCase
5
7
  def test_current_view
@@ -18,74 +20,69 @@ class TC_MultiView < Test::Unit::TestCase
18
20
  assert_equal(view2, multi_view.current_view)
19
21
  end
20
22
 
21
- # def test_behaviours
22
- # html = <<EOF
23
- # <html>
24
- # <span lapillus:id="multiview">single_view comes here</span>
25
- # <lapillus:fragment lapillus:id="single1">
26
- # <span lapillus:id="label">some content here</span>
27
- # </lapillus:fragment>
28
- # <lapillus:fragment lapillus:id="single2">
29
- # <a lapillus:id="link" href="#">
30
- # <span lapillus:id="link_label">some content here</span>
31
- # </a>
32
- # </lapillus:fragment>
33
- # </html>
34
- #EOF
35
- # single1 = SingleView.new("single1") do
36
- # add(Label.new("label", "simple label"))
37
- # end
38
- # multi_view = MultiView.new("multiview", [single1])
39
- # multi_view.value = "single1"
40
- # multi_view.add_behaviour(OnClick.new)
41
- # page = Webpage.new
42
- # page.add multi_view
43
- # output = page.render(html)
44
- # puts output
45
- # end
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
23
+ def test_multiview_with_behaviours
24
+ html = <<EOF
25
+ <html>
26
+ <span lapillus:id="multiview">single_view comes here</span>
27
+ <lapillus:fragment lapillus:id="single1">
28
+ <span lapillus:id="label">some content here</span>
29
+ </lapillus:fragment>
30
+ <lapillus:fragment lapillus:id="single2">
31
+ <a lapillus:id="link" href="#">
32
+ <span lapillus:id="link_label">some content here</span>
33
+ </a>
34
+ </lapillus:fragment>
35
+ </html>
36
+ EOF
37
+ expected = <<EOF
38
+ <html>
39
+ <span lapillus:id="multiview" onclick="new Ajax.Request('', { method: 'get', parameters: { listener:'multiview' }}); return false;">
40
+ <span lapillus:id="label">simple label</span>
41
+ </span>
42
+
43
+
44
+ </html>
45
+ EOF
46
+ single1 = SingleView.new(:single1)
47
+ single1.add(Label.new(:label, :model => "simple label"))
48
+ multi_view = MultiView.new(:multiview, [single1])
49
+ multi_view.mode = :single1
50
+ multi_view.add_behaviour(OnClick.new)
51
+ page = Webpage.new
52
+ page.add multi_view
53
+ output = page.render(html)
54
+ assert_equal(expected, output+"\n")
55
+ end
55
56
 
56
- # def xtest_switch_view
57
- # single1 = SingleView.new("single1") do
58
- # add(Label.new("label", "simple label"))
59
- # end
60
- # single2 = SingleView.new("single2") do
61
- # add(AjaxLink.new("link") do
62
- # add(Label.new("link_label", "text inside link"))
63
- # on_click do
64
- #
65
- # end
66
- # end)
67
- # end
68
- # multi_view = MultiView.new("multiview", [single1, single2])
69
- # multi_view.value = "single1"
70
- # html = <<EOF
71
- # <html>
72
- # <span lapillus:id="multiview">single_view comes here</span>
73
- # <lapillus:fragment lapillus:id="single1">
74
- # <span lapillus:id="label">some content here</span>
75
- # </lapillus:fragment>
76
- # <lapillus:fragment lapillus:id="single2">
77
- # <a lapillus:id="link" href="#">
78
- # <span lapillus:id="link_label">some content here</span>
79
- # </a>
80
- # </lapillus:fragment>
81
- # </html>
82
- #EOF
83
- # page = Webpage.new
84
- # page.add multi_view
85
- # output = page.render(html)
86
- # puts output
87
- # assert_equal(single1,multi_view.get_single_view('single1'))
88
- # end
57
+ def test_switch_view
58
+ single1 = SingleView.new(:single1)
59
+ single1.add(Label.new(:label, :model => "simple label"))
60
+ single2 = SingleView.new(:single2)
61
+ link = AjaxLink.new(:link)
62
+ single2.add(link)
63
+ link.add(Label.new(:link_label, :model=>"text inside link"))
64
+ multi_view = MultiView.new(:multiview, [single1, single2])
65
+ multi_view.model = "single1"
66
+ html = <<EOF
67
+ <html>
68
+ <span lapillus:id="multiview">single_view comes here</span>
69
+ <lapillus:fragment lapillus:id="single1">
70
+ <span lapillus:id="label">some content here</span>
71
+ </lapillus:fragment>
72
+ <lapillus:fragment lapillus:id="single2">
73
+ <a lapillus:id="link" href="#">
74
+ <span lapillus:id="link_label">some content here</span>
75
+ </a>
76
+ </lapillus:fragment>
77
+ </html>
78
+ EOF
79
+ page = Webpage.new
80
+ page.add multi_view
81
+ multi_view.mode = :single2
82
+ output = page.render(html)
83
+ assert(output.include?("lapillus:id=\"link\""))
84
+ assert_equal(single2,multi_view.current_view)
85
+ end
89
86
 
90
87
 
91
88
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: lapillus
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2008-01-29 00:00:00 +01:00
6
+ version: 0.0.4
7
+ date: 2008-02-04 00:00:00 +01:00
8
8
  summary: Component based webframework written in Ruby
9
9
  require_paths:
10
10
  - lib