alephant-publisher 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a49863adb8505ddd85a58aab37e7043fd452ac9
4
- data.tar.gz: 39179346260fd678fac58c25c3b8cf9eeebae695
3
+ metadata.gz: aa40ce959677b14f7a5c135013a4deac722a26a7
4
+ data.tar.gz: 4eaf4ef0c0d96ba7829bdbb8ddaf9318b71d8d9d
5
5
  SHA512:
6
- metadata.gz: 44ac49a5fe767655da98a1fb15fb7863d242eb8a3b330af545a28ba4f41a20b8661e7db80c6fb6c5e0cb91b8f028dd65a7fc2a9fd12ba5923189a9544936d498
7
- data.tar.gz: 3615cdd1c53f7f466e58fcde11d15d3b665b43b89d5c9e86cd3f2d9e0a7dff86d2c0e33dd9c72dff867b1b7b7ec4c8fc1361378b029d34847069e7b896b32a64
6
+ metadata.gz: 3b1868ff97a51e4157dbdf3e4f82c786292c13b8911e76587e22ca8d01eafdd6d7abd4ac6057e3bac937db6a10d76f1dd1b38b6023919d1c8ca0af4043fc1abd
7
+ data.tar.gz: 13ffe1f81e279b4567fe016a3fbb5d59be49fe0fe7f1a7760c477c3494b8e43644d08bf7477f06c38b47b1a1d1fd9ef1320c3669cd0dc35dec1e524213f12fb8
@@ -36,11 +36,12 @@ Gem::Specification.new do |spec|
36
36
  spec.add_runtime_dependency 'jsonpath'
37
37
  spec.add_runtime_dependency 'crimp'
38
38
  spec.add_runtime_dependency 'peach'
39
+ spec.add_runtime_dependency 'i18n'
40
+ spec.add_runtime_dependency 'hashie'
39
41
  spec.add_runtime_dependency 'alephant-support'
40
42
  spec.add_runtime_dependency 'alephant-sequencer'
41
43
  spec.add_runtime_dependency 'alephant-cache'
42
44
  spec.add_runtime_dependency 'alephant-logger'
43
- spec.add_runtime_dependency 'alephant-renderer'
44
45
  spec.add_runtime_dependency 'alephant-lookup'
45
46
  spec.add_runtime_dependency 'alephant-preview'
