malline 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/COPYING +674 -0
  2. data/COPYING.LESSER +165 -0
  3. data/README +24 -0
  4. data/bin/malline +20 -0
  5. data/lib/malline.rb +108 -0
  6. data/lib/malline/erb_out.rb +29 -0
  7. data/lib/malline/form_builder.rb +33 -0
  8. data/lib/malline/rails.rb +45 -0
  9. data/lib/malline/template.rb +124 -0
  10. data/lib/malline/view_proxy.rb +54 -0
  11. data/lib/malline/view_wrapper.rb +91 -0
  12. data/lib/malline/view_xhtml.rb +71 -0
  13. data/scripts/html2mn.rb +93 -0
  14. data/test/examples/_action.mn +4 -0
  15. data/test/examples/_action.target +1 -0
  16. data/test/examples/_one.mn +1 -0
  17. data/test/examples/_one.target +1 -0
  18. data/test/examples/_partial.mn +2 -0
  19. data/test/examples/_partial.target +1 -0
  20. data/test/examples/_three.rhtml +2 -0
  21. data/test/examples/_two.mn +1 -0
  22. data/test/examples/_two.target +1 -0
  23. data/test/examples/capture.mn +13 -0
  24. data/test/examples/capture.target +1 -0
  25. data/test/examples/class.mn +6 -0
  26. data/test/examples/class.target +1 -0
  27. data/test/examples/escape.mn +4 -0
  28. data/test/examples/escape.target +1 -0
  29. data/test/examples/fragment_cache.mn +10 -0
  30. data/test/examples/fragment_cache.target +1 -0
  31. data/test/examples/frontpage.mn +6 -0
  32. data/test/examples/frontpage.target +1 -0
  33. data/test/examples/hello_world.mn +2 -0
  34. data/test/examples/hello_world.target +1 -0
  35. data/test/examples/helper.mn +5 -0
  36. data/test/examples/helper.target +1 -0
  37. data/test/examples/helper2.mn +5 -0
  38. data/test/examples/helper2.target +1 -0
  39. data/test/examples/helper_shortcut.mn +5 -0
  40. data/test/examples/helper_shortcut.target +1 -0
  41. data/test/examples/id.mn +3 -0
  42. data/test/examples/id.target +1 -0
  43. data/test/examples/layout.mn +8 -0
  44. data/test/examples/layout.target +4 -0
  45. data/test/examples/lists.mn +13 -0
  46. data/test/examples/lists.target +1 -0
  47. data/test/examples/nested.mn +6 -0
  48. data/test/examples/nested.target +1 -0
  49. data/test/examples/options.mn +10 -0
  50. data/test/examples/options.target +1 -0
  51. data/test/examples/partials.mn +5 -0
  52. data/test/examples/partials.target +1 -0
  53. data/test/examples/self.mn +2 -0
  54. data/test/examples/self.target +1 -0
  55. data/test/examples/text.mn +4 -0
  56. data/test/examples/text.target +1 -0
  57. data/test/examples/whitespace.mn +9 -0
  58. data/test/examples/whitespace.target +1 -0
  59. data/test/examples/xhtml.mn +11 -0
  60. data/test/examples/xhtml.target +4 -0
  61. data/test/kernel.org.html +107 -0
  62. data/test/kernel.org.mn +657 -0
  63. data/test/malline_test.rb +192 -0
  64. data/test/malline_test_helpers.rb +57 -0
  65. metadata +110 -0
