taggart 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/lib/taggart.rb +19 -6
- data/spec/taggart_spec.rb +45 -0
- data/taggart.gemspec +2 -2
- metadata +4 -4
data/README
CHANGED
@@ -26,15 +26,15 @@ Playtime:
|
|
26
26
|
"Gimme a".br
|
27
27
|
|
28
28
|
Issues:
|
29
|
-
- "hello".
|
29
|
+
- "hello".sub('world', 'world') returns
|
30
30
|
"<sub world world>hello</sub>"
|
31
31
|
Not really perfect
|
32
32
|
|
33
33
|
Future??? (with your blessing)
|
34
|
-
-
|
35
|
-
"/pages/about_us.html".href
|
34
|
+
- Potential validations - could check file, size, etc
|
36
35
|
|
37
36
|
History
|
37
|
+
- Added href and img feature.
|
38
38
|
- Created Gem
|
39
39
|
- Pushed code to Git.
|
40
40
|
- Created test Gem.
|
@@ -53,5 +53,5 @@ Feedback welcome!!
|
|
53
53
|
|
54
54
|
Author: Jocke Selin <jocke@selincite.com>
|
55
55
|
Date: 2012-02-16
|
56
|
-
Version: 0.0.
|
56
|
+
Version: 0.0.4 Build 009
|
57
57
|
Github: https://github.com/jocke/taggart
|
data/lib/taggart.rb
CHANGED
@@ -26,15 +26,15 @@
|
|
26
26
|
# "Gimme a".br
|
27
27
|
#
|
28
28
|
# Issues:
|
29
|
-
# - "hello".
|
29
|
+
# - "hello".sub('world', 'world') returns
|
30
30
|
# "<sub world world>hello</sub>"
|
31
31
|
# Not really perfect
|
32
32
|
#
|
33
33
|
# Future??? (with your blessing)
|
34
|
-
#
|
35
|
-
# "/pages/about_us.html".href
|
34
|
+
# - Potential validations - could check file, size, etc
|
36
35
|
#
|
37
36
|
# History
|
37
|
+
# - Added href and img feature.
|
38
38
|
# - Created Gem
|
39
39
|
# - Pushed code to Git.
|
40
40
|
# - Created test Gem.
|
@@ -52,8 +52,8 @@
|
|
52
52
|
# Feedback welcome!!
|
53
53
|
#
|
54
54
|
# Author: Jocke Selin <jocke@selincite.com>
|
55
|
-
# Date: 2012-
|
56
|
-
# Version: 0.0.
|
55
|
+
# Date: 2012-03-05
|
56
|
+
# Version: 0.0.4 Build 009
|
57
57
|
# Github: https://github.com/jocke/taggart
|
58
58
|
|
59
59
|
module Taggart
|
@@ -92,6 +92,19 @@ module Taggart
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
|
96
|
+
def href(label = nil, *args)
|
97
|
+
option_str = parse_options(args << {href: self})
|
98
|
+
label ||= self
|
99
|
+
"<a#{option_str}>#{label}</a>"
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def img(*args)
|
104
|
+
option_str = parse_options(args << {src: self})
|
105
|
+
"<img#{option_str} />"
|
106
|
+
end
|
107
|
+
|
95
108
|
|
96
109
|
private
|
97
110
|
|
@@ -138,7 +151,7 @@ module Taggart
|
|
138
151
|
end
|
139
152
|
|
140
153
|
|
141
|
-
standard_tags = %w{ h1 h2 h3 h4 h5 h6 strong p em title table thead tbody th td tfoot div span abbr acronym address dd dl dt li ol ul tt pre sup }
|
154
|
+
standard_tags = %w{ h1 h2 h3 h4 h5 h6 strong p a em title table thead tbody th td tfoot div span abbr acronym address dd dl dt li ol ul tt pre sup }
|
142
155
|
special_tags = [['tr', '_tr'], ['sub', '_sub']]
|
143
156
|
tags = standard_tags + special_tags
|
144
157
|
puts "Tag definitions: #{tags.inspect}" if DEBUG
|
data/spec/taggart_spec.rb
CHANGED
@@ -136,4 +136,49 @@ describe Taggart::Array, "#array_attribute_tag" do
|
|
136
136
|
%w(First Second Third Fourth Fifth Sizt Seventh).li.ol.should == "<ol><li>First</li><li>Second</li><li>Third</li><li>Fourth</li><li>Fifth</li><li>Sizt</li><li>Seventh</li></ol>"
|
137
137
|
end
|
138
138
|
end
|
139
|
+
|
140
|
+
|
141
|
+
describe Taggart::String, "Special tags" do
|
142
|
+
context "href tags" do
|
143
|
+
it "renders a basic <a href>-tag." do
|
144
|
+
"/hello/world.html".href("Hello World").should == "<a href=\"/hello/world.html\">Hello World</a>"
|
145
|
+
end
|
146
|
+
|
147
|
+
it "renders a basic <a href>-tag without an explicit label." do
|
148
|
+
"/hello/world.html".href.should == "<a href=\"/hello/world.html\">/hello/world.html</a>"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "renders a <a href>-tag with an attribute." do
|
152
|
+
"/hello/world.html".href("Hello World", {class: :linky}).should == "<a class=\"linky\" href=\"/hello/world.html\">Hello World</a>"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "renders a <a href>-tag with an attribute, but without an explicit label." do
|
156
|
+
"/hello/world.html".href(nil, {class: :linky}).should == "<a class=\"linky\" href=\"/hello/world.html\">/hello/world.html</a>"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "renders a <a href>-tag with two attributes." do
|
160
|
+
"/hello/world.html".href("Hello World", {class: :linky, title: 'Clicky the linky!'}).should == "<a class=\"linky\" title=\"Clicky the linky!\" href=\"/hello/world.html\">Hello World</a>"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "img tags" do
|
165
|
+
it "renders a basic <img>-tag." do
|
166
|
+
"/path/to/img.png".img.should == "<img src=\"/path/to/img.png\" />"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "renders a <img>-tag with an attribute." do
|
170
|
+
"/path/to/img.png".img({class: :thumbnail}).should == "<img class=\"thumbnail\" src=\"/path/to/img.png\" />"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "renders a <img>-tag with two attributes." do
|
174
|
+
"/path/to/img.png".img({class: :slideshow, alt: :'Rainbows and fluffy animals'}).should == "<img class=\"slideshow\" alt=\"Rainbows and fluffy animals\" src=\"/path/to/img.png\" />"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "combinations" do
|
179
|
+
it "renders a clickable image" do
|
180
|
+
"/path/to/img.png".img({class: :thumbnail}).a(href: '/hello/world.html').should == "<a href=\"/hello/world.html\"><img class=\"thumbnail\" src=\"/path/to/img.png\" /></a>"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
139
184
|
end
|
data/taggart.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "taggart"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.date = "2012-
|
3
|
+
s.version = "0.0.4"
|
4
|
+
s.date = "2012-03-05"
|
5
5
|
s.summary = "Simple HTML tag by String extension."
|
6
6
|
s.description = "Tag your strings in a simple and easy way by running \"Hello World\".h1 for example."
|
7
7
|
s.authors = ["Jocke Selin"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taggart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70119724335800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70119724335800
|
25
25
|
description: Tag your strings in a simple and easy way by running "Hello World".h1
|
26
26
|
for example.
|
27
27
|
email:
|