radius 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,153 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class QuickstartTest < Test::Unit::TestCase
4
+
5
+ def test_hello_world
6
+ context = Radius::Context.new
7
+ context.define_tag "hello" do |tag|
8
+ "Hello #{tag.attr['name'] || 'World'}!"
9
+ end
10
+ parser = Radius::Parser.new(context)
11
+ assert_equal "<p>Hello World!</p>", parser.parse('<p><radius:hello /></p>')
12
+ assert_equal "<p>Hello John!</p>", parser.parse('<p><radius:hello name="John" /></p>')
13
+ end
14
+
15
+ def test_example_2
16
+ require 'redcloth'
17
+ context = Radius::Context.new
18
+ context.define_tag "textile" do |tag|
19
+ contents = tag.expand
20
+ RedCloth.new(contents).to_html
21
+ end
22
+ parser = Radius::Parser.new(context)
23
+ assert_equal "<h1>Hello <b>World</b>!</h1>", parser.parse('<radius:textile>h1. Hello **World**!</radius:textile>')
24
+ end
25
+
26
+ def test_nested_example
27
+ context = Radius::Context.new
28
+
29
+ context.define_tag "stooge" do |tag|
30
+ content = ''
31
+ ["Larry", "Moe", "Curly"].each do |name|
32
+ tag.locals.name = name
33
+ content << tag.expand
34
+ end
35
+ content
36
+ end
37
+
38
+ context.define_tag "stooge:name" do |tag|
39
+ tag.locals.name
40
+ end
41
+
42
+ parser = Radius::Parser.new(context)
43
+
44
+ template = <<-TEMPLATE
45
+ <ul>
46
+ <radius:stooge>
47
+ <li><radius:name /></li>
48
+ </radius:stooge>
49
+ </ul>
50
+ TEMPLATE
51
+
52
+ output = <<-OUTPUT
53
+ <ul>
54
+
55
+ <li>Larry</li>
56
+
57
+ <li>Moe</li>
58
+
59
+ <li>Curly</li>
60
+
61
+ </ul>
62
+ OUTPUT
63
+
64
+ assert_equal output, parser.parse(template)
65
+ end
66
+
67
+ class User
68
+ attr_accessor :name, :age, :email
69
+ end
70
+ def test_exposing_objects_example
71
+ context = Radius::Context.new
72
+ parser = Radius::Parser.new(context)
73
+
74
+ context.define_tag "count", :for => 1
75
+ assert_equal "1", parser.parse("<radius:count />")
76
+
77
+ user = User.new
78
+ user.name, user.age, user.email = "John", 29, "john@example.com"
79
+ context.define_tag "user", :for => user, :expose => [ :name, :age, :email ]
80
+ assert_equal "John", parser.parse("<radius:user><radius:name /></radius:user>")
81
+
82
+ assert_equal "John", parser.parse("<radius:user:name />")
83
+ end
84
+
85
+ class LazyContext < Radius::Context
86
+ def tag_missing(tag, attr, &block)
87
+ "<strong>ERROR: Undefined tag `#{tag}' with attributes #{attr.inspect}</strong>"
88
+ end
89
+ end
90
+ def test_tag_missing_example
91
+ parser = Radius::Parser.new(LazyContext.new, :tag_prefix => 'lazy')
92
+ output = %{<strong>ERROR: Undefined tag `weird' with attributes {"value"=>"true"}</strong>}
93
+ assert_equal output, parser.parse('<lazy:weird value="true" />')
94
+ end
95
+
96
+ def test_tag_globals_example
97
+ context = Radius::Context.new
98
+ parser = Radius::Parser.new(context)
99
+
100
+ context.define_tag "inc" do |tag|
101
+ tag.globals.count ||= 0
102
+ tag.globals.count += 1
103
+ ""
104
+ end
105
+
106
+ context.define_tag "count" do |tag|
107
+ tag.globals.count || 0
108
+ end
109
+
110
+ assert_equal "0 1", parser.parse("<radius:count /> <radius:inc /><radius:count />")
111
+ end
112
+
113
+ class Person
114
+ attr_accessor :name, :friend
115
+ def initialize(name)
116
+ @name = name
117
+ end
118
+ end
119
+ def test_tag_locals_and_globals_example
120
+ jack = Person.new('Jack')
121
+ jill = Person.new('Jill')
122
+ jack.friend = jill
123
+ jill.friend = jack
124
+
125
+ context = Radius::Context.new do |c|
126
+ c.define_tag "jack" do |tag|
127
+ tag.locals.person = jack
128
+ tag.expand
129
+ end
130
+ c.define_tag "jill" do |tag|
131
+ tag.locals.person = jill
132
+ tag.expand
133
+ end
134
+ c.define_tag "name" do |tag|
135
+ tag.locals.person.name rescue tag.missing!
136
+ end
137
+ c.define_tag "friend" do |tag|
138
+ tag.locals.person = tag.locals.person.friend rescue tag.missing!
139
+ tag.expand
140
+ end
141
+ end
142
+
143
+ parser = Radius::Parser.new(context, :tag_prefix => 'r')
144
+
145
+ assert_equal "Jack", parser.parse('<r:jack:name />') #=> "Jack"
146
+ assert_equal "Jill", parser.parse('<r:jill:name />') #=> "Jill"
147
+ assert_equal "Jack", parser.parse('<r:jill:friend:name />') #=> "Jack"
148
+ assert_equal "Jack", parser.parse('<r:jack:friend:friend:name />') #=> "Jack"
149
+ assert_equal "Jack and Jill", parser.parse('<r:jill><r:friend:name /> and <r:name /></r:jill>') #=> "Jack and Jill"
150
+ assert_raises(Radius::UndefinedTagError) { parser.parse('<r:name />') } # raises a Radius::UndefinedTagError exception
151
+ end
152
+
153
+ end
@@ -0,0 +1,28 @@
1
+ require 'timeout'
2
+
3
+ unless defined? RADIUS_LIB
4
+
5
+ RADIUS_LIB = File.join(File.dirname(__FILE__), '..', 'lib')
6
+ $LOAD_PATH << RADIUS_LIB
7
+
8
+ require 'radius'
9
+ require 'test/unit'
10
+
11
+ module RadiusTestHelper
12
+ class TestContext < Radius::Context; end
13
+
14
+ def new_context
15
+ Radius::Context.new do |c|
16
+ c.define_tag("reverse" ) { |tag| tag.expand.reverse }
17
+ c.define_tag("capitalize") { |tag| tag.expand.upcase }
18
+ c.define_tag("attr" ) { |tag| tag.attr.inspect }
19
+ c.define_tag("echo" ) { |tag| tag.attr['value'] }
20
+ c.define_tag("wrap" ) { |tag| "[#{tag.expand}]" }
21
+ end
22
+ end
23
+
24
+ def define_tag(name, options = {}, &block)
25
+ @context.define_tag name, options, &block
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,75 +1,123 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
3
- specification_version: 1
4
2
  name: radius
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2006-06-20 00:00:00 -04:00
8
- summary: Powerful tag-based template system.
9
- require_paths:
10
- - lib
11
- email:
12
- homepage: http://radius.rubyforge.org
13
- rubyforge_project: radius
14
- description: Radius is a small, but powerful tag-based template language for Ruby similar to the ones used in MovableType and TextPattern. It has tags similar to HTML or XML, but can be used to generate any form of plain text (not just HTML).
15
- autorequire: radius
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.6.1
25
5
  platform: ruby
26
- signing_key:
6
+ authors:
7
+ - John W. Long (me@johnwlong.com)
8
+ - David Chelimsky (dchelimsky@gmail.com)
9
+ - Bryce Kerley (bkerley@brycekerley.net)
10
+ autorequire:
11
+ bindir: bin
27
12
  cert_chain:
28
- authors: []
13
+ - |
14
+ -----BEGIN CERTIFICATE-----
15
+ MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQswCQYDVQQDDAJtZTEZ
16
+ MBcGCgmSJomT8ixkARkWCWpvaG53bG9uZzETMBEGCgmSJomT8ixkARkWA2NvbTAe
17
+ Fw0wNzA5MjUwNTA3MDNaFw0wODA5MjQwNTA3MDNaMD0xCzAJBgNVBAMMAm1lMRkw
18
+ FwYKCZImiZPyLGQBGRYJam9obndsb25nMRMwEQYKCZImiZPyLGQBGRYDY29tMIIB
19
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8MjmSgpGWiy+PyyumoFLnA/w
20
+ gOymrqEIoHwlNRV8Z2RcZkrUHuKnFcH8ShqRww+/1BBnDJlx2rGrQ8d2W75f+xKj
21
+ hxVwA+eFbLtpMMe1E0qfD69F2sQk5/+dB7WwtF4kI0vt/rHne4hYj7dN/OeJ248q
22
+ dfZbxohWzSlPg0zopxlQ7WuFjZKclkUNx9Euv7K04imu4i7Q5ThCldV3VVrBFqCq
23
+ VhI8lAeg7Yln1t6SaPLQ3AqQlq2hk8MA7APy4LdWaN03cunfKwkHVVwPaSD8ualr
24
+ wrBQsmIrc4f3h9hJq0Ri1u/k4B2CTxaRLA34mb7MrpwZo5RqFd3x512MJaqfhQID
25
+ AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU2eSXhP+B
26
+ 7zF3qc5Rrb75aLF7BXowDQYJKoZIhvcNAQEFBQADggEBAFdj2/TsGJSaeFXoMixS
27
+ ojVHMctKErQkA2pRM7URVyeLljJweAies3qlfpPSuUTcWFLpJf7+So1CNrU7OzXa
28
+ UNAIhlWzz+knSeMahQWyMQvNGW3nt07PEkaosVdsi/Y6hO+YKNiZicBFuKw7fFUl
29
+ 1FQHJMmy4+bTXxWl6RUymFiDhIjagLHbr09igGHaIOptys1k7Fxpx3xBDNr/IC0H
30
+ c5GbUePwwNafnjsl9cQo3Xka285/d0IOT4grVUmAeLAh601oR/YGtsHDC7B0jWqq
31
+ S4yE0yydTjVFpgazHI/CP2fneTHKbaf+H6jwNRzKN9HtcDpP2yO0tYhtmMotuZUd
32
+ qXI=
33
+ -----END CERTIFICATE-----
34
+
35
+ date: 2009-09-16 00:00:00 -04:00
36
+ default_executable:
37
+ dependencies:
38
+ - !ruby/object:Gem::Dependency
39
+ name: newgem
40
+ type: :development
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.2
47
+ version:
48
+ - !ruby/object:Gem::Dependency
49
+ name: hoe
50
+ type: :development
51
+ version_requirement:
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.3.3
57
+ version:
58
+ description: ""
59
+ email:
60
+ - me@johnwlong.com
61
+ executables: []
29
62
 
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - Manifest.txt
67
+ - README.rdoc
68
+ - QUICKSTART.rdoc
30
69
  files:
31
70
  - CHANGELOG
32
- - lib
33
- - pkg
34
- - QUICKSTART
71
+ - Manifest.txt
72
+ - QUICKSTART.rdoc
73
+ - README.rdoc
35
74
  - Rakefile
36
- - README
37
- - ROADMAP
38
- - test
39
75
  - lib/radius.rb
40
- - pkg/radius-0.5.0
41
- - pkg/radius-0.5.0.gem
42
- - pkg/radius-0.5.0.tgz
43
- - pkg/radius-0.5.0.zip
44
- - pkg/radius-0.5.0/CHANGELOG
45
- - pkg/radius-0.5.0/lib
46
- - pkg/radius-0.5.0/pkg
47
- - pkg/radius-0.5.0/QUICKSTART
48
- - pkg/radius-0.5.0/Rakefile
49
- - pkg/radius-0.5.0/README
50
- - pkg/radius-0.5.0/ROADMAP
51
- - pkg/radius-0.5.0/test
52
- - pkg/radius-0.5.0/lib/radius.rb
53
- - pkg/radius-0.5.0/test/radius_test.rb
54
- - test/radius_test.rb
55
- test_files: []
76
+ - lib/radius/context.rb
77
+ - lib/radius/delegating_open_struct.rb
78
+ - lib/radius/error.rb
79
+ - lib/radius/parse_tag.rb
80
+ - lib/radius/parser.rb
81
+ - lib/radius/parser/scan.rb
82
+ - lib/radius/parser/scan.rl
83
+ - lib/radius/tag_binding.rb
84
+ - lib/radius/tag_definitions.rb
85
+ - lib/radius/utility.rb
86
+ - lib/radius/version.rb
87
+ - tasks/scan.rake
88
+ - test/context_test.rb
89
+ - test/parser_test.rb
90
+ - test/test_helper.rb
91
+ has_rdoc: true
92
+ homepage: http://radius.rubyforge.org
93
+ licenses: []
56
94
 
95
+ post_install_message:
57
96
  rdoc_options:
58
- - --title
59
- - Radius -- Powerful Tag-Based Templates
60
- - --line-numbers
61
97
  - --main
62
- - README
63
- extra_rdoc_files:
64
- - README
65
- - QUICKSTART
66
- - ROADMAP
67
- - CHANGELOG
68
- executables: []
69
-
70
- extensions: []
71
-
72
- requirements:
73
- - none
74
- dependencies: []
98
+ - README.rdoc
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
75
114
 
115
+ rubyforge_project: radius
116
+ rubygems_version: 1.3.4
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: ""
120
+ test_files:
121
+ - test/context_test.rb
122
+ - test/parser_test.rb
123
+ - test/quickstart_test.rb
Binary file
data/README DELETED
@@ -1,97 +0,0 @@
1
- = Radius -- Powerful Tag-Based Templates
2
-
3
- Radius is a powerful tag-based template language for Ruby inspired by the template languages
4
- used in MovableType[http://www.movabletype.org] and TextPattern[http://www.textpattern.com].
5
- It uses tags similar to XML, but can be used to generate any form of plain text (HTML, e-mail,
6
- etc...).
7
-
8
- == Example
9
-
10
- With Radius, it is extremely easy to create custom tags and parse them. Here's a small
11
- example:
12
-
13
- require 'radius'
14
-
15
- # Define tags on a context that will be available to a template:
16
- context = Radius::Context.new do |c|
17
- c.define_tag 'hello' do
18
- 'Hello world'
19
- end
20
- c.define_tag 'repeat' do |tag|
21
- number = (tag.attr['times'] || '1').to_i
22
- result = ''
23
- number.times { result << tag.expand }
24
- result
25
- end
26
- end
27
-
28
- # Create a parser to parse tags that begin with 'r:'
29
- parser = Radius::Parser.new(context, :tag_prefix => 'r')
30
-
31
- # Parse tags and output the result
32
- puts parser.parse(%{A small example:\n<r:repeat times="3">* <r:hello />!\n</r:repeat>})
33
-
34
- Output:
35
-
36
- A small example:
37
- * Hello world!
38
- * Hello world!
39
- * Hello world!
40
-
41
-
42
- = Quick Start
43
-
44
- Read the QUICKSTART[link:files/QUICKSTART.html] to get up and running fast with Radius.
45
-
46
-
47
- == Download
48
-
49
- The latest version of Radius can be found on RubyForge:
50
-
51
- http://rubyforge.org/projects/radius/
52
-
53
-
54
- == Installation
55
-
56
- It is recommended that you install Radius using the RubyGems packaging system:
57
-
58
- % gem install --remote radius
59
-
60
- You can also install Radius by copying lib/radius.rb into the Ruby load path.
61
-
62
-
63
- == License
64
-
65
- Radius is free software and may be redistributed under the terms of the MIT-LICENSE:
66
-
67
- Copyright (c) 2006, John W. Long
68
-
69
- Permission is hereby granted, free of charge, to any person obtaining a copy of this
70
- software and associated documentation files (the "Software"), to deal in the Software
71
- without restriction, including without limitation the rights to use, copy, modify, merge,
72
- publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
73
- to whom the Software is furnished to do so, subject to the following conditions:
74
-
75
- The above copyright notice and this permission notice shall be included in all copies or
76
- substantial portions of the Software.
77
-
78
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
79
- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
80
- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
81
- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
82
- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
83
- DEALINGS IN THE SOFTWARE.
84
-
85
-
86
- == The Future
87
-
88
- Radius is nearing completion, but is still very much in the development stages. Take a look
89
- at the ROADMAP[link:files/ROADMAP.html] to see where we want to go.
90
-
91
- If you are interested in helping with the development of Radiant, contact me and we'll talk.
92
-
93
- Enjoy!
94
-
95
- --
96
- John Long ::
97
- http://wiseheartdesign.com