taggart 0.0.6 → 0.0.7
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/README.markdown +21 -2
- data/lib/taggart.rb +148 -15
- data/spec/taggart_spec.rb +32 -8
- data/taggart.gemspec +14 -11
- metadata +4 -4
data/README.markdown
CHANGED
@@ -126,6 +126,21 @@ Naturally they all also work with attributes.
|
|
126
126
|
See the `spec/taggart_spec.rb` for more examples (until I have time to do a bigger-better-faster-example file).
|
127
127
|
|
128
128
|
|
129
|
+
Informational:
|
130
|
+
--------------
|
131
|
+
If you get lost in Taggart or if you're just curious about what Taggart
|
132
|
+
can do, I've created a few informational things for you. In the IRB
|
133
|
+
console you can now run:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
Taggart.help # For generic information about Taggart (or Taggart.info)
|
137
|
+
Taggart.tags # For a list of different tags and other curious
|
138
|
+
things.
|
139
|
+
```
|
140
|
+
|
141
|
+
There's also some constants that you can access, such as `VERSION`, and
|
142
|
+
tags, see the aforementioned `Taggart.help` and `Taggart.tags`.
|
143
|
+
|
129
144
|
Background:
|
130
145
|
-----------
|
131
146
|
I have a lot of Ruby code that marks some String in an HTML tag, usually with a
|
@@ -164,6 +179,10 @@ Taggart is now active, which means you can play around.
|
|
164
179
|
History
|
165
180
|
-------
|
166
181
|
|
182
|
+
- Added informational Taggart.help and Taggart.tags.
|
183
|
+
- Moved several tags into arrays for easier reference.
|
184
|
+
- Created Taggart::VERSION and Taggart::BUILD for reference and DRYness.
|
185
|
+
- Changed some of the labels in the test file.
|
167
186
|
- Added `<table>` to Array that creates single or multi row tables.
|
168
187
|
- Added `<ol>` and `<ul>` tags to the Array so you can now generate lists in one fast action.
|
169
188
|
- Added `<script>`-tag. You can now add `"my-script.js".script` and `"alert('Hello World!')".script`.
|
@@ -207,8 +226,8 @@ Feedback welcome!!
|
|
207
226
|
|
208
227
|
Author: Jocke Selin <jocke@selincite.com> @jockeselin
|
209
228
|
|
210
|
-
Date: 2012-
|
229
|
+
Date: 2012-05-09
|
211
230
|
|
212
|
-
Version: 0.0.
|
231
|
+
Version: 0.0.7 Build 012
|
213
232
|
|
214
233
|
Github: <https://github.com/jocke/taggart>
|
data/lib/taggart.rb
CHANGED
@@ -2,15 +2,153 @@
|
|
2
2
|
# ===========================================
|
3
3
|
# Author: Jocke Selin <jocke@selincite.com>
|
4
4
|
# @jockeselin
|
5
|
-
# Date: 2012-
|
6
|
-
# Version: 0.0.
|
5
|
+
# Date: 2012-05-09
|
6
|
+
# Version: 0.0.7 Build 012
|
7
7
|
# Github: https://github.com/jocke/taggart
|
8
8
|
|
9
9
|
module Taggart
|
10
|
+
|
11
|
+
VERSION = '0.0.7'
|
12
|
+
BUILD = '012'
|
13
|
+
|
14
|
+
def self.help
|
15
|
+
puts "Welcome to Taggart (#{VERSION} Build #{BUILD})"
|
16
|
+
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
17
|
+
puts "Taggart is a library that allows you to easily"
|
18
|
+
puts "turn a string (or array) into an HTML tag or more tags"
|
19
|
+
puts "by simply calling the 'tag-method' on the string."
|
20
|
+
puts "Examples:"
|
21
|
+
puts " 'Hello World!'.h1 --> <h1>Hello World!</h1>'"
|
22
|
+
puts " 'Important'.span(class: :important) "
|
23
|
+
puts " --> <span class=\"important\">Important</span>"
|
24
|
+
puts " 'Break'.br --> Break<br />"
|
25
|
+
puts " %w(a b c).ul --> <ul><li>a</li><li>b</li><li>c</li></ul>"
|
26
|
+
puts "\nFor a list of tags run Taggart.tags"
|
27
|
+
puts "Other informational stuff:"
|
28
|
+
puts " - Version: Taggart::VERSION"
|
29
|
+
puts " - Build: Taggart::BUILD"
|
30
|
+
puts "\nPlease note that Taggart is considered 'experimental' (but"
|
31
|
+
puts "fairly stable) and in early development, so please help make"
|
32
|
+
puts "Taggart better; send suggestions, bug fixes, improvements, etc"
|
33
|
+
puts "to the author, and do fork the code and send pull requests if"
|
34
|
+
puts "you've made an improvement - Thanks!"
|
35
|
+
puts "\n\nAuthor: Jocke Selin <jocke@selincite.com> @jockeselin"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.info
|
39
|
+
self.help
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.tags
|
43
|
+
puts "Taggart's tags:"
|
44
|
+
puts "~~~~~~~~~~~~~~~"
|
45
|
+
puts "This is a list of the tags that Taggart can generate, for your pleasure"
|
46
|
+
puts "\nStandard tags:"
|
47
|
+
puts "--------------"
|
48
|
+
puts "These tags have a start- and end-tag and the take any number of"
|
49
|
+
puts "attributes in the form of a hash with key-value pairs."
|
50
|
+
output_tags(Taggart::String::STANDARD_TAGS)
|
51
|
+
puts "\nSpecial tags"
|
52
|
+
puts "------------"
|
53
|
+
puts "These tags behave like the Standard tags, but there's already a"
|
54
|
+
puts "method defined for the String instance so these tags have to be"
|
55
|
+
puts "treated in a slightly special way, in that the tag that's ouputted"
|
56
|
+
puts "doesn't have the same method name. I.e to output <tr> you call '._tr'"
|
57
|
+
puts "however, you don't really need to bother with knowing this as Taggart"
|
58
|
+
puts "does some magic behind the scenes to determine wheter you are asking"
|
59
|
+
puts "for a Taggart tag or the original method."
|
60
|
+
Taggart::String::SPECIAL_TAGS.sort.each do |tag_pair|
|
61
|
+
puts " Tag: #{('<' + tag_pair[0] + '>').ljust(6)} Method: .#{tag_pair[1]}"
|
62
|
+
end
|
63
|
+
puts "\nSingle Tags"
|
64
|
+
puts "-------------"
|
65
|
+
puts "Single tags are tags that do not an end tag, <br> is one such tag"
|
66
|
+
puts "In Taggart Single Tags behave just like Standard tags; you can"
|
67
|
+
puts "add attributes to them."
|
68
|
+
output_tags(Taggart::String::SINGLE_TAGS)
|
69
|
+
puts "\nSmart Tags"
|
70
|
+
puts "------------"
|
71
|
+
puts "These tags go to the gifted class and can speak elvish. They know what"
|
72
|
+
puts "you want from them. They don't behave like the other ones in the sense"
|
73
|
+
puts "that you have a string that you want to turn into something, not just a"
|
74
|
+
puts "simple tag."
|
75
|
+
puts "Here's the pupils of the gifted class:"
|
76
|
+
puts ".img - Turns a URL to an image into an img tag."
|
77
|
+
puts ".href - turns a URL into the href-portion of an A-tag, takes the link"
|
78
|
+
puts " content as a parameter, and also other attributes as 2nd argument."
|
79
|
+
puts ".script - Either turns a URL to a script file into a <script src..></script>"
|
80
|
+
puts " tag, or embeds a script source in <script></script> tags. Smart!"
|
81
|
+
puts "\nArray tags"
|
82
|
+
puts "----------"
|
83
|
+
puts "The Array Tags generate HTML tags out of a list of strings in an array."
|
84
|
+
puts "For example, you can turn an array into list items by callin the .li-"
|
85
|
+
puts "method on the array."
|
86
|
+
puts "You can also pass attributes to the tags as with the Standard Tags"
|
87
|
+
puts "The tags are:"
|
88
|
+
puts " td li"
|
89
|
+
puts "\nSmart Array Tags"
|
90
|
+
puts "-----------------"
|
91
|
+
puts "The Smart Array Tags are all a bit more smartly dressed than the"
|
92
|
+
puts "proletarian Array Tags. Namely, they figure out what you do."
|
93
|
+
puts "Here's the honour roll"
|
94
|
+
puts "Method Tag Special powers"
|
95
|
+
puts ".ol - Turns an array into an ordered list, wrapping the array elements"
|
96
|
+
puts " in <li> tags so you get your awesome list in one go"
|
97
|
+
puts ".ul - The almost identical twin of .ol"
|
98
|
+
puts ".tr - Like .ol and .li, but wraps the array in <tr> tags with every"
|
99
|
+
puts " element wrapped in a <td> tag."
|
100
|
+
puts ".table - The smartest of them all. Creates a complete table from a, one or"
|
101
|
+
puts " two dimensional Array. Each array is wrapped in the <tr> tag with"
|
102
|
+
puts " every element in the Array in <td> tags. It's all finished off"
|
103
|
+
puts " with a decoration of <table>."
|
104
|
+
puts "\nTag arrays and methods"
|
105
|
+
puts "----------------------"
|
106
|
+
puts "You can access the following arrays and methods containing the tags."
|
107
|
+
puts "Tags Array Method"
|
108
|
+
puts "Standard tags Taggart::String::STANDARD_TAGS Taggart.standard_tags"
|
109
|
+
puts "Special tags Taggart::String::SPECIAL_TAGS Taggart.special_tags"
|
110
|
+
puts "Single tags Taggart::String::SINGLE_TAGS Taggart.single_tags"
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def self.standard_tags
|
115
|
+
Taggart::String::STANDARD_TAGS
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.special_tags
|
119
|
+
Taggart::String::SPECIAL_TAGS
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.single_tags
|
123
|
+
Taggart::String::SINGLE_TAGS
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def self.output_tags(tags)
|
130
|
+
columns = 4
|
131
|
+
padding = 14
|
132
|
+
|
133
|
+
print " "
|
134
|
+
tags.sort.each_with_index do |tag, index|
|
135
|
+
index += 1
|
136
|
+
print "#{tag.ljust(padding)}"
|
137
|
+
print "\n " if ((index % columns) == 0) and (index > 0)
|
138
|
+
end
|
139
|
+
puts "\n\n"
|
140
|
+
end
|
141
|
+
|
10
142
|
module String
|
11
143
|
|
12
144
|
DEBUG = false
|
13
|
-
|
145
|
+
STANDARD_TAGS = %w{ h1 h2 h3 h4 h5 h6 a title html head table thead tfoot button fieldset form label
|
146
|
+
select legend option textarea body blockquote q tbody th td tfoot style div
|
147
|
+
span abbr acronym address dd dl dt li ol caption ul em strong p tt pre sup del
|
148
|
+
small cite code } # This is not a complete list - please tweet or pull req.
|
149
|
+
SPECIAL_TAGS = [['tr', '_tr'], ['sub', '_sub']]
|
150
|
+
TAGS = STANDARD_TAGS + SPECIAL_TAGS
|
151
|
+
SINGLE_TAGS = %w{br hr input link meta}
|
14
152
|
|
15
153
|
# Redefining <tr> to work with both translate-tr and tag-tr
|
16
154
|
def dual_tr(*args)
|
@@ -60,11 +198,11 @@ module Taggart
|
|
60
198
|
"<script#{option_str}>#{self}</script>"
|
61
199
|
end
|
62
200
|
end
|
63
|
-
|
64
|
-
|
201
|
+
|
202
|
+
|
65
203
|
private
|
66
|
-
|
67
|
-
|
204
|
+
|
205
|
+
|
68
206
|
# Parses the options for the tags
|
69
207
|
def parse_options(args)
|
70
208
|
return "" if args.nil?
|
@@ -106,13 +244,7 @@ module Taggart
|
|
106
244
|
end
|
107
245
|
|
108
246
|
|
109
|
-
|
110
|
-
select legend option textarea body blockquote q tbody th td tfoot style div
|
111
|
-
span abbr acronym address dd dl dt li ol caption ul em strong p tt pre sup del
|
112
|
-
small cite code } # This is not a complete list - please tweet or pull req.
|
113
|
-
special_tags = [['tr', '_tr'], ['sub', '_sub']]
|
114
|
-
tags = standard_tags + special_tags
|
115
|
-
tags.each do |tag|
|
247
|
+
TAGS.each do |tag|
|
116
248
|
if tag.class.name == 'String'
|
117
249
|
self.attribute_tag(tag)
|
118
250
|
else
|
@@ -120,7 +252,8 @@ module Taggart
|
|
120
252
|
end
|
121
253
|
end
|
122
254
|
|
123
|
-
|
255
|
+
|
256
|
+
SINGLE_TAGS.each do |tag|
|
124
257
|
self.single_attribute_tag(tag)
|
125
258
|
end
|
126
259
|
|
data/spec/taggart_spec.rb
CHANGED
@@ -1,7 +1,31 @@
|
|
1
|
-
# Run with rake or
|
1
|
+
# Run with rake or with: rspec -fd -c taggart_spec.rb
|
2
2
|
|
3
3
|
require 'taggart.rb'
|
4
4
|
|
5
|
+
describe Taggart, "informational" do
|
6
|
+
|
7
|
+
it "should respond to help" do
|
8
|
+
Taggart.should respond_to(:help)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to tags" do
|
12
|
+
Taggart.should respond_to(:tags)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns an array when asked for standard tags" do
|
16
|
+
Taggart.standard_tags.should be_an(Array)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns an array when asked for special tags" do
|
20
|
+
Taggart.special_tags.should be_an(Array)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns an array when asked for single tags" do
|
24
|
+
Taggart.single_tags.should be_an(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
5
29
|
describe Taggart::String, "#attribute_tags" do
|
6
30
|
|
7
31
|
it "returns a standard tag without any attributes" do
|
@@ -35,23 +59,23 @@ end
|
|
35
59
|
|
36
60
|
describe Taggart::Array, "#array_attribute_tag" do
|
37
61
|
|
38
|
-
it "returns
|
62
|
+
it "returns the elements in the array wrapped with li-tags when calling .li method" do
|
39
63
|
%w{one two three}.li.should == "<li>one</li><li>two</li><li>three</li>"
|
40
64
|
end
|
41
65
|
|
42
|
-
it "returns
|
66
|
+
it "returns the elements with an attribute wrapped in td when calling the td method on the array" do
|
43
67
|
%w{one two three}.td(class: :programmers).should == "<td class=\"programmers\">one</td><td class=\"programmers\">two</td><td class=\"programmers\">three</td>"
|
44
68
|
end
|
45
69
|
|
46
|
-
it "returns
|
70
|
+
it "returns the array elements wrapped in td tags and two attributes when called with two attribute parameters" do
|
47
71
|
%w{one two three}.td(class: :programmers, id: :unpossible).should == "<td class=\"programmers\" id=\"unpossible\">one</td><td class=\"programmers\" id=\"unpossible\">two</td><td class=\"programmers\" id=\"unpossible\">three</td>"
|
48
72
|
end
|
49
73
|
|
50
|
-
it "returns
|
74
|
+
it "returns the elements in the array wrapped with td when calling the td method" do
|
51
75
|
[:one, :two, :three].td.should == "<td>one</td><td>two</td><td>three</td>"
|
52
76
|
end
|
53
77
|
|
54
|
-
it "
|
78
|
+
it "renders a nested set of td-tags when the td method is called no a nested array" do
|
55
79
|
[:one, [:nine, :eight, :seven], :two, :three].td.should == "<td>one</td><td><td>nine</td><td>eight</td><td>seven</td></td><td>two</td><td>three</td>"
|
56
80
|
end
|
57
81
|
|
@@ -139,7 +163,7 @@ describe Taggart::Array, "#array_attribute_tag" do
|
|
139
163
|
end
|
140
164
|
|
141
165
|
|
142
|
-
describe Taggart::String, "
|
166
|
+
describe Taggart::String, "Smart tags" do
|
143
167
|
context "href tags" do
|
144
168
|
it "renders a basic <a href>-tag." do
|
145
169
|
"/hello/world.html".href("Hello World").should == "<a href=\"/hello/world.html\">Hello World</a>"
|
@@ -243,4 +267,4 @@ describe Taggart::Array, "#array_attribute_tag" do
|
|
243
267
|
end
|
244
268
|
end
|
245
269
|
end
|
246
|
-
end
|
270
|
+
end
|
data/taggart.gemspec
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
require 'date'
|
2
|
+
require './lib/taggart.rb'
|
3
|
+
|
1
4
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
s.date
|
5
|
-
s.summary
|
6
|
-
s.description
|
7
|
-
s.authors
|
8
|
-
s.email
|
9
|
-
s.homepage
|
5
|
+
s.name = "taggart"
|
6
|
+
s.version = Taggart::VERSION
|
7
|
+
s.date = Date.today.strftime('%Y-%m-%d')
|
8
|
+
s.summary = "Tag Strings with HTML; 'Hello World'.h1"
|
9
|
+
s.description = "Tag your strings in a simple and easy way by running \"Hello World\".h1 for example."
|
10
|
+
s.authors = ["Jocke Selin"]
|
11
|
+
s.email = ["jocke@selincite.com"]
|
12
|
+
s.homepage = "https://github.com/jocke/taggart"
|
10
13
|
s.require_paths = ["lib"]
|
11
|
-
s.files
|
12
|
-
s.test_files
|
14
|
+
s.files = ["lib/taggart.rb", "Rakefile", "taggart.gemspec", "README.markdown"]
|
15
|
+
s.test_files = ["spec/taggart_spec.rb"]
|
13
16
|
s.add_development_dependency "rspec"
|
14
17
|
s.post_install_message = "Thanks for showing interest in Taggart! Please provide feedback to jocke@selincite.com!"
|
15
|
-
end
|
18
|
+
end
|
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.7
|
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-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70207965639160 !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: *70207965639160
|
25
25
|
description: Tag your strings in a simple and easy way by running "Hello World".h1
|
26
26
|
for example.
|
27
27
|
email:
|