isaac-malline 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/History.txt +34 -0
- data/Manifest.txt +72 -0
- data/README +24 -0
- data/README.txt +33 -0
- data/Rakefile +74 -0
- data/bin/malline +20 -0
- data/github.rb +6 -0
- data/init.rb +2 -0
- data/lib/malline.rb +109 -0
- data/lib/malline/adapters/rails-2.0.rb +72 -0
- data/lib/malline/adapters/rails-2.1.rb +103 -0
- data/lib/malline/erb_out.rb +34 -0
- data/lib/malline/form_builder.rb +44 -0
- data/lib/malline/plugin.rb +34 -0
- data/lib/malline/plugins/xhtml.rb +77 -0
- data/lib/malline/rails.rb +46 -0
- data/lib/malline/template.rb +185 -0
- data/lib/malline/view_proxy.rb +87 -0
- data/lib/malline/view_wrapper.rb +95 -0
- data/malline.gemspec +34 -0
- data/scripts/html2mn.rb +93 -0
- data/test/examples/_action.mn +4 -0
- data/test/examples/_action.target +1 -0
- data/test/examples/_one.mn +1 -0
- data/test/examples/_one.target +1 -0
- data/test/examples/_partial.mn +2 -0
- data/test/examples/_partial.target +1 -0
- data/test/examples/_three.rhtml +2 -0
- data/test/examples/_two.mn +1 -0
- data/test/examples/_two.target +1 -0
- data/test/examples/capture.mn +13 -0
- data/test/examples/capture.target +1 -0
- data/test/examples/class.mn +6 -0
- data/test/examples/class.target +1 -0
- data/test/examples/escape.mn +4 -0
- data/test/examples/escape.target +1 -0
- data/test/examples/frontpage.mn +6 -0
- data/test/examples/frontpage.target +1 -0
- data/test/examples/hello_world.mn +2 -0
- data/test/examples/hello_world.target +1 -0
- data/test/examples/helper.mn +5 -0
- data/test/examples/helper.target +1 -0
- data/test/examples/helper2.mn +5 -0
- data/test/examples/helper2.target +1 -0
- data/test/examples/helper_shortcut.mn +5 -0
- data/test/examples/helper_shortcut.target +1 -0
- data/test/examples/id.mn +3 -0
- data/test/examples/id.target +1 -0
- data/test/examples/layout.mn +8 -0
- data/test/examples/layout.target +4 -0
- data/test/examples/lists.mn +13 -0
- data/test/examples/lists.target +1 -0
- data/test/examples/nested.mn +6 -0
- data/test/examples/nested.target +1 -0
- data/test/examples/options.mn +10 -0
- data/test/examples/options.target +1 -0
- data/test/examples/partials.mn +5 -0
- data/test/examples/partials.target +1 -0
- data/test/examples/self.mn +2 -0
- data/test/examples/self.target +1 -0
- data/test/examples/text.mn +4 -0
- data/test/examples/text.target +1 -0
- data/test/examples/whitespace.mn +9 -0
- data/test/examples/whitespace.target +1 -0
- data/test/examples/xhtml.mn +11 -0
- data/test/examples/xhtml.target +4 -0
- data/test/kernel.org.html +107 -0
- data/test/kernel.org.mn +657 -0
- data/test/malline_test.rb +171 -0
- data/test/malline_test_helpers.rb +82 -0
- metadata +136 -0
@@ -0,0 +1,171 @@
|
|
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
|
+
|
23
|
+
class MallineTest < Test::Unit::TestCase
|
24
|
+
include Malline
|
25
|
+
include MallineTestHelpers
|
26
|
+
|
27
|
+
def test_simple
|
28
|
+
Base.setopt :strict => false, :xhtml => false do
|
29
|
+
assert_xml_equal('<foo id="a"><bar class="a b"/>blabla</foo>',
|
30
|
+
Base.render do
|
31
|
+
foo.a! do
|
32
|
+
bar.a.b
|
33
|
+
_'blabla'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_basics
|
41
|
+
images = [Image.new(1, '/image/img1', 'Image 1'), Image.new(2, '/2', 'Image 2')]
|
42
|
+
|
43
|
+
out = Base.new(View.new).render nil, :images => images do
|
44
|
+
html do
|
45
|
+
body do
|
46
|
+
div.header!
|
47
|
+
div.imagelist.images! "There are some images:" do
|
48
|
+
@images.each do |im|
|
49
|
+
a(:href => image_path(im)) { img :src => im.url }
|
50
|
+
span.caption.imagetext im.caption
|
51
|
+
end
|
52
|
+
txt! "No more images"
|
53
|
+
end
|
54
|
+
div.footer! { span 'footer' }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
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)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_tag!
|
62
|
+
Base.setopt :strict => false, :xhtml => false do
|
63
|
+
out = Base.render do
|
64
|
+
foo do
|
65
|
+
tag!('foobar', :foobar => 'foobar') do
|
66
|
+
tag!('foobar2', :foobar => 'foobar2') do
|
67
|
+
bar do
|
68
|
+
foo
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
assert_xml_equal('<foo><foobar foobar="foobar"><foobar2 foobar="foobar2"><bar><foo/></bar></foobar2></foobar></foo>', out)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_defined_tags
|
79
|
+
tpl = Base.setopt :strict => false, :xhtml => false do
|
80
|
+
Base.new(View.new)
|
81
|
+
end
|
82
|
+
b = Proc.new do
|
83
|
+
foo do
|
84
|
+
zoo :a => 'b' do
|
85
|
+
bar
|
86
|
+
end
|
87
|
+
_zoo
|
88
|
+
xoo.bar
|
89
|
+
end
|
90
|
+
end
|
91
|
+
out = tpl.render nil, &b
|
92
|
+
# zoo isn't rendered, because there is helper named zoo
|
93
|
+
assert_xml_equal('<foo>zoo output<xoo class="bar"/></foo>', out)
|
94
|
+
|
95
|
+
tpl.definetags :zoo
|
96
|
+
out = tpl.render nil, &b
|
97
|
+
assert_xml_equal('<foo>zoo output<xoo class="bar"/></foo>', out)
|
98
|
+
|
99
|
+
tpl.definetags! :zoo
|
100
|
+
out = tpl.render nil, &b
|
101
|
+
assert_xml_equal('<foo><zoo a="b"><bar/></zoo>zoo output<xoo class="bar"/></foo>', out)
|
102
|
+
|
103
|
+
out = Base.setopt :strict => false, :xhtml => false do
|
104
|
+
Base.render &b
|
105
|
+
end
|
106
|
+
assert_xml_equal('<foo><zoo a="b"><bar/></zoo><_zoo/><xoo class="bar"/></foo>', out)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_xhtml
|
110
|
+
Base.setopt :strict => true, :xhtml => true do
|
111
|
+
out = Base.render do
|
112
|
+
html do
|
113
|
+
body do
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_xml_equal('<html><body></body></html>', out)
|
119
|
+
|
120
|
+
error = ''
|
121
|
+
begin
|
122
|
+
Base.render do
|
123
|
+
foo
|
124
|
+
end
|
125
|
+
rescue => e
|
126
|
+
error = e.message
|
127
|
+
end
|
128
|
+
assert(error =~ /undefined local variable or method/)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_file
|
133
|
+
Base.setopt :strict => true, :xhtml => true do
|
134
|
+
tpl = Base.new(View.new)
|
135
|
+
html = File.read(File.join(File.dirname(__FILE__), 'kernel.org.html'))
|
136
|
+
mn = tpl.render(File.read(File.join(File.dirname(__FILE__), 'kernel.org.mn')))
|
137
|
+
assert_xml_equal(html, mn)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_capture
|
142
|
+
Base.setopt :strict => false, :xhtml => false do
|
143
|
+
out = Base.render do
|
144
|
+
foo do
|
145
|
+
@captured = capture do
|
146
|
+
a { b 'Yo' }
|
147
|
+
end
|
148
|
+
x
|
149
|
+
end
|
150
|
+
bar { self << @captured }
|
151
|
+
txt! 'EOF'
|
152
|
+
end
|
153
|
+
assert_xml_equal('<foo><x/></foo><bar><a><b>Yo</b></a></bar>EOF', out)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_examples
|
158
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'examples', '*.mn')).each do |file|
|
159
|
+
assert_xml_equal(File.read(file.sub(/\.mn$/, '.target')),
|
160
|
+
Base.new(View.new).render(File.read(file))+"\n", file)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_erbout
|
165
|
+
string = ""
|
166
|
+
erb = ErbOut.new string
|
167
|
+
erb.concat 'Foo'
|
168
|
+
erb << 'Bar'
|
169
|
+
assert_equal('FooBar', string)
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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
|
+
require 'malline.rb'
|
20
|
+
|
21
|
+
module MallineTestHelpers
|
22
|
+
include REXML
|
23
|
+
Image = Struct.new "Image", :id, :url, :caption
|
24
|
+
def assert_xml_equal a, b, c=""
|
25
|
+
if convert(Document.new(a)) != convert(Document.new(b))
|
26
|
+
assert_equal a, b, c
|
27
|
+
else
|
28
|
+
assert true
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
assert_equal a, b, c
|
32
|
+
end
|
33
|
+
def attributes element
|
34
|
+
element.attributes.keys.sort.collect {|k| " #{k}=\"#{element.attributes[k]}\""}.join
|
35
|
+
end
|
36
|
+
# quick hack to compare two html files
|
37
|
+
def convert e
|
38
|
+
output = ''
|
39
|
+
if e.is_a?(Array)
|
40
|
+
e.each {|el| output << convert(el) }
|
41
|
+
elsif e.respond_to?(:children) or e.is_a?(Element)
|
42
|
+
output << "<#{e.name}"
|
43
|
+
output << attributes(e) if e.respond_to?(:has_attributes?) and e.has_attributes?
|
44
|
+
output << ">"
|
45
|
+
e.children.each {|el| output << convert(el) } unless e.children.empty?
|
46
|
+
output << "</#{e.name}>"
|
47
|
+
else
|
48
|
+
output << e.to_s
|
49
|
+
end
|
50
|
+
output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Controller
|
55
|
+
def perform_caching
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Comment
|
61
|
+
end
|
62
|
+
|
63
|
+
class View
|
64
|
+
def initialize
|
65
|
+
@controller = Controller.new
|
66
|
+
end
|
67
|
+
def image_path(im)
|
68
|
+
"/images/#{im.is_a?(MallineTestHelpers::Image) ? im.id : 'img'}"
|
69
|
+
end
|
70
|
+
def truncate(str, size = 10)
|
71
|
+
str[0...size]
|
72
|
+
end
|
73
|
+
def render hash
|
74
|
+
Malline::Base.new(View.new).render File.read(File.join(File.dirname(__FILE__), hash[:partial].sub(/\//, '/_') + '.mn')) rescue ''
|
75
|
+
end
|
76
|
+
def link_to *args
|
77
|
+
'link'
|
78
|
+
end
|
79
|
+
def zoo *args
|
80
|
+
'zoo output'
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isaac-malline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Riku Palom\xC3\xA4ki"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-06 00:00:00 -07:00
|
13
|
+
default_executable: malline
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.3
|
23
|
+
version:
|
24
|
+
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. See documentation on http://www.malline.org/ Copyright \xC2\xA9 2007,2008 Riku Palom\xC3\xA4ki, riku@palomaki.fi Malline is released under GNU Lesser General Public License. Example Rails template file images.html.mn: xhtml do _render :partial => 'head' body do div.images! \"There are some images:\" do images.each do |im| a(:href => img_path(im)) { img :src => im.url } span.caption im.caption end _\"No more images\" end div.footer! { _render :partial => 'footer' } end end"
|
25
|
+
email:
|
26
|
+
- riku@palomaki.fi
|
27
|
+
executables:
|
28
|
+
- malline
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
files:
|
36
|
+
- COPYING
|
37
|
+
- COPYING.LESSER
|
38
|
+
- History.txt
|
39
|
+
- Manifest.txt
|
40
|
+
- README
|
41
|
+
- README.txt
|
42
|
+
- Rakefile
|
43
|
+
- bin/malline
|
44
|
+
- github.rb
|
45
|
+
- init.rb
|
46
|
+
- lib/malline.rb
|
47
|
+
- lib/malline/adapters/rails-2.0.rb
|
48
|
+
- lib/malline/adapters/rails-2.1.rb
|
49
|
+
- lib/malline/erb_out.rb
|
50
|
+
- lib/malline/form_builder.rb
|
51
|
+
- lib/malline/plugin.rb
|
52
|
+
- lib/malline/plugins/xhtml.rb
|
53
|
+
- lib/malline/rails.rb
|
54
|
+
- lib/malline/template.rb
|
55
|
+
- lib/malline/view_proxy.rb
|
56
|
+
- lib/malline/view_wrapper.rb
|
57
|
+
- malline.gemspec
|
58
|
+
- scripts/html2mn.rb
|
59
|
+
- test/examples/_action.mn
|
60
|
+
- test/examples/_action.target
|
61
|
+
- test/examples/_one.mn
|
62
|
+
- test/examples/_one.target
|
63
|
+
- test/examples/_partial.mn
|
64
|
+
- test/examples/_partial.target
|
65
|
+
- test/examples/_three.rhtml
|
66
|
+
- test/examples/_two.mn
|
67
|
+
- test/examples/_two.target
|
68
|
+
- test/examples/capture.mn
|
69
|
+
- test/examples/capture.target
|
70
|
+
- test/examples/class.mn
|
71
|
+
- test/examples/class.target
|
72
|
+
- test/examples/escape.mn
|
73
|
+
- test/examples/escape.target
|
74
|
+
- test/examples/frontpage.mn
|
75
|
+
- test/examples/frontpage.target
|
76
|
+
- test/examples/hello_world.mn
|
77
|
+
- test/examples/hello_world.target
|
78
|
+
- test/examples/helper.mn
|
79
|
+
- test/examples/helper.target
|
80
|
+
- test/examples/helper2.mn
|
81
|
+
- test/examples/helper2.target
|
82
|
+
- test/examples/helper_shortcut.mn
|
83
|
+
- test/examples/helper_shortcut.target
|
84
|
+
- test/examples/id.mn
|
85
|
+
- test/examples/id.target
|
86
|
+
- test/examples/layout.mn
|
87
|
+
- test/examples/layout.target
|
88
|
+
- test/examples/lists.mn
|
89
|
+
- test/examples/lists.target
|
90
|
+
- test/examples/nested.mn
|
91
|
+
- test/examples/nested.target
|
92
|
+
- test/examples/options.mn
|
93
|
+
- test/examples/options.target
|
94
|
+
- test/examples/partials.mn
|
95
|
+
- test/examples/partials.target
|
96
|
+
- test/examples/self.mn
|
97
|
+
- test/examples/self.target
|
98
|
+
- test/examples/text.mn
|
99
|
+
- test/examples/text.target
|
100
|
+
- test/examples/whitespace.mn
|
101
|
+
- test/examples/whitespace.target
|
102
|
+
- test/examples/xhtml.mn
|
103
|
+
- test/examples/xhtml.target
|
104
|
+
- test/kernel.org.html
|
105
|
+
- test/kernel.org.mn
|
106
|
+
- test/malline_test.rb
|
107
|
+
- test/malline_test_helpers.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://www.malline.org/
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options:
|
112
|
+
- --main
|
113
|
+
- README.txt
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: "0"
|
121
|
+
version:
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: "0"
|
127
|
+
version:
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project: malline
|
131
|
+
rubygems_version: 1.2.0
|
132
|
+
signing_key:
|
133
|
+
specification_version: 2
|
134
|
+
summary: Malline is a full-featured template system designed to be a replacement for ERB views in Rails or any other framework
|
135
|
+
test_files: []
|
136
|
+
|