46
47
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Publisher
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -0,0 +1,58 @@
1
+ require 'alephant/logger'
2
+
3
+ module Alephant
4
+ module Publisher
5
+ class ViewMapper
6
+ include Logger
7
+ include Renderer
8
+
9
+ DEFAULT_LOCATION = 'components'
10
+
11
+ def initialize(component_id, view_base_path=nil)
12
+ self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil?
13
+ @component_id = component_id
14
+ end
15
+
16
+ def base_path
17
+ @base_path || DEFAULT_LOCATION
18
+ end
19
+
20
+ def base_path=(path)
21
+ @base_path = File.directory?(path) ? path : (raise "Invalid path: '#{path}'")
22
+ end
23
+
24
+ def generate(data)
25
+ model_locations.reduce({}) do |obj, file|
26
+ obj.tap do |o|
27
+ model_id = model_id_for file
28
+ o[model_id] = model(model_id, data)
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def model(view_id, data)
36
+ require model_location_for view_id
37
+ Views.get_registered_class(view_id).new(data)
38
+ end
39
+
40
+ def model_location_for(view_id)
41
+ File.join(base_path, 'models', "#{view_id}.rb")
42
+ end
43
+
44
+ def model_locations
45
+ Dir[model_base_path]
46
+ end
47
+
48
+ def model_base_path
49
+ "#{base_path}/models/*"
50
+ end
51
+
52
+ def model_id_for(location)
53
+ location.split('/').last.sub(/\.rb/, '')
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,44 @@
1
+ require 'alephant/publisher/views'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ module Alephant::Publisher::Views
6
+ module Base
7
+ def self.included base
8
+ base.send :include, InstanceMethods
9
+ base.extend ClassMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+ attr_reader :data, :content_type, :base_path
14
+
15
+ def initialize(data = {})
16
+ @data = Hashie::Mash.new data
17
+ @base_path = self.class.base_path
18
+
19
+ setup
20
+ end
21
+
22
+ def to_h
23
+ whitelist.reduce({}) { |m,s| m.tap { |m| m[s] = self.send(s) } }
24
+ end
25
+
26
+ def setup; end
27
+ def whitelist; [] end
28
+ end
29
+
30
+ module ClassMethods
31
+ attr_accessor :base_path
32
+
33
+ def inherited(subclass)
34
+ current_dir = File.dirname(caller.first[/^[^:]+/])
35
+ dir_path = Pathname.new(File.join(current_dir,'..')).realdirpath
36
+
37
+ subclass.base_path = dir_path.to_s
38
+
39
+ Alephant::Publisher::Views.register(subclass)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,60 @@
1
+ require 'alephant/publisher/views/base'
2
+ require 'mustache'
3
+ require 'i18n'
4
+
5
+ module Alephant::Publisher::Views
6
+ class Html < Mustache
7
+ include Base
8
+
9
+ def setup
10
+ @content_type = "text/html"
11
+ load_translations_from base_path
12
+ end
13
+
14
+ def locale
15
+ :en
16
+ end
17
+
18
+ private
19
+
20
+ def load_translations_from(base_path)
21
+ if I18n.load_path.empty?
22
+ I18n.config.enforce_available_locales = false
23
+ I18n.load_path = i18n_load_path_from(base_path)
24
+ I18n.backend.load_translations
25
+ end
26
+ end
27
+
28
+ def i18n_load_path_from(base_path)
29
+ Dir[
30
+ File.join(
31
+ Pathname.new(base_path).parent,
32
+ 'locale',
33
+ '*.yml')
34
+ ]
35
+ .flatten
36
+ .uniq
37
+ end
38
+
39
+ def t(key, params = {})
40
+ I18n.locale = locale
41
+ prefix = /\/([^\/]+)\.mustache/.match(template_file)[1]
42
+ params.merge! :default => key unless params[:default]
43
+ translation = I18n.translate("#{prefix}.#{key}", params)
44
+ end
45
+
46
+ def template
47
+ @template_string ||= File.open(template_file).read
48
+ end
49
+
50
+ def template_name
51
+ Mustache.underscore(self.class.to_s).split('/').last
52
+ end
53
+
54
+ def template_file
55
+ File.join(base_path,'templates',"#{template_name}.#{template_extension}")
56
+ end
57
+
58
+ end
59
+ end
60
+
@@ -0,0 +1,18 @@
1
+ require 'alephant/publisher/views/base'
2
+ require 'json'
3
+
4
+ module Alephant::Publisher::Views
5
+ class Json
6
+ include Base
7
+
8
+ def setup
9
+ @content_type = "application/json"
10
+ end
11
+
12
+ def render
13
+ JSON.generate(to_h)
14
+ end
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,26 @@
1
+ require 'alephant/publisher/views/html'
2
+ require 'alephant/publisher/views/json'
3
+
4
+ module Alephant
5
+ module Publisher
6
+ module Views
7
+ @@views = {}
8
+
9
+ def self.register(klass)
10
+ @@views[underscorify(klass.name.split('::').last)] = klass
11
+ end
12
+
13
+ def self.get_registered_class(id)
14
+ @@views[id]
15
+ end
16
+
17
+ def self.underscorify(str)
18
+ str.gsub(/::/, '/').
19
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
20
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
21
+ tr("-", "_").
22
+ downcase
23
+ end
24
+ end
25
+ end
26
+ end
@@ -8,7 +8,7 @@ require 'alephant/lookup'
8
8
  require 'alephant/logger'
9
9
  require 'alephant/sequencer'
10
10
  require 'alephant/support/parser'
11
- require 'alephant/publisher/render_mapper'
11
+ require 'alephant/publisher/view_mapper'
12
12
 
13
13
  module Alephant
14
14
  module Publisher
@@ -23,7 +23,7 @@ module Alephant
23
23
  end
24
24
 
25
25
  def mapper
