formz 0.0.4 → 0.1.0
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 +17 -8
- data/Manifest +7 -3
- data/Rakefile +2 -2
- data/formz.gemspec +7 -7
- data/lib/formz.rb +1 -2
- data/lib/formz/version.rb +1 -1
- data/lib/tagz.rb +30 -0
- data/lib/tagz/helpers.rb +123 -0
- data/lib/tagz/import.rb +7 -0
- data/lib/tagz/tagz.rb +204 -0
- data/lib/tagz/version.rb +4 -0
- data/spec/tagz_helpers_spec.rb +80 -0
- data/spec/tagz_spec.rb +86 -0
- metadata +16 -10
- data/tasks/docs.rake +0 -13
- data/tasks/gemspec.rake +0 -3
- data/tasks/spec.rake +0 -25
data/History.rdoc
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
0.1.0 / 2009-11-18
|
|
3
|
+
==================
|
|
3
4
|
|
|
4
|
-
*
|
|
5
|
+
* Vendorized tagz lib
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
0.0.4 / 2009-10-05
|
|
8
|
+
==================
|
|
7
9
|
|
|
8
|
-
*
|
|
10
|
+
* Added .field class to form wrappers
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
0.0.3 / 2009-10-05
|
|
13
|
+
==================
|
|
11
14
|
|
|
12
|
-
*
|
|
15
|
+
* Errors on models should display regardless of it being a new record
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
0.0.2 / 2009-10-05
|
|
18
|
+
==================
|
|
15
19
|
|
|
16
|
-
*
|
|
20
|
+
* Fixed errors module
|
|
21
|
+
|
|
22
|
+
0.0.1 / YYYY-MM-DD
|
|
23
|
+
==================
|
|
24
|
+
|
|
25
|
+
* Initial release
|
data/Manifest
CHANGED
|
@@ -17,6 +17,11 @@ lib/formz/labels.rb
|
|
|
17
17
|
lib/formz/models.rb
|
|
18
18
|
lib/formz/version.rb
|
|
19
19
|
lib/formz/wrappers.rb
|
|
20
|
+
lib/tagz.rb
|
|
21
|
+
lib/tagz/helpers.rb
|
|
22
|
+
lib/tagz/import.rb
|
|
23
|
+
lib/tagz/tagz.rb
|
|
24
|
+
lib/tagz/version.rb
|
|
20
25
|
spec/autoencoding_spec.rb
|
|
21
26
|
spec/descriptions_spec.rb
|
|
22
27
|
spec/errors_spec.rb
|
|
@@ -27,7 +32,6 @@ spec/labels_spec.rb
|
|
|
27
32
|
spec/models_spec.rb
|
|
28
33
|
spec/spec.opts
|
|
29
34
|
spec/spec_helper.rb
|
|
35
|
+
spec/tagz_helpers_spec.rb
|
|
36
|
+
spec/tagz_spec.rb
|
|
30
37
|
spec/wrappers_spec.rb
|
|
31
|
-
tasks/docs.rake
|
|
32
|
-
tasks/gemspec.rake
|
|
33
|
-
tasks/spec.rake
|
data/Rakefile
CHANGED
|
@@ -10,9 +10,9 @@ Echoe.new "formz", Formz::VERSION do |p|
|
|
|
10
10
|
p.email = "tj@vision-media.ca"
|
|
11
11
|
p.summary = "Framework independant tag helpers"
|
|
12
12
|
p.url = "http://github.com/visionmedia/formz"
|
|
13
|
-
p.runtime_dependencies << '
|
|
13
|
+
p.runtime_dependencies << 'rext >=0.5.0'
|
|
14
14
|
p.development_dependencies << 'rspec_hpricot_matchers >=1.0.0'
|
|
15
15
|
p.development_dependencies << 'thoughtbot-factory_girl'
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
task :gemspec => [:build_gemspec]
|
data/formz.gemspec
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{formz}
|
|
5
|
-
s.version = "0.0
|
|
5
|
+
s.version = "0.1.0"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
|
9
|
-
s.date = %q{2009-
|
|
9
|
+
s.date = %q{2009-12-01}
|
|
10
10
|
s.description = %q{Framework independant tag helpers}
|
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/formz.rb", "lib/formz/autoencoding.rb", "lib/formz/descriptions.rb", "lib/formz/errors.rb", "lib/formz/fauxmethod.rb", "lib/formz/helpers.rb", "lib/formz/import.rb", "lib/formz/labels.rb", "lib/formz/models.rb", "lib/formz/version.rb", "lib/formz/wrappers.rb", "
|
|
13
|
-
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "benchmarks/small.rb", "examples/model.rb", "examples/small.rb", "formz.gemspec", "lib/formz.rb", "lib/formz/autoencoding.rb", "lib/formz/descriptions.rb", "lib/formz/errors.rb", "lib/formz/fauxmethod.rb", "lib/formz/helpers.rb", "lib/formz/import.rb", "lib/formz/labels.rb", "lib/formz/models.rb", "lib/formz/version.rb", "lib/formz/wrappers.rb", "spec/autoencoding_spec.rb", "spec/descriptions_spec.rb", "spec/errors_spec.rb", "spec/factories/user.rb", "spec/fauxmethod_spec.rb", "spec/helpers_spec.rb", "spec/labels_spec.rb", "spec/models_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/
|
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/formz.rb", "lib/formz/autoencoding.rb", "lib/formz/descriptions.rb", "lib/formz/errors.rb", "lib/formz/fauxmethod.rb", "lib/formz/helpers.rb", "lib/formz/import.rb", "lib/formz/labels.rb", "lib/formz/models.rb", "lib/formz/version.rb", "lib/formz/wrappers.rb", "lib/tagz.rb", "lib/tagz/helpers.rb", "lib/tagz/import.rb", "lib/tagz/tagz.rb", "lib/tagz/version.rb"]
|
|
13
|
+
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "benchmarks/small.rb", "examples/model.rb", "examples/small.rb", "formz.gemspec", "lib/formz.rb", "lib/formz/autoencoding.rb", "lib/formz/descriptions.rb", "lib/formz/errors.rb", "lib/formz/fauxmethod.rb", "lib/formz/helpers.rb", "lib/formz/import.rb", "lib/formz/labels.rb", "lib/formz/models.rb", "lib/formz/version.rb", "lib/formz/wrappers.rb", "lib/tagz.rb", "lib/tagz/helpers.rb", "lib/tagz/import.rb", "lib/tagz/tagz.rb", "lib/tagz/version.rb", "spec/autoencoding_spec.rb", "spec/descriptions_spec.rb", "spec/errors_spec.rb", "spec/factories/user.rb", "spec/fauxmethod_spec.rb", "spec/helpers_spec.rb", "spec/labels_spec.rb", "spec/models_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/tagz_helpers_spec.rb", "spec/tagz_spec.rb", "spec/wrappers_spec.rb"]
|
|
14
14
|
s.homepage = %q{http://github.com/visionmedia/formz}
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Formz", "--main", "README.rdoc"]
|
|
16
16
|
s.require_paths = ["lib"]
|
|
@@ -23,16 +23,16 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
s.specification_version = 3
|
|
24
24
|
|
|
25
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
26
|
-
s.add_runtime_dependency(%q<
|
|
26
|
+
s.add_runtime_dependency(%q<rext>, [">= 0.5.0"])
|
|
27
27
|
s.add_development_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
|
|
28
28
|
s.add_development_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
|
|
29
29
|
else
|
|
30
|
-
s.add_dependency(%q<
|
|
30
|
+
s.add_dependency(%q<rext>, [">= 0.5.0"])
|
|
31
31
|
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
|
|
32
32
|
s.add_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
|
|
33
33
|
end
|
|
34
34
|
else
|
|
35
|
-
s.add_dependency(%q<
|
|
35
|
+
s.add_dependency(%q<rext>, [">= 0.5.0"])
|
|
36
36
|
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
|
|
37
37
|
s.add_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
|
|
38
38
|
end
|
data/lib/formz.rb
CHANGED
data/lib/formz/version.rb
CHANGED
data/lib/tagz.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 :Helpers, 'tagz/helpers'
|
|
30
|
+
end
|
data/lib/tagz/helpers.rb
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
|
|
2
|
+
module Tagz
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# = Helpers
|
|
6
|
+
#
|
|
7
|
+
# Tagz::Helpers consists of methods which
|
|
8
|
+
# assist creation of common tag combinations
|
|
9
|
+
# and standards. For example images may simply
|
|
10
|
+
# call image('foo.png'), as a shortcut for
|
|
11
|
+
# tag(:img, :src => 'foo.png').
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
module Helpers
|
|
15
|
+
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Return image tag to _path_.
|
|
20
|
+
#
|
|
21
|
+
# === Examples
|
|
22
|
+
#
|
|
23
|
+
# image 'foo.png'
|
|
24
|
+
# # => <img src="foo.png" />
|
|
25
|
+
#
|
|
26
|
+
# image 'foo.png', :alt => 'Kung-foo'
|
|
27
|
+
# # => <img src="foo.png" alt="Kung-foo">
|
|
28
|
+
#
|
|
29
|
+
|
|
30
|
+
def image path, attrs = {}
|
|
31
|
+
Tagz.tag :img, { :src => path }.merge(attrs)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
# Return stylesheet link tag to _path_. When a _block_
|
|
36
|
+
# is passed, a style tag will be created with the yielded
|
|
37
|
+
# value as its contents.
|
|
38
|
+
#
|
|
39
|
+
# === Examples
|
|
40
|
+
#
|
|
41
|
+
# stylesheet do
|
|
42
|
+
# "body {
|
|
43
|
+
# color: blue;
|
|
44
|
+
# }"
|
|
45
|
+
# end
|
|
46
|
+
# # => <style>body { ... }</style>
|
|
47
|
+
#
|
|
48
|
+
#
|
|
49
|
+
# stylesheet 'style.css', :media => :print
|
|
50
|
+
# # => <link rel="stylesheet" href="style.css" media="print" />
|
|
51
|
+
#
|
|
52
|
+
|
|
53
|
+
def stylesheet path = nil, attrs = {}, &block
|
|
54
|
+
return tag(:style, yield, { :type => 'text/css' }.merge(attrs)) if block
|
|
55
|
+
Tagz.tag :link, { :rel => 'stylesheet', :href => path }.merge(attrs)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
##
|
|
59
|
+
# Return script tag to _path_. When a _block_ is passed,
|
|
60
|
+
# a script tag will be created with the yielded value as
|
|
61
|
+
# its contents.
|
|
62
|
+
#
|
|
63
|
+
# === Examples
|
|
64
|
+
#
|
|
65
|
+
# javascript do
|
|
66
|
+
# "foo"
|
|
67
|
+
# end
|
|
68
|
+
# # => <script type="text/javascript">foo</script>
|
|
69
|
+
#
|
|
70
|
+
# javascript 'jquery.js'
|
|
71
|
+
# # => <script type="text/javascript" src="jquery.js"></script>
|
|
72
|
+
#
|
|
73
|
+
|
|
74
|
+
def javascript path = nil, attrs = {}, &block
|
|
75
|
+
contents = yield if block
|
|
76
|
+
Tagz.tag :script, contents, { :type => 'text/javascript', :src => path }.merge(attrs)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
##
|
|
80
|
+
# Return meta tag _name_ with _contents_.
|
|
81
|
+
#
|
|
82
|
+
# === Examples
|
|
83
|
+
#
|
|
84
|
+
# meta :keywords, 'foo bar'
|
|
85
|
+
# meta :description, 'Welcome to foo bar'
|
|
86
|
+
#
|
|
87
|
+
# # => <meta name="keywords" contents="foo bar">
|
|
88
|
+
# # => <meta name="description" contents="Welcome to foo bar">
|
|
89
|
+
#
|
|
90
|
+
|
|
91
|
+
def meta name, contents
|
|
92
|
+
Tagz.tag :meta, :name => name, :contents => contents
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
##
|
|
96
|
+
# Return CDATA tag with _contents_.
|
|
97
|
+
#
|
|
98
|
+
# === Examples
|
|
99
|
+
#
|
|
100
|
+
# cdata '<foo>'
|
|
101
|
+
# # => <![CDATA[<foo>]]>
|
|
102
|
+
#
|
|
103
|
+
|
|
104
|
+
def cdata contents
|
|
105
|
+
"<![CDATA[#{contents}]]>"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
#--
|
|
109
|
+
# Delegates
|
|
110
|
+
#++
|
|
111
|
+
|
|
112
|
+
module Delegates
|
|
113
|
+
%w( cdata meta javascript stylesheet image ).each do |meth|
|
|
114
|
+
class_eval <<-EOF
|
|
115
|
+
def #{meth} *args, &block
|
|
116
|
+
@contents << Tagz::Helpers.#{meth}(*args, &block)
|
|
117
|
+
end
|
|
118
|
+
EOF
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
end
|
data/lib/tagz/import.rb
ADDED
data/lib/tagz/tagz.rb
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
#--
|
|
53
|
+
# Tag
|
|
54
|
+
#++
|
|
55
|
+
|
|
56
|
+
class Tag
|
|
57
|
+
|
|
58
|
+
##
|
|
59
|
+
# Tag name.
|
|
60
|
+
|
|
61
|
+
attr_reader :name
|
|
62
|
+
|
|
63
|
+
##
|
|
64
|
+
# Contents string.
|
|
65
|
+
|
|
66
|
+
attr_reader :contents
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# Attributes hash.
|
|
70
|
+
|
|
71
|
+
attr_reader :attrs
|
|
72
|
+
|
|
73
|
+
##
|
|
74
|
+
# Block proc.
|
|
75
|
+
|
|
76
|
+
attr_reader :proc
|
|
77
|
+
|
|
78
|
+
#:nodoc:
|
|
79
|
+
|
|
80
|
+
def initialize name, contents = nil, attrs = {}, &block
|
|
81
|
+
@name, @contents, @attrs, @proc = name, (contents || ''), attrs, block
|
|
82
|
+
block.yield_or_eval self if block
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# Append tag to contents.
|
|
87
|
+
|
|
88
|
+
def tag *args, &block
|
|
89
|
+
@contents << Tagz.tag(*args, &block).to_s
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# Return tag string.
|
|
94
|
+
|
|
95
|
+
def to_s
|
|
96
|
+
create_tag name, contents, attrs, &proc
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
module_function
|
|
101
|
+
|
|
102
|
+
##
|
|
103
|
+
# Return markup for tag _name_. Optionally _contents_ may
|
|
104
|
+
# be passed, which is literal content for spanning tags such
|
|
105
|
+
# as textarea, etc. A hash of _attrs_ may be passed as the
|
|
106
|
+
# second or third argument.
|
|
107
|
+
#
|
|
108
|
+
# Self closing tags such as <br/>, <input/> etc are automatically
|
|
109
|
+
# closed, and boolean attributes of "selected", "checked" etc
|
|
110
|
+
# are mirrored or removed when true or false.
|
|
111
|
+
#
|
|
112
|
+
# === Examples
|
|
113
|
+
#
|
|
114
|
+
# tag :br
|
|
115
|
+
# # => <br/>
|
|
116
|
+
#
|
|
117
|
+
# tag :div
|
|
118
|
+
# # => <div></div>
|
|
119
|
+
#
|
|
120
|
+
# tag :div, 'hello'
|
|
121
|
+
# # => <div>hello</div>
|
|
122
|
+
#
|
|
123
|
+
# tag :div, 'hello', :id => 'comment'
|
|
124
|
+
# # => <div id="comment">hello</div>
|
|
125
|
+
#
|
|
126
|
+
# tag :div, :id => 'comment'
|
|
127
|
+
# # => <div id="comment"></div>
|
|
128
|
+
#
|
|
129
|
+
# tag :div do
|
|
130
|
+
# tag :p, 'Hello World'
|
|
131
|
+
# end
|
|
132
|
+
# # => <div><p>Hello World</p></div>
|
|
133
|
+
#
|
|
134
|
+
# tag :div do |div|
|
|
135
|
+
# div.tag :p, 'Hello World'
|
|
136
|
+
# end
|
|
137
|
+
# # => <div><p>Hello World</p></div>
|
|
138
|
+
#
|
|
139
|
+
# tag :input, :type => :checkbox, :checked => true
|
|
140
|
+
# # => <input type="checkbox" checked="checked" />
|
|
141
|
+
#
|
|
142
|
+
|
|
143
|
+
def tag name, contents = nil, attrs = {}, &block
|
|
144
|
+
attrs, contents = contents, nil if contents.is_a? Hash
|
|
145
|
+
Tag.new(name, contents, attrs, &block).to_s
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
#:stopdoc:
|
|
149
|
+
|
|
150
|
+
def create_tag name, contents = nil, attrs = {}
|
|
151
|
+
self_closing_tag?(name) ?
|
|
152
|
+
self_closing_tag(name, attrs) :
|
|
153
|
+
open_tag(name, attrs) + contents.to_s + closing_tag(name)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
##
|
|
157
|
+
# Check if _name_ is a boolean attribute.
|
|
158
|
+
|
|
159
|
+
def boolean_attribute? name
|
|
160
|
+
name.in? BOOLEAN_ATTRIBUTES
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
##
|
|
164
|
+
# Check if tag _name_ is a self-closing tag.
|
|
165
|
+
|
|
166
|
+
def self_closing_tag? name
|
|
167
|
+
name.in? SELF_CLOSING_TAGS
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
##
|
|
171
|
+
# Return a self closing tag of _name_, with _attrs_.
|
|
172
|
+
|
|
173
|
+
def self_closing_tag name, attrs = {}
|
|
174
|
+
"\n<#{name}#{normalize_html_attributes(attrs)}/>"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
##
|
|
178
|
+
# Return an opening tag of _name_, with _attrs_.
|
|
179
|
+
|
|
180
|
+
def open_tag name, attrs = {}
|
|
181
|
+
"\n<#{name}#{normalize_html_attributes(attrs)}>"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
##
|
|
185
|
+
# Normalize _attrs_, replacing boolean keys
|
|
186
|
+
# with their mirrored values.
|
|
187
|
+
|
|
188
|
+
def normalize_html_attributes attrs = {}
|
|
189
|
+
return if attrs.blank?
|
|
190
|
+
attrs.each do |name, value|
|
|
191
|
+
if boolean_attribute? name
|
|
192
|
+
value ? attrs[name] = name : attrs.delete(name)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
' ' + attrs.to_html_attributes
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
##
|
|
199
|
+
# Return closing tag of _name_.
|
|
200
|
+
|
|
201
|
+
def closing_tag name
|
|
202
|
+
"</#{name}>"
|
|
203
|
+
end
|
|
204
|
+
end
|
data/lib/tagz/version.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
describe Tagz do
|
|
3
|
+
describe Helpers do
|
|
4
|
+
it "should allow calling helpers within tag blocks" do
|
|
5
|
+
markup = tag :head do |head|
|
|
6
|
+
head.meta :keywords, 'foo bar'
|
|
7
|
+
head.meta :description, 'some foo bar'
|
|
8
|
+
end
|
|
9
|
+
markup.should have_tag('head') do |head|
|
|
10
|
+
head.should have_tag('meta[@name=keywords]')
|
|
11
|
+
head.should have_tag('meta[@name=description]')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#cdata" do
|
|
16
|
+
it "should return a CDATA tag" do
|
|
17
|
+
cdata('<foo>').should == '<![CDATA[<foo>]]>'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "#meta" do
|
|
22
|
+
it "should accept name and contents" do
|
|
23
|
+
meta(:keywords, 'some foo bar').should have_tag('meta[@name=keywords]')
|
|
24
|
+
meta(:keywords, 'some foo bar').should have_tag('meta[@contents=some foo bar]')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "#image" do
|
|
29
|
+
it "should accept a path as the first argument" do
|
|
30
|
+
image('foo.png').should have_tag('img[@src=foo.png]')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should accept a hash of attributes" do
|
|
34
|
+
image('foo.png', :alt => 'Kung-foo').should have_tag('img[@alt=Kung-foo]')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#stylesheet" do
|
|
39
|
+
it "should return inline style tags when a block is passed" do
|
|
40
|
+
markup = stylesheet do
|
|
41
|
+
'body {}'
|
|
42
|
+
end
|
|
43
|
+
markup.should have_tag('style', 'body {}')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should assign rel attribute" do
|
|
47
|
+
stylesheet('style.css').should have_tag('link[@rel=stylesheet]')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should assign href attribute" do
|
|
51
|
+
stylesheet('style.css').should have_tag('link[@href=style.css]')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should accept a hash of attributes" do
|
|
55
|
+
stylesheet('style.css', :media => :print).should have_tag('link[@media=print]')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#javascript" do
|
|
61
|
+
it "should return inline javascript tag when a block is passed" do
|
|
62
|
+
markup = javascript do
|
|
63
|
+
'foo'
|
|
64
|
+
end
|
|
65
|
+
markup.should have_tag('script', 'foo')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should assign type attribute" do
|
|
69
|
+
javascript('jquery.js').should have_tag('script[@type=text/javascript]')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should assign src attribute" do
|
|
73
|
+
javascript('jquery.js').should have_tag('script[@src=jquery.js]')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should accept a hash of attributes" do
|
|
77
|
+
javascript('jquery.js', :foo => :bar).should have_tag('script[@foo=bar]')
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/spec/tagz_spec.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
|
|
25
|
+
it "should accept blocks to populate contents" do
|
|
26
|
+
markup = tag :form do |div|
|
|
27
|
+
div.tag :h2, 'Login'
|
|
28
|
+
div.tag :input, :type => :text
|
|
29
|
+
div.tag :input, :type => :submit, :value => 'Submit'
|
|
30
|
+
end
|
|
31
|
+
markup.should have_tag('form') do |form|
|
|
32
|
+
form.should have_tag('h2', 'Login')
|
|
33
|
+
form.should have_tag('input[@type=text]')
|
|
34
|
+
form.should have_tag('input[@type=submit]')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should evaluate blocks to populate contents" do
|
|
39
|
+
markup = tag :form do
|
|
40
|
+
tag :h2, 'Login'
|
|
41
|
+
tag :input, :type => :text
|
|
42
|
+
tag :input, :type => :submit, :value => 'Submit'
|
|
43
|
+
end
|
|
44
|
+
markup.should have_tag('form') do |form|
|
|
45
|
+
form.should have_tag('h2', 'Login')
|
|
46
|
+
form.should have_tag('input[@type=text]')
|
|
47
|
+
form.should have_tag('input[@type=submit]')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should work with deep nesting" do
|
|
52
|
+
markup = tag :form do |div|
|
|
53
|
+
div.tag :h2, 'Comment'
|
|
54
|
+
div.tag :div do |div|
|
|
55
|
+
div.tag :textarea, :id => 'comments'
|
|
56
|
+
div.tag :input, :type => 'submit'
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
markup.should have_tag('form') do |form|
|
|
60
|
+
form.should have_tag('h2', 'Comment')
|
|
61
|
+
form.should have_tag('div') do |div|
|
|
62
|
+
div.should have_tag('textarea[@id=comments]')
|
|
63
|
+
div.should have_tag('input[@type=submit]')
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should work with deep nesting when evaluating blocks" do
|
|
69
|
+
markup = tag :form do
|
|
70
|
+
tag :h2, 'Comment'
|
|
71
|
+
tag :div do
|
|
72
|
+
tag :textarea, :id => 'comments'
|
|
73
|
+
tag :input, :type => 'submit'
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
markup.should have_tag('form') do |form|
|
|
77
|
+
form.should have_tag('h2', 'Comment')
|
|
78
|
+
form.should have_tag('div') do |div|
|
|
79
|
+
div.should have_tag('textarea[@id=comments]')
|
|
80
|
+
div.should have_tag('input[@type=submit]')
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: formz
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TJ Holowaychuk
|
|
@@ -9,18 +9,18 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-12-01 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
16
|
+
name: rext
|
|
17
17
|
type: :runtime
|
|
18
18
|
version_requirement:
|
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
|
20
20
|
requirements:
|
|
21
21
|
- - ">="
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version:
|
|
23
|
+
version: 0.5.0
|
|
24
24
|
version:
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: rspec_hpricot_matchers
|
|
@@ -61,9 +61,11 @@ extra_rdoc_files:
|
|
|
61
61
|
- lib/formz/models.rb
|
|
62
62
|
- lib/formz/version.rb
|
|
63
63
|
- lib/formz/wrappers.rb
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
64
|
+
- lib/tagz.rb
|
|
65
|
+
- lib/tagz/helpers.rb
|
|
66
|
+
- lib/tagz/import.rb
|
|
67
|
+
- lib/tagz/tagz.rb
|
|
68
|
+
- lib/tagz/version.rb
|
|
67
69
|
files:
|
|
68
70
|
- History.rdoc
|
|
69
71
|
- Manifest
|
|
@@ -84,6 +86,11 @@ files:
|
|
|
84
86
|
- lib/formz/models.rb
|
|
85
87
|
- lib/formz/version.rb
|
|
86
88
|
- lib/formz/wrappers.rb
|
|
89
|
+
- lib/tagz.rb
|
|
90
|
+
- lib/tagz/helpers.rb
|
|
91
|
+
- lib/tagz/import.rb
|
|
92
|
+
- lib/tagz/tagz.rb
|
|
93
|
+
- lib/tagz/version.rb
|
|
87
94
|
- spec/autoencoding_spec.rb
|
|
88
95
|
- spec/descriptions_spec.rb
|
|
89
96
|
- spec/errors_spec.rb
|
|
@@ -94,10 +101,9 @@ files:
|
|
|
94
101
|
- spec/models_spec.rb
|
|
95
102
|
- spec/spec.opts
|
|
96
103
|
- spec/spec_helper.rb
|
|
104
|
+
- spec/tagz_helpers_spec.rb
|
|
105
|
+
- spec/tagz_spec.rb
|
|
97
106
|
- spec/wrappers_spec.rb
|
|
98
|
-
- tasks/docs.rake
|
|
99
|
-
- tasks/gemspec.rake
|
|
100
|
-
- tasks/spec.rake
|
|
101
107
|
has_rdoc: true
|
|
102
108
|
homepage: http://github.com/visionmedia/formz
|
|
103
109
|
licenses: []
|
data/tasks/docs.rake
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
namespace :docs do
|
|
3
|
-
|
|
4
|
-
desc 'Remove rdoc products'
|
|
5
|
-
task :remove => [:clobber_docs]
|
|
6
|
-
|
|
7
|
-
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
|
8
|
-
task :open do
|
|
9
|
-
browser = ENV["BROWSER"] || "safari"
|
|
10
|
-
sh "open -a #{browser} doc/index.html"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
end
|
data/tasks/gemspec.rake
DELETED
data/tasks/spec.rake
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|