visionmedia-tagz 1.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/History.rdoc +8 -0
- data/Manifest +18 -0
- data/README.rdoc +65 -0
- data/Rakefile +17 -0
- data/lib/tagz/buffer.rb +50 -0
- data/lib/tagz/helpers.rb +106 -0
- data/lib/tagz/import.rb +6 -0
- data/lib/tagz/tagz.rb +151 -0
- data/lib/tagz/version.rb +4 -0
- data/lib/tagz.rb +31 -0
- data/spec/buffer_spec.rb +27 -0
- data/spec/helpers_spec.rb +69 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/tagz_spec.rb +25 -0
- data/tagz.gemspec +36 -0
- data/tasks/docs.rake +18 -0
- data/tasks/gemspec.rake +3 -0
- data/tasks/spec.rake +25 -0
- metadata +109 -0
data/History.rdoc
ADDED
data/Manifest
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
History.rdoc
|
2
|
+
lib/tagz/buffer.rb
|
3
|
+
lib/tagz/helpers.rb
|
4
|
+
lib/tagz/import.rb
|
5
|
+
lib/tagz/tagz.rb
|
6
|
+
lib/tagz/version.rb
|
7
|
+
lib/tagz.rb
|
8
|
+
Manifest
|
9
|
+
Rakefile
|
10
|
+
README.rdoc
|
11
|
+
spec/buffer_spec.rb
|
12
|
+
spec/helpers_spec.rb
|
13
|
+
spec/spec_helper.rb
|
14
|
+
spec/tagz_spec.rb
|
15
|
+
tagz.gemspec
|
16
|
+
tasks/docs.rake
|
17
|
+
tasks/gemspec.rake
|
18
|
+
tasks/spec.rake
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
= Tagz
|
3
|
+
|
4
|
+
Framework independant tag helpers.
|
5
|
+
|
6
|
+
== Features
|
7
|
+
|
8
|
+
* Simple / Fast tag creation
|
9
|
+
* Highly extendable
|
10
|
+
* Framework independant
|
11
|
+
* Block capture buffering (nested tags)
|
12
|
+
* Several helpers
|
13
|
+
|
14
|
+
== Helpers
|
15
|
+
|
16
|
+
* #javascript
|
17
|
+
* #stylesheet
|
18
|
+
* #image
|
19
|
+
* #meta
|
20
|
+
* #cdata
|
21
|
+
|
22
|
+
== Cherry Pick
|
23
|
+
|
24
|
+
Tagz does not force you to use anything, simply include
|
25
|
+
the autoloaded modules where you like:
|
26
|
+
|
27
|
+
include Tagz
|
28
|
+
include Tagz::Buffer
|
29
|
+
include Tagz::Helpers
|
30
|
+
|
31
|
+
Or import them all!
|
32
|
+
|
33
|
+
require 'tagz/import'
|
34
|
+
|
35
|
+
== Formz
|
36
|
+
|
37
|
+
If you like Tagz, and want framework independant, sexy,
|
38
|
+
and super extendable forms, check out:
|
39
|
+
|
40
|
+
http://github.com/visionmedia/formz
|
41
|
+
|
42
|
+
== License
|
43
|
+
|
44
|
+
(The MIT License)
|
45
|
+
|
46
|
+
Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
49
|
+
a copy of this software and associated documentation files (the
|
50
|
+
'Software'), to deal in the Software without restriction, including
|
51
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
52
|
+
distribute, sublicense, an d/or sell copies of the Software, and to
|
53
|
+
permit persons to whom the Software is furnished to do so, subject to
|
54
|
+
the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be
|
57
|
+
included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
60
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
61
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
62
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
63
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
65
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
$:.unshift 'lib'
|
3
|
+
require 'tagz'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake'
|
6
|
+
require 'echoe'
|
7
|
+
|
8
|
+
Echoe.new "tagz", Tagz::VERSION do |p|
|
9
|
+
p.author = "TJ Holowaychuk"
|
10
|
+
p.email = "tj@vision-media.ca"
|
11
|
+
p.summary = "Framework independant tag helpers"
|
12
|
+
p.url = "http://github.com/visionmedia/tagz"
|
13
|
+
p.runtime_dependencies << 'visionmedia-rext >= 0.1.0'
|
14
|
+
p.development_dependencies << 'rspec_hpricot_matchers >= 1.0.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir['tasks/**/*.rake'].sort.each { |f| load f }
|
data/lib/tagz/buffer.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
# = Buffer
|
4
|
+
#
|
5
|
+
# When included, Tagz::Buffer allows a tag's block
|
6
|
+
# to have several calls to #tag, which are collected
|
7
|
+
# and assigned as the parent tag's contents.
|
8
|
+
#
|
9
|
+
# === Examples
|
10
|
+
#
|
11
|
+
# tag :div do
|
12
|
+
# tag :label, 'Comments:', :for => :comments
|
13
|
+
# tag :textarea, :id => :comments
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# <div>
|
17
|
+
# <label for="comments">Comments:</label>
|
18
|
+
# <textarea id="comments"></textarea>
|
19
|
+
# </div>
|
20
|
+
#
|
21
|
+
|
22
|
+
module Tagz::Buffer
|
23
|
+
|
24
|
+
#:stopdoc:
|
25
|
+
|
26
|
+
class Base
|
27
|
+
def initialize
|
28
|
+
@buffer = ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_tag *args, &block
|
32
|
+
@buffer << Buffer.create_tag(*args, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
@buffer
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_tag name, contents, attrs, &block
|
41
|
+
if block
|
42
|
+
buffer = Base.new
|
43
|
+
buffer.instance_eval &block
|
44
|
+
super name, "#{contents}#{buffer}", attrs
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/tagz/helpers.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
# = Helpers
|
4
|
+
#
|
5
|
+
# Tagz::Helpers consists of methods which
|
6
|
+
# assist creation of common tag combinations
|
7
|
+
# and standards. For example images may simply
|
8
|
+
# call image('foo.png'), as a shortcut for
|
9
|
+
# tag(:img, :src => 'foo.png').
|
10
|
+
#
|
11
|
+
|
12
|
+
module Tagz::Helpers
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
##
|
17
|
+
# Return image tag to _path_.
|
18
|
+
#
|
19
|
+
# === Examples
|
20
|
+
#
|
21
|
+
# image 'foo.png'
|
22
|
+
# # => <img src="foo.png" />
|
23
|
+
#
|
24
|
+
# image 'foo.png', :alt => 'Kung-foo'
|
25
|
+
# # => <img src="foo.png" alt="Kung-foo">
|
26
|
+
#
|
27
|
+
|
28
|
+
def image path, attrs = {}
|
29
|
+
tag :img, { :src => path }.merge(attrs)
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Return stylesheet link tag to _path_. When a _block_
|
34
|
+
# is passed, a style tag will be created with the yielded
|
35
|
+
# value as its contents.
|
36
|
+
#
|
37
|
+
# === Examples
|
38
|
+
#
|
39
|
+
# stylesheet do
|
40
|
+
# "body {
|
41
|
+
# color: blue;
|
42
|
+
# }"
|
43
|
+
# end
|
44
|
+
# # => <style>body { ... }</style>
|
45
|
+
#
|
46
|
+
#
|
47
|
+
# stylesheet 'style.css', :media => :print
|
48
|
+
# # => <link rel="stylesheet" href="style.css" media="print" />
|
49
|
+
#
|
50
|
+
|
51
|
+
def stylesheet path = nil, attrs = {}, &block
|
52
|
+
return tag(:style, yield, { :type => 'text/css' }.merge(attrs)) if block
|
53
|
+
tag :link, { :rel => 'stylesheet', :href => path }.merge(attrs)
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Return script tag to _path_. When a _block_ is passed,
|
58
|
+
# a script tag will be created with the yielded value as
|
59
|
+
# its contents.
|
60
|
+
#
|
61
|
+
# === Examples
|
62
|
+
#
|
63
|
+
# javascript do
|
64
|
+
# "foo"
|
65
|
+
# end
|
66
|
+
# # => <script type="text/javascript">foo</script>
|
67
|
+
#
|
68
|
+
# javascript 'jquery.js'
|
69
|
+
# # => <script type="text/javascript" src="jquery.js"></script>
|
70
|
+
#
|
71
|
+
|
72
|
+
def javascript path = nil, attrs = {}, &block
|
73
|
+
contents = yield if block
|
74
|
+
tag :script, contents, { :type => 'text/javascript', :src => path }.merge(attrs)
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Return meta tag _name_ with _contents_.
|
79
|
+
#
|
80
|
+
# === Examples
|
81
|
+
#
|
82
|
+
# meta :keywords, 'foo bar'
|
83
|
+
# meta :description, 'Welcome to foo bar'
|
84
|
+
#
|
85
|
+
# # => <meta name="keywords" contents="foo bar">
|
86
|
+
# # => <meta name="description" contents="Welcome to foo bar">
|
87
|
+
#
|
88
|
+
|
89
|
+
def meta name, contents
|
90
|
+
tag :meta, :name => name, :contents => contents
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Return CDATA tag with _contents_.
|
95
|
+
#
|
96
|
+
# === Examples
|
97
|
+
#
|
98
|
+
# cdata '<foo>'
|
99
|
+
# # => <![CDATA[<foo>]]>
|
100
|
+
#
|
101
|
+
|
102
|
+
def cdata contents
|
103
|
+
"<![CDATA[#{contents}]]>"
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/lib/tagz/import.rb
ADDED
data/lib/tagz/tagz.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
|
2
|
+
##
|
3
|
+
# = Tagz
|
4
|
+
#
|
5
|
+
# Simple, unified #tag helper module. To add functionality
|
6
|
+
# to your tags, simply include a module and super to #create_tag
|
7
|
+
# like below:
|
8
|
+
#
|
9
|
+
# module Tagz
|
10
|
+
# module Labels
|
11
|
+
# def create_tag name, contents, attrs, &block
|
12
|
+
# label = attrs.delete :label
|
13
|
+
# if label && label_tag?(name)
|
14
|
+
# tag(:label, "#{label}:", :for => attrs[:name]) << super
|
15
|
+
# else
|
16
|
+
# super
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def label_tag? name
|
21
|
+
# name.to_s.in? %w( textarea input select )
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# include Tagz::Labels
|
27
|
+
#
|
28
|
+
# With our newly included Tagz::Labels, all calls to #tag will
|
29
|
+
# be passed to #create_tag, in turn adding our labels when
|
30
|
+
# appropriate.
|
31
|
+
#
|
32
|
+
# tag :textarea, :name => :comments, :label => 'Comments'
|
33
|
+
#
|
34
|
+
# <label for="comments">Comments:</label>
|
35
|
+
# <textarea name="comments"></textarea>
|
36
|
+
#
|
37
|
+
|
38
|
+
module Tagz
|
39
|
+
|
40
|
+
#--
|
41
|
+
# Self closing elements.
|
42
|
+
#++
|
43
|
+
|
44
|
+
SELF_CLOSING_TAGS = :input, :link, :base, :area, :br, :hr, :img, :meta
|
45
|
+
|
46
|
+
#--
|
47
|
+
# Boolean attributes.
|
48
|
+
#++
|
49
|
+
|
50
|
+
BOOLEAN_ATTRIBUTES = :selected, :checked, :disabled, :readonly, :multiple, :defer
|
51
|
+
|
52
|
+
module_function
|
53
|
+
|
54
|
+
##
|
55
|
+
# Return markup for tag _name_. Optionally _contents_ may
|
56
|
+
# be passed, which is literal content for spanning tags such
|
57
|
+
# as textarea, etc. A hash of _attrs_ may be passed as the
|
58
|
+
# second or third argument.
|
59
|
+
#
|
60
|
+
# Self closing tags such as <br/>, <input/> etc are automatically
|
61
|
+
# closed, and boolean attributes of "selected", "checked" etc
|
62
|
+
# are mirrored or removed when true or false.
|
63
|
+
#
|
64
|
+
# === Examples
|
65
|
+
#
|
66
|
+
# tag :br
|
67
|
+
# # => <br/>
|
68
|
+
#
|
69
|
+
# tag :div
|
70
|
+
# # => <div></div>
|
71
|
+
#
|
72
|
+
# tag :div, 'hello'
|
73
|
+
# # => <div>hello</div>
|
74
|
+
#
|
75
|
+
# tag :div, 'hello', :id => 'comment'
|
76
|
+
# # => <div id="comment">hello</div>
|
77
|
+
#
|
78
|
+
# tag :div :id => 'comment'
|
79
|
+
# # => <div id="comment"></div>
|
80
|
+
#
|
81
|
+
# tag :div do
|
82
|
+
# tag :p, 'Hello World'
|
83
|
+
# end
|
84
|
+
# # => <div><p>Hello World</p></div>
|
85
|
+
#
|
86
|
+
# tag :input, :type => :checkbox, :checked => true
|
87
|
+
# # => <input type="checkbox" checked="checked" />
|
88
|
+
#
|
89
|
+
|
90
|
+
def tag name, contents = nil, attrs = {}, &block
|
91
|
+
attrs, contents = contents, nil if contents.is_a? Hash
|
92
|
+
create_tag name, contents, attrs, &block
|
93
|
+
end
|
94
|
+
|
95
|
+
#:stopdoc:
|
96
|
+
|
97
|
+
def create_tag name, contents = nil, attrs = {}, &block
|
98
|
+
self_closing_tag?(name) ?
|
99
|
+
self_closing_tag(name, attrs) :
|
100
|
+
open_tag(name, attrs) + contents.to_s + closing_tag(name)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Check if _name_ is a boolean attribute.
|
105
|
+
|
106
|
+
def boolean_attribute? name
|
107
|
+
name.in? BOOLEAN_ATTRIBUTES
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Check if tag _name_ is a self-closing tag.
|
112
|
+
|
113
|
+
def self_closing_tag? name
|
114
|
+
name.in? SELF_CLOSING_TAGS
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Return a self closing tag of _name_, with _attrs_.
|
119
|
+
|
120
|
+
def self_closing_tag name, attrs = {}
|
121
|
+
"\n<#{name}#{normalize_html_attributes(attrs)}/>"
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Return an opening tag of _name_, with _attrs_.
|
126
|
+
|
127
|
+
def open_tag name, attrs = {}
|
128
|
+
"\n<#{name}#{normalize_html_attributes(attrs)}>"
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Normalize _attrs_, replacing boolean keys
|
133
|
+
# with their mirrored values.
|
134
|
+
|
135
|
+
def normalize_html_attributes attrs = {}
|
136
|
+
return if attrs.blank?
|
137
|
+
attrs.each do |name, value|
|
138
|
+
if boolean_attribute? name
|
139
|
+
value ? attrs[name] = name : attrs.delete(name)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
' ' + attrs.to_html_attributes
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Return closing tag of _name_.
|
147
|
+
|
148
|
+
def closing_tag name
|
149
|
+
"</#{name}>"
|
150
|
+
end
|
151
|
+
end
|
data/lib/tagz/version.rb
ADDED
data/lib/tagz.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'rext/all'
|
25
|
+
require 'tagz/tagz'
|
26
|
+
require 'tagz/version'
|
27
|
+
|
28
|
+
module Tagz
|
29
|
+
autoload :Buffer, 'tagz/buffer'
|
30
|
+
autoload :Helpers, 'tagz/helpers'
|
31
|
+
end
|
data/spec/buffer_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
describe Tagz do
|
3
|
+
describe Buffer do
|
4
|
+
it "should buffer all tag contents within a block" do
|
5
|
+
markup = tag :div do
|
6
|
+
tag :label, 'Comments:', :for => :comments
|
7
|
+
tag :textarea, :id => :comments
|
8
|
+
end
|
9
|
+
markup.should have_tag('div') do |div|
|
10
|
+
div.should have_tag('label[@for=comments]', 'Comments:')
|
11
|
+
div.should have_tag('textarea[@id=comments]')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should prepend contents when both contents and block are present" do
|
16
|
+
markup = tag :div, 'Cookies' do
|
17
|
+
tag :label, 'Comments:', :for => :comments
|
18
|
+
tag :textarea, :id => :comments
|
19
|
+
end
|
20
|
+
markup.should have_tag('div') do |div|
|
21
|
+
div.inner_text.should match(/^Cookies/)
|
22
|
+
div.should have_tag('label[@for=comments]', 'Comments:')
|
23
|
+
div.should have_tag('textarea[@id=comments]')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
describe Tagz do
|
3
|
+
describe Helpers do
|
4
|
+
describe "#cdata" do
|
5
|
+
it "should return a CDATA tag" do
|
6
|
+
cdata('<foo>').should == '<![CDATA[<foo>]]>'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#meta" do
|
11
|
+
it "should accept name and contents" do
|
12
|
+
meta(:keywords, 'some foo bar').should have_tag('meta[@name=keywords]')
|
13
|
+
meta(:keywords, 'some foo bar').should have_tag('meta[@contents=some foo bar]')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#image" do
|
18
|
+
it "should accept a path as the first argument" do
|
19
|
+
image('foo.png').should have_tag('img[@src=foo.png]')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept a hash of attributes" do
|
23
|
+
image('foo.png', :alt => 'Kung-foo').should have_tag('img[@alt=Kung-foo]')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#stylesheet" do
|
28
|
+
it "should return inline style tags when a block is passed" do
|
29
|
+
markup = stylesheet do
|
30
|
+
'body {}'
|
31
|
+
end
|
32
|
+
markup.should have_tag('style', 'body {}')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should assign rel attribute" do
|
36
|
+
stylesheet('style.css').should have_tag('link[@rel=stylesheet]')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should assign href attribute" do
|
40
|
+
stylesheet('style.css').should have_tag('link[@href=style.css]')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should accept a hash of attributes" do
|
44
|
+
stylesheet('style.css', :media => :print).should have_tag('link[@media=print]')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#javascript" do
|
50
|
+
it "should return inline javascript tag when a block is passed" do
|
51
|
+
markup = javascript do
|
52
|
+
'foo'
|
53
|
+
end
|
54
|
+
markup.should have_tag('script', 'foo')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should assign type attribute" do
|
58
|
+
javascript('jquery.js').should have_tag('script[@type=text/javascript]')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should assign src attribute" do
|
62
|
+
javascript('jquery.js').should have_tag('script[@src=jquery.js]')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should accept a hash of attributes" do
|
66
|
+
javascript('jquery.js', :foo => :bar).should have_tag('script[@foo=bar]')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/tagz_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
describe Tagz do
|
3
|
+
describe "#tag" do
|
4
|
+
it "should return a simple tag when only a tag name is passed" do
|
5
|
+
tag(:div).should have_tag(:div)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should self-close appropriate tags automatically" do
|
9
|
+
tag(:br).should include('<br/>')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow a hash of attributes to be passed" do
|
13
|
+
tag(:input, :type => :text).should have_tag('input[@type=text]')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow contents to be passed" do
|
17
|
+
tag(:textarea, 'hello', :id => 'comments').should have_tag('textarea[@id=comments]', 'hello')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should mirror boolean attributes" do
|
21
|
+
tag(:input, :type => :checkbox, :checked => true).should have_tag('input[@checked=checked]')
|
22
|
+
tag(:input, :type => :checkbox, :checked => false).should_not have_tag('input[@checked=checked]')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/tagz.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tagz}
|
5
|
+
s.version = "1.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["TJ Holowaychuk"]
|
9
|
+
s.date = %q{2009-05-08}
|
10
|
+
s.description = %q{Framework independant tag helpers}
|
11
|
+
s.email = %q{tj@vision-media.ca}
|
12
|
+
s.extra_rdoc_files = ["lib/tagz/buffer.rb", "lib/tagz/helpers.rb", "lib/tagz/import.rb", "lib/tagz/tagz.rb", "lib/tagz/version.rb", "lib/tagz.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["History.rdoc", "lib/tagz/buffer.rb", "lib/tagz/helpers.rb", "lib/tagz/import.rb", "lib/tagz/tagz.rb", "lib/tagz/version.rb", "lib/tagz.rb", "Manifest", "Rakefile", "README.rdoc", "spec/buffer_spec.rb", "spec/helpers_spec.rb", "spec/spec_helper.rb", "spec/tagz_spec.rb", "tagz.gemspec", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
14
|
+
s.homepage = %q{http://github.com/visionmedia/tagz}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tagz", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{tagz}
|
18
|
+
s.rubygems_version = %q{1.3.3}
|
19
|
+
s.summary = %q{Framework independant tag helpers}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<visionmedia-rext>, [">= 0", "= 0.1.0"])
|
27
|
+
s.add_development_dependency(%q<rspec_hpricot_matchers>, [">= 0", "= 1.0.0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<visionmedia-rext>, [">= 0", "= 0.1.0"])
|
30
|
+
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 0", "= 1.0.0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<visionmedia-rext>, [">= 0", "= 0.1.0"])
|
34
|
+
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 0", "= 1.0.0"])
|
35
|
+
end
|
36
|
+
end
|
data/tasks/docs.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
desc 'Docs'
|
3
|
+
task :docs do
|
4
|
+
sh 'sdoc -N lib/tagz'
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :docs do
|
8
|
+
|
9
|
+
desc 'Remove rdoc products'
|
10
|
+
task :remove => [:clobber_docs]
|
11
|
+
|
12
|
+
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
13
|
+
task :open => [:docs] do
|
14
|
+
browser = ENV["BROWSER"] || "safari"
|
15
|
+
sh "open -a #{browser} doc/index.html"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/tasks/gemspec.rake
ADDED
data/tasks/spec.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run all specifications"
|
5
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
6
|
+
t.libs << "lib"
|
7
|
+
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :spec do
|
11
|
+
|
12
|
+
desc "Run all specifications verbosely"
|
13
|
+
Spec::Rake::SpecTask.new(:verbose) do |t|
|
14
|
+
t.libs << "lib"
|
15
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run specific specification verbosely (specify SPEC)"
|
19
|
+
Spec::Rake::SpecTask.new(:select) do |t|
|
20
|
+
t.libs << "lib"
|
21
|
+
t.spec_files = [ENV["SPEC"]]
|
22
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visionmedia-tagz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TJ Holowaychuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: visionmedia-rext
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
- - "="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
version:
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec_hpricot_matchers
|
30
|
+
type: :development
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "0"
|
37
|
+
- - "="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.0.0
|
40
|
+
version:
|
41
|
+
description: Framework independant tag helpers
|
42
|
+
email: tj@vision-media.ca
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
extra_rdoc_files:
|
48
|
+
- lib/tagz/buffer.rb
|
49
|
+
- lib/tagz/helpers.rb
|
50
|
+
- lib/tagz/import.rb
|
51
|
+
- lib/tagz/tagz.rb
|
52
|
+
- lib/tagz/version.rb
|
53
|
+
- lib/tagz.rb
|
54
|
+
- README.rdoc
|
55
|
+
- tasks/docs.rake
|
56
|
+
- tasks/gemspec.rake
|
57
|
+
- tasks/spec.rake
|
58
|
+
files:
|
59
|
+
- History.rdoc
|
60
|
+
- lib/tagz/buffer.rb
|
61
|
+
- lib/tagz/helpers.rb
|
62
|
+
- lib/tagz/import.rb
|
63
|
+
- lib/tagz/tagz.rb
|
64
|
+
- lib/tagz/version.rb
|
65
|
+
- lib/tagz.rb
|
66
|
+
- Manifest
|
67
|
+
- Rakefile
|
68
|
+
- README.rdoc
|
69
|
+
- spec/buffer_spec.rb
|
70
|
+
- spec/helpers_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- spec/tagz_spec.rb
|
73
|
+
- tagz.gemspec
|
74
|
+
- tasks/docs.rake
|
75
|
+
- tasks/gemspec.rake
|
76
|
+
- tasks/spec.rake
|
77
|
+
has_rdoc: false
|
78
|
+
homepage: http://github.com/visionmedia/tagz
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --line-numbers
|
82
|
+
- --inline-source
|
83
|
+
- --title
|
84
|
+
- Tagz
|
85
|
+
- --main
|
86
|
+
- README.rdoc
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "1.2"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: tagz
|
104
|
+
rubygems_version: 1.2.0
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Framework independant tag helpers
|
108
|
+
test_files: []
|
109
|
+
|