26
- @mapper ||= RenderMapper.new(
26
+ @mapper ||= ViewMapper.new(
27
27
  config[:renderer_id],
28
28
  config[:view_path]
29
29
  )
@@ -49,17 +49,17 @@ module Alephant
49
49
  protected
50
50
 
51
51
  def perform
52
- Proc.new { renders.peach { |id, r| write(id, r) } }
52
+ Proc.new { views.each { |id, view| write(id, view) } }
53
53
  end
54
54
 
55
- def write(id, r)
55
+ def write(id, view)
56
56
  seq_for(id).sequence(message) do
57
- store(id, r.render, location_for(id))
57
+ store(id, view, location_for(id))
58
58
  end
59
59
  end
60
60
 
61
- def store(id, content, location)
62
- cache.put(location, content, :msg_id => message.id)
61
+ def store(id, view, location)
62
+ cache.put(location, view.render, view.content_type, :msg_id => message.id)
63
63
  lookup.write(id, options, seq_id, location)
64
64
  end
65
65
 
@@ -68,7 +68,7 @@ module Alephant
68
68
  end
69
69
 
70
70
  def batch
71
- @batch ||= (renders.count > 1) ? seq_for(config[:renderer_id]) : nil
71
+ @batch ||= (views.count > 1) ? seq_for(config[:renderer_id]) : nil
72
72
  end
73
73
 
74
74
  def batch?
@@ -92,8 +92,8 @@ module Alephant
92
92
  @seq_id ||= Sequencer::Sequencer.sequence_id_from(message, config[:sequence_id_path])
93
93
  end
94
94
 
95
- def renders
96
- @renders ||= mapper.generate(data)
95
+ def views
96
+ @views ||= mapper.generate(data)
97
97
  end
98
98
 
99
99
  def opt_hash
@@ -7,6 +7,8 @@ require 'alephant/publisher/sqs_helper/archiver'
7
7
  require 'alephant/logger'
8
8
  require 'alephant/support/aop'
9
9
  require 'alephant/publisher/processor'
10
+ require 'alephant/publisher/views'
11
+ require 'alephant/publisher/views/base'
10
12
 
11
13
  module Alephant
12
14
  module Publisher
@@ -4,7 +4,7 @@ describe Alephant::Publisher::SQSHelper::Archiver do
4
4
  describe "#see" do
5
5
  it "calls cache put with the correct params" do
6
6
  time_now = DateTime.parse("Feb 24 1981")
7
- DateTime.stub(:now).and_return(time_now)
7
+ allow(DateTime).to receive(:now).and_return(time_now)
8
8
 
9
9
  q = double("queue").as_null_object
10
10
  c = double("cache").as_null_object
@@ -1,5 +1,5 @@
1
1
  module MyApp
2
- class Bar < ::Alephant::Views::Base
2
+ class Bar < Alephant::Publisher::Views::Html
3
3
  def content
4
4
  @data[:content]
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module MyApp
2
- class Foo < ::Alephant::Views::Base
2
+ class Foo < Alephant::Publisher::Views::Html
3
3
  def content
4
4
  @data[:content]
5
5
  end
@@ -0,0 +1,21 @@
1
+ module MyApp
2
+ class Json < Alephant::Publisher::Views::Json
3
+
4
+ def whitelist
5
+ ['item1', 'item2']
6
+ end
7
+
8
+ def item1
9
+ @data[:foo]
10
+ end
11
+
12
+ def item2
13
+ @data[:bar]
14
+ end
15
+
16
+ def baz
17
+ @data[:baz]
18
+ end
19
+
20
+ end
21
+ end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Alephant::Publisher::Processor do
4
4
 
5
5
  before(:each) do
6
- Alephant::Publisher::Writer.any_instance.stub(:initialize)
7
- Alephant::Publisher::Writer.any_instance.stub(:run!)
6
+ allow_any_instance_of(Alephant::Publisher::Writer).to receive(:initialize)
7
+ allow_any_instance_of(Alephant::Publisher::Writer).to receive(:run!)
8
8
  end
9
9
 
10
10
  describe "#consume(msg)" do
@@ -5,7 +5,7 @@ describe Alephant::Publisher do
5
5
  let(:instance) { Alephant::Publisher.create(options) }
6
6
 
7
7
  before(:each) do
8
- Alephant::Publisher::SQSHelper::Queue.any_instance.stub(:initialize)
8
+ allow_any_instance_of(Alephant::Publisher::SQSHelper::Queue).to receive(:initialize)
9
9
  end
10
10
 
11
11
  describe "#initialize(opts = {}, logger)" do
@@ -1,20 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alephant::Publisher::RenderMapper do
3
+ describe Alephant::Publisher::ViewMapper do
4
4
  let(:component_id) { :foo }
5
5
  let(:data) {{ :foo => :bar }}
6
6
  let(:path) { File.join(File.dirname(__FILE__), 'fixtures/components') }
7
7
 
8
- subject { Alephant::Publisher::RenderMapper }
9
-
10
- before(:each) do
11
- File.stub(:directory?).and_return(true)
12
- end
8
+ subject { Alephant::Publisher::ViewMapper }
13
9
 
14
10
  describe "initialize(view_base_path)" do
15
11
  context "view_base_path = invalid_path" do
16
12
  it "should raise an error" do
17
- File.stub(:directory?).and_return(false)
18
13
  expect {
19
14
  subject.new(component_id, './invalid_path')
20
15
  }.to raise_error
@@ -24,8 +19,8 @@ describe Alephant::Publisher::RenderMapper do
24
19
  context "view_base_path = '.'" do
25
20
  it "sets base_path" do
26
21
  expect(
27
- subject.new(component_id, '.').base_path
28
- ).to eq("./#{component_id}")
22
+ subject.new(component_id, path).base_path
23
+ ).to eq("#{path}/#{component_id}")
29
24
  end
