alephant 0.0.9.1-java → 0.0.9.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant.rb +1 -2
- data/lib/alephant/models/multi_renderer.rb +24 -28
- data/lib/alephant/preview/server.rb +2 -2
- data/lib/alephant/version.rb +1 -1
- data/spec/alephant_spec.rb +3 -6
- data/spec/fixtures/components/foo/models/foo.rb +1 -1
- data/spec/multi_renderer_spec.rb +50 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6716ed6da6972be045f19e4ee574a719bbe637e3
|
4
|
+
data.tar.gz: 7e2c247eebaa860b20b2594451a922be357341e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11ccd5ae937a3e19cd6c31319dc7f922763fc129425c4102eb1513fbecf8fe5e6584187cdc9ca9e408ab1d520a0cd5ba4a725bc969e1e93a726b67b43be1336b
|
7
|
+
data.tar.gz: 79f418dcd1f62dd7d8b5360a176331d2e8c475c6e61260287c2e97bc9bf017487de442b2222b21fe459e0cd829b5a0b87d2ef1a2232658e3ce0364d9f44fd9c2
|
data/lib/alephant.rb
CHANGED
@@ -18,7 +18,6 @@ module Alephant
|
|
18
18
|
attr_reader :sequencer, :queue, :cache, :renderer
|
19
19
|
|
20
20
|
VALID_OPTS = [
|
21
|
-
:model_file,
|
22
21
|
:s3_bucket_id,
|
23
22
|
:s3_object_path,
|
24
23
|
:s3_object_id,
|
@@ -44,7 +43,7 @@ module Alephant
|
|
44
43
|
|
45
44
|
@queue = Queue.new(@sqs_queue_id)
|
46
45
|
@cache = Cache.new(@s3_bucket_id, @s3_object_path)
|
47
|
-
@multi_renderer = MultiRenderer.new(@
|
46
|
+
@multi_renderer = MultiRenderer.new(@component_id, @view_path)
|
48
47
|
@parser = Parser.new
|
49
48
|
end
|
50
49
|
|
@@ -2,9 +2,9 @@ module Alephant
|
|
2
2
|
class MultiRenderer
|
3
3
|
DEFAULT_LOCATION = 'components'
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
self.base_path = view_base_path unless view_base_path.nil?
|
7
|
-
@
|
5
|
+
def initialize(component_id, view_base_path=nil)
|
6
|
+
self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil?
|
7
|
+
@component_id = component_id
|
8
8
|
@logger = ::Alephant.logger
|
9
9
|
end
|
10
10
|
|
@@ -17,63 +17,59 @@ module Alephant
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def render(data)
|
20
|
-
instance = create_instance(data)
|
21
|
-
|
22
20
|
template_locations.reduce({}) do |obj, file|
|
23
21
|
template_id = template_id_for file
|
22
|
+
|
24
23
|
obj.tap do |o|
|
25
24
|
o[template_id.to_sym] = render_template(
|
26
25
|
template_id,
|
27
|
-
data
|
28
|
-
instance
|
26
|
+
data
|
29
27
|
)
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
def render_template(template_file, data
|
32
|
+
def render_template(template_file, data)
|
35
33
|
renderer(
|
36
34
|
template_file,
|
37
35
|
base_path,
|
38
|
-
|
39
|
-
).render
|
36
|
+
data
|
37
|
+
).render
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
40
|
+
def renderer(template_file, base_path, data)
|
41
|
+
Renderer.new(template_file, base_path, create_instance(template_file, data))
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_instance(template_file, data)
|
43
45
|
begin
|
44
|
-
create_model(
|
46
|
+
create_model(template_file, data)
|
45
47
|
rescue Exception => e
|
46
48
|
@logger.error("Renderer.model: exeception #{e.message}")
|
47
49
|
raise Errors::ViewModelNotFound
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
def renderer(template_file, base_path, model_object)
|
52
|
-
Renderer.new(template_file, base_path, model_object)
|
53
|
-
end
|
54
|
-
|
55
53
|
private
|
56
|
-
def
|
57
|
-
|
54
|
+
def create_model(template_file, data)
|
55
|
+
require model_location_for template_file
|
56
|
+
klass = Views.get_registered_class("#{@component_id}_#{template_file}")
|
57
|
+
|
58
|
+
@logger.info("Renderer.model: creating new klass #{klass}")
|
59
|
+
klass.new(data)
|
58
60
|
end
|
59
61
|
|
60
|
-
def
|
61
|
-
|
62
|
-
Views.get_registered_class(@model_file)
|
62
|
+
def model_location_for(template_file)
|
63
|
+
File.join(base_path, 'models', "#{template_file}.rb")
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
-
|
67
|
-
klass.new(data)
|
66
|
+
def template_locations
|
67
|
+
Dir.glob("#{base_path}/templates/*")
|
68
68
|
end
|
69
69
|
|
70
70
|
def template_id_for(template_location)
|
71
71
|
template_location.split('/').last.sub(/\.mustache/, '')
|
72
72
|
end
|
73
73
|
|
74
|
-
def model_location
|
75
|
-
File.join(base_path, 'models', "#{@model_file}.rb")
|
76
|
-
end
|
77
|
-
|
78
74
|
end
|
79
75
|
end
|
@@ -60,11 +60,11 @@ module Alephant
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def base_path
|
63
|
-
"#{Dir.pwd}/components
|
63
|
+
"#{Dir.pwd}/components"
|
64
64
|
end
|
65
65
|
|
66
66
|
def fixture_location
|
67
|
-
"#{base_path}/fixtures/#{fixture}.json"
|
67
|
+
"#{base_path}/#{id}/fixtures/#{fixture}.json"
|
68
68
|
end
|
69
69
|
|
70
70
|
def preview_template_location
|
data/lib/alephant/version.rb
CHANGED
data/spec/alephant_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Alephant do
|
4
|
-
let(:model_file) { 'foo' }
|
5
4
|
subject { Alephant::Alephant }
|
6
5
|
|
7
6
|
describe "initialize(opts = {})" do
|
@@ -19,7 +18,6 @@ describe Alephant::Alephant do
|
|
19
18
|
|
20
19
|
it "sets specified options" do
|
21
20
|
instance = subject.new({
|
22
|
-
:model_file => :model_file,
|
23
21
|
:s3_bucket_id => :s3_bucket_id,
|
24
22
|
:s3_object_path => :s3_object_path,
|
25
23
|
:s3_object_id => :s3_object_id,
|
@@ -30,7 +28,6 @@ describe Alephant::Alephant do
|
|
30
28
|
:component_id => :component_id
|
31
29
|
})
|
32
30
|
|
33
|
-
expect(instance.model_file).to eq(:model_file);
|
34
31
|
expect(instance.s3_bucket_id).to eq(:s3_bucket_id);
|
35
32
|
expect(instance.s3_object_path).to eq(:s3_object_path);
|
36
33
|
expect(instance.s3_object_id).to eq(:s3_object_id);
|
@@ -44,7 +41,6 @@ describe Alephant::Alephant do
|
|
44
41
|
it "sets unspecified options to nil" do
|
45
42
|
instance = subject.new
|
46
43
|
|
47
|
-
expect(instance.model_file).to eq(nil);
|
48
44
|
expect(instance.s3_bucket_id).to eq(nil);
|
49
45
|
expect(instance.s3_object_path).to eq(nil);
|
50
46
|
expect(instance.s3_object_id).to eq(nil);
|
@@ -90,10 +86,11 @@ describe Alephant::Alephant do
|
|
90
86
|
|
91
87
|
context "initializes @multi_renderer" do
|
92
88
|
it "MultiRenderer class to be initialized" do
|
93
|
-
Alephant::MultiRenderer
|
89
|
+
Alephant::MultiRenderer
|
90
|
+
.should_receive(:new)
|
91
|
+
.with('foo', 'components')
|
94
92
|
|
95
93
|
instance = subject.new({
|
96
|
-
:model_file => model_file,
|
97
94
|
:view_path => 'components',
|
98
95
|
:component_id => 'foo'
|
99
96
|
})
|
data/spec/multi_renderer_spec.rb
CHANGED
@@ -1,95 +1,103 @@
|
|
1
|
+
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Alephant::MultiRenderer do
|
4
|
-
let(:
|
5
|
+
let(:component_id) { :foo }
|
5
6
|
subject { Alephant::MultiRenderer }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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)
|
8
|
+
describe "initialize(view_base_path)" do
|
9
|
+
context "view_base_path = invalid_path" do
|
10
|
+
it "should raise InvalidViewPath" do
|
11
|
+
expect {
|
12
|
+
instance = subject.new(component_id, './invalid_path')
|
13
|
+
}.to raise_error(
|
14
|
+
Alephant::Errors::InvalidViewPath
|
15
|
+
)
|
21
16
|
end
|
22
17
|
end
|
23
18
|
|
24
19
|
context "view_base_path = '.'" do
|
25
20
|
it "sets base_path" do
|
26
|
-
|
21
|
+
File.stub(:directory?).and_return(true)
|
22
|
+
expect(subject.new(component_id, '.').base_path).to eq("./#{component_id}")
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
|
-
context "view_base_path =
|
31
|
-
it "
|
32
|
-
expect
|
33
|
-
instance = subject.new(model_file, './invalid_path')
|
34
|
-
}.to raise_error(
|
35
|
-
Alephant::Errors::InvalidViewPath
|
36
|
-
)
|
26
|
+
context "view_base_path = nil" do
|
27
|
+
it "sets base_path" do
|
28
|
+
expect(subject.new(component_id).base_path).to eq(Alephant::MultiRenderer::DEFAULT_LOCATION)
|
37
29
|
end
|
38
30
|
end
|
39
31
|
end
|
40
32
|
|
41
|
-
describe "
|
33
|
+
describe "render_template(template_file, data, instance = nil)" do
|
34
|
+
before(:each) do
|
35
|
+
File.stub(:directory?).and_return(true)
|
36
|
+
end
|
37
|
+
|
42
38
|
context "instance is not nil" do
|
43
|
-
let(:data) {
|
44
|
-
|
39
|
+
let(:data) {{ :foo => :bar }}
|
40
|
+
|
45
41
|
it "renders the specified template" do
|
42
|
+
Alephant::MultiRenderer.any_instance.stub(:create_instance)
|
43
|
+
Alephant::Renderer.any_instance.stub(:render).and_return('content')
|
44
|
+
|
46
45
|
expect(
|
47
|
-
|
46
|
+
subject.new(component_id, '.')
|
47
|
+
.render_template('foo', data)
|
48
48
|
).to eq('content')
|
49
49
|
end
|
50
50
|
end
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
expect(
|
56
|
-
@instance.render_template('foo', data, nil)
|
57
|
-
).to eq('content')
|
58
|
-
end
|
53
|
+
describe "render(data)" do
|
54
|
+
before(:each) do
|
55
|
+
File.stub(:directory?).and_return(true)
|
59
56
|
end
|
60
57
|
|
58
|
+
it "calls ::Alephant::renderer.render() for each template found" do
|
59
|
+
Alephant::MultiRenderer.any_instance.stub(:create_instance)
|
60
|
+
Alephant::Renderer.any_instance.stub(:render).and_return('content')
|
61
61
|
|
62
|
-
|
62
|
+
Dir.stub(:glob).and_return(['/some/path/foo.mustache', '/some/path/bar.mustache'])
|
63
63
|
|
64
|
-
describe "#render(data)" do
|
65
|
-
it "calls ::Alephant::renderer.render() for each template found" do
|
66
64
|
templates = {
|
67
65
|
:foo => 'content',
|
68
66
|
:bar => 'content'
|
69
67
|
}
|
70
68
|
|
71
|
-
|
69
|
+
instance = subject.new(component_id, '.')
|
70
|
+
|
71
|
+
content = instance.render({ :foo => :bar })
|
72
|
+
|
73
|
+
expect(content.size).to eq(2)
|
74
|
+
|
72
75
|
content.each do |template_type, rendered_content|
|
73
76
|
expect(rendered_content).to eq(templates[template_type])
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
|
-
describe "
|
81
|
+
describe "create_instance(template_file, data)" do
|
82
|
+
before(:each) do
|
83
|
+
File.stub(:directory?).and_return(true)
|
84
|
+
end
|
85
|
+
|
79
86
|
let(:data) {{ :key => :value }}
|
80
87
|
|
81
88
|
it "returns the model" do
|
82
|
-
|
89
|
+
instance = subject.new(component_id, 'fixtures/components')
|
90
|
+
model = instance.create_instance('foo', data)
|
83
91
|
model.should be_an Alephant::Views::Base
|
84
92
|
expect(model.data).to eq(data)
|
85
93
|
end
|
86
94
|
|
87
95
|
context "invalid model" do
|
88
96
|
it 'should raise ViewModelNotFound' do
|
89
|
-
instance = subject.new(
|
97
|
+
instance = subject.new(component_id, @base_path)
|
90
98
|
|
91
99
|
expect {
|
92
|
-
instance.create_instance(data)
|
100
|
+
instance.create_instance('invalid_model', data)
|
93
101
|
}.to raise_error(
|
94
102
|
Alephant::Errors::ViewModelNotFound
|
95
103
|
)
|
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.9.
|
4
|
+
version: 0.0.9.2
|
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-02-
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|