radius-ts 1.0.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.
@@ -0,0 +1,151 @@
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
+ parser = Radius::Parser.new
72
+
73
+ parser.context.define_tag "count", :for => 1
74
+ assert_equal "1", parser.parse("<radius:count />")
75
+
76
+ user = User.new
77
+ user.name, user.age, user.email = "John", 29, "john@example.com"
78
+ parser.context.define_tag "user", :for => user, :expose => [ :name, :age, :email ]
79
+ assert_equal "John", parser.parse("<radius:user><radius:name /></radius:user>")
80
+
81
+ assert_equal "John", parser.parse("<radius:user:name />")
82
+ end
83
+
84
+ class LazyContext < Radius::Context
85
+ def tag_missing(tag, attr, &block)
86
+ "<strong>ERROR: Undefined tag `#{tag}' with attributes #{attr.inspect}</strong>"
87
+ end
88
+ end
89
+ def test_tag_missing_example
90
+ parser = Radius::Parser.new(LazyContext.new, :tag_prefix => 'lazy')
91
+ output = %{<strong>ERROR: Undefined tag `weird' with attributes {"value"=>"true"}</strong>}
92
+ assert_equal output, parser.parse('<lazy:weird value="true" />')
93
+ end
94
+
95
+ def test_tag_globals_example
96
+ parser = Radius::Parser.new
97
+
98
+ parser.context.define_tag "inc" do |tag|
99
+ tag.globals.count ||= 0
100
+ tag.globals.count += 1
101
+ ""
102
+ end
103
+
104
+ parser.context.define_tag "count" do |tag|
105
+ tag.globals.count || 0
106
+ end
107
+
108
+ assert_equal "0 1", parser.parse("<radius:count /> <radius:inc /><radius:count />")
109
+ end
110
+
111
+ class Person
112
+ attr_accessor :name, :friend
113
+ def initialize(name)
114
+ @name = name
115
+ end
116
+ end
117
+ def test_tag_locals_and_globals_example
118
+ jack = Person.new('Jack')
119
+ jill = Person.new('Jill')
120
+ jack.friend = jill
121
+ jill.friend = jack
122
+
123
+ context = Radius::Context.new do |c|
124
+ c.define_tag "jack" do |tag|
125
+ tag.locals.person = jack
126
+ tag.expand
127
+ end
128
+ c.define_tag "jill" do |tag|
129
+ tag.locals.person = jill
130
+ tag.expand
131
+ end
132
+ c.define_tag "name" do |tag|
133
+ tag.locals.person.name rescue tag.missing!
134
+ end
135
+ c.define_tag "friend" do |tag|
136
+ tag.locals.person = tag.locals.person.friend rescue tag.missing!
137
+ tag.expand
138
+ end
139
+ end
140
+
141
+ parser = Radius::Parser.new(context, :tag_prefix => 'r')
142
+
143
+ assert_equal "Jack", parser.parse('<r:jack:name />') #=> "Jack"
144
+ assert_equal "Jill", parser.parse('<r:jill:name />') #=> "Jill"
145
+ assert_equal "Jack", parser.parse('<r:jill:friend:name />') #=> "Jack"
146
+ assert_equal "Jack", parser.parse('<r:jack:friend:friend:name />') #=> "Jack"
147
+ assert_equal "Jack and Jill", parser.parse('<r:jill><r:friend:name /> and <r:name /></r:jill>') #=> "Jack and Jill"
148
+ assert_raises(Radius::UndefinedTagError) { parser.parse('<r:name />') } # raises a Radius::UndefinedTagError exception
149
+ end
150
+
151
+ end
@@ -0,0 +1,32 @@
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
+ @parser.context.define_tag name, options, &block
26
+ end
27
+
28
+ def define_global_tag(name, options = {}, &block)
29
+ @context.define_tag name, options, &block
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radius-ts
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John W. Long (me@johnwlong.com)
8
+ - David Chelimsky (dchelimsky@gmail.com)
9
+ - Bryce Kerley (bkerley@brycekerley.net)
10
+ - Todd Willey (todd@rubidine.com)
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2010-02-06 00:00:00 -05:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: newgem
20
+ type: :development
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.2
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: hoe
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.3.3
37
+ version:
38
+ description: A templating lanuage based on MovableType and TextPattern. Originally implemented by John Long.
39
+ email:
40
+ - todd@rubidine.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - Manifest.txt
47
+ - README.rdoc
48
+ - QUICKSTART.rdoc
49
+ files:
50
+ - CHANGELOG
51
+ - Manifest.txt
52
+ - QUICKSTART.rdoc
53
+ - README.rdoc
54
+ - Rakefile
55
+ - lib/radius.rb
56
+ - lib/radius/context.rb
57
+ - lib/radius/delegating_open_struct.rb
58
+ - lib/radius/error.rb
59
+ - lib/radius/parse_tag.rb
60
+ - lib/radius/parser.rb
61
+ - lib/radius/parser/scan.rb
62
+ - lib/radius/parser/scan.rl
63
+ - lib/radius/tag_binding.rb
64
+ - lib/radius/tag_definitions.rb
65
+ - lib/radius/utility.rb
66
+ - lib/radius/version.rb
67
+ - tasks/scan.rake
68
+ - test/context_test.rb
69
+ - test/parser_test.rb
70
+ - test/test_helper.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/xtoddx/radius-ts
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --main
78
+ - README.rdoc
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ requirements: []
94
+
95
+ rubyforge_project: radius-ts
96
+ rubygems_version: 1.3.5
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Radius templating language with thread safety patches.
100
+ test_files:
101
+ - test/context_test.rb
102
+ - test/multithreaded_test.rb
103
+ - test/parser_test.rb
104
+ - test/quickstart_test.rb