30
25
  end
31
26
 
@@ -33,27 +28,11 @@ describe Alephant::Publisher::RenderMapper do
33
28
  it "sets base_path" do
34
29
  expect(
35
30
  subject.new(component_id).base_path
36
- ).to eq(Alephant::Publisher::RenderMapper::DEFAULT_LOCATION)
31
+ ).to eq(Alephant::Publisher::ViewMapper::DEFAULT_LOCATION)
37
32
  end
38
33
  end
39
34
  end
40
35
 
41
- describe "create_renderer(template_file, data)" do
42
- it "Returns a valid renderer" do
43
- expect(
44
- subject.new(component_id, path)
45
- .create_renderer('foo', { :content => 'hello'})
46
- ).to be_a(Alephant::Renderer::Mustache)
47
- end
48
-
49
- it "Returns expected rendered content from a render" do
50
- expect(
51
- subject.new(component_id, path)
52
- .create_renderer('foo', { :content => 'hello'}).render
53
- ).to eq("hello\n")
54
- end
55
- end
56
-
57
36
  describe "generate(data)" do
58
37
  it "calls create_renderer for each template found" do
59
38
  expect(
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/components/foo/models/json'
3
+
4
+ describe Alephant::Publisher::Views::Json do
5
+ let(:data) { {'foo' => 'test', 'bar' => 'white', 'baz' => 'list'} }
6
+
7
+ describe "#content_type" do
8
+
9
+ it "sets the correct content type" do
10
+ expect(MyApp::Json.new(data).content_type).to eq('application/json')
11
+ end
12
+
13
+ end
14
+
15
+ describe "#to_h" do
16
+
17
+ it "generates a hash based on the white list" do
18
+ expected_result = {'item1' => 'test', 'item2' => 'white'}
19
+ expect(MyApp::Json.new(data).to_h).to eq(expected_result)
20
+ end
21
+
22
+ end
23
+
24
+ describe "#render" do
25
+
26
+ it "returns generated json" do
27
+ expected_result = "{\"item1\":\"test\",\"item2\":\"white\"}"
28
+ expect(MyApp::Json.new(data).render).to eq(expected_result)
29
+ end
30
+
31
+ end
32
+
33
+ end
data/spec/writer_spec.rb CHANGED
@@ -17,52 +17,34 @@ describe Alephant::Publisher::Writer do
17
17
  before(:each) do
18
18
  AWS.stub!
19
19
 
20
- Alephant::Publisher::RenderMapper
21
- .any_instance
22
- .should_receive(:initialize)
20
+ allow_any_instance_of(Alephant::Publisher::ViewMapper).to receive(:initialize)
23
21
  .with(
24
22
  opts[:renderer_id],
25
23
  opts[:view_path]
26
24
  )
27
25
 
28
- Alephant::Cache
29
- .any_instance
30
- .should_receive(:initialize)
26
+ allow_any_instance_of(Alephant::Cache).to receive(:initialize)
31
27
  .with(
32
28
  opts[:s3_bucket_id],
33
29
  opts[:s3_object_path]
34
30
  )
35
31
 
36
- Alephant::Sequencer::SequenceTable
37
- .any_instance
38
- .stub(:create)
32
+ allow_any_instance_of(Alephant::Sequencer::SequenceTable).to receive(:create)
39
33
 
40
- Alephant::Sequencer::Sequencer
41
- .any_instance
42
- .stub(:sequencer_id_from)
34
+ allow_any_instance_of(Alephant::Sequencer::Sequencer).to receive(:sequencer_id_from)
43
35
  .and_return(1)
44
36
 
45
- Alephant::Sequencer::Sequencer
46
- .any_instance
47
- .stub(:set_last_seen)
37
+ allow_any_instance_of(Alephant::Sequencer::Sequencer).to receive(:set_last_seen)
48
38
 
49
- Alephant::Sequencer::Sequencer
50
- .any_instance
51
- .stub(:get_last_seen)
39
+ allow_any_instance_of(Alephant::Sequencer::Sequencer).to receive(:get_last_seen)
52
40
 
53
- Alephant::Lookup::LookupTable
54
- .any_instance
55
- .stub(:create)
41
+ allow_any_instance_of(Alephant::Lookup::LookupTable).to receive(:create)
56
42
 
57
- Alephant::Lookup::LookupTable
58
- .any_instance
59
- .stub(:table_name)
43
+ allow_any_instance_of(Alephant::Lookup::LookupTable).to receive(:table_name)
60
44
 
61
- Alephant::Publisher::RenderMapper
62
- .any_instance
63
- .stub(:generate)
45
+ allow_any_instance_of(Alephant::Publisher::ViewMapper).to receive(:generate)
64
46
  .and_return({
65
- 'component_id' => Struct.new(:render).new('content')
47
+ 'component_id' => Struct.new(:render, :content_type).new('content', 'foo/bar')
66
48
  })
67
49
 
68
50
  end
@@ -85,11 +67,9 @@ describe Alephant::Publisher::Writer do
85
67
  end
86
68
 
87
69
  it "should write the correct lookup location" do
88
- Alephant::Cache.any_instance.stub(:put)
70
+ allow_any_instance_of(Alephant::Cache).to receive(:put)
89
71
 
90
- Alephant::Lookup::LookupHelper
91
- .any_instance
92
- .should_receive(:write)
72
+ allow_any_instance_of(Alephant::Lookup::LookupHelper).to receive(:write)
93
73
  .with(
94
74
  "component_id",
95
75
  {:variant=>"foo"},
@@ -99,12 +79,10 @@ describe Alephant::Publisher::Writer do
99
79
  end
100
80
 
101
81
  it "should put the correct location, content to cache" do
102
- Alephant::Lookup::LookupHelper.any_instance.stub(:write)
82
+ allow_any_instance_of(Alephant::Lookup::LookupHelper).to receive(:write)
103
83
 
104
- Alephant::Cache
105
- .any_instance
106
- .should_receive(:put)
107
- .with(expected_location, "content", :msg_id=>"id")
84
+ allow_any_instance_of(Alephant::Cache).to receive(:put)
85
+ .with(expected_location, "content", "foo/bar", :msg_id=>"id")
108
86
  end
109
87
 
110
88
  after do
metadata CHANGED
@@ -1,351 +1,365 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Integralist
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
- requirement: !ruby/object:Gem::Requirement
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
21
23
  requirements:
22
24
  - - ~>
23
25
  - !ruby/object:Gem::Version
24
26
  version: '1.5'
25
- prerelease: false
26
- type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
29
  requirement: !ruby/object:Gem::Requirement
35
30
  requirements:
36
31
  - - '>='
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
39
- prerelease: false
40
34
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: rspec-nc
35
+ prerelease: false
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
38
  - - '>='
46
39
  - !ruby/object:Gem::Version
47
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-nc
48
43
  requirement: !ruby/object:Gem::Requirement
49
44
  requirements:
50
45
  - - '>='
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
- prerelease: false
54
48
  type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: guard
49
+ prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
62
57
  requirement: !ruby/object:Gem::Requirement
63
58
  requirements:
64
59
  - - '>='
65
60
  - !ruby/object:Gem::Version
66
61
  version: '0'
67
- prerelease: false
68
62
  type: :development
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
63
+ prerelease: false
71
64
  version_requirements: !ruby/object:Gem::Requirement
72
65
  requirements:
73
66
  - - '>='
74
67
  - !ruby/object:Gem::Version
75
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
76
71
  requirement: !ruby/object:Gem::Requirement
77
72
  requirements:
78
73
  - - '>='
79
74
  - !ruby/object:Gem::Version
80
75
  version: '0'
81
- prerelease: false
82
76
  type: :development
83
- - !ruby/object:Gem::Dependency
84
- name: pry
77
+ prerelease: false
85
78
  version_requirements: !ruby/object:Gem::Requirement
86
79
  requirements:
87
80
  - - '>='
88
81
  - !ruby/object:Gem::Version
89
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
90
85
  requirement: !ruby/object:Gem::Requirement
91
86
  requirements:
92
87
  - - '>='
93
88
  - !ruby/object:Gem::Version
94
89
  version: '0'
95
- prerelease: false
96
90
  type: :development
97
- - !ruby/object:Gem::Dependency
98
- name: pry-remote
91
+ prerelease: false
99
92
  version_requirements: !ruby/object:Gem::Requirement
100
93
  requirements:
101
94
  - - '>='
102
95
  - !ruby/object:Gem::Version
103
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-remote
104
99
  requirement: !ruby/object:Gem::Requirement
105
100
  requirements:
106
101
  - - '>='
107
102
  - !ruby/object:Gem::Version
108
103
  version: '0'
109
- prerelease: false
110
104
  type: :development
111
- - !ruby/object:Gem::Dependency
112
- name: pry-nav
105
+ prerelease: false
113
106
  version_requirements: !ruby/object:Gem::Requirement
114
107
  requirements:
115
108
  - - '>='
116
109
  - !ruby/object:Gem::Version
117
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-nav
118
113
  requirement: !ruby/object:Gem::Requirement
119
114
  requirements:
120
115
  - - '>='
121
116
  - !ruby/object:Gem::Version
122
117
  version: '0'
123
- prerelease: false
124
118
  type: :development
125
- - !ruby/object:Gem::Dependency
126
- name: sinatra
119
+ prerelease: false
127
120
  version_requirements: !ruby/object:Gem::Requirement
128
121
  requirements:
129
122
  - - '>='
130
123
  - !ruby/object:Gem::Version
131
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sinatra
132
127
  requirement: !ruby/object:Gem::Requirement
133
128
  requirements:
134
129
  - - '>='
135
130
  - !ruby/object:Gem::Version
136
131
  version: '0'
137
- prerelease: false
138
132
  type: :runtime
139
- - !ruby/object:Gem::Dependency
140
- name: faraday
133
+ prerelease: false
141
134
  version_requirements: !ruby/object:Gem::Requirement
142
135
  requirements:
143
136
  - - '>='
144
137
  - !ruby/object:Gem::Version
145
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday
146
141
  requirement: !ruby/object:Gem::Requirement
147
142
  requirements:
148
143
  - - '>='
149
144
  - !ruby/object:Gem::Version
150
145
  version: '0'
151
- prerelease: false
152
146
  type: :runtime
153
- - !ruby/object:Gem::Dependency
154
- name: trollop
147
+ prerelease: false
155
148
  version_requirements: !ruby/object:Gem::Requirement
156
149
  requirements:
157
150
  - - '>='
158
151
  - !ruby/object:Gem::Version
159
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: trollop
160
155
  requirement: !ruby/object:Gem::Requirement
161
156
  requirements:
162
157
  - - '>='
163
158
  - !ruby/object:Gem::Version
164
159
  version: '0'
165
- prerelease: false
166
160
  type: :runtime
167
- - !ruby/object:Gem::Dependency
168
- name: rake
161
+ prerelease: false
169
162
  version_requirements: !ruby/object:Gem::Requirement
170
163
  requirements:
171
164
  - - '>='
172
165
  - !ruby/object:Gem::Version
173
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rake
174
169
  requirement: !ruby/object:Gem::Requirement
175
170
  requirements:
176
171
  - - '>='
177
172
  - !ruby/object:Gem::Version
178
173
  version: '0'
179
- prerelease: false
180
174
  type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: aws-sdk
183
- version_requirements: !ruby/object:Gem::Requirement
183
+ requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ~>
186
186
  - !ruby/object:Gem::Version
187
187
  version: '1.0'
188
- requirement: !ruby/object:Gem::Requirement
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
189
191
  requirements:
190
192
  - - ~>
191
193
  - !ruby/object:Gem::Version
192
194
  version: '1.0'
193
- prerelease: false
194
- type: :runtime
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: mustache
197
- version_requirements: !ruby/object:Gem::Requirement
197
+ requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '>='
200
200
  - !ruby/object:Gem::Version
201
201
  version: 0.99.5
202
- requirement: !ruby/object:Gem::Requirement
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
203
205
  requirements:
204
206
  - - '>='
205
207
  - !ruby/object:Gem::Version
206
208
  version: 0.99.5
207
- prerelease: false
208
- type: :runtime
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: jsonpath
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
211
218
  version_requirements: !ruby/object:Gem::Requirement
212
219
  requirements:
213
220
  - - '>='
214
221
  - !ruby/object:Gem::Version
215
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: crimp
216
225
  requirement: !ruby/object:Gem::Requirement
217
226
  requirements:
218
227
  - - '>='
219
228
  - !ruby/object:Gem::Version
220
229
  version: '0'
221
- prerelease: false
222
230
  type: :runtime
223
- - !ruby/object:Gem::Dependency
224
- name: crimp
231
+ prerelease: false
225
232
  version_requirements: !ruby/object:Gem::Requirement
226
233
  requirements:
227
234
  - - '>='
228
235
  - !ruby/object:Gem::Version
229
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: peach
230
239
  requirement: !ruby/object:Gem::Requirement
231
240
  requirements:
232
241
  - - '>='
233
242
  - !ruby/object:Gem::Version
234
243
  version: '0'
235
- prerelease: false
236
244
  type: :runtime
237
- - !ruby/object:Gem::Dependency
238
- name: peach
245
+ prerelease: false
239
246
  version_requirements: !ruby/object:Gem::Requirement
240
247
  requirements:
241
248
  - - '>='
242
249
  - !ruby/object:Gem::Version
243
250
  version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: i18n
244
253
  requirement: !ruby/object:Gem::Requirement
245
254
  requirements:
246
255
  - - '>='
247
256
  - !ruby/object:Gem::Version
248
257
  version: '0'
249
- prerelease: false
250
258
  type: :runtime
251
- - !ruby/object:Gem::Dependency
252
- name: alephant-support
259
+ prerelease: false
253
260
  version_requirements: !ruby/object:Gem::Requirement
254
261
  requirements:
255
262
  - - '>='
256
263
  - !ruby/object:Gem::Version
257
264
  version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: hashie
258
267
  requirement: !ruby/object:Gem::Requirement
259
268
  requirements:
260
269
  - - '>='
261
270
  - !ruby/object:Gem::Version
262
271
  version: '0'
263
- prerelease: false
264
272
  type: :runtime
265
- - !ruby/object:Gem::Dependency
266
- name: alephant-sequencer
273
+ prerelease: false
267
274
  version_requirements: !ruby/object:Gem::Requirement
268
275
  requirements:
269
276
  - - '>='
270
277
  - !ruby/object:Gem::Version
271
278
  version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: alephant-support
272
281
  requirement: !ruby/object:Gem::Requirement
273
282
  requirements:
274
283
  - - '>='
275
284
  - !ruby/object:Gem::Version
276
285
  version: '0'
277
- prerelease: false
278
286
  type: :runtime
279
- - !ruby/object:Gem::Dependency
280
- name: alephant-cache
287
+ prerelease: false
281
288
  version_requirements: !ruby/object:Gem::Requirement
282
289
  requirements:
283
290
  - - '>='
284
291
  - !ruby/object:Gem::Version
285
292
  version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: alephant-sequencer
286
295
  requirement: !ruby/object:Gem::Requirement
287
296
  requirements:
288
297
  - - '>='
289
298
  - !ruby/object:Gem::Version
290
299
  version: '0'
291
- prerelease: false
292
300
  type: :runtime
293
- - !ruby/object:Gem::Dependency
294
- name: alephant-logger
301
+ prerelease: false
295
302
  version_requirements: !ruby/object:Gem::Requirement
296
303
  requirements:
297
304
  - - '>='
298
305
  - !ruby/object:Gem::Version
299
306
  version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: alephant-cache
300
309
  requirement: !ruby/object:Gem::Requirement
301
310
  requirements:
302
311
  - - '>='
303
312
  - !ruby/object:Gem::Version
304
313
  version: '0'
305
- prerelease: false
306
314
  type: :runtime
307
- - !ruby/object:Gem::Dependency
308
- name: alephant-renderer
315
+ prerelease: false
309
316
  version_requirements: !ruby/object:Gem::Requirement
310
317
  requirements:
311
318
  - - '>='
312
319
  - !ruby/object:Gem::Version
313
320
  version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: alephant-logger
314
323
  requirement: !ruby/object:Gem::Requirement
315
324
  requirements:
316
325
  - - '>='
317
326
  - !ruby/object:Gem::Version
318
327
  version: '0'
319
- prerelease: false
320
328
  type: :runtime
321
- - !ruby/object:Gem::Dependency
322
- name: alephant-lookup
329
+ prerelease: false
323
330
  version_requirements: !ruby/object:Gem::Requirement
324
331
  requirements:
325
332
  - - '>='
326
333
  - !ruby/object:Gem::Version
327
334
  version: '0'
335
+ - !ruby/object:Gem::Dependency
336
+ name: alephant-lookup
328
337
  requirement: !ruby/object:Gem::Requirement
329
338
  requirements:
330
339
  - - '>='
331
340
  - !ruby/object:Gem::Version
332
341
  version: '0'
333
- prerelease: false
334
342
  type: :runtime
335
- - !ruby/object:Gem::Dependency
336
- name: alephant-preview
343
+ prerelease: false
337
344
  version_requirements: !ruby/object:Gem::Requirement
338
345
  requirements:
339
346
  - - '>='
340
347
  - !ruby/object:Gem::Version
341
348
  version: '0'
349
+ - !ruby/object:Gem::Dependency
350
+ name: alephant-preview
342
351
  requirement: !ruby/object:Gem::Requirement
343
352
  requirements:
344
353
  - - '>='
345
354
  - !ruby/object:Gem::Version
346
355
  version: '0'
347
- prerelease: false
348
356
  type: :runtime
357
+ prerelease: false
358
+ version_requirements: !ruby/object:Gem::Requirement
359
+ requirements:
360
+ - - '>='
361
+ - !ruby/object:Gem::Version
362
+ version: '0'
349
363
  description: Static publishing to S3 based on SQS messages
350
364
  email:
351
365
  - mark.mcdx@gmail.com
@@ -366,27 +380,33 @@ files:
366
380
  - lib/alephant/publisher/options.rb
367
381
  - lib/alephant/publisher/processor.rb
368
382
  - lib/alephant/publisher/processor/base.rb
369
- - lib/alephant/publisher/render_mapper.rb
370
383
  - lib/alephant/publisher/sqs_helper/archiver.rb
371
384
  - lib/alephant/publisher/sqs_helper/queue.rb
372
385
  - lib/alephant/publisher/version.rb
386
+ - lib/alephant/publisher/view_mapper.rb
387
+ - lib/alephant/publisher/views.rb
388
+ - lib/alephant/publisher/views/base.rb
389
+ - lib/alephant/publisher/views/html.rb
390
+ - lib/alephant/publisher/views/json.rb
373
391
  - lib/alephant/publisher/writer.rb
374
392
  - spec/archiver_spec.rb
375
393
  - spec/fixtures/components/foo/models/bar.rb
376
394
  - spec/fixtures/components/foo/models/foo.rb
395
+ - spec/fixtures/components/foo/models/json.rb
377
396
  - spec/fixtures/components/foo/templates/bar.mustache
378
397
  - spec/fixtures/components/foo/templates/foo.mustache
379
398
  - spec/processor_spec.rb
380
399
  - spec/publisher_spec.rb
381
400
  - spec/queue_spec.rb
382
- - spec/render_mapper_spec.rb
383
401
  - spec/spec_helper.rb
402
+ - spec/view_mapper_spec.rb
403
+ - spec/views_json_spec.rb
384
404
  - spec/writer_spec.rb
385
405
  homepage: https://github.com/BBC-News/alephant-publisher
386
406
  licenses:
387
407
  - MIT
388
408
  metadata: {}
389
- post_install_message:
409
+ post_install_message:
390
410
  rdoc_options: []
391
411
  require_paths:
392
412
  - lib
@@ -401,20 +421,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
421
  - !ruby/object:Gem::Version
402
422
  version: '0'
403
423
  requirements: []
404
- rubyforge_project:
405
- rubygems_version: 2.1.9
406
- signing_key:
424
+ rubyforge_project:
425
+ rubygems_version: 2.2.2
426
+ signing_key:
407
427
  specification_version: 4
408
428
  summary: Static publishing to S3 based on SQS messages
409
429
  test_files:
410
430
  - spec/archiver_spec.rb
411
431
  - spec/fixtures/components/foo/models/bar.rb
412
432
  - spec/fixtures/components/foo/models/foo.rb
433
+ - spec/fixtures/components/foo/models/json.rb
413
434
  - spec/fixtures/components/foo/templates/bar.mustache
414
435
  - spec/fixtures/components/foo/templates/foo.mustache
415
436
  - spec/processor_spec.rb
416
437
  - spec/publisher_spec.rb
417
438
  - spec/queue_spec.rb
418
- - spec/render_mapper_spec.rb
419
439
  - spec/spec_helper.rb
440
+ - spec/view_mapper_spec.rb
441
+ - spec/views_json_spec.rb
420
442
  - spec/writer_spec.rb
@@ -1,59 +0,0 @@
1
- require 'alephant/logger'
2
-
3
- module Alephant
4
- module Publisher
5
- class RenderMapper
6
- include ::Alephant::Logger
7
- DEFAULT_LOCATION = 'components'
8
-
9
- def initialize(component_id, view_base_path=nil)
10
- self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil?
11
- @component_id = component_id
12
- end
13
-
14
- def base_path
15
- @base_path || DEFAULT_LOCATION
16
- end
17
-
18
- def base_path=(path)
19
- @base_path = File.directory?(path) ? path : (raise "Invalid path: '#{path}'")
20
- end
21
-
22
- def generate(data)
23
- template_locations.reduce({}) do |obj, file|
24
- template_id = template_id_for file
25
- obj.tap { |o| o[template_id] = create_renderer(template_id, data) }
26
- end
27
- end
28
-
29
- def create_renderer(template_file, data)
30
- model = instantiate_model(template_file, data)
31
- Renderer.create(template_file, base_path, model)
32
- end
33
-
34
- private
35
-
36
- def instantiate_model(view_id, data)
37
- require model_location_for view_id
38
- Views.get_registered_class(view_id).new(data)
39
- end
40
-
41
- def model_location_for(template_file)
42
- File.join(base_path, 'models', "#{template_file}.rb")
43
- end
44
-
45
- def template_locations
46
- Dir[template_base_path]
47
- end
48
-
49
- def template_base_path
50
- "#{base_path}/templates/*"
51
- end
52
-
53
- def template_id_for(template_location)
54
- template_location.split('/').last.sub(/\.mustache/, '')
55
- end
56
-
57
- end
58
- end
59
- end