@@ -0,0 +1,192 @@
1
+ # Copyright © 2007,2008 Riku Palomäki
2
+ #
3
+ # This file is part of Malline.
4
+ #
5
+ # Malline is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Malline is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Malline. If not, see <http://www.gnu.org/licenses/>.
17
+ t = File.expand_path(File.join(File.dirname(__FILE__), '..'))
18
+ $: << t
19
+ $: << File.join(t, 'lib')
20
+ require 'test/unit'
21
+ require 'test/malline_test_helpers.rb'
22
+ require 'malline.rb'
23
+
24
+ class Controller
25
+ def perform_caching
26
+ false
27
+ end
28
+ end
29
+
30
+ class Comment
31
+ end
32
+
33
+ class View
34
+ def initialize
35
+ @controller = Controller.new
36
+ end
37
+ def image_path(im)
38
+ "/images/#{im.is_a?(MallineTestHelpers::Image) ? im.id : 'img'}"
39
+ end
40
+ def truncate(str, size = 10)
41
+ str[0...size]
42
+ end
43
+ def render hash
44
+ Malline::Base.new(View.new).render File.read(File.join(File.dirname(__FILE__), hash[:partial].sub(/\//, '/_') + '.mn')) rescue ''
45
+ end
46
+ def link_to *args
47
+ 'link'
48
+ end
49
+ end
50
+
51
+
52
+ class MallineTest < Test::Unit::TestCase
53
+ include Malline
54
+ include MallineTestHelpers
55
+
56
+ def test_simple
57
+ Base.setopt :strict => false, :xhtml => false do
58
+ assert_xml_equal('<foo id="a"><bar class="a b"/></foo>',
59
+ Base.render do
60
+ foo.a! do
61
+ bar.a.b
62
+ end
63
+ end
64
+ )
65
+ end
66
+ end
67
+
68
+ def test_basics
69
+ images = [Image.new(1, '/image/img1', 'Image 1'), Image.new(2, '/2', 'Image 2')]
70
+
71
+ out = Base.new(View.new).render nil, :images => images do
72
+ html do
73
+ body do
74
+ div.header!
75
+ div.imagelist.images! "There are some images:" do
76
+ @images.each do |im|
77
+ a(:href => image_path(im)) { img :src => im.url }
78
+ span.caption.imagetext im.caption
79
+ end
80
+ txt! "No more images"
81
+ end
82
+ div.footer! { span 'footer' }
83
+ end
84
+ end
85
+ end
86
+ assert_xml_equal('<html><body><div id="header"></div><div class="imagelist" id="images">There are some images:<a href="/images/1"><img src="/image/img1"/></a><span class="caption imagetext">Image 1</span><a href="/images/2"><img src="/2"/></a><span class="caption imagetext">Image 2</span>No more images</div><div id="footer"><span>footer</span></div></body></html>', out)
87
+ end
88
+
89
+ def test_tag!
90
+ Base.setopt :strict => false, :xhtml => false do
91
+ out = Base.render do
92
+ foo do
93
+ tag!('foobar', :foobar => 'foobar') do
94
+ tag!('foobar2', :foobar => 'foobar2') do
95
+ bar do
96
+ foo
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ assert_xml_equal('<foo><foobar foobar="foobar"><foobar2 foobar="foobar2"><bar><foo/></bar></foobar2></foobar></foo>', out)
103
+ end
104
+ end
105
+
106
+ def test_defined_tags
107
+ tpl = Base.setopt :strict => false, :xhtml => false do
108
+ Base.new(View.new)
109
+ end
110
+ b = Proc.new do
111
+ foo do
112
+ xxx :a => 'b' do
113
+ bar
114
+ end
115
+ end
116
+ end
117
+ out = tpl.render nil, &b
118
+ assert_xml_equal('<foo/>', out)
119
+
120
+ tpl.definetags :xxx
121
+ out = tpl.render nil, &b
122
+ assert_xml_equal('<foo><xxx a="b"><bar/></xxx></foo>', out)
123
+
124
+ out = Base.setopt :strict => false, :xhtml => false do
125
+ Base.render &b
126
+ end
127
+ assert_xml_equal('<foo/>', out)
128
+ end
129
+
130
+ def test_xhtml
131
+ Base.setopt :strict => true, :xhtml => true do
132
+ out = Base.render do
133
+ html do
134
+ body do
135
+ end
136
+ end
137
+ end
138
+
139
+ assert_xml_equal('<html><body></body></html>', out)
140
+
141
+ error = ''
142
+ begin
143
+ Base.render do
144
+ foo
145
+ end
146
+ rescue => e
147
+ error = e.message
148
+ end
149
+ assert(error =~ /undefined local variable or method/)
150
+ end
151
+ end
152
+
153
+ def test_file
154
+ Base.setopt :strict => true, :xhtml => true do
155
+ tpl = Base.new(View.new)
156
+ html = File.read(File.join(File.dirname(__FILE__), 'kernel.org.html'))
157
+ mn = tpl.render(File.read(File.join(File.dirname(__FILE__), 'kernel.org.mn')))
158
+ assert_xml_equal(html, mn)
159
+ end
160
+ end
161
+
162
+ def test_capture
163
+ Base.setopt :strict => false, :xhtml => false do
164
+ out = Base.render do
165
+ foo do
166
+ @captured = capture do
167
+ a { b 'Yo' }
168
+ end
169
+ x
170
+ end
171
+ bar { self << @captured }
172
+ txt! 'EOF'
173
+ end
174
+ assert_xml_equal('<foo><x/></foo><bar><a><b>Yo</b></a></bar>EOF', out)
175
+ end
176
+ end
177
+
178
+ def test_examples
179
+ Dir.glob(File.join(File.dirname(__FILE__), 'examples', '*.mn')).each do |file|
180
+ assert_xml_equal(File.read(file.sub(/\.mn$/, '.target')),
181
+ Base.new(View.new).render(File.read(file))+"\n", file)
182
+ end
183
+ end
184
+
185
+ def test_erbout
186
+ string = ""
187
+ erb = ErbOut.new string
188
+ erb.concat 'Foo'
189
+ erb << 'Bar'
190
+ assert_equal('FooBar', string)
191
+ end
192
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright © 2007,2008 Riku Palomäki
2
+ #
3
+ # This file is part of Malline.
4
+ #
5
+ # Malline is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # Malline is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with Malline. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "rexml/document"
19
+
20
+ module Kernel
21
+ def xxx *args
22
+ end
23
+ end
24
+
25
+ module MallineTestHelpers
26
+ include REXML
27
+ Image = Struct.new "Image", :id, :url, :caption
28
+ def assert_xml_equal a, b, c=""
29
+ if convert(Document.new(a)) != convert(Document.new(b))
30
+ assert_equal a, b, c
31
+ else
32
+ assert true
33
+ end
34
+ rescue
35
+ assert_equal a, b, c
36
+ end
37
+ def attributes element
38
+ element.attributes.keys.sort.collect {|k| " #{k}=\"#{element.attributes[k]}\""}.join
39
+ end
40
+ # quick hack to compare two html files
41
+ def convert e
42
+ output = ''
43
+ if e.is_a?(Array)
44
+ e.each {|el| output << convert(el) }
45
+ elsif e.respond_to?(:children) or e.is_a?(Element)
46
+ output << "<#{e.name}"
47
+ output << attributes(e) if e.respond_to?(:has_attributes?) and e.has_attributes?
48
+ output << ">"
49
+ e.children.each {|el| output << convert(el) } unless e.children.empty?
50
+ output << "</#{e.name}>"
51
+ else
52
+ output << e.to_s
53
+ end
54
+ output
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: malline
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.2
7
+ date: 2008-04-01 00:00:00 +03:00
8
+ summary: Malline is a full-featured pure Ruby template system designed to be a replacement for ERB views in Rails or any other framework. See http://www.malline.org/ for more info.
9
+ require_paths:
10
+ - lib
11
+ email: riku@palomaki.fi
12
+ homepage: http://www.malline.org/
13
+ rubyforge_project: malline
14
+ description: Malline is a full-featured template system designed to be a replacement for ERB views in Rails or any other framework. It also includes standalone bin/malline to compile Malline templates to XML in commandline. All Malline templates are pure Ruby, see http://www.malline.org/ for more info.
15
+ autorequire: malline
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - "Riku Palom\xC3\xA4ki"
31
+ files:
32
+ - lib/malline.rb
33
+ - lib/malline/erb_out.rb
34
+ - lib/malline/view_xhtml.rb
35
+ - lib/malline/form_builder.rb
36
+ - lib/malline/view_wrapper.rb
37
+ - lib/malline/template.rb
38
+ - lib/malline/view_proxy.rb
39
+ - lib/malline/rails.rb
40
+ - bin/malline
41
+ - COPYING.LESSER
42
+ - COPYING
43
+ - README
44
+ - scripts/html2mn.rb
45
+ - test/examples
46
+ - test/kernel.org.mn
47
+ - test/malline_test.rb
48
+ - test/malline_test_helpers.rb
49
+ - test/kernel.org.html
50
+ - test/examples/_partial.target
51
+ - test/examples/options.target
52
+ - test/examples/_two.mn
53
+ - test/examples/xhtml.target
54
+ - test/examples/hello_world.mn
55
+ - test/examples/lists.target
56
+ - test/examples/layout.mn
57
+ - test/examples/helper.mn
58
+ - test/examples/_one.mn
59
+ - test/examples/class.target
60
+ - test/examples/nested.mn
61
+ - test/examples/text.mn
62
+ - test/examples/frontpage.mn
63
+ - test/examples/helper_shortcut.target
64
+ - test/examples/_action.target
65
+ - test/examples/_partial.mn
66
+ - test/examples/options.mn
67
+ - test/examples/partials.target
68
+ - test/examples/xhtml.mn
69
+ - test/examples/lists.mn
70
+ - test/examples/fragment_cache.target
71
+ - test/examples/class.mn
72
+ - test/examples/self.target
73
+ - test/examples/id.target
74
+ - test/examples/whitespace.target
75
+ - test/examples/helper_shortcut.mn
76
+ - test/examples/_action.mn
77
+ - test/examples/escape.target
78
+ - test/examples/helper2.target
79
+ - test/examples/capture.target
80
+ - test/examples/partials.mn
81
+ - test/examples/_three.rhtml
82
+ - test/examples/_two.target
83
+ - test/examples/hello_world.target
84
+ - test/examples/fragment_cache.mn
85
+ - test/examples/layout.target
86
+ - test/examples/self.mn
87
+ - test/examples/helper.target
88
+ - test/examples/id.mn
89
+ - test/examples/_one.target
90
+ - test/examples/whitespace.mn
91
+ - test/examples/nested.target
92
+ - test/examples/escape.mn
93
+ - test/examples/text.target
94
+ - test/examples/helper2.mn
95
+ - test/examples/frontpage.target
96
+ - test/examples/capture.mn
97
+ test_files:
98
+ - test/malline_test.rb
99
+ rdoc_options: []
100
+
101
+ extra_rdoc_files:
102
+ - README
103
+ executables:
104
+ - malline
105
+ extensions: []
106
+
107
+ requirements: []
108
+
109
+ dependencies: []
110
+