reviewed_braai 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ReviewedBraai
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ReviewedBraai'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec)
25
+
26
+ task :default => :spec
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,34 @@
1
+ module ReviewedBraai
2
+ class Attachment
3
+ IMAGE_VERSION = 'original'
4
+
5
+ def initialize(source, options={})
6
+ @data = source.data || {}
7
+ @data['name'] ||= source.name
8
+ @data['description'] ||= source.description
9
+
10
+ @type = source.type
11
+ if @type == 'file'
12
+ content_type = @data['content_type']
13
+ if content_type.match(/image/)
14
+ @type = 'image'
15
+ @data['url'] = (source.versions || {})[IMAGE_VERSION] || source.url
16
+ end
17
+ end
18
+ end
19
+
20
+ def template
21
+ file = File.expand_path("./templates/#{@type}.html", File.dirname(__FILE__))
22
+
23
+ if File.exists?(file)
24
+ File.read(file)
25
+ else
26
+ raise ReviewedBraai::TagRenderError::TemplateNotFound.new("Unable to find template at #{file}") unless File.exists?(file)
27
+ end
28
+ end
29
+
30
+ def render
31
+ Braai::Template.new(template).render(@data)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ module ReviewedBraai
2
+ class TagRenderError < StandardError
3
+
4
+ attr_accessor :key
5
+
6
+ def initialize(opts={})
7
+ error = {
8
+ error_class: "ReviewedBraai::TagRenderError",
9
+ error_message: "Tag Render Error",
10
+ key: "Key not supplied"
11
+ }.merge!(opts)
12
+
13
+ @key = error[:key]
14
+
15
+ Airbrake.notify(error) if defined?(Airbrake)
16
+
17
+ super(error[:error_message])
18
+ end
19
+
20
+ class TemplateNotFound < TagRenderError
21
+ def initialize(error={})
22
+ error = { error_message: "Template not Found" }.merge!(error)
23
+ super(error)
24
+ end
25
+ end
26
+
27
+ class SourceNotFound < TagRenderError
28
+ def initialize(error={})
29
+ error = { error_message: "Source Not Found" }.merge!(error)
30
+ super(error)
31
+ end
32
+ end
33
+
34
+ class AttachmentNotFound < TagRenderError
35
+ def initialize(error={})
36
+ error = { error_message: "Attachment Not Found" }.merge!(error)
37
+ super(error)
38
+ end
39
+ end
40
+
41
+ class ProductNotFound < TagRenderError
42
+ def initialize(error={})
43
+ error = { error_message: "Product Not Found" }.merge!(error)
44
+ super(error)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ require 'reviewed_braai/handlers/base'
2
+ require 'reviewed_braai/handlers/articles'
3
+ require 'reviewed_braai/handlers/products'
4
+ require 'reviewed_braai/handlers/attachments'
@@ -0,0 +1,23 @@
1
+ module ReviewedBraai
2
+ module Handlers
3
+ class ArticleMethod < ReviewedBraai::Handlers::Base
4
+ def perform
5
+ source.send(matches[1])
6
+ end
7
+ end
8
+
9
+ class ArticleAttachmentById < ReviewedBraai::Handlers::Base
10
+ def perform
11
+ attachment = match_attachment(:id, matches[1])
12
+ ::ReviewedBraai::Attachment.new(attachment).render
13
+ end
14
+ end
15
+
16
+ class ArticleAttachmentByName < ReviewedBraai::Handlers::Base
17
+ def perform
18
+ attachment = match_attachment(:name, matches[1])
19
+ ::ReviewedBraai::Attachment.new(attachment).render
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module ReviewedBraai
2
+ module Handlers
3
+ class AttachmentsById < ReviewedBraai::Handlers::Base
4
+ def perform
5
+ attachment = match_attachment(all_attachments, :id, matches[1])
6
+ ::ReviewedBraai::Attachment.new(attachment).render
7
+ end
8
+ end
9
+
10
+ class AttachmentsByName < ReviewedBraai::Handlers::Base
11
+ def perform
12
+ attachment = match_attachment(all_attachments, :name, matches[1])
13
+ ::ReviewedBraai::Attachment.new(attachment).render
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,56 @@
1
+ module ReviewedBraai
2
+ module Handlers
3
+ class Base
4
+ include ReviewedBraai::Helpers
5
+
6
+ attr_accessor :template, :key, :matches, :source
7
+
8
+ class << self
9
+
10
+ def call(template, key, matches)
11
+ begin
12
+ handler = self.new(template, key, matches)
13
+ rescue => e
14
+ return rescue_from_error(key)
15
+ end
16
+
17
+ handler.safe_perform
18
+ end
19
+
20
+ def rescue_from_error(key)
21
+ "<!-- #{key} -->"
22
+ end
23
+ end
24
+
25
+ def initialize(template, key, matches)
26
+ @template = template
27
+ @key = key
28
+ @matches = matches
29
+ @source = extract_source(template)
30
+ end
31
+
32
+ def safe_perform
33
+ begin
34
+ perform
35
+ rescue => e
36
+ rescue_from_error(e)
37
+ end
38
+ end
39
+
40
+ def perform
41
+ "<!-- #{key} -->"
42
+ end
43
+
44
+ def extract_source(template)
45
+ unless source = template.attributes[:source]
46
+ raise ::ReviewedBraai::TagRenderError::SourceNotFound.new(default_args)
47
+ end
48
+ return source
49
+ end
50
+
51
+ def rescue_from_error(key)
52
+ self.class.rescue_from_error(key)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,46 @@
1
+ module ReviewedBraai
2
+ module Handlers
3
+ class ProductMethod < ReviewedBraai::Handlers::Base
4
+ def perform
5
+ primary_product.send(matches[1])
6
+ end
7
+ end
8
+
9
+ class ProductAttachmentById < ReviewedBraai::Handlers::Base
10
+ def perform
11
+ attachment = match_attachment(primary_product.attachments, :id, matches[1])
12
+ ::ReviewedBraai::Attachment.new(attachment).render
13
+ end
14
+ end
15
+
16
+ class ProductAttachmentByName < ReviewedBraai::Handlers::Base
17
+ def perform
18
+ attachment = match_attachment(primary_product.attachments, :name, matches[1])
19
+ ::ReviewedBraai::Attachment.new(attachment).render
20
+ end
21
+ end
22
+
23
+ class ProductsMethod < ReviewedBraai::Handlers::Base
24
+ def perform
25
+ product = match_product(:id, matches[1])
26
+ product.send(matches[2])
27
+ end
28
+ end
29
+
30
+ class ProductsAttachmentById < ReviewedBraai::Handlers::Base
31
+ def perform
32
+ product = match_product(:id, matches[1])
33
+ attachment = match_attachment(product.attachments, :id, matches[2])
34
+ ::ReviewedBraai::Attachment.new(attachment).render
35
+ end
36
+ end
37
+
38
+ class ProductsAttachmentByName < ReviewedBraai::Handlers::Base
39
+ def perform
40
+ product = match_product(:id, matches[1])
41
+ attachment = match_attachment(product.attachments, :name, matches[2])
42
+ ::ReviewedBraai::Attachment.new(attachment).render
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module ReviewedBraai
2
+ module Helpers
3
+
4
+ def primary_product
5
+ unless product = source.primary_product
6
+ raise ::ReviewedBraai::TagRenderError::ProductNotFound.new(default_args)
7
+ end
8
+ return product
9
+ end
10
+
11
+ def match_attachment(attachments = source.attachments, attr, match)
12
+ if attachment = attachments.find { |a| a.send(attr) == match }
13
+ attachment
14
+ else
15
+ raise ::ReviewedBraai::TagRenderError::AttachmentNotFound.new(default_args)
16
+ end
17
+ end
18
+
19
+ def match_product(products = source.products, attr, match)
20
+ if product = products.find { |a| a.send(attr) == match }
21
+ product
22
+ else
23
+ raise ::ReviewedBraai::TagRenderError::ProductNotFound.new(default_args)
24
+ end
25
+ end
26
+
27
+ def all_attachments
28
+ attachments = []
29
+ attachments << source.attachments
30
+ attachments << source.primary_product.attachments if source.primary_product
31
+ attachments << source.products.map{ |x| x.attachments }
32
+ attachments.flatten!
33
+ end
34
+
35
+ def default_args
36
+ { key: key, parameters: { template: template, key: key, matches: matches, source: source } }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module ReviewedBraai
2
+ module Matchers
3
+ module Article
4
+ Braai::Template.map(/({{\s*article\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ArticleMethod)
5
+ Braai::Template.map(/({{\s*article.attachments\((\w+)\)\s*}})/i, ReviewedBraai::Handlers::ArticleAttachmentById)
6
+ Braai::Template.map(/({{\s*article.attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ArticleAttachmentByName)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module ReviewedBraai
2
+ module Matchers
3
+ module Attachment
4
+ Braai::Template.map(/({{\s*attachments\((\w+)\))/i, ReviewedBraai::Handlers::AttachmentsById)
5
+ Braai::Template.map(/({{\s*attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::AttachmentsByName)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module ReviewedBraai
2
+ module Matchers
3
+ module Product
4
+ Braai::Template.map(/({{\s*product\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductMethod)
5
+ Braai::Template.map(/({{\s*product.attachments\((\w+)\)\s*}})/i, ReviewedBraai::Handlers::ProductAttachmentById)
6
+ Braai::Template.map(/({{\s*product.attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductAttachmentByName)
7
+ Braai::Template.map(/({{\s*products\((\w+)\)\.(\w+)\s*}})/i, ReviewedBraai::Handlers::ProductsMethod)
8
+ Braai::Template.map(/({{\s*products\((\w+)\)\.attachments\((\w+)\)\s*}})/i, ReviewedBraai::Handlers::ProductsAttachmentById)
9
+ Braai::Template.map(/({{\s*products\((\w+)\)\.attachments\[['|"]([^\]\}]+)['|"]\]\s*}})/i, ReviewedBraai::Handlers::ProductsAttachmentByName)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ require 'reviewed_braai/matchers/product'
2
+ require 'reviewed_braai/matchers/attachment'
3
+ require 'reviewed_braai/matchers/article'
@@ -0,0 +1,10 @@
1
+ <script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
2
+ <object id="myPlayer" class="BrightcoveExperience">
3
+ <param name="bgcolor" value="#FFFFFF" />
4
+ <param name="width" value="559" />
5
+ <param name="height" value="412" />
6
+ <param name="playerID" value="1832000879001" />
7
+ <param name="playerKey" value="AQ~~,AAAAstMe5SE~,5vOZeV6rFDb4JUBomUtNzVLbOfHyhc1i" />
8
+ <param name="isVid" value="true" />
9
+ <param name="@videoPlayer" value="{{ brightcove_id }}" />
10
+ </object>
@@ -0,0 +1 @@
1
+ <img src="{{ url }}" alt="{{ description }}" class="attachment" />
@@ -0,0 +1,3 @@
1
+ module ReviewedBraai
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'braai'
2
+ require 'ostruct'
3
+
4
+ require 'reviewed_braai/helpers'
5
+ require 'reviewed_braai/attachment'
6
+ require 'reviewed_braai/handler'
7
+ require 'reviewed_braai/errors'
8
+ require 'reviewed_braai/matchers'
9
+
10
+ module ReviewedBraai
11
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :reviewed_braai do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reviewed_braai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Incorvia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: braai
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email:
48
+ - kincorvia@reviewed.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/reviewed_braai/attachment.rb
54
+ - lib/reviewed_braai/errors.rb
55
+ - lib/reviewed_braai/handler.rb
56
+ - lib/reviewed_braai/handlers/articles.rb
57
+ - lib/reviewed_braai/handlers/attachments.rb
58
+ - lib/reviewed_braai/handlers/base.rb
59
+ - lib/reviewed_braai/handlers/products.rb
60
+ - lib/reviewed_braai/helpers.rb
61
+ - lib/reviewed_braai/matchers/article.rb
62
+ - lib/reviewed_braai/matchers/attachment.rb
63
+ - lib/reviewed_braai/matchers/product.rb
64
+ - lib/reviewed_braai/matchers.rb
65
+ - lib/reviewed_braai/templates/brightcove_video.html
66
+ - lib/reviewed_braai/templates/image.html
67
+ - lib/reviewed_braai/version.rb
68
+ - lib/reviewed_braai.rb
69
+ - lib/tasks/reviewed_braai_tasks.rake
70
+ - MIT-LICENSE
71
+ - Rakefile
72
+ - README.rdoc
73
+ homepage: http://www.reviewed.com
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.24
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Braai matchers for Reviewed.com
97
+ test_files: []
98
+ has_rdoc: