cm_tag 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in campaign_monitor.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ campaign_monitor (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ campaign_monitor ()!
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/cm_tag.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cm_tag/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cm_tag"
7
+ s.version = CampaignMonitor::VERSION
8
+ s.authors = ["Pragash"]
9
+ s.email = ["pragashonlink@gmail.com"]
10
+ s.homepage = "http://pragashblog.blogspot.com"
11
+ s.summary = %q{Campaign monitor tags in rails}
12
+ s.description = %q{This gem can be used to implement campaign monitor tags in a rails application}
13
+
14
+ s.rubyforge_project = "campaign_monitor"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/lib/cm_tag.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "cm_tag/version"
2
+ require "cm_tag/campaign_tag"
3
+ require "cm_tag/campaign_process"
4
+
5
+ module CMTag
6
+ class << self
7
+ def find_tags(html)
8
+ cp = ProcessTag::CampaignProcess.new
9
+ cp.process(html)
10
+
11
+ return cp.get_tags
12
+ end
13
+
14
+ def update_tags(html, params = {}, replace_tags = false)
15
+ cp = ProcessTag::CampaignProcess.new
16
+ cp.update_tags(html, params, replace_tags)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require 'cm_tag/process.rb'
2
+
3
+ module ProcessTag
4
+
5
+ class CampaignProcess
6
+ include Process
7
+
8
+ def process(html)
9
+ raise ArgumentError, "Argument [html] cannot be empty" if html.rstrip == ""
10
+
11
+ self.find_all(html)
12
+ end
13
+
14
+ def update_tags(html, params = {}, replace_tags = false)
15
+ raise ArgumentError, "Argument [params] cannot be empty" unless params.length > 0
16
+ raise ArgumentError, "Argument [html] cannot be empty" if html.rstrip == ""
17
+
18
+ #load the html tags
19
+ self.find_all(html)
20
+
21
+ html = self.update_campaign_tags(html, params, (@description_tags.nil? && []) || @description_tags)
22
+ html = self.update_campaign_tags(html, params, (@title_tags.nil? && []) || @title_tags)
23
+ html = self.update_campaign_tags(html, params, (@imgsrc_tags.nil? && []) || @imgsrc_tags)
24
+ html = self.update_campaign_tags(html, params, (@linkhref_tags.nil? && []) || @linkhref_tags)
25
+
26
+ puts "replace tags #{replace_tags}"
27
+
28
+ if replace_tags
29
+ html = self.transform_campaign_to_html_tags(html, params, (@description_tags.nil? && []) || @description_tags)
30
+ html = self.transform_campaign_to_html_tags(html, params, (@title_tags.nil? && []) || @title_tags)
31
+ html = self.transform_campaign_to_html_tags(html, params, (@imgsrc_tags.nil? && []) || @imgsrc_tags)
32
+ html = self.transform_campaign_to_html_tags(html, params, (@linkhref_tags.nil? && []) || @linkhref_tags)
33
+ end
34
+
35
+ html
36
+ end
37
+
38
+ def get_tags
39
+ tags = {}
40
+ tags[:description] = (@description_tags.nil? && []) || @description_tags
41
+ tags[:title] = (@title_tags.nil? && []) || @title_tags
42
+ tags[:image] = (@imgsrc_tags.nil? && []) || @imgsrc_tags
43
+ tags[:href] = (@linkhref_tags.nil? && []) || @linkhref_tags
44
+
45
+ tags
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,107 @@
1
+ module ProcessTag
2
+
3
+ class CampaignTag
4
+ attr_accessor :id, :type, :label, :value, :arr_html
5
+
6
+ def regex_for_current_data
7
+ values = get_values
8
+
9
+ tag = "<%"
10
+ tag << type
11
+ tag << "(.*?)"
12
+ tag << "name"
13
+ tag << "(.*?)"
14
+ tag << "="
15
+ tag << "(.*?)"
16
+ tag << "['\"\]"
17
+ tag << values[0]
18
+ tag << "['\"\]"
19
+ tag << "(.*?)"
20
+ tag << "value"
21
+ tag << "(.*?)"
22
+ tag << "="
23
+ tag << "(.*?)"
24
+ tag << "%>"
25
+
26
+ regex = Regexp.new(tag)
27
+
28
+ regex
29
+ end
30
+
31
+ def regex_to_replace_campaign_tags(value)
32
+ values = get_values
33
+
34
+ tag = "<%"
35
+ tag << "(.*?)"
36
+ tag << type
37
+ tag << "(.*?)"
38
+ tag << "name"
39
+ tag << "(.*?)"
40
+ tag << "="
41
+ tag << "(.*?)"
42
+ tag << values[0]
43
+ tag << "(.*?)"
44
+ tag << "value"
45
+ tag << "(.*?)"
46
+ tag << "="
47
+ tag << "(.*?)"
48
+ tag << "['\"\]"
49
+ tag << value
50
+ tag << "['\"\]"
51
+ tag << "(.*?)"
52
+ tag << "%>"
53
+
54
+ regex = Regexp.new(tag)
55
+
56
+ regex
57
+ end
58
+
59
+ def generate_html_content(value)
60
+ replace_value = ""
61
+ html_tag = ""
62
+
63
+ case type
64
+ when "description"
65
+ html_tag = "p"
66
+ when "title"
67
+ html_tag = "span"
68
+ end
69
+
70
+ case html_tag
71
+ when "p", "span"
72
+ replace_value = "<#{html_tag}>#{value}</#{html_tag}>"
73
+ else
74
+ replace_value = value
75
+ end
76
+
77
+ replace_value
78
+ end
79
+
80
+ def generate_element_with_new_value(value)
81
+ values = get_values
82
+
83
+ "<%#{type} name=\"#{values[0]}\ value=\"#{value}\"%>"
84
+ end
85
+
86
+ def get_values
87
+ v = []
88
+
89
+ arr_html.each do |d|
90
+ unless d.rstrip == ""
91
+ v << d
92
+
93
+ break if v.length == 2
94
+ end
95
+ end
96
+
97
+ if v.length == 0
98
+ v << ""
99
+ v << ""
100
+ end
101
+
102
+ v
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,100 @@
1
+ module Process
2
+ #regular expression for html fields
3
+ DESC_EXP = "<%description(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
4
+ TTL_EXP = "<%title(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
5
+ IMAGE_EXP = "<%imgsrc(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
6
+ HREF_EXP = "<%linkhref(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
7
+
8
+ #regular expression for date fields
9
+ CD_EXP = "<%currentday%>"
10
+ CDN_EXP = "<%currentdayname%>"
11
+ CM_EXP = "<%currentmonth%>"
12
+ CMN_EXP = "<%currentmonthname%>"
13
+ CY_EXP = "<%currentyear%>"
14
+
15
+ def find_all(html)
16
+ find_html_tags(html)
17
+ end
18
+
19
+ #update the current campaign tags with new values
20
+ def update_campaign_tags(html, params, values)
21
+ i = 0
22
+
23
+ values.each do |value|
24
+ field_id = "#{value.type}_tag_#{i}"
25
+ input_value = (params[field_id.to_s].nil? && '') || params[field_id.to_s]
26
+ rx = value.regex_for_current_data #generate and extract the correct element to be replaced
27
+
28
+ html = html.gsub(rx, value.generate_element_with_new_value(input_value)) #replace the new value in the html data
29
+
30
+ i += 1
31
+ end
32
+
33
+ html
34
+ end
35
+
36
+ def transform_campaign_to_html_tags(html, params, values)
37
+ i = 0
38
+
39
+ values.each do |value|
40
+ field_id = "#{value.type}_tag_#{i}"
41
+ input_value = (params[field_id.to_s].nil? && '') || params[field_id.to_s]
42
+ rx = value.regex_to_replace_campaign_tags(input_value)
43
+ new_value = value.generate_html_content(input_value)
44
+
45
+ html = html.gsub(rx, new_value) #replace the new value in the html data
46
+
47
+ i += 1
48
+ end
49
+
50
+ html
51
+ end
52
+
53
+ #[[" ", "", "", "name", " ", "", "", "default", ""]]
54
+ def find_html_tags(html)
55
+ [DESC_EXP, TTL_EXP, IMAGE_EXP, HREF_EXP].each do |exp|
56
+ name = ""
57
+ i = 0
58
+
59
+ if exp == DESC_EXP
60
+ name = "description"
61
+ elsif exp == TTL_EXP
62
+ name = "title"
63
+ elsif exp == IMAGE_EXP
64
+ name = "imgsrc"
65
+ elsif exp == HREF_EXP
66
+ name = "linkhref"
67
+ end
68
+
69
+ eval("@#{name}_tags = []")
70
+ matches = self.scan_exp(html, exp)
71
+ next if matches.length == 0
72
+
73
+ matches.each do |m|
74
+ tag = ProcessTag::CampaignTag.new
75
+ tag.type = name
76
+ tag.arr_html = m #the array
77
+
78
+ #get name, value attributes from the tag
79
+ values = tag.get_values
80
+
81
+ tag.label = values[0] #name attribute
82
+ tag.value = values[1] #value attribute
83
+ tag.id = "#{name}_tag_#{i}"
84
+
85
+ eval("@#{name}_tags << tag")
86
+ i += 1
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ def scan_exp(html, exp)
94
+ regex = Regexp.new(exp)
95
+ matches = html.scan(regex)
96
+
97
+ matches
98
+ end
99
+
100
+ end
@@ -0,0 +1,3 @@
1
+ module CampaignMonitor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,170 @@
1
+ require 'cm_tag/campaign_tag'
2
+
3
+ module DataHelper
4
+ def generate_description_tags
5
+ desc = []
6
+
7
+ tag = ProcessTag::CampaignTag.new
8
+ tag.id = "description_tag_0"
9
+ tag.type = "description"
10
+ tag.label = "description 1"
11
+ tag.value = "This is description 1"
12
+ desc << tag
13
+
14
+ tag = ProcessTag::CampaignTag.new
15
+ tag.id = "description_tag_1"
16
+ tag.type = "description"
17
+ tag.label = "description 2"
18
+ tag.value = "This is description 2"
19
+ desc << tag
20
+
21
+ tag = ProcessTag::CampaignTag.new
22
+ tag.id = "description_tag_2"
23
+ tag.type = "description"
24
+ tag.label = "description 3"
25
+ tag.value = "This is description 3"
26
+ desc << tag
27
+
28
+ tag = ProcessTag::CampaignTag.new
29
+ tag.id = "description_tag_3"
30
+ tag.type = "description"
31
+ tag.label = "description 4"
32
+ tag.value = "This is description 4"
33
+ desc << tag
34
+
35
+ desc
36
+ end
37
+
38
+ def generate_title_tags
39
+ ttls = []
40
+
41
+ tag = ProcessTag::CampaignTag.new
42
+ tag.id = "title_tag_0"
43
+ tag.type = "title"
44
+ tag.label = "title 1"
45
+ tag.value = "This is title 1"
46
+ ttls << tag
47
+
48
+ tag = ProcessTag::CampaignTag.new
49
+ tag.id = "title_tag_1"
50
+ tag.type = "title"
51
+ tag.label = "title 2"
52
+ tag.value = "This is title 2"
53
+ ttls << tag
54
+
55
+ tag = ProcessTag::CampaignTag.new
56
+ tag.id = "title_tag_2"
57
+ tag.type = "title"
58
+ tag.label = "title 3"
59
+ tag.value = "This is title 3"
60
+ ttls << tag
61
+
62
+ tag = ProcessTag::CampaignTag.new
63
+ tag.id = "title_tag_3"
64
+ tag.type = "title"
65
+ tag.label = "title 4"
66
+ tag.value = "This is title 4"
67
+ ttls << tag
68
+
69
+ ttls
70
+ end
71
+
72
+ def generate_image_tags
73
+ images = []
74
+
75
+ tag = ProcessTag::CampaignTag.new
76
+ tag.id = "imgsrc_tag_0"
77
+ tag.type = "imgsrc"
78
+ tag.label = "Image source 1"
79
+ tag.value = "This is image 1"
80
+ images << tag
81
+
82
+ tag = ProcessTag::CampaignTag.new
83
+ tag.id = "imgsrc_tag_1"
84
+ tag.type = "imgsrc"
85
+ tag.label = "Image source 2"
86
+ tag.value = "This is image 2"
87
+ images << tag
88
+
89
+ tag = ProcessTag::CampaignTag.new
90
+ tag.id = "imgsrc_tag_2"
91
+ tag.type = "imgsrc"
92
+ tag.label = "Image source 3"
93
+ tag.value = "This is image 3"
94
+ images << tag
95
+
96
+ tag = ProcessTag::CampaignTag.new
97
+ tag.id = "imgsrc_tag_3"
98
+ tag.type = "imgsrc"
99
+ tag.label = "Image source 4"
100
+ tag.value = "This is image 4"
101
+ images << tag
102
+
103
+ images
104
+ end
105
+
106
+ def generate_href_tags
107
+ href = []
108
+
109
+ tag = ProcessTag::CampaignTag.new
110
+ tag.id = "linkhref_tag_0"
111
+ tag.type = "linkhref"
112
+ tag.label = "Href link 1"
113
+ tag.value = "This is href link 1"
114
+ href << tag
115
+
116
+ tag = ProcessTag::CampaignTag.new
117
+ tag.id = "linkhref_tag_1"
118
+ tag.type = "linkhref"
119
+ tag.label = "Href link 2"
120
+ tag.value = "This is href link 2"
121
+ href << tag
122
+
123
+ tag = ProcessTag::CampaignTag.new
124
+ tag.id = "linkhref_tag_2"
125
+ tag.type = "linkhref"
126
+ tag.label = "Href link 3"
127
+ tag.value = "This is href link 3"
128
+ href << tag
129
+
130
+ tag = ProcessTag::CampaignTag.new
131
+ tag.id = "linkhref_tag_3"
132
+ tag.type = "linkhref"
133
+ tag.label = "Href link 4"
134
+ tag.value = "This is href link 4"
135
+ href << tag
136
+
137
+ href
138
+ end
139
+
140
+ def check(tag)
141
+ f = File.open("/home/pragash/my_project/cm_tag/test/fixtures/#{tag}.html", "r")
142
+ html = ''
143
+ while(h = f.gets)
144
+ html << h
145
+ end
146
+
147
+ tags = CMTag.find_tags(html)
148
+ desc_hash = tags[tag.to_sym]
149
+ desc = eval("generate_#{tag}_tags")
150
+ equal = check_data(desc_hash, desc)
151
+
152
+ equal
153
+ end
154
+
155
+ def check_data(results, control_results)
156
+ i = 0
157
+ equal = false
158
+
159
+ results.each do |item|
160
+ equal = (control_results[i].id == item.id && control_results[i].type == item.type && control_results[i].label == item.label && control_results[i].value == item.value)
161
+
162
+ break unless equal
163
+
164
+ i += 1
165
+ end
166
+
167
+ equal
168
+ end
169
+
170
+ end
@@ -0,0 +1,72 @@
1
+ #image tag = src="<campaign_image path='(.*?)'\/>"
2
+ #title = <campaign_title value=('|")(.*?)('|")\/>
3
+ #sample code
4
+ #>> exp = "\<campaign_title value=('|\")(.*?)('|\")\/>"
5
+ #=> "<campaign_title value=('|\")(.*?)('|\")/>"
6
+ #>> title = "<campaign_title value='test tile'/>"
7
+ #=> "<campaign_title value='test tile'/>"
8
+ #>> regex = Regexp.new(exp)
9
+ #=> /<campaign_title value=('|")(.*?)('|")\/>/
10
+ #>> title.match(regex)
11
+ #=> #<MatchData "<campaign_title value='test tile'/>" 1:"'" 2:"test tile" 3:"'">
12
+ #>> match = title.match(regex)
13
+ #=> #<MatchData "<campaign_title value='test tile'/>" 1:"'" 2:"test tile" 3:"'">
14
+ #>> arr = match.to_a
15
+ #=> ["<campaign_title value='test tile'/>", "'", "test tile", "'"]
16
+ #>> arr[2]
17
+ #=> "test tile"
18
+ #description = <campaign_description value=('|")(.*?)('|")\/>
19
+ #href = <campaign_href url=('|")(.*?)('|")\/>
20
+ #current day = <currentday\/>
21
+ #current day name = <currentdayname\/>
22
+ #current month = <currentmonth\/>
23
+ #current month name = <currentmonthname\/>
24
+ #current year = <currentyear\/>
25
+ #<html><head><title></title></head><body><%title name="ttl_text" value="default title"%><%description name="ttl_text" #value="default description"%><%currentday%><%currentdayname%><%currentmonth%><%currentmonthname%><%currentyear%></body></html>
26
+ #title
27
+ #<%title(.*?)name=['"](.*?)['"](.*?)value=['"](.*?)['"]%>
28
+ #description
29
+ #<%description(.*?)name=['"](.*?)['"](.*?)value=['"](.*?)['"]%>
30
+
31
+ #read file
32
+
33
+ puts "Reading file............."
34
+
35
+ html = ''
36
+
37
+ file = File.open('/home/pragash/Desktop/sample.html', 'r')
38
+ while(f = file.gets)
39
+ html << f
40
+ end
41
+
42
+ #description data
43
+ puts "Extract description data"
44
+
45
+ exp = "<%description(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
46
+ regex = Regexp.new(exp)
47
+ matches = html.scan(regex)
48
+ puts matches.inspect
49
+
50
+ #title data
51
+ puts "Extract title data"
52
+
53
+ exp = "<%title(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
54
+ regex = Regexp.new(exp)
55
+ matches = html.scan(regex)
56
+ puts matches.inspect
57
+
58
+ #image source
59
+ puts "Extract image source"
60
+
61
+ exp = "<%imgsrc(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
62
+ regex = Regexp.new(exp)
63
+ matches = html.scan(regex)
64
+ puts matches.inspect
65
+
66
+ #href
67
+ puts "Extract href"
68
+
69
+ exp = "<%linkhref(.*?)name(.*?)=(.*?)['\"\](.*?)['\"\](.*?)value(.*?)=(.*?)['\"\](.*?)['\"\](.*?)%>"
70
+ regex = Regexp.new(exp)
71
+ matches = html.scan(regex)
72
+ puts matches.inspect
data/sample.html ADDED
@@ -0,0 +1,8 @@
1
+ <html><head><title></title></head><body><%title name="ttl_text_1" value="default title 1"%><%description name="desc_text_1" value="default description_1"%><%description name="desc_text_2" value="default description_2"%><%currentday%><%currentdayname%><%currentmonth%><%currentmonthname%><%currentyear%></body></html><%description name="desc_text_3" value="default description_3"%>
2
+ <%title name="ttl_text_2" value="default title 2"%>
3
+ <%title name="ttl_text_3" value="default title 3"%><%title name="ttl_text_4" value="default title 4"%><%title name="ttl_text_5" value="default title 5"%><%imgsrc name="Google image" value="http://www.google.com"%>
4
+ <%imgsrc name="Yahoo image" value="http://www.yahoo.com"%><%linkhref name = "Google link" value="http://www.google.com"%><%linkhref name = "Yahoo link"value = "http://www.yahoo.com"%>
5
+
6
+ [" ", "", "", "desc_text_1", " ", "", "", "default description_1", ""]
7
+
8
+ <%description name="desc_text_1" value=(.*?)%>
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+
11
+ <%description name="description 1" value="This is description 1" %>
12
+ <%description name="description 2" value="This is description 2" %>
13
+ <%description name="description 3" value="This is description 3" %>
14
+ <%description name="description 4" value="This is description 4" %>
15
+
16
+ <p>
17
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
18
+ </p>
19
+ </body>
20
+ </html>
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+
11
+ <%linkhref name="Href link 1" value="This is href link 1" %>
12
+ <%linkhref name="Href link 2" value="This is href link 2" %>
13
+ <%linkhref name="Href link 3" value="This is href link 3" %>
14
+ <%linkhref name="Href link 4" value="This is href link 4" %>
15
+
16
+ <p>
17
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
18
+ </p>
19
+ </body>
20
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
+ <html>
3
+ <head>
4
+ <title>Sample template</title>
5
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
6
+ </head>
7
+ <body bgcolor="#ffffff" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0">
8
+ <table cellspacing="0" bgcolor="#ffffff" border="0" cellpadding="0" width="100%">
9
+ <tr>
10
+ <td>
11
+ <%description name="Description 1" value="Description 1" %>
12
+ </td>
13
+ </tr>
14
+ <tr>
15
+ <td>
16
+ <%description name="Description 2" value="Description 2" %>
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <td>
21
+ <%title name="Title 1" value="Title 1" %>
22
+ </td>
23
+ </tr>
24
+ <tr>
25
+ <td>
26
+ <%title name="Title 2" value="Title 2" %>
27
+ </td>
28
+ </tr>
29
+ <tr>
30
+ <td>
31
+ <img src="<%imgsrc name="Image 1" value="Image 1" %>" alt="This is image 1" />
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td>
36
+ <img src="<%imgsrc name="Image 2" value="Image 2" %>" alt="This is image 2" />
37
+ </td>
38
+ </tr>
39
+ <tr>
40
+ <td>
41
+ <a href="<%linkhref name="Link 1" value="Link 1" %>">Link 1</a>
42
+ </td>
43
+ </tr>
44
+ <tr>
45
+ <td>
46
+ <a href="<%linkhref name="Link 2" value="Link 2" %>">Link 2</a>
47
+ </td>
48
+ </tr>
49
+ </table>
50
+ </body>
51
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+ <%description name="description 1" value="This is description 1" %>
11
+ <%title name="title 1" value="This is title 1" %>
12
+ <a href="<%linkhref name="Href link 1" value="This is href link 1" %>">Link to URL</a>
13
+ <img src="<%imgsrc name="Image source 1" value="This is image 1" %>"/>
14
+ <p>
15
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
16
+ </p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+
11
+ <img src="<%imgsrc name="Image source 1" value="This is image 1" %>" alt="This is image 1" />
12
+ <img src="<%imgsrc name="Image source 2" value="This is image 2" %>" alt="This is image 2" />
13
+ <img src="<%imgsrc name="Image source 3" value="This is image 3" %>" alt="This is image 3" />
14
+ <img src="<%imgsrc name="Image source 4" value="This is image 4" %>" alt="This is image 4" />
15
+
16
+ <p>
17
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
18
+ </p>
19
+ </body>
20
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+ <p>This is a new description</p>
11
+ <span>This is a new title</span>
12
+ <a href="http://google.com">Link to URL</a>
13
+ <img src="http://www.google.com/images/nav_logo86.png"/>
14
+ <p>
15
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
16
+ </p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
+ <html>
3
+ <head>
4
+ <title>Sample template</title>
5
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
6
+ </head>
7
+ <body bgcolor="#ffffff" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0">
8
+ <table cellspacing="0" bgcolor="#ffffff" border="0" cellpadding="0" width="100%">
9
+ <tr>
10
+ <td>
11
+ <p>This is a new description 1</p>
12
+ </td>
13
+ </tr>
14
+ <tr>
15
+ <td>
16
+ <p>This is a new description 2</p>
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <td>
21
+ <span>This is a new title 1</span>
22
+ </td>
23
+ </tr>
24
+ <tr>
25
+ <td>
26
+ <span>This is a new title 2</span>
27
+ </td>
28
+ </tr>
29
+ <tr>
30
+ <td>
31
+ <img src="This is a new image 1" alt="This is image 1" />
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td>
36
+ <img src="This is a new image 2" alt="This is image 2" />
37
+ </td>
38
+ </tr>
39
+ <tr>
40
+ <td>
41
+ <a href="This is a new link 1">Link 1</a>
42
+ </td>
43
+ </tr>
44
+ <tr>
45
+ <td>
46
+ <a href="This is a new link 2">Link 2</a>
47
+ </td>
48
+ </tr>
49
+ </table>
50
+ </body>
51
+ </html>
@@ -0,0 +1,35 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+
11
+ <%description name="description 1" value="This is description 1" %>
12
+ <%description name="description 2" value="This is description 2" %>
13
+ <%description name="description 3" value="This is description 3" %>
14
+ <%description name="description 4" value="This is description 4" %>
15
+
16
+ <%title name="title 1" value="This is title 1" %>
17
+ <%title name="title 2" value="This is title 2" %>
18
+ <%title name="title 3" value="This is title 3" %>
19
+ <%title name="title 4" value="This is title 4" %>
20
+
21
+ <%imgsrc name="imgsrc 1" value="This is image source 1" %>
22
+ <%imgsrc name="imgsrc 2" value="This is image source 2" %>
23
+ <%imgsrc name="imgsrc 3" value="This is image source 3" %>
24
+ <%imgsrc name="imgsrc 4" value="This is image source 4" %>
25
+
26
+ <%linkhref name="linkhref 1" value="This is link 1" %>
27
+ <%linkhref name="linkhref 2" value="This is link 2" %>
28
+ <%linkhref name="linkhref 3" value="This is link 3" %>
29
+ <%linkhref name="linkhref 4" value="This is link 4" %>
30
+
31
+ <p>
32
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
33
+ </p>
34
+ </body>
35
+ </html>
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ </title>
5
+ </head>
6
+ <body>
7
+ <p>
8
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
9
+ </p>
10
+
11
+ <%title name="title 1" value="This is title 1" %>
12
+ <%title name="title 2" value="This is title 2" %>
13
+ <%title name="title 3" value="This is title 3" %>
14
+ <%title name="title 4" value="This is title 4" %>
15
+
16
+ <p>
17
+ Spawner is a generator of sample/test data for databases. It can be configured to output delimited text or SQL insert statements. It can also insert directly into a MySQL 5.x database. Includes many field types, most of which are configurable.
18
+ </p>
19
+ </body>
20
+ </html>
@@ -0,0 +1,75 @@
1
+ require 'test/unit'
2
+ require 'cm_tag'
3
+ require 'cm_tag/campaign_tag'
4
+ require 'cm_tag/campaign_process'
5
+ require 'helpers/data_helper'
6
+
7
+ class TestHtmlReplace < Test::Unit::TestCase
8
+ include DataHelper
9
+
10
+ def test_replace_campaign_tags
11
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/html_with_tag.html", "r")
12
+
13
+ html = ''
14
+ while(h = f.gets)
15
+ html << h
16
+ end
17
+
18
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/real_html.html", "r")
19
+ replaced_html = ''
20
+ while(h = f.gets)
21
+ replaced_html << h
22
+ end
23
+
24
+ cp = ProcessTag::CampaignProcess.new
25
+
26
+ params = {}
27
+ params["imgsrc_tag_0"] = "http://www.google.com/images/nav_logo86.png"
28
+ params["linkhref_tag_0"] = "http://google.com"
29
+ params["title_tag_0"] = "This is a new title"
30
+ params["description_tag_0"] = "This is a new description"
31
+
32
+ new_html = cp.update_tags(html, params, true)
33
+
34
+ assert_equal replaced_html, new_html
35
+
36
+ f.close
37
+ end
38
+
39
+ def test_real_html
40
+ html = ''
41
+ file = File.open("#{File.dirname(__FILE__)}/fixtures/html_template.html")
42
+
43
+ while(f = file.gets)
44
+ html << f
45
+ end
46
+ file.close
47
+
48
+ replaced_html = ''
49
+ file = File.open("#{File.dirname(__FILE__)}/fixtures/replaced_html_template.html")
50
+
51
+ while(f = file.gets)
52
+ replaced_html << f
53
+ end
54
+ file.close
55
+
56
+ params = {}
57
+ params["description_tag_0"] = "This is a new description 1"
58
+ params["description_tag_1"] = "This is a new description 2"
59
+
60
+ params["title_tag_0"] = "This is a new title 1"
61
+ params["title_tag_1"] = "This is a new title 2"
62
+
63
+ params["imgsrc_tag_0"] = "This is a new image 1"
64
+ params["imgsrc_tag_1"] = "This is a new image 2"
65
+
66
+ params["linkhref_tag_0"] = "This is a new link 1"
67
+ params["linkhref_tag_1"] = "This is a new link 2"
68
+
69
+ cp = ProcessTag::CampaignProcess.new
70
+ new_html = cp.update_tags(html, params, true)
71
+
72
+ assert_equal new_html, replaced_html
73
+ end
74
+
75
+ end
data/test/test_tag.rb ADDED
@@ -0,0 +1,128 @@
1
+ require 'test/unit'
2
+ require 'cm_tag'
3
+ require 'cm_tag/campaign_tag'
4
+ require 'cm_tag/campaign_process'
5
+ require 'helpers/data_helper'
6
+
7
+ class TestTag < Test::Unit::TestCase
8
+ include DataHelper
9
+
10
+ def test_find_tags
11
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/sample1.html", "r")
12
+
13
+ html = ''
14
+ while(h = f.gets)
15
+ html << h
16
+ end
17
+
18
+ tags = CMTag.find_tags(html)
19
+
20
+ assert_equal tags.length, 4
21
+ end
22
+
23
+ def test_detail_tags
24
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/sample1.html", "r")
25
+
26
+ html = ''
27
+ while(h = f.gets)
28
+ html << h
29
+ end
30
+
31
+ count = 0
32
+ tags = CMTag.find_tags(html)
33
+ tags.collect{|k,v| count += v.length }
34
+
35
+ assert_equal count, 16
36
+ end
37
+
38
+ def test_tags
39
+ ["description", "title", "image", "href"].each do |tag|
40
+ equal = check(tag)
41
+ assert_equal equal, true
42
+ end
43
+ end
44
+
45
+ def test_description_replace_values
46
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/description.html", "r")
47
+
48
+ html = ''
49
+ while(h = f.gets)
50
+ html << h
51
+ end
52
+
53
+ cp = ProcessTag::CampaignProcess.new
54
+
55
+ params = {}
56
+ params["description_tag_0"] = "Description has been changed to sample 1"
57
+ params["description_tag_1"] = "Description has been changed to sample 2"
58
+ params["description_tag_2"] = "Description has been changed to sample 3"
59
+ params["description_tag_3"] = "Description has been changed to sample 4"
60
+
61
+ new_html = cp.update_tags(html, params)
62
+
63
+ assert_not_equal html, new_html
64
+ end
65
+
66
+ def test_title_replace_values
67
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/title.html", "r")
68
+
69
+ html = ''
70
+ while(h = f.gets)
71
+ html << h
72
+ end
73
+
74
+ cp = ProcessTag::CampaignProcess.new
75
+
76
+ params = {}
77
+ params["title_tag_0"] = "Title has been changed to sample 1"
78
+ params["title_tag_1"] = "Title has been changed to sample 2"
79
+ params["title_tag_2"] = "Title has been changed to sample 3"
80
+ params["title_tag_3"] = "Title has been changed to sample 4"
81
+
82
+ new_html = cp.update_tags(html, params)
83
+
84
+ assert_not_equal html, new_html
85
+ end
86
+
87
+ def test_image_src_replace_values
88
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/image.html", "r")
89
+
90
+ html = ''
91
+ while(h = f.gets)
92
+ html << h
93
+ end
94
+
95
+ cp = ProcessTag::CampaignProcess.new
96
+
97
+ params = {}
98
+ params["imgsrc_tag_0"] = "Image has been changed to sample 1"
99
+ params["imgsrc_tag_1"] = "Image has been changed to sample 2"
100
+ params["imgsrc_tag_2"] = "Image has been changed to sample 3"
101
+ params["imgsrc_tag_3"] = "Image has been changed to sample 4"
102
+
103
+ new_html = cp.update_tags(html, params)
104
+
105
+ assert_not_equal html, new_html
106
+ end
107
+
108
+ def test_link_href_replace_values
109
+ f = File.open("#{File.dirname(__FILE__)}/fixtures/href.html", "r")
110
+
111
+ html = ''
112
+ while(h = f.gets)
113
+ html << h
114
+ end
115
+
116
+ cp = ProcessTag::CampaignProcess.new
117
+
118
+ params = {}
119
+ params["linkhref_tag_0"] = "This is href link 1 has been changed"
120
+ params["linkhref_tag_1"] = "This is href link 2 has been changed"
121
+ params["linkhref_tag_2"] = "This is href link 3 has been changed"
122
+ params["linkhref_tag_3"] = "This is href link 4 has been changed"
123
+
124
+ new_html = cp.update_tags(html, params)
125
+
126
+ assert_not_equal html, new_html
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cm_tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pragash
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-10-19 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This gem can be used to implement campaign monitor tags in a rails application
17
+ email:
18
+ - pragashonlink@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - Rakefile
29
+ - cm_tag.gemspec
30
+ - lib/cm_tag.rb
31
+ - lib/cm_tag/campaign_process.rb
32
+ - lib/cm_tag/campaign_tag.rb
33
+ - lib/cm_tag/process.rb
34
+ - lib/cm_tag/version.rb
35
+ - lib/helpers/data_helper.rb
36
+ - regular_expressions
37
+ - sample.html
38
+ - test/fixtures/description.html
39
+ - test/fixtures/href.html
40
+ - test/fixtures/html_template.html
41
+ - test/fixtures/html_with_tag.html
42
+ - test/fixtures/image.html
43
+ - test/fixtures/real_html.html
44
+ - test/fixtures/replaced_html_template.html
45
+ - test/fixtures/sample1.html
46
+ - test/fixtures/title.html
47
+ - test/test_html_replace.rb
48
+ - test/test_tag.rb
49
+ has_rdoc: true
50
+ homepage: http://pragashblog.blogspot.com
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: campaign_monitor
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Campaign monitor tags in rails
77
+ test_files: []
78
+