text-marker 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/textmarker/tag.rb +47 -2
- data/lib/textmarker/version.rb +1 -1
- data/spec/tag_spec.rb +55 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a937f76e90d27cbcd5e702f50737a29f4868d7bf
|
4
|
+
data.tar.gz: 4a438d011ff7764655f5648d3d6181dce14f74c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee4617a10db90868f137e4ce9bc1a7af732b9e85370f3146654ca1e5789693a07a4299e0566dc2df6c94289efb35a162b9cae2d21f4c431ae5d267d4570cafd
|
7
|
+
data.tar.gz: b7f6026a48e8981874b51a3960212f9768265d5b28dffce7db190f62b6b58b8ab5941e6a012cf95be4a864e7b93e69c85f91c96029d0ae34271621010386ba3e
|
data/lib/textmarker/tag.rb
CHANGED
@@ -2,10 +2,15 @@ require "textmarker/version"
|
|
2
2
|
|
3
3
|
module TextMarker
|
4
4
|
class Tag
|
5
|
-
|
6
|
-
attr_reader :open_tag, :close_tag
|
5
|
+
attr_reader :tag, :open_tag, :close_tag, :background_color, :text_color
|
7
6
|
|
8
7
|
def initialize(tag=:span, background_color=:yellow, text_color=:black)
|
8
|
+
@valid_tags = get_valid_html_tags
|
9
|
+
|
10
|
+
validate_tag(tag)
|
11
|
+
validate_color(background_color)
|
12
|
+
validate_color(text_color)
|
13
|
+
|
9
14
|
@tag = tag
|
10
15
|
@background_color = background_color
|
11
16
|
@text_color = text_color
|
@@ -18,8 +23,48 @@ module TextMarker
|
|
18
23
|
generate_open_tag + generate_close_tag
|
19
24
|
end
|
20
25
|
|
26
|
+
def tag=(tag)
|
27
|
+
validate_tag(tag)
|
28
|
+
@tag = tag
|
29
|
+
end
|
30
|
+
|
31
|
+
def background_color=(background_color)
|
32
|
+
validate_color(background_color)
|
33
|
+
@background_color = background_color
|
34
|
+
end
|
35
|
+
|
36
|
+
def text_color=(text_color)
|
37
|
+
validate_color(text_color)
|
38
|
+
@text_color = text_color
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def get_valid_html_tags
|
44
|
+
Set.new [:h1, :h2, :h3, :h4, :h5, :h6, :span, :div, :p, :a, :button, :center, :strong, :u, :b, :i]
|
45
|
+
end
|
46
|
+
|
21
47
|
private
|
22
48
|
|
49
|
+
def validate_tag(tag)
|
50
|
+
exception_error_message = ":tag must be one of these html tags "\
|
51
|
+
":h1, :h2, :h3, :h4, :h5, :h6, :span, :div, "\
|
52
|
+
":p, :a, :button, :center, :strong, :u, :b, :i"
|
53
|
+
raise(ArgumentError, exception_error_message) unless is_html_tag_valid? tag
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_color(color)
|
57
|
+
array_colors = [:aqua, :black, :blue, :fuchsia, :gray, :green, :lime, :maroon, :navy, :olive, :orange, :purple, :red, :silver, :teal, :white, :yellow]
|
58
|
+
exception_error_message = "The color must be a css color value like #ffffff or one of these standard colors "\
|
59
|
+
":aqua, :black, :blue, :fuchsia, :gray, :green, :lime, :maroon, :navy, :olive, "\
|
60
|
+
":orange, :purple, :red, :silver, :teal, :white, :yellow"
|
61
|
+
raise(ArgumentError, exception_error_message) if not array_colors.include? color and color.match(/#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b/).nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def is_html_tag_valid?(tag)
|
65
|
+
@valid_tags.include? tag
|
66
|
+
end
|
67
|
+
|
23
68
|
def generate_open_tag
|
24
69
|
"<#{@tag} style='background_color: #{@background_color}; color: #{@text_color};'>"
|
25
70
|
end
|
data/lib/textmarker/version.rb
CHANGED
data/spec/tag_spec.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "TextMarker::Tag
|
3
|
+
describe "TextMarker::Tag" do
|
4
4
|
before(:each) do
|
5
5
|
@instance_default = TextMarker::Tag.new
|
6
6
|
@instance = TextMarker::Tag.new :h1, :black, :white
|
7
|
+
@exception_error_message_for_tag = ":tag must be one of these html tags "\
|
8
|
+
":h1, :h2, :h3, :h4, :h5, :h6, :span, :div, "\
|
9
|
+
":p, :a, :button, :center, :strong, :u, :b, :i"
|
10
|
+
@exception_error_message_for_color = "The color must be a css color value like #ffffff or one of these standard colors "\
|
11
|
+
":aqua, :black, :blue, :fuchsia, :gray, :green, :lime, :maroon, :navy, :olive, "\
|
12
|
+
":orange, :purple, :red, :silver, :teal, :white, :yellow"
|
7
13
|
end
|
8
14
|
|
9
15
|
it 'Shoud create a Default Tag object' do
|
@@ -25,4 +31,52 @@ describe "TextMarker::Tag.new" do
|
|
25
31
|
expect(@instance.text_color).to eq :white
|
26
32
|
expect(@instance.to_s).to eq "<h1 style='background_color: black; color: white;'></h1>"
|
27
33
|
end
|
34
|
+
|
35
|
+
it 'Should raise a ArgumentException creating Tag' do
|
36
|
+
expect { TextMarker::Tag.new :error }.to raise_error(ArgumentError, @exception_error_message_for_tag)
|
37
|
+
expect { TextMarker::Tag.new :span, :error }.to raise_error(ArgumentError, @exception_error_message_for_color)
|
38
|
+
expect { TextMarker::Tag.new :span, :white, :error }.to raise_error(ArgumentError, @exception_error_message_for_color)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Should set tag to :h3' do
|
42
|
+
expect(@instance_default.tag).to eq :span
|
43
|
+
@instance_default.tag = :h3
|
44
|
+
expect(@instance_default.tag).to eq :h3
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'Should set background_color to :black' do
|
48
|
+
expect(@instance_default.background_color).to eq :yellow
|
49
|
+
@instance_default.background_color = :black
|
50
|
+
expect(@instance_default.background_color).to eq :black
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'Should set background_color to #000000' do
|
54
|
+
expect(@instance_default.background_color).to eq :yellow
|
55
|
+
@instance_default.background_color = '#000000'
|
56
|
+
expect(@instance_default.background_color).to eq '#000000'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'Should set text_color to :white' do
|
60
|
+
expect(@instance_default.text_color).to eq :black
|
61
|
+
@instance_default.text_color = :white
|
62
|
+
expect(@instance_default.text_color).to eq :white
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'Should set background_color to #ffffff' do
|
66
|
+
expect(@instance_default.text_color).to eq :black
|
67
|
+
@instance_default.text_color = '#ffffff'
|
68
|
+
expect(@instance_default.text_color).to eq '#ffffff'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'Should raise a ArgumentException setting Tag tag' do
|
72
|
+
expect { @instance_default.tag = :error }.to raise_error(ArgumentError, @exception_error_message_for_tag)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'Should raise a ArgumentException setting Tag background_color' do
|
76
|
+
expect { @instance_default.background_color = :error }.to raise_error(ArgumentError, @exception_error_message_for_color)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'Should raise a ArgumentException setting Tag text_color' do
|
80
|
+
expect { @instance_default.text_color = :error }.to raise_error(ArgumentError, @exception_error_message_for_color)
|
81
|
+
end
|
28
82
|
end
|