adify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +110 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/adify.gemspec +88 -0
- data/lib/adify.rb +53 -0
- data/lib/adify/controller.rb +46 -0
- data/lib/adify/helper.rb +18 -0
- data/lib/adify/model.rb +41 -0
- data/lib/generators/adify/USAGE +8 -0
- data/lib/generators/adify/templates/_dfp.html.erb +1 -0
- data/lib/generators/adify_generator.rb +14 -0
- data/spec/adify_spec.rb +47 -0
- data/spec/spec_helper.rb +28 -0
- metadata +253 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create ruby-1.8.7@adify
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "rails", ">= 2.3.5"
|
5
|
+
gem "activesupport", ">= 2.3.5"
|
6
|
+
gem "activerecord", ">= 2.3.5"
|
7
|
+
gem "actionpack", ">= 2.3.5"
|
8
|
+
gem 'deep_merge'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rspec-rails", "~> 2.3.0"
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.6.0"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
gem 'ruby-debug'
|
18
|
+
gem 'sqlite3'
|
19
|
+
end
|
20
|
+
|
21
|
+
group :test do
|
22
|
+
gem 'ruby-debug'
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
arel (2.0.10)
|
32
|
+
builder (2.1.2)
|
33
|
+
columnize (0.3.2)
|
34
|
+
deep_merge (0.1.0)
|
35
|
+
diff-lcs (1.1.2)
|
36
|
+
erubis (2.6.6)
|
37
|
+
abstract (>= 1.0.0)
|
38
|
+
git (1.2.5)
|
39
|
+
i18n (0.5.0)
|
40
|
+
jeweler (1.6.0)
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
git (>= 1.2.5)
|
43
|
+
rake
|
44
|
+
linecache (0.43)
|
45
|
+
mail (2.2.19)
|
46
|
+
activesupport (>= 2.3.6)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.16)
|
51
|
+
polyglot (0.3.1)
|
52
|
+
rack (1.2.3)
|
53
|
+
rack-mount (0.6.14)
|
54
|
+
rack (>= 1.0.0)
|
55
|
+
rack-test (0.5.7)
|
56
|
+
rack (>= 1.0)
|
57
|
+
rails (3.0.7)
|
58
|
+
actionmailer (= 3.0.7)
|
59
|
+
actionpack (= 3.0.7)
|
60
|
+
activerecord (= 3.0.7)
|
61
|
+
activeresource (= 3.0.7)
|
62
|
+
activesupport (= 3.0.7)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
railties (= 3.0.7)
|
65
|
+
railties (3.0.7)
|
66
|
+
actionpack (= 3.0.7)
|
67
|
+
activesupport (= 3.0.7)
|
68
|
+
rake (>= 0.8.7)
|
69
|
+
thor (~> 0.14.4)
|
70
|
+
rake (0.9.0)
|
71
|
+
rcov (0.9.9)
|
72
|
+
rspec (2.3.0)
|
73
|
+
rspec-core (~> 2.3.0)
|
74
|
+
rspec-expectations (~> 2.3.0)
|
75
|
+
rspec-mocks (~> 2.3.0)
|
76
|
+
rspec-core (2.3.1)
|
77
|
+
rspec-expectations (2.3.0)
|
78
|
+
diff-lcs (~> 1.1.2)
|
79
|
+
rspec-mocks (2.3.0)
|
80
|
+
rspec-rails (2.3.1)
|
81
|
+
actionpack (~> 3.0)
|
82
|
+
activesupport (~> 3.0)
|
83
|
+
railties (~> 3.0)
|
84
|
+
rspec (~> 2.3.0)
|
85
|
+
ruby-debug (0.10.4)
|
86
|
+
columnize (>= 0.1)
|
87
|
+
ruby-debug-base (~> 0.10.4.0)
|
88
|
+
ruby-debug-base (0.10.4)
|
89
|
+
linecache (>= 0.3)
|
90
|
+
sqlite3 (1.3.3)
|
91
|
+
thor (0.14.6)
|
92
|
+
treetop (1.4.9)
|
93
|
+
polyglot (>= 0.3.1)
|
94
|
+
tzinfo (0.3.27)
|
95
|
+
|
96
|
+
PLATFORMS
|
97
|
+
ruby
|
98
|
+
|
99
|
+
DEPENDENCIES
|
100
|
+
actionpack (>= 2.3.5)
|
101
|
+
activerecord (>= 2.3.5)
|
102
|
+
activesupport (>= 2.3.5)
|
103
|
+
bundler (~> 1.0.0)
|
104
|
+
deep_merge
|
105
|
+
jeweler (~> 1.6.0)
|
106
|
+
rails (>= 2.3.5)
|
107
|
+
rcov
|
108
|
+
rspec-rails (~> 2.3.0)
|
109
|
+
ruby-debug
|
110
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Eric Harrison
|
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,19 @@
|
|
1
|
+
= Adify
|
2
|
+
|
3
|
+
Adify is a simple to use (hopefully) rails gem that builds up ad tags for cashing in on your users. Adify is built to work with any ad server. The initial build will only include DFP (Google Ad Manager) as that is what I need this gem for.
|
4
|
+
|
5
|
+
This is just the initial version and isn't really complete. I haven't worked with other adservers so it might be a little tailored to double click. Also the generator is butchered right now.
|
6
|
+
|
7
|
+
== Contributing to adify
|
8
|
+
|
9
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
10
|
+
* Fork me
|
11
|
+
* Start a feature/bugfix branch
|
12
|
+
* Do stuff
|
13
|
+
* Tests. Pull requests without tests will be flogged publically. Feel free to flog me for forgetting tests then add them.\
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Eric Harrison. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "adify"
|
18
|
+
gem.homepage = "http://github.com/fuelxc/adify"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "create ad tags for common ad servers easily."
|
21
|
+
gem.description = "Adify lets you create ad tags easily and quickly with a simple common structure"
|
22
|
+
gem.email = "eharrison@classifiedadventures.com"
|
23
|
+
gem.authors = ["Eric Harrison"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "adify #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/adify.gemspec
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{adify}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Eric Harrison"]
|
12
|
+
s.date = %q{2011-05-30}
|
13
|
+
s.description = %q{Adify lets you create ad tags easily and quickly with a simple common structure}
|
14
|
+
s.email = %q{eharrison@classifiedadventures.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"adify.gemspec",
|
30
|
+
"lib/adify.rb",
|
31
|
+
"lib/adify/controller.rb",
|
32
|
+
"lib/adify/helper.rb",
|
33
|
+
"lib/adify/model.rb",
|
34
|
+
"lib/generators/adify/USAGE",
|
35
|
+
"lib/generators/adify/templates/_dfp.html.erb",
|
36
|
+
"lib/generators/adify_generator.rb",
|
37
|
+
"spec/adify_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/fuelxc/adify}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.5.1}
|
44
|
+
s.summary = %q{create ad tags for common ad servers easily.}
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<rails>, [">= 2.3.5"])
|
51
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
52
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
|
53
|
+
s.add_runtime_dependency(%q<actionpack>, [">= 2.3.5"])
|
54
|
+
s.add_runtime_dependency(%q<deep_merge>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec-rails>, ["~> 2.3.0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
58
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rails>, [">= 2.3.5"])
|
63
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
64
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
65
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
66
|
+
s.add_dependency(%q<deep_merge>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.3.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
72
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<rails>, [">= 2.3.5"])
|
76
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
77
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
78
|
+
s.add_dependency(%q<actionpack>, [">= 2.3.5"])
|
79
|
+
s.add_dependency(%q<deep_merge>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.3.0"])
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
82
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
83
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
84
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
85
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
data/lib/adify.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require "active_record"
|
3
|
+
require "active_support"
|
4
|
+
|
5
|
+
require 'deep_merge'
|
6
|
+
|
7
|
+
require 'adify/controller'
|
8
|
+
require "adify/model"
|
9
|
+
require "adify/helper"
|
10
|
+
|
11
|
+
#methods both controller and models call
|
12
|
+
module Adify
|
13
|
+
module InstanceMethods
|
14
|
+
def adify(*args)
|
15
|
+
self.adify_instance_attributes = *args
|
16
|
+
end
|
17
|
+
|
18
|
+
def adify_attributes
|
19
|
+
ad_attr = self.adify_instance_attributes || {}
|
20
|
+
self.class.adify_attributes.deep_merge(ad_attr) rescue ad_attr
|
21
|
+
end
|
22
|
+
|
23
|
+
def adification(item = nil)
|
24
|
+
ad_attr = item.nil? ? self.adify_attributes : self.adify_attributes.deep_merge(item.adify_attributes)
|
25
|
+
item_for_adification = item.nil? ? self : item
|
26
|
+
@adification_of_item = ad_attr.update_values{|v| get_adify_value(item_for_adification,v)}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def get_adify_value(*args)
|
31
|
+
self.class.send(:get_adify_value, *args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class ActiveRecord::Base
|
37
|
+
include Adify::Model
|
38
|
+
end
|
39
|
+
|
40
|
+
class ActionController::Base
|
41
|
+
include Adify::Controller
|
42
|
+
end
|
43
|
+
|
44
|
+
class ActionView::Base
|
45
|
+
include AdifyHelper
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
class Hash
|
50
|
+
def update_values(&block)
|
51
|
+
self.update(self){|k,v| block.call v}
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Adify
|
2
|
+
module Controller
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
#TODO: refactor this up so both model and controller use same code. DRY
|
8
|
+
module ClassMethods
|
9
|
+
def adify(*args)
|
10
|
+
class_eval <<-EOV
|
11
|
+
cattr_accessor :adify_#{self.to_s.tableize.gsub(/\//,'_')}_attributes
|
12
|
+
cattr_accessor :adify_tag_number
|
13
|
+
|
14
|
+
def self.adify_attributes=(hash)
|
15
|
+
self.adify_#{self.to_s.tableize}_attributes = hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.adify_attributes
|
19
|
+
self.ancestors[1].adify_attributes.deep_merge(self.adify_#{self.to_s.tableize.gsub(/\//,'_')}_attributes) rescue self.adify_#{self.to_s.tableize.gsub(/\//,'_')}_attributes
|
20
|
+
end
|
21
|
+
EOV
|
22
|
+
|
23
|
+
attr_accessor :adify_instance_attributes
|
24
|
+
helper_method :adification
|
25
|
+
send :include, ::Adify::InstanceMethods
|
26
|
+
|
27
|
+
def self.adification
|
28
|
+
@adification_of_item = self.adify_attributes.update_values{|v| get_adify_value(self,v)}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def get_adify_value(item,value)
|
33
|
+
case value.class.to_s
|
34
|
+
when 'Array' then value.each.collect{|v| get_adify_value(item,v)}
|
35
|
+
when 'Proc' then value.call item
|
36
|
+
when 'Hash' then value.update(value){|k,v| get_adify_value(item,v)}
|
37
|
+
when 'Symbol' then item.respond_to?(value) ? item.send(value) : value
|
38
|
+
else value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
self.adify_attributes = *args
|
42
|
+
self.adify_tag_number = 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/adify/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module AdifyHelper
|
2
|
+
|
3
|
+
def adify_tag(args)
|
4
|
+
item = args.delete(:item) rescue nil
|
5
|
+
partial = args.delete(:partial) || 'adify/dfp'
|
6
|
+
tag_attributes = adification(item).merge(args)
|
7
|
+
#pass in the hash as a parameter too in case they need all the value but don't know the names
|
8
|
+
render :partial => partial, :locals => tag_attributes.merge(:tag_attributes => tag_attributes.clone)
|
9
|
+
end
|
10
|
+
|
11
|
+
def random(length)
|
12
|
+
Array.new(length){rand 9}.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def tag_number
|
16
|
+
@controller.class.adify_tag_number += 1
|
17
|
+
end
|
18
|
+
end
|
data/lib/adify/model.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Adify
|
2
|
+
module Model
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
#TODO: refactor this up so both model and controller use same code. DRY
|
8
|
+
module ClassMethods
|
9
|
+
def adify(*args)
|
10
|
+
@@adify_class_attributes = HashWithIndifferentAccess.new()
|
11
|
+
attr_accessor :adify_instance_attributes
|
12
|
+
send :include, ::Adify::InstanceMethods
|
13
|
+
|
14
|
+
def self.adify_attributes=(hash)
|
15
|
+
@@adify_class_attributes = hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.adification
|
19
|
+
@adification_of_item = self.adify_attributes.update_values{|v| get_adify_value(self,v)}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.adify_attributes
|
23
|
+
super.deep_merge(@@adify_class_attributes) rescue @@adify_class_attributes
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def get_adify_value(item,value)
|
28
|
+
case value.class
|
29
|
+
when Array then value.each.collect{|v| self.get_adify_value(item,v)}
|
30
|
+
when Proc then (value.call item).to_s
|
31
|
+
when Hash then value.update(value){|k,v| self.get_adify_value(item,v)}
|
32
|
+
when Symbol then item.respond_to?(value) ? item.send(value) : value
|
33
|
+
else value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
self.adify_attributes = *args
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<iframe width="<%= width %>" height="<%= height %>" scrolling="no" frameborder="0" class="adIframe" tabindex="-1" src="http://ad.au.doubleclick.net/adi/rea.buy/homepage/sales/vic;sect=homepage;state=vic;proptype=null;type=sales;pos=article1;sz=<%= width %>x<%= height %>;tile=<%= tile %>;ord=<%= ord %>?" style="visibility: hidden; "></iframe>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Adify
|
2
|
+
class AdifyGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :partial_type, :type => :string, :default => "dfp"
|
5
|
+
|
6
|
+
def self.banner
|
7
|
+
"rails generate adify:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_partial
|
11
|
+
template "_#{partial_type}.html.erb", "app/views/adify/_#{partial_type}.html.erb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/adify_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class Item < ActiveRecord::Base
|
4
|
+
adify :item_only => :id, :override_by_item => 'item'
|
5
|
+
|
6
|
+
def id
|
7
|
+
"item id via symbol"
|
8
|
+
end
|
9
|
+
|
10
|
+
def proc
|
11
|
+
"proc return"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyBaseController < ActionController::Base
|
16
|
+
adify :override_by_item => 'Base', :base_only => ['base_arry_only_1', {:item1 => 'base array only 2'}], :override_by_controller => 'base', :override_by_action => 'base'
|
17
|
+
end
|
18
|
+
|
19
|
+
class MyController < MyBaseController
|
20
|
+
adify :override_by_item => 'Controller', :controller_only => :symbol_no_method, :override_by_controller => 'controller', :override_by_action => 'controller'
|
21
|
+
|
22
|
+
def index
|
23
|
+
#maybe rename this
|
24
|
+
adify(:override_by_item => "Action", :override_by_action => 'Action', :action_only => Proc.new(){|item| item.proc})
|
25
|
+
item = Item.new
|
26
|
+
@adtag = adification(item)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Adify do
|
31
|
+
describe 'adification' do
|
32
|
+
it "should merge things properly" do
|
33
|
+
app = MyController.new
|
34
|
+
adify = app.index
|
35
|
+
adify.should_not be_nil
|
36
|
+
adify.should == {
|
37
|
+
:override_by_action => "Action",
|
38
|
+
:override_by_item => "item",
|
39
|
+
:controller_only => :symbol_no_method,
|
40
|
+
:base_only => ["base_arry_only_1", {:item1 => "base array only 2"}],
|
41
|
+
:action_only => "proc return",
|
42
|
+
:override_by_controller => "controller",
|
43
|
+
:item_only => "item id via symbol"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'active_record'
|
4
|
+
require 'action_controller'
|
5
|
+
require 'rspec'
|
6
|
+
require 'adify'
|
7
|
+
require 'sqlite3'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
#ActiveRecord::Schema.verbose = false
|
18
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
19
|
+
|
20
|
+
ActiveRecord::Base.configurations = true
|
21
|
+
ActiveRecord::Schema.define(:version => 1) do
|
22
|
+
create_table :items do |t|
|
23
|
+
t.datetime :created_at
|
24
|
+
t.datetime :updated_at
|
25
|
+
t.string :name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
metadata
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Eric Harrison
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-30 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 5
|
34
|
+
version: 2.3.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 5
|
50
|
+
version: 2.3.5
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: activerecord
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 9
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
- 5
|
66
|
+
version: 2.3.5
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 9
|
78
|
+
segments:
|
79
|
+
- 2
|
80
|
+
- 3
|
81
|
+
- 5
|
82
|
+
version: 2.3.5
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: deep_merge
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
type: :runtime
|
98
|
+
version_requirements: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rspec-rails
|
101
|
+
prerelease: false
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ~>
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 2
|
110
|
+
- 3
|
111
|
+
- 0
|
112
|
+
version: 2.3.0
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: bundler
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 23
|
124
|
+
segments:
|
125
|
+
- 1
|
126
|
+
- 0
|
127
|
+
- 0
|
128
|
+
version: 1.0.0
|
129
|
+
type: :development
|
130
|
+
version_requirements: *id007
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: jeweler
|
133
|
+
prerelease: false
|
134
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ~>
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 15
|
140
|
+
segments:
|
141
|
+
- 1
|
142
|
+
- 6
|
143
|
+
- 0
|
144
|
+
version: 1.6.0
|
145
|
+
type: :development
|
146
|
+
version_requirements: *id008
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: rcov
|
149
|
+
prerelease: false
|
150
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 3
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
version: "0"
|
159
|
+
type: :development
|
160
|
+
version_requirements: *id009
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: ruby-debug
|
163
|
+
prerelease: false
|
164
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
hash: 3
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
173
|
+
type: :development
|
174
|
+
version_requirements: *id010
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: sqlite3
|
177
|
+
prerelease: false
|
178
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
hash: 3
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
version: "0"
|
187
|
+
type: :development
|
188
|
+
version_requirements: *id011
|
189
|
+
description: Adify lets you create ad tags easily and quickly with a simple common structure
|
190
|
+
email: eharrison@classifiedadventures.com
|
191
|
+
executables: []
|
192
|
+
|
193
|
+
extensions: []
|
194
|
+
|
195
|
+
extra_rdoc_files:
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.rdoc
|
198
|
+
files:
|
199
|
+
- .document
|
200
|
+
- .rspec
|
201
|
+
- .rvmrc
|
202
|
+
- Gemfile
|
203
|
+
- Gemfile.lock
|
204
|
+
- LICENSE.txt
|
205
|
+
- README.rdoc
|
206
|
+
- Rakefile
|
207
|
+
- VERSION
|
208
|
+
- adify.gemspec
|
209
|
+
- lib/adify.rb
|
210
|
+
- lib/adify/controller.rb
|
211
|
+
- lib/adify/helper.rb
|
212
|
+
- lib/adify/model.rb
|
213
|
+
- lib/generators/adify/USAGE
|
214
|
+
- lib/generators/adify/templates/_dfp.html.erb
|
215
|
+
- lib/generators/adify_generator.rb
|
216
|
+
- spec/adify_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
has_rdoc: true
|
219
|
+
homepage: http://github.com/fuelxc/adify
|
220
|
+
licenses:
|
221
|
+
- MIT
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
|
225
|
+
require_paths:
|
226
|
+
- lib
|
227
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
hash: 3
|
233
|
+
segments:
|
234
|
+
- 0
|
235
|
+
version: "0"
|
236
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
|
+
none: false
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
hash: 3
|
242
|
+
segments:
|
243
|
+
- 0
|
244
|
+
version: "0"
|
245
|
+
requirements: []
|
246
|
+
|
247
|
+
rubyforge_project:
|
248
|
+
rubygems_version: 1.5.1
|
249
|
+
signing_key:
|
250
|
+
specification_version: 3
|
251
|
+
summary: create ad tags for common ad servers easily.
|
252
|
+
test_files: []
|
253
|
+
|