radius 0.0.2 → 0.5.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/CHANGELOG +12 -0
- data/QUICKSTART +232 -45
- data/README +61 -15
- data/ROADMAP +4 -10
- data/Rakefile +50 -8
- data/lib/radius.rb +415 -75
- data/test/radius_test.rb +263 -113
- metadata +3 -4
- data/DSL-SPEC +0 -151
data/DSL-SPEC
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
=DSL Specification
|
2
|
-
|
3
|
-
I haven't implemented a domain specific languages for Contexts yet, but I am hoping to
|
4
|
-
do so in a future release. Below are some thoughts (in code) for how I would like it to
|
5
|
-
work. Note that with a robust DSL you will be able to define that certain tags are
|
6
|
-
only valid within certain containing tags.
|
7
|
-
|
8
|
-
class StoreContext < Radius::Context
|
9
|
-
def initialize(options)
|
10
|
-
@prefix = "r" # all tags must be prefixed with "r"
|
11
|
-
@user = options[:user]
|
12
|
-
@cart = options[:cart]
|
13
|
-
@session = options[:session]
|
14
|
-
end
|
15
|
-
|
16
|
-
# expose the @user object variable
|
17
|
-
container(:user, :exposes => :user) do
|
18
|
-
# Use protect() on an object that has been exposed to prevent access to
|
19
|
-
# an attribute in a template. Conversely you could use the expose() method
|
20
|
-
# to expose specific attributes to the template and protect all others.
|
21
|
-
protect :password
|
22
|
-
|
23
|
-
# add a single tag that returns the session_id
|
24
|
-
tag :session_id do |attributes|
|
25
|
-
@session.id
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# expose the @cart object as the basket tag
|
30
|
-
container(:basket, :exposes => :cart) do
|
31
|
-
expand do |attributes|
|
32
|
-
#
|
33
|
-
# some initialization code with attributes before handling
|
34
|
-
# content block
|
35
|
-
#
|
36
|
-
yeild
|
37
|
-
end
|
38
|
-
|
39
|
-
container(:items, :exposes => :item) do
|
40
|
-
expand do |attributes|
|
41
|
-
@cart.items.each do |@item|
|
42
|
-
yield
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
container :cart do
|
49
|
-
expand do |attributes|
|
50
|
-
yield
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class User
|
56
|
-
attr_accessor :name, :login, :password, :email
|
57
|
-
def initialize(name, login, password, email)
|
58
|
-
@name, @login, @password, @email = name, login, password, email
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Session
|
63
|
-
attr_accessor :id
|
64
|
-
def initialize(id)
|
65
|
-
@id = id
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class Cart
|
70
|
-
attr_accessor :items
|
71
|
-
|
72
|
-
def initialize(*items)
|
73
|
-
@items = [items].flatten
|
74
|
-
end
|
75
|
-
|
76
|
-
def total
|
77
|
-
@items.map { |line_item| line_item.total }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class LineItem
|
82
|
-
attr_accessor :name, :description, :quantity, :item_price
|
83
|
-
def intialize(name, description, price, quantity)
|
84
|
-
@name, @description, @price, @quantity = name, description, price, quantity
|
85
|
-
end
|
86
|
-
def full_price
|
87
|
-
@price * @quantity
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
receipt = <<-RECEIPT
|
92
|
-
<p><r:user:name />, thank you for shopping with us! An order summary
|
93
|
-
is printed below for your convinience. Please print a copy for your records.</p>
|
94
|
-
<r:cart>
|
95
|
-
<table>
|
96
|
-
<thead>
|
97
|
-
<tr>
|
98
|
-
<td>Product</td>
|
99
|
-
<td>Price</td>
|
100
|
-
<td>Quantity</td>
|
101
|
-
<td>Totals</td>
|
102
|
-
</tr>
|
103
|
-
</thead>
|
104
|
-
<tbody>
|
105
|
-
<r:items>
|
106
|
-
<tr>
|
107
|
-
<td>
|
108
|
-
<strong><r:name /></strong><br >
|
109
|
-
<r:description />
|
110
|
-
</td>
|
111
|
-
<td><r:price /></td>
|
112
|
-
<td><r:quanity /></td>
|
113
|
-
<td><r:full_price /></td>
|
114
|
-
</tr>
|
115
|
-
</r:items>
|
116
|
-
</tbody>
|
117
|
-
<tr>
|
118
|
-
<td colspan="3">Total</td>
|
119
|
-
<td><r:total /></td>
|
120
|
-
</tr>
|
121
|
-
</table>
|
122
|
-
</r:cart>
|
123
|
-
RECEIPT
|
124
|
-
|
125
|
-
user = User.new('John', 'johnboy', 'm@x!mu5', 'johnboy@maximus.com')
|
126
|
-
cart = Cart.new(
|
127
|
-
LineItem.new('15in PowerBook', "Apple's premium notebook computer.", 1995.98, 1),
|
128
|
-
LineItem.new('Mac Notebook Case', "A beautiful black notebook case designed for Apple Powerbooks.", 54.05, 1)
|
129
|
-
)
|
130
|
-
session = Session.new('a4bd386e512bacd581')
|
131
|
-
|
132
|
-
context = StoreContext.new(
|
133
|
-
:user => user,
|
134
|
-
:cart => cart,
|
135
|
-
:session => session
|
136
|
-
)
|
137
|
-
|
138
|
-
template = Radius::Template.new(
|
139
|
-
:text => receipt,
|
140
|
-
:context => context
|
141
|
-
)
|
142
|
-
|
143
|
-
template.compile! # based on context parses text into abstract syntax tree
|
144
|
-
puts template.expand # outputs expanded template
|
145
|
-
|
146
|
-
# alternate usage
|
147
|
-
parser = Radius::Parser.new(context)
|
148
|
-
puts parser.parse(receipt) # compiles and outputs expanded template
|
149
|
-
|
150
|
-
# another alternate
|
151
|
-
puts Radius.parse(receipt, context)
|