hypertemplate 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +83 -75
- data/lib/hypertemplate/hook/rails.rb +20 -1
- data/lib/hypertemplate/hook/tilt.rb +1 -2
- data/lib/hypertemplate/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -20,65 +20,65 @@ the integration tests for hook samples.
|
|
20
20
|
|
21
21
|
## Hypertemplate DSL
|
22
22
|
|
23
|
-
products {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
23
|
+
products {
|
24
|
+
link "order", orders_url, "type" => "application/xml"
|
25
|
+
@products.each do |prod|
|
26
|
+
product {
|
27
|
+
link :self, product_url(prod)
|
28
|
+
id prod.id
|
29
|
+
name prod.name
|
30
|
+
price prod.price
|
31
|
+
}
|
32
|
+
end
|
33
|
+
}
|
34
34
|
|
35
35
|
|
36
36
|
Generates the following representations:
|
37
37
|
|
38
38
|
### JSON
|
39
39
|
|
40
|
-
{"products":
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
40
|
+
{"products":
|
41
|
+
{"link":[
|
42
|
+
{"type":"application/xml",
|
43
|
+
"rel":"order",
|
44
|
+
"href":"http://localhost:3000/orders"}],
|
45
|
+
"product":[
|
46
|
+
{"link":
|
47
|
+
[{"rel":"self",
|
48
|
+
"href":"http://localhost:3000/products/2",
|
49
|
+
"type":"application/json"}],
|
50
|
+
"id":2,
|
51
|
+
"name":"Rest Training (20h)",
|
52
|
+
"price":"800.0"},
|
53
|
+
{"link":
|
54
|
+
[{"rel":"self",
|
55
|
+
"href":"http://localhost:3000/products/3",
|
56
|
+
"type":"application/json"}],
|
57
|
+
"id":3,
|
58
|
+
"name":"Modern Software architecture and Design (20h)",
|
59
|
+
"price":"800.0"}
|
60
|
+
]
|
61
|
+
}
|
61
62
|
}
|
62
|
-
}
|
63
63
|
|
64
64
|
### XML
|
65
65
|
|
66
|
-
<?xml version="1.0"?>
|
67
|
-
<products>
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
</products>
|
66
|
+
<?xml version="1.0"?>
|
67
|
+
<products>
|
68
|
+
<link type="application/xml" rel="order" href="http://localhost:3000/orders"/>
|
69
|
+
<product>
|
70
|
+
<link rel="self" href="http://localhost:3000/products/2" type="application/xml"/>
|
71
|
+
<id>2</id>
|
72
|
+
<name>Rest Training (20h)</name>
|
73
|
+
<price>800.0</price>
|
74
|
+
</product>
|
75
|
+
<product>
|
76
|
+
<link rel="self" href="http://localhost:3000/products/3" type="application/xml"/>
|
77
|
+
<id>3</id>
|
78
|
+
<name>Modern Software architecture and Design (20h)</name>
|
79
|
+
<price>800.0</price>
|
80
|
+
</product>
|
81
|
+
</products>
|
82
82
|
|
83
83
|
|
84
84
|
|
@@ -97,32 +97,40 @@ then forked from [Tokamak](http://github.com/abril/tokamak). See LICENSE.txt*
|
|
97
97
|
|
98
98
|
## A more complex example
|
99
99
|
|
100
|
-
order {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
100
|
+
order {
|
101
|
+
link "self", order_url(@order)
|
102
|
+
link "payment", order_payments_url(@order), "type" => "application/xml"
|
103
|
+
link "calendar", order_calendar_url(@order), "type" => "text/calendar"
|
104
|
+
address @order.address
|
105
|
+
price @order.price
|
106
|
+
state @order.state
|
107
|
+
payments {
|
108
|
+
@order.payments.each do |p|
|
109
|
+
payment do
|
110
|
+
value p.value
|
111
|
+
state p.state
|
112
|
+
end
|
113
|
+
end
|
114
|
+
}
|
115
|
+
items {
|
116
|
+
@order.items.each do |i|
|
117
|
+
item do
|
118
|
+
id i.product.id
|
119
|
+
name i.product.name
|
120
|
+
price i.product.price
|
121
|
+
quantity i.quantity
|
122
|
+
end
|
123
|
+
end
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
## Testing with Rails and Rspec
|
128
|
+
|
129
|
+
In order to test Hypertemplate with Rails and RSpec, you have to invoke
|
130
|
+
|
131
|
+
render_views
|
132
|
+
|
133
|
+
in your controller specs.
|
126
134
|
|
127
135
|
## Questions? Help?
|
128
136
|
|
@@ -35,7 +35,7 @@ module Hypertemplate
|
|
35
35
|
include ::ActionView::TemplateHandlers::Compilable
|
36
36
|
|
37
37
|
def compile(template)
|
38
|
-
"@content_type_helpers =
|
38
|
+
"@content_type_helpers = controller.hypertemplate_registry[self.response.content_type].helper; " +
|
39
39
|
"extend @content_type_helpers; " +
|
40
40
|
"extend Hypertemplate::Hook::Rails::Helpers; " +
|
41
41
|
"code_block = lambda { #{template.source} };" +
|
@@ -44,7 +44,26 @@ module Hypertemplate
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
module Rails3Adapter
|
48
|
+
def _pick_partial_template(path) #:nodoc:
|
49
|
+
return path unless path.is_a?(String)
|
50
|
+
prefix = controller_path unless path.include?(?/)
|
51
|
+
find_template(path, prefix, true).instance_eval do
|
52
|
+
unless respond_to?(:path)
|
53
|
+
def path; virtual_path end
|
54
|
+
end
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
47
60
|
module Helpers
|
61
|
+
|
62
|
+
def self.extend_object(base)
|
63
|
+
super
|
64
|
+
base.extend(Rails3Adapter) unless base.respond_to?(:_pick_partial_template)
|
65
|
+
end
|
66
|
+
|
48
67
|
# Load a partial template to execute in describe
|
49
68
|
#
|
50
69
|
# For example:
|
@@ -25,12 +25,11 @@ module Hypertemplate
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def initialize_engine
|
28
|
-
return if defined?(::Hypertemplate)
|
29
28
|
require_template_library 'hypertemplate'
|
30
29
|
end
|
31
30
|
|
32
31
|
def prepare
|
33
|
-
@media_type = options[:media_type]
|
32
|
+
@media_type = options[:media_type] || @options[:media_type]
|
34
33
|
raise Hypertemplate::BuilderError.new("Content type required to build representation.") unless @media_type
|
35
34
|
end
|
36
35
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hypertemplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Guilherme Silveira & Hypertemplate & Tokamak & Restfulie team
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_pure
|