hypertemplate 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -20,65 +20,65 @@ the integration tests for hook samples.
20
20
 
21
21
  ## Hypertemplate DSL
22
22
 
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
- }
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
- {"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
- ]
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
- <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>
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
- 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
- }
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 = @controller.hypertemplate_registry[self.response.content_type].helper; " +
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
 
@@ -2,7 +2,7 @@ module Hypertemplate
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hypertemplate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
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-05-24 00:00:00 Z
13
+ date: 2011-07-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json_pure