omniturize 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,9 +38,7 @@ module Omniturize
38
38
  def filter_collection_for_action(collection, action)
39
39
  return collection if action.blank?
40
40
  collection.select do |element|
41
- (element.only.present? && element.only.include?(action.try(:to_sym))) ||
42
- (element.except.present? && !element.except.include?(action.try(:to_sym))) ||
43
- (element.only.blank? && element.except.blank?)
41
+ element.passes_filter?(action)
44
42
  end
45
43
  end
46
44
 
@@ -77,13 +75,21 @@ module Omniturize
77
75
  end
78
76
  end
79
77
 
78
+ def find_vars(name, options = {})
79
+ meta_vars_to_vars(self.class.find_meta_vars(name, options))
80
+ end
81
+
80
82
  def find_var(name, options = {})
81
- vars(options[:action]).detect{|x|x.matches_name?(name)}
83
+ find_vars(name, options).first
84
+ end
85
+
86
+ def find_values(name, options = {})
87
+ find_vars(name, options).map(&:value)
82
88
  end
83
89
 
84
90
  def meta_vars_to_vars(meta_vars)
85
91
  meta_vars.inject([]) do |vars, meta_var|
86
- vars << meta_var.value(controller) if meta_var
92
+ vars << (meta_var.value(controller) if meta_var) rescue nil
87
93
  vars
88
94
  end
89
95
  end
@@ -36,7 +36,21 @@ module Omniture
36
36
 
37
37
  def return_var(scope)
38
38
  value_procs.map{ |p| scope.instance_eval(&p) }.flatten.uniq.join(delimiter)
39
- #scope.instance_eval(&p)
40
39
  end
40
+
41
+ def passes_filter?(filter)
42
+ passes_only_filter?(filter) && passes_except_filter?(filter)
43
+ end
44
+
45
+ private
46
+
47
+ def passes_only_filter?(filter)
48
+ only.blank? || only.detect{|x| x.is_a?(Regexp) ? filter.match(x) : filter.to_sym == x.to_sym}.present?
49
+ end
50
+
51
+ def passes_except_filter?(filter)
52
+ except.blank? || except.detect{|x| x.is_a?(Regexp) ? filter.match(x) : filter.to_sym == x.to_sym}.blank?
53
+ end
54
+
41
55
  end
42
56
  end
@@ -48,6 +48,20 @@ module Omniturize
48
48
  else raise ArgumentError.new('name must be a String or a Regexp')
49
49
  end
50
50
  end
51
-
51
+
52
+ def passes_filter?(filter)
53
+ passes_only_filter?(filter) && passes_except_filter?(filter)
54
+ end
55
+
56
+ private
57
+
58
+ def passes_only_filter?(filter)
59
+ only.blank? || only.detect{|x| x.is_a?(Regexp) ? filter.match(x) : filter.to_sym == x.to_sym}.present?
60
+ end
61
+
62
+ def passes_except_filter?(filter)
63
+ except.blank? || except.detect{|x| x.is_a?(Regexp) ? filter.match(x) : filter.to_sym == x.to_sym}.blank?
64
+ end
65
+
52
66
  end
53
67
  end
@@ -8,9 +8,11 @@ module Omniturize
8
8
  end
9
9
 
10
10
  def js(options = {})
11
+ html_options = []
12
+ options[:html_options].each_pair{|k,v| html_options << "#{k}=\"#{v}\""} if options[:html_options].present?
11
13
  output = <<-JS
12
14
  <script type="text/javascript" language="JavaScript" src="#{Omniturize::js_src}"></script>
13
- <script type="text/javascript" language="JavaScript">
15
+ <script type="text/javascript" language="JavaScript" #{html_options.join(' ')}>
14
16
  #{js_vars(options)}
15
17
  #{print_js_events(options)}
16
18
  #{print_js_snippets(options)}
@@ -42,7 +44,7 @@ module Omniturize
42
44
 
43
45
  def print_js_events(options = {})
44
46
  values = js_events(options).join(',')
45
- values.blank? ? nil : "s.events = \"#{values}\""
47
+ values.blank? ? nil : "s.events=\"#{values}\""
46
48
  end
47
49
 
48
50
  def print_js_snippets(options = {})
@@ -1,3 +1,3 @@
1
1
  module Omniturize
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -21,7 +21,7 @@ module Omniturize
21
21
 
22
22
  @reporter ||= begin
23
23
  options[:controller].present? ? "#{options[:controller].classify}Reporter".constantize.new(self) :
24
- "#{self.controller_name.capitalize}Reporter".constantize.new(self)
24
+ "#{self.class.name.gsub(/Controller$/, '')}Reporter".constantize.new(self)
25
25
  rescue NameError
26
26
  BasicReporter.new(self)
27
27
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniturize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - eLafo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-13 00:00:00 Z
18
+ date: 2011-09-17 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: This gem integrates Omniture SiteCatalyst into your web app. You can specify vars, events and custom javascript for every action of a controller. This gem is proudly based on the omniture_client gem, from which it takes much code and ideas