alephant 0.0.8.2-java → 0.0.9-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +9 -2
- data/lib/alephant.rb +8 -9
- data/lib/alephant/models/multi_renderer.rb +79 -0
- data/lib/alephant/models/renderer.rb +14 -47
- data/lib/alephant/preview/server.rb +10 -5
- data/lib/alephant/version.rb +1 -1
- data/spec/alephant_spec.rb +48 -40
- data/spec/fixtures/{views/models/example.rb → components/foo/models/foo.rb} +1 -1
- data/spec/fixtures/{views/templates/example.mustache → components/foo/templates/bar.mustache} +0 -0
- data/spec/fixtures/components/foo/templates/foo.mustache +1 -0
- data/spec/multi_renderer_spec.rb +99 -0
- data/spec/renderer_spec.rb +33 -110
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e70ac398cb94b4e56959960048cfae7f5973463c
|
4
|
+
data.tar.gz: 9161ab004f0f784442f7aa18d26de4ab6e9082d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b3294a258632a30d5096f65f74127bca9b778ca769e82c04a7841a55e7f5b2214155395d70ff90560e33a9b2d8d3d5f7d92f2cfd7243c15cd23f6336fc8349
|
7
|
+
data.tar.gz: 2ed9b6e729d77ece8291d74c1c801c380ccbc731fde600d8b31859feff2bd914df96e92f1a9379d28235ffbd772fc594b1dc72c0ae43748b088cca2667d141fd
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -44,7 +44,6 @@ opts = {
|
|
44
44
|
:s3_object_id => 'object_id',
|
45
45
|
:table_name => 'your_dynamo_db_table',
|
46
46
|
:sqs_queue_id => 'https://your_amazon_sqs_queue_url',
|
47
|
-
:view_id => 'my_view_id',
|
48
47
|
:sequential_proc => Proc.new { |last_seen_id, data|
|
49
48
|
last_seen_id < data["sequence_id"].to_i
|
50
49
|
},
|
@@ -136,10 +135,18 @@ PREVIEW_TEMPLATE_URL="http://yourapp.com/template"
|
|
136
135
|
|
137
136
|
**Example Remote Template**
|
138
137
|
|
139
|
-
|
138
|
+
`id` is the component/folder name
|
139
|
+
|
140
|
+
`template` is the mustache template file name
|
141
|
+
|
142
|
+
`location_in_page` should be something like (for example) `page_head` (specified within a `preview.mustache` file that the consuming application needs to create).
|
143
|
+
|
144
|
+
- `http://localhost:4567/component/id/template`
|
145
|
+
- `http://localhost:4567/preview/id/template/location_in_page`
|
140
146
|
|
141
147
|
`alephant update`
|
142
148
|
|
143
149
|
**In page**
|
150
|
+
|
144
151
|
`/preview/:id/:region/?:fixture?`
|
145
152
|
|
data/lib/alephant.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
$: << File.dirname(__FILE__)
|
2
|
-
|
3
1
|
require 'aws-sdk'
|
4
2
|
|
5
3
|
require_relative 'env'
|
@@ -8,6 +6,7 @@ require 'alephant/models/logger'
|
|
8
6
|
require 'alephant/models/queue'
|
9
7
|
require 'alephant/models/cache'
|
10
8
|
require 'alephant/models/renderer'
|
9
|
+
require 'alephant/models/multi_renderer'
|
11
10
|
require 'alephant/models/sequencer'
|
12
11
|
require 'alephant/models/parser'
|
13
12
|
|
@@ -19,15 +18,16 @@ module Alephant
|
|
19
18
|
attr_reader :sequencer, :queue, :cache, :renderer
|
20
19
|
|
21
20
|
VALID_OPTS = [
|
21
|
+
:model_file,
|
22
22
|
:s3_bucket_id,
|
23
23
|
:s3_object_path,
|
24
24
|
:s3_object_id,
|
25
25
|
:table_name,
|
26
26
|
:sqs_queue_id,
|
27
|
-
:view_id,
|
28
27
|
:view_path,
|
29
28
|
:sequential_proc,
|
30
|
-
:set_last_seen_proc
|
29
|
+
:set_last_seen_proc,
|
30
|
+
:component_id
|
31
31
|
]
|
32
32
|
|
33
33
|
def initialize(opts = {}, logger = nil)
|
@@ -44,7 +44,7 @@ module Alephant
|
|
44
44
|
|
45
45
|
@queue = Queue.new(@sqs_queue_id)
|
46
46
|
@cache = Cache.new(@s3_bucket_id, @s3_object_path)
|
47
|
-
@
|
47
|
+
@multi_renderer = MultiRenderer.new(@model_file, "#{@view_path}/#{@component_id}")
|
48
48
|
@parser = Parser.new
|
49
49
|
end
|
50
50
|
|
@@ -53,10 +53,9 @@ module Alephant
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def write(data)
|
56
|
-
@
|
57
|
-
@
|
58
|
-
|
59
|
-
)
|
56
|
+
@multi_renderer.render(data).each do |id, item|
|
57
|
+
@cache.put(id, item)
|
58
|
+
end
|
60
59
|
end
|
61
60
|
|
62
61
|
def receive(msg)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Alephant
|
2
|
+
class MultiRenderer
|
3
|
+
DEFAULT_LOCATION = 'components'
|
4
|
+
|
5
|
+
def initialize(model_file, view_base_path=nil)
|
6
|
+
self.base_path = view_base_path unless view_base_path.nil?
|
7
|
+
@model_file = model_file
|
8
|
+
@logger = ::Alephant.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_path
|
12
|
+
@base_path || DEFAULT_LOCATION
|
13
|
+
end
|
14
|
+
|
15
|
+
def base_path=(path)
|
16
|
+
@base_path = File.directory?(path) ? path : (raise Errors::InvalidViewPath)
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(data)
|
20
|
+
instance = create_instance(data)
|
21
|
+
|
22
|
+
template_locations.reduce({}) do |obj, file|
|
23
|
+
template_id = template_id_for file
|
24
|
+
obj.tap do |o|
|
25
|
+
o[template_id.to_sym] = render_template(
|
26
|
+
template_id,
|
27
|
+
data,
|
28
|
+
instance
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_template(template_file, data, instance = nil)
|
35
|
+
renderer(
|
36
|
+
template_file,
|
37
|
+
base_path,
|
38
|
+
instance.nil? ? create_instance(data) : instance
|
39
|
+
).render.chomp!
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_instance(data)
|
43
|
+
begin
|
44
|
+
create_model(klass, data)
|
45
|
+
rescue Exception => e
|
46
|
+
@logger.error("Renderer.model: exeception #{e.message}")
|
47
|
+
raise Errors::ViewModelNotFound
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def renderer(template_file, base_path, model_object)
|
52
|
+
Renderer.new(template_file, base_path, model_object)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def template_locations
|
57
|
+
Dir.glob("#{base_path}/templates/*")
|
58
|
+
end
|
59
|
+
|
60
|
+
def klass
|
61
|
+
require model_location
|
62
|
+
Views.get_registered_class(@model_file)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_model(klass, data)
|
66
|
+
@logger.info("Renderer.model: creating new klass #{klass}")
|
67
|
+
klass.new(data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def template_id_for(template_location)
|
71
|
+
template_location.split('/').last.sub(/\.mustache/, '')
|
72
|
+
end
|
73
|
+
|
74
|
+
def model_location
|
75
|
+
File.join(base_path, 'models', "#{@model_file}.rb")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -3,63 +3,30 @@ require 'mustache'
|
|
3
3
|
|
4
4
|
module Alephant
|
5
5
|
class Renderer
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
@
|
14
|
-
self.base_path = view_base_path unless view_base_path.nil?
|
15
|
-
|
16
|
-
@logger.info("Renderer.initialize: end with self.base_path set to #{self.base_path}")
|
6
|
+
attr_reader :template_file
|
7
|
+
|
8
|
+
def initialize(template_file, base_path, model)
|
9
|
+
@logger = ::Alephant.logger
|
10
|
+
@template_file = template_file
|
11
|
+
@base_path = base_path
|
12
|
+
@model = model
|
13
|
+
@logger.info("Renderer.initialize: end with @base_path set to #{@base_path}")
|
17
14
|
end
|
18
15
|
|
19
|
-
def render
|
20
|
-
@logger.info("Renderer.render: rendered template
|
21
|
-
Mustache.render(
|
22
|
-
template(@id),
|
23
|
-
model(@id,data)
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def base_path
|
28
|
-
@base_path || DEFAULT_LOCATION
|
29
|
-
end
|
16
|
+
def render
|
17
|
+
@logger.info("Renderer.render: rendered template #{template_file}")
|
30
18
|
|
31
|
-
|
32
|
-
if File.directory?(path)
|
33
|
-
@base_path = path
|
34
|
-
else
|
35
|
-
@logger.error("Renderer.base_path=(path): error of invalid view path #{path}")
|
36
|
-
raise Errors::InvalidViewPath
|
37
|
-
end
|
19
|
+
Mustache.render(template, @model)
|
38
20
|
end
|
39
21
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
begin
|
44
|
-
require model_location
|
45
|
-
klass = ::Alephant::Views.get_registered_class(id)
|
46
|
-
@logger.info("Renderer.model: klass set to #{klass}")
|
47
|
-
rescue Exception => e
|
48
|
-
@logger.error("Renderer.model: view model with id #{id} not found")
|
49
|
-
raise Errors::ViewModelNotFound
|
50
|
-
end
|
51
|
-
|
52
|
-
@logger.info("Renderer.model: creating new klass with data #{data}")
|
53
|
-
klass.new(data)
|
54
|
-
end
|
22
|
+
def template
|
23
|
+
template_location = File.join(@base_path, 'templates', "#{template_file}.mustache")
|
55
24
|
|
56
|
-
def template(id)
|
57
|
-
template_location = File.join(base_path,'templates',"#{id}.mustache")
|
58
25
|
begin
|
59
26
|
@logger.info("Renderer.template: #{template_location}")
|
60
27
|
File.open(template_location).read
|
61
28
|
rescue Exception => e
|
62
|
-
@logger.error("Renderer.template: view
|
29
|
+
@logger.error("Renderer.template: view template #{template_file} not found")
|
63
30
|
raise Errors::ViewTemplateNotFound
|
64
31
|
end
|
65
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'alephant/models/parser'
|
3
|
-
require 'alephant/models/
|
3
|
+
require 'alephant/models/multi_renderer'
|
4
4
|
require 'alephant/views/preview'
|
5
5
|
require 'faraday'
|
6
6
|
require 'json'
|
@@ -10,11 +10,11 @@ module Alephant
|
|
10
10
|
module Preview
|
11
11
|
class Server < Sinatra::Base
|
12
12
|
|
13
|
-
get '/preview/:id/:region/?:fixture?' do
|
13
|
+
get '/preview/:id/:template/:region/?:fixture?' do
|
14
14
|
render_preview
|
15
15
|
end
|
16
16
|
|
17
|
-
get '/component/:id/?:fixture?' do
|
17
|
+
get '/component/:id/:template/?:fixture?' do
|
18
18
|
render_component
|
19
19
|
end
|
20
20
|
|
@@ -26,10 +26,15 @@ module Alephant
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def render_component
|
29
|
-
|
29
|
+
MultiRenderer.new(id, base_path).render_template(template, fixture_data)
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
+
|
34
|
+
def template
|
35
|
+
params['template']
|
36
|
+
end
|
37
|
+
|
33
38
|
def region
|
34
39
|
params['region']
|
35
40
|
end
|
@@ -55,7 +60,7 @@ module Alephant
|
|
55
60
|
end
|
56
61
|
|
57
62
|
def base_path
|
58
|
-
"#{Dir.pwd}/
|
63
|
+
"#{Dir.pwd}/components/#{id}"
|
59
64
|
end
|
60
65
|
|
61
66
|
def fixture_location
|
data/lib/alephant/version.rb
CHANGED
data/spec/alephant_spec.rb
CHANGED
@@ -1,54 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Alephant do
|
4
|
+
let(:model_file) { 'foo' }
|
4
5
|
subject { Alephant::Alephant }
|
5
6
|
|
6
7
|
describe "initialize(opts = {})" do
|
7
8
|
before(:each) do
|
8
|
-
sequencer
|
9
|
-
queue
|
10
|
-
cache
|
11
|
-
|
9
|
+
sequencer = double()
|
10
|
+
queue = double()
|
11
|
+
cache = double()
|
12
|
+
multi_renderer = double()
|
12
13
|
|
13
14
|
Alephant::Sequencer.any_instance.stub(:initialize).and_return(sequencer)
|
14
15
|
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
15
16
|
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
16
|
-
Alephant::
|
17
|
+
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
17
18
|
end
|
18
19
|
|
19
20
|
it "sets specified options" do
|
20
21
|
instance = subject.new({
|
22
|
+
:model_file => :model_file,
|
21
23
|
:s3_bucket_id => :s3_bucket_id,
|
22
24
|
:s3_object_path => :s3_object_path,
|
23
25
|
:s3_object_id => :s3_object_id,
|
24
26
|
:table_name => :table_name,
|
25
27
|
:sqs_queue_id => :sqs_queue_id,
|
26
|
-
:view_id => :view_id,
|
27
28
|
:sequential_proc => :sequential_proc,
|
28
|
-
:set_last_seen_proc => :set_last_seen_proc
|
29
|
+
:set_last_seen_proc => :set_last_seen_proc,
|
30
|
+
:component_id => :component_id
|
29
31
|
})
|
30
32
|
|
33
|
+
expect(instance.model_file).to eq(:model_file);
|
31
34
|
expect(instance.s3_bucket_id).to eq(:s3_bucket_id);
|
32
35
|
expect(instance.s3_object_path).to eq(:s3_object_path);
|
33
36
|
expect(instance.s3_object_id).to eq(:s3_object_id);
|
34
37
|
expect(instance.table_name).to eq(:table_name);
|
35
38
|
expect(instance.sqs_queue_id).to eq(:sqs_queue_id);
|
36
|
-
expect(instance.view_id).to eq(:view_id);
|
37
39
|
expect(instance.sequential_proc).to eq(:sequential_proc);
|
38
40
|
expect(instance.set_last_seen_proc).to eq(:set_last_seen_proc);
|
41
|
+
expect(instance.component_id).to eq(:component_id);
|
39
42
|
end
|
40
43
|
|
41
44
|
it "sets unspecified options to nil" do
|
42
45
|
instance = subject.new
|
43
46
|
|
47
|
+
expect(instance.model_file).to eq(nil);
|
44
48
|
expect(instance.s3_bucket_id).to eq(nil);
|
45
49
|
expect(instance.s3_object_path).to eq(nil);
|
46
50
|
expect(instance.s3_object_id).to eq(nil);
|
47
51
|
expect(instance.table_name).to eq(nil);
|
48
52
|
expect(instance.sqs_queue_id).to eq(nil);
|
49
|
-
expect(instance.view_id).to eq(nil);
|
50
53
|
expect(instance.sequential_proc).to eq(nil);
|
51
54
|
expect(instance.set_last_seen_proc).to eq(nil);
|
55
|
+
expect(instance.component_id).to eq(nil);
|
52
56
|
end
|
53
57
|
|
54
58
|
context "initializes @sequencer" do
|
@@ -84,39 +88,30 @@ describe Alephant::Alephant do
|
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
87
|
-
context "initializes @
|
88
|
-
it "
|
89
|
-
Alephant::
|
90
|
-
|
91
|
-
instance = subject.new({
|
92
|
-
:view_id => :view_id,
|
93
|
-
:view_path => nil
|
94
|
-
})
|
95
|
-
end
|
96
|
-
|
97
|
-
it "with Renderer.new(@view_id, @view_path)" do
|
98
|
-
Alephant::Renderer.should_receive(:new).with(:view_id, :view_path)
|
91
|
+
context "initializes @multi_renderer" do
|
92
|
+
it "MultiRenderer class to be initialized" do
|
93
|
+
Alephant::MultiRenderer.should_receive(:new).with(model_file, 'components/foo')
|
99
94
|
|
100
95
|
instance = subject.new({
|
101
|
-
:
|
102
|
-
:view_path
|
96
|
+
:model_file => model_file,
|
97
|
+
:view_path => 'components',
|
98
|
+
:component_id => 'foo'
|
103
99
|
})
|
104
100
|
end
|
105
|
-
|
106
101
|
end
|
107
102
|
end
|
108
103
|
|
109
104
|
describe "run!" do
|
110
105
|
before(:each) do
|
111
|
-
sequencer
|
112
|
-
queue
|
113
|
-
cache
|
114
|
-
|
106
|
+
sequencer = double()
|
107
|
+
queue = double()
|
108
|
+
cache = double()
|
109
|
+
multi_renderer = double()
|
115
110
|
|
116
111
|
Alephant::Sequencer.any_instance.stub(:initialize).and_return(sequencer)
|
117
112
|
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
118
113
|
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
119
|
-
Alephant::
|
114
|
+
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
120
115
|
end
|
121
116
|
|
122
117
|
it "returns a Thread" do
|
@@ -143,15 +138,15 @@ describe Alephant::Alephant do
|
|
143
138
|
|
144
139
|
describe "receive(msg)" do
|
145
140
|
before(:each) do
|
146
|
-
sequencer
|
147
|
-
queue
|
148
|
-
cache
|
149
|
-
|
141
|
+
sequencer = double()
|
142
|
+
queue = double()
|
143
|
+
cache = double()
|
144
|
+
multi_renderer = double()
|
150
145
|
|
151
146
|
Alephant::Sequencer.any_instance.stub(:initialize).and_return(sequencer)
|
152
147
|
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
153
148
|
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
154
|
-
Alephant::
|
149
|
+
Alephant::MultiRenderer.any_instance.stub(:initialize).and_return(multi_renderer)
|
155
150
|
end
|
156
151
|
|
157
152
|
it "takes json as an argument" do
|
@@ -184,18 +179,31 @@ describe Alephant::Alephant do
|
|
184
179
|
before(:each) do
|
185
180
|
sequencer = double()
|
186
181
|
queue = double()
|
187
|
-
cache = double()
|
188
|
-
renderer = double()
|
189
182
|
|
190
183
|
Alephant::Sequencer.any_instance.stub(:initialize).and_return(sequencer)
|
191
184
|
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
192
|
-
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
193
|
-
Alephant::Renderer.any_instance.stub(:initialize).and_return(renderer)
|
194
185
|
end
|
195
186
|
|
196
187
|
it "puts rendered data into the S3 Cache" do
|
197
|
-
|
198
|
-
|
188
|
+
templates = {
|
189
|
+
:foo => 'content',
|
190
|
+
:bar => 'content'
|
191
|
+
}
|
192
|
+
|
193
|
+
Alephant::Cache
|
194
|
+
.any_instance
|
195
|
+
.should_receive(:put)
|
196
|
+
.with(:foo, templates[:foo])
|
197
|
+
|
198
|
+
Alephant::Cache
|
199
|
+
.any_instance
|
200
|
+
.should_receive(:put)
|
201
|
+
.with(:bar, templates[:bar])
|
202
|
+
|
203
|
+
Alephant::MultiRenderer
|
204
|
+
.any_instance
|
205
|
+
.stub(:render)
|
206
|
+
.and_return(templates)
|
199
207
|
|
200
208
|
instance = subject.new({
|
201
209
|
:s3_object_id => :s3_object_id
|
data/spec/fixtures/{views/templates/example.mustache → components/foo/templates/bar.mustache}
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{{content}}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::MultiRenderer do
|
4
|
+
let(:model_file) { 'foo' }
|
5
|
+
subject { Alephant::MultiRenderer }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@instance = subject.new(model_file)
|
9
|
+
@instance.base_path = File.join(
|
10
|
+
File.dirname(__FILE__),
|
11
|
+
'fixtures',
|
12
|
+
'components',
|
13
|
+
'foo'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".initialize(view_base_path)" do
|
18
|
+
context "view_base_path = nil" do
|
19
|
+
it "sets base_path" do
|
20
|
+
expect(subject.new(model_file).base_path).to eq(Alephant::MultiRenderer::DEFAULT_LOCATION)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "view_base_path = '.'" do
|
25
|
+
it "sets base_path" do
|
26
|
+
expect(subject.new(model_file, '.').base_path).to eq('.')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "view_base_path = invalid_path" do
|
31
|
+
it "should raise InvalidViewPath" do
|
32
|
+
expect {
|
33
|
+
instance = subject.new(model_file, './invalid_path')
|
34
|
+
}.to raise_error(
|
35
|
+
Alephant::Errors::InvalidViewPath
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#render_template(template_file, data, instance = nil)" do
|
42
|
+
context "instance is not nil" do
|
43
|
+
let(:data) { { :foo => :bar } }
|
44
|
+
let(:model_instance) { @instance.create_instance(data) }
|
45
|
+
it "renders the specified template" do
|
46
|
+
expect(
|
47
|
+
@instance.render_template('foo', data, model_instance)
|
48
|
+
).to eq('content')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "instance is nil" do
|
53
|
+
let(:data) { { :foo => :bar } }
|
54
|
+
it "renders the specified template" do
|
55
|
+
expect(
|
56
|
+
@instance.render_template('foo', data, nil)
|
57
|
+
).to eq('content')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#render(data)" do
|
65
|
+
it "calls ::Alephant::renderer.render() for each template found" do
|
66
|
+
templates = {
|
67
|
+
:foo => 'content',
|
68
|
+
:bar => 'content'
|
69
|
+
}
|
70
|
+
|
71
|
+
content = @instance.render({ :foo => :bar })
|
72
|
+
content.each do |template_type, rendered_content|
|
73
|
+
expect(rendered_content).to eq(templates[template_type])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#create_instance(data)" do
|
79
|
+
let(:data) {{ :key => :value }}
|
80
|
+
|
81
|
+
it "returns the model" do
|
82
|
+
model = @instance.create_instance(data)
|
83
|
+
model.should be_an Alephant::Views::Base
|
84
|
+
expect(model.data).to eq(data)
|
85
|
+
end
|
86
|
+
|
87
|
+
context "invalid model" do
|
88
|
+
it 'should raise ViewModelNotFound' do
|
89
|
+
instance = subject.new('invalid_model_file', @base_path)
|
90
|
+
|
91
|
+
expect {
|
92
|
+
instance.create_instance(data)
|
93
|
+
}.to raise_error(
|
94
|
+
Alephant::Errors::ViewModelNotFound
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/renderer_spec.rb
CHANGED
@@ -1,48 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Renderer do
|
4
|
-
let(:
|
4
|
+
let(:template_file) { 'foo' }
|
5
|
+
let(:base_path) { :base_path }
|
6
|
+
let(:model) { :model }
|
5
7
|
subject { Alephant::Renderer }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
before(:each) do
|
10
|
+
@base_path = File.join(
|
11
|
+
File.dirname(__FILE__),
|
12
|
+
'fixtures',
|
13
|
+
'components',
|
14
|
+
'foo'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "initialize(template_file, base_path, model)" do
|
19
|
+
context "template_file = :template_file" do
|
20
|
+
it "sets the attribute template_file" do
|
21
|
+
expect(subject.new(template_file, base_path, model).template_file).to eq(template_file)
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
describe "template(
|
21
|
-
let(:id) { 'example' }
|
26
|
+
describe "template()" do
|
22
27
|
it "returns the template" do
|
23
|
-
instance = subject.new(
|
24
|
-
|
25
|
-
File.dirname(__FILE__),
|
26
|
-
'fixtures',
|
27
|
-
'views'
|
28
|
-
)
|
29
|
-
|
30
|
-
template = instance.template(id)
|
28
|
+
instance = subject.new(template_file, @base_path, model)
|
29
|
+
template = instance.template
|
31
30
|
expect(template).to eq("{{content}}\n")
|
32
31
|
end
|
33
32
|
|
34
33
|
context 'invalid template' do
|
35
|
-
let(:id) { 'invalid_example' }
|
36
34
|
it 'should raise ViewTemplateNotFound' do
|
37
|
-
instance = subject.new(
|
38
|
-
instance.base_path = File.join(
|
39
|
-
File.dirname(__FILE__),
|
40
|
-
'fixtures',
|
41
|
-
'views'
|
42
|
-
)
|
35
|
+
instance = subject.new('invalid_example', @base_path, model)
|
43
36
|
|
44
37
|
expect {
|
45
|
-
instance.template
|
38
|
+
instance.template
|
46
39
|
}.to raise_error(
|
47
40
|
Alephant::Errors::ViewTemplateNotFound
|
48
41
|
)
|
@@ -50,90 +43,20 @@ describe Alephant::Renderer do
|
|
50
43
|
end
|
51
44
|
end
|
52
45
|
|
53
|
-
describe "
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
'fixtures',
|
61
|
-
'views'
|
62
|
-
)
|
63
|
-
|
64
|
-
model = instance.model(id, data)
|
65
|
-
model.should be_an Alephant::Views::Base
|
66
|
-
expect(model.data).to eq(data)
|
67
|
-
end
|
68
|
-
|
69
|
-
context "invalid model" do
|
70
|
-
let(:id) { 'invalid_example' }
|
71
|
-
it 'should raise ViewModelNotFound' do
|
72
|
-
instance = subject.new(id)
|
73
|
-
instance.base_path = File.join(
|
74
|
-
File.dirname(__FILE__),
|
75
|
-
'fixtures',
|
76
|
-
'views'
|
77
|
-
)
|
78
|
-
expect {
|
79
|
-
instance.model(id, data)
|
80
|
-
}.to raise_error(
|
81
|
-
Alephant::Errors::ViewModelNotFound
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "base_path" do
|
88
|
-
it "should return DEFAULT_LOCATION" do
|
89
|
-
expect(subject.new(id).base_path).to eq(
|
90
|
-
Alephant::Renderer::DEFAULT_LOCATION
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
|
-
context "base_path = '.'" do
|
95
|
-
let(:base_path) { '.' }
|
96
|
-
it "should return '.'" do
|
97
|
-
instance = subject.new(id)
|
98
|
-
instance.base_path = base_path
|
99
|
-
expect(instance.base_path).to eq(base_path)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "base_path=(path)" do
|
105
|
-
context "base_path = valid_path" do
|
106
|
-
let(:valid_path) {'.'}
|
107
|
-
it "should set the base_path" do
|
108
|
-
instance = subject.new(id)
|
109
|
-
instance.base_path = valid_path
|
110
|
-
expect(instance.base_path).to eq(valid_path)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "base_path = invalid_path" do
|
115
|
-
let(:invalid_path) {'./invalid_path'}
|
116
|
-
it "should raise InvalidViewPath" do
|
117
|
-
instance = subject.new(id)
|
118
|
-
expect {
|
119
|
-
instance.base_path = invalid_path
|
120
|
-
}.to raise_error(
|
121
|
-
Alephant::Errors::InvalidViewPath
|
122
|
-
)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
46
|
+
describe "render()" do
|
47
|
+
it 'renders a template returned from template(template_file)' do
|
48
|
+
Mustache
|
49
|
+
.any_instance
|
50
|
+
.stub(:render)
|
51
|
+
.with(:template, :model)
|
52
|
+
.and_return(:content)
|
126
53
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
.
|
131
|
-
Alephant::Renderer.any_instance.stub(:template)
|
132
|
-
.with(id).and_return(:template)
|
133
|
-
Alephant::Renderer.any_instance.stub(:model)
|
134
|
-
.with(id, :data).and_return(:model)
|
54
|
+
Alephant::Renderer
|
55
|
+
.any_instance
|
56
|
+
.stub(:template)
|
57
|
+
.and_return(:template)
|
135
58
|
|
136
|
-
expect(subject.new(
|
59
|
+
expect(subject.new(template_file, @base_path, model).render).to eq(:content)
|
137
60
|
end
|
138
61
|
end
|
139
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/alephant/errors/view_template_not_found.rb
|
217
217
|
- lib/alephant/models/cache.rb
|
218
218
|
- lib/alephant/models/logger.rb
|
219
|
+
- lib/alephant/models/multi_renderer.rb
|
219
220
|
- lib/alephant/models/parser.rb
|
220
221
|
- lib/alephant/models/queue.rb
|
221
222
|
- lib/alephant/models/renderer.rb
|
@@ -232,9 +233,11 @@ files:
|
|
232
233
|
- lib/tasks/preview.rake
|
233
234
|
- spec/alephant_spec.rb
|
234
235
|
- spec/cache_spec.rb
|
235
|
-
- spec/fixtures/
|
236
|
-
- spec/fixtures/
|
236
|
+
- spec/fixtures/components/foo/models/foo.rb
|
237
|
+
- spec/fixtures/components/foo/templates/bar.mustache
|
238
|
+
- spec/fixtures/components/foo/templates/foo.mustache
|
237
239
|
- spec/logger_spec.rb
|
240
|
+
- spec/multi_renderer_spec.rb
|
238
241
|
- spec/parser_spec.rb
|
239
242
|
- spec/queue_spec.rb
|
240
243
|
- spec/renderer_spec.rb
|
@@ -267,9 +270,11 @@ summary: Static Publishing in the Cloud
|
|
267
270
|
test_files:
|
268
271
|
- spec/alephant_spec.rb
|
269
272
|
- spec/cache_spec.rb
|
270
|
-
- spec/fixtures/
|
271
|
-
- spec/fixtures/
|
273
|
+
- spec/fixtures/components/foo/models/foo.rb
|
274
|
+
- spec/fixtures/components/foo/templates/bar.mustache
|
275
|
+
- spec/fixtures/components/foo/templates/foo.mustache
|
272
276
|
- spec/logger_spec.rb
|
277
|
+
- spec/multi_renderer_spec.rb
|
273
278
|
- spec/parser_spec.rb
|
274
279
|
- spec/queue_spec.rb
|
275
280
|
- spec/renderer_spec.rb
|