attrtastic 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +17 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/attrtastic.gemspec +63 -0
- data/lib/attrtastic.rb +111 -0
- data/rails/init.rb +2 -0
- data/test/helper.rb +45 -0
- data/test/test_attribute.rb +123 -0
- data/test/test_attributes.rb +105 -0
- data/test/test_attrtastic.rb +88 -0
- data/test/test_semantic_attributes_helper.rb +51 -0
- metadata +84 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Boruta Miroslaw
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= attrtastic
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2009 Boruta Miroslaw. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "attrtastic"
|
8
|
+
gem.summary = %Q{summary}
|
9
|
+
gem.description = %Q{description}
|
10
|
+
gem.email = "boruta.miroslaw@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/MBO/attrtastic"
|
12
|
+
gem.authors = ["Boruta Miroslaw"]
|
13
|
+
gem.add_development_dependency "yard", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'yard'
|
47
|
+
YARD::Rake::YardocTask.new
|
48
|
+
rescue LoadError
|
49
|
+
task :yardoc do
|
50
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
51
|
+
end
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/attrtastic.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{attrtastic}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Boruta Miroslaw"]
|
12
|
+
s.date = %q{2010-01-03}
|
13
|
+
s.description = %q{description}
|
14
|
+
s.email = %q{boruta.miroslaw@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"attrtastic.gemspec",
|
29
|
+
"lib/attrtastic.rb",
|
30
|
+
"rails/init.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_attribute.rb",
|
33
|
+
"test/test_attributes.rb",
|
34
|
+
"test/test_attrtastic.rb",
|
35
|
+
"test/test_semantic_attributes_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/MBO/attrtastic}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{summary}
|
42
|
+
s.test_files = [
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_attrtastic.rb",
|
45
|
+
"test/test_attribute.rb",
|
46
|
+
"test/test_semantic_attributes_helper.rb",
|
47
|
+
"test/test_attributes.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/attrtastic.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module Attrtastic
|
2
|
+
|
3
|
+
class SemanticAttributesBuilder
|
4
|
+
|
5
|
+
@@value_methods = %w/ to_label display_name full_name name title username login value to_s /
|
6
|
+
|
7
|
+
attr_reader :record, :template
|
8
|
+
|
9
|
+
def initialize(record, template)
|
10
|
+
@record, @template = record, template
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes(*args, &block)
|
14
|
+
options = {}
|
15
|
+
if args.last and args.last.kind_of? Hash
|
16
|
+
options = args.last
|
17
|
+
args = args[0 .. -2]
|
18
|
+
end
|
19
|
+
options[:html] ||= {}
|
20
|
+
|
21
|
+
html_class = [ "attributes", options[:html].delete(:class) ].compact.join(" ")
|
22
|
+
html_header_class = [ "legend", options[:html].delete(:header_class) ].compact.join(" ")
|
23
|
+
|
24
|
+
template.concat(template.tag(:div, {:class => html_class}, true))
|
25
|
+
|
26
|
+
if args.first and args.first.is_a? String
|
27
|
+
header = args.shift
|
28
|
+
template.concat(template.content_tag(:div, header, :class => html_header_class))
|
29
|
+
end
|
30
|
+
|
31
|
+
if block_given?
|
32
|
+
template.concat(template.tag(:ol, {}, true))
|
33
|
+
yield
|
34
|
+
template.concat("</ol>")
|
35
|
+
elsif args.present?
|
36
|
+
template.concat(template.tag(:ol, {}, true))
|
37
|
+
attrs = args.map {|method| attribute(method, options)}.compact.join
|
38
|
+
template.concat(attrs)
|
39
|
+
template.concat("</ol>")
|
40
|
+
end
|
41
|
+
|
42
|
+
template.concat("</div>")
|
43
|
+
end
|
44
|
+
|
45
|
+
def attribute(*args, &block)
|
46
|
+
options = {}
|
47
|
+
if args.last and args.last.kind_of? Hash
|
48
|
+
options = args.last
|
49
|
+
args = args[0 .. -2]
|
50
|
+
end
|
51
|
+
options[:html] ||= {}
|
52
|
+
|
53
|
+
method = args.shift
|
54
|
+
|
55
|
+
html_label_class = [ "label", options[:html][:label_class] ].compact.join(" ")
|
56
|
+
html_value_class = [ "value", options[:html][:value_class] ].compact.join(" ")
|
57
|
+
html_class = [ "attribute", options[:html][:class] ].compact.join(" ")
|
58
|
+
|
59
|
+
label = options.key?(:label) ? options[:label] : label_for_attribute(method)
|
60
|
+
label_content = template.content_tag(:span, label, :class => html_label_class)
|
61
|
+
|
62
|
+
unless block_given?
|
63
|
+
value = options.key?(:value) ? options[:value] : value_of_attribute(method)
|
64
|
+
value_content = template.content_tag(:span, value, :class => html_value_class)
|
65
|
+
|
66
|
+
if value.present? or options[:display_empty]
|
67
|
+
content = [ label_content, value_content ].join
|
68
|
+
template.content_tag(:li, content, :class => html_class)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
template.concat(template.tag(:li, {:class => html_class}, true))
|
72
|
+
template.concat(label_content)
|
73
|
+
template.concat(template.tag(:span, {:class => html_value_class}, true))
|
74
|
+
yield
|
75
|
+
template.concat("</span>")
|
76
|
+
template.concat("</li>")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def label_for_attribute(method)
|
83
|
+
if record.class.respond_to?(:human_attribute_name)
|
84
|
+
record.class.human_attribute_name(method.to_s)
|
85
|
+
else
|
86
|
+
method.to_s.send(:humanize)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def value_of_attribute(method)
|
91
|
+
record.send(method).to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
module SemanticAttributesHelper
|
97
|
+
|
98
|
+
def semantic_attributes_for(record, options = {}, &block)
|
99
|
+
options[:html] ||= {}
|
100
|
+
|
101
|
+
html_class = [ "attrtastic", record.class.to_s.underscore, options[:html][:class] ].compact.join(" ")
|
102
|
+
|
103
|
+
concat(tag(:div, { :class => html_class}, true))
|
104
|
+
yield SemanticAttributesBuilder.new(record, self) if block_given?
|
105
|
+
concat("</div>")
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
data/rails/init.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'action_view'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
require 'attrtastic'
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
def html(string)
|
10
|
+
string.split(/\n/m).map(&:strip).join
|
11
|
+
end
|
12
|
+
def setup_fixtures
|
13
|
+
@user = User.new.tap do |u|
|
14
|
+
u.first_name,u.last_name = "John","Doe"
|
15
|
+
u.email = "john@doe.com"
|
16
|
+
end
|
17
|
+
@blog = Blog.new.tap{|b| b.name,b.url,b.author = "IT Pro Blog","http://www.it.pro.blog",@user}
|
18
|
+
@blog.posts = [
|
19
|
+
Post.new.tap{|p| p.title,p.content = "Hello World!","Hello World!\nInitial post"},
|
20
|
+
Post.new.tap{|p| p.title,p.content = "Sorry","Sorry for long delay. Had much stuff on my head..."},
|
21
|
+
]
|
22
|
+
|
23
|
+
ActionView::Base.send :include, Attrtastic::SemanticAttributesHelper
|
24
|
+
@template = ActionView::Base.new.tap{ |av| av.output_buffer = "" }
|
25
|
+
@user_builder = Attrtastic::SemanticAttributesBuilder.new(@user, @template)
|
26
|
+
@blog_builder = Attrtastic::SemanticAttributesBuilder.new(@blog, @template)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class User
|
31
|
+
attr_accessor :first_name, :last_name, :email, :title
|
32
|
+
|
33
|
+
def full_name
|
34
|
+
[last_name,first_name].join(", ")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Blog
|
39
|
+
attr_accessor :name, :url, :author, :posts
|
40
|
+
delegate :full_name, :to => :author, :prefix => true
|
41
|
+
end
|
42
|
+
|
43
|
+
class Post
|
44
|
+
attr_accessor :title, :content
|
45
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAttribute < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_fixtures
|
7
|
+
end
|
8
|
+
|
9
|
+
def test__attribute__output
|
10
|
+
expected = html <<-EOHTML
|
11
|
+
<li class="attribute">
|
12
|
+
<span class="label">Full name</span>
|
13
|
+
<span class="value">Doe, John</span>
|
14
|
+
</li>
|
15
|
+
EOHTML
|
16
|
+
|
17
|
+
actual = @user_builder.attribute(:full_name)
|
18
|
+
assert_equal expected, actual
|
19
|
+
end
|
20
|
+
|
21
|
+
def test__attribute__with_empty_value
|
22
|
+
actual = @user_builder.attribute(:title)
|
23
|
+
assert_nil actual
|
24
|
+
|
25
|
+
expected = html <<-EOHTML
|
26
|
+
<li class="attribute">
|
27
|
+
<span class="label">Title</span>
|
28
|
+
<span class="value"></span>
|
29
|
+
</li>
|
30
|
+
EOHTML
|
31
|
+
|
32
|
+
actual = @user_builder.attribute(:title, :display_empty => true)
|
33
|
+
assert_equal expected, actual
|
34
|
+
end
|
35
|
+
|
36
|
+
def test__attribute__with_custom_label
|
37
|
+
expected = html <<-EOHTML
|
38
|
+
<li class="attribute">
|
39
|
+
<span class="label">Name</span>
|
40
|
+
<span class="value">Doe, John</span>
|
41
|
+
</li>
|
42
|
+
EOHTML
|
43
|
+
|
44
|
+
actual = @user_builder.attribute(:full_name, :label => "Name")
|
45
|
+
assert_equal expected, actual
|
46
|
+
end
|
47
|
+
|
48
|
+
def test__attribute__with_custom_value
|
49
|
+
expected = html <<-EOHTML
|
50
|
+
<li class="attribute">
|
51
|
+
<span class="label">Full name</span>
|
52
|
+
<span class="value">Sir Doe, John</span>
|
53
|
+
</li>
|
54
|
+
EOHTML
|
55
|
+
|
56
|
+
actual = @user_builder.attribute(:full_name, :value => "Sir #{@user.full_name}")
|
57
|
+
assert_equal expected, actual
|
58
|
+
end
|
59
|
+
|
60
|
+
def test__attribute__with_empty_custom_value
|
61
|
+
assert_nil @user_builder.attribute(:full_name, :value => nil)
|
62
|
+
assert_nil @user_builder.attribute(:full_name, :value => "")
|
63
|
+
|
64
|
+
expected = html <<-EOHTML
|
65
|
+
<li class="attribute">
|
66
|
+
<span class="label">Full name</span>
|
67
|
+
<span class="value"></span>
|
68
|
+
</li>
|
69
|
+
EOHTML
|
70
|
+
|
71
|
+
actual = @user_builder.attribute(:full_name, :value => nil, :display_empty => true)
|
72
|
+
assert_equal expected, actual
|
73
|
+
|
74
|
+
actual = @user_builder.attribute(:full_name, :value => "", :display_empty => true)
|
75
|
+
assert_equal expected, actual
|
76
|
+
end
|
77
|
+
|
78
|
+
def test__attribute__with_block
|
79
|
+
block_run = false
|
80
|
+
@user_builder.attribute :full_name do
|
81
|
+
block_run = true
|
82
|
+
end
|
83
|
+
assert block_run
|
84
|
+
end
|
85
|
+
|
86
|
+
def test__attribute__output_with_block
|
87
|
+
expected = html <<-EOHTML
|
88
|
+
<li class="attribute">
|
89
|
+
<span class="label">Full name</span>
|
90
|
+
<span class="value">John Doe!!!</span>
|
91
|
+
</li>
|
92
|
+
EOHTML
|
93
|
+
|
94
|
+
@user_builder.attribute :full_name do
|
95
|
+
@user_builder.template.output_buffer << "John Doe"
|
96
|
+
3.times do
|
97
|
+
@user_builder.template.output_buffer << "!"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
actual = @template.output_buffer.to_s
|
101
|
+
assert_equal expected, actual
|
102
|
+
end
|
103
|
+
|
104
|
+
def test__attribute__with_block_and_custom_label
|
105
|
+
expected = html <<-EOHTML
|
106
|
+
<li class="attribute">
|
107
|
+
<span class="label">Full name</span>
|
108
|
+
<span class="value">John Doe!!!</span>
|
109
|
+
</li>
|
110
|
+
EOHTML
|
111
|
+
|
112
|
+
@user_builder.attribute :label => "Full name" do
|
113
|
+
@user_builder.template.output_buffer << "John Doe"
|
114
|
+
3.times do
|
115
|
+
@user_builder.template.output_buffer << "!"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
actual = @template.output_buffer.to_s
|
119
|
+
assert_equal expected, actual
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAttributes < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_fixtures
|
7
|
+
end
|
8
|
+
|
9
|
+
def test__attributes__shoul_run_block
|
10
|
+
block_run = false
|
11
|
+
@user_builder.attributes do
|
12
|
+
block_run = true
|
13
|
+
end
|
14
|
+
|
15
|
+
assert block_run
|
16
|
+
end
|
17
|
+
|
18
|
+
def test__attributes__output_without_block
|
19
|
+
expected = html <<-EOHTML
|
20
|
+
<div class="attributes">
|
21
|
+
</div>
|
22
|
+
EOHTML
|
23
|
+
|
24
|
+
@user_builder.attributes
|
25
|
+
actual = @template.output_buffer.to_s
|
26
|
+
|
27
|
+
assert_equal expected, actual
|
28
|
+
end
|
29
|
+
|
30
|
+
def test__attributes__output
|
31
|
+
expected = html <<-EOHTML
|
32
|
+
<div class="attributes">
|
33
|
+
<ol>
|
34
|
+
</ol>
|
35
|
+
</div>
|
36
|
+
EOHTML
|
37
|
+
|
38
|
+
@user_builder.attributes do end
|
39
|
+
actual = @template.output_buffer.to_s
|
40
|
+
|
41
|
+
assert_equal expected, actual
|
42
|
+
end
|
43
|
+
|
44
|
+
def test__attributes__with_header
|
45
|
+
expected = html <<-EOHTML
|
46
|
+
<div class="attributes">
|
47
|
+
<div class="legend">Legend</div>
|
48
|
+
<ol>
|
49
|
+
</ol>
|
50
|
+
</div>
|
51
|
+
EOHTML
|
52
|
+
|
53
|
+
@user_builder.attributes "Legend" do end
|
54
|
+
actual = @template.output_buffer.to_s
|
55
|
+
assert_equal expected, actual
|
56
|
+
end
|
57
|
+
|
58
|
+
def test__attributes__with_fields_list
|
59
|
+
expected = html <<-EOHTML
|
60
|
+
<div class="attributes">
|
61
|
+
<ol>
|
62
|
+
<li class="attribute">
|
63
|
+
<span class="label">Full name</span>
|
64
|
+
<span class="value">Doe, John</span>
|
65
|
+
</li>
|
66
|
+
<li class="attribute">
|
67
|
+
<span class="label">Email</span>
|
68
|
+
<span class="value">john@doe.com</span>
|
69
|
+
</li>
|
70
|
+
</ol>
|
71
|
+
</div>
|
72
|
+
EOHTML
|
73
|
+
|
74
|
+
@user_builder.attributes :full_name, :email
|
75
|
+
actual = @template.output_buffer.to_s
|
76
|
+
assert_equal expected, actual
|
77
|
+
end
|
78
|
+
|
79
|
+
def test__attributes__with_fields_list_header_and_options
|
80
|
+
expected = html <<-EOHTML
|
81
|
+
<div class="attributes contact">
|
82
|
+
<div class="legend">Contact</div>
|
83
|
+
<ol>
|
84
|
+
<li class="attribute">
|
85
|
+
<span class="label">Full name</span>
|
86
|
+
<span class="value">Doe, John</span>
|
87
|
+
</li>
|
88
|
+
<li class="attribute">
|
89
|
+
<span class="label">Title</span>
|
90
|
+
<span class="value"></span>
|
91
|
+
</li>
|
92
|
+
<li class="attribute">
|
93
|
+
<span class="label">Email</span>
|
94
|
+
<span class="value">john@doe.com</span>
|
95
|
+
</li>
|
96
|
+
</ol>
|
97
|
+
</div>
|
98
|
+
EOHTML
|
99
|
+
|
100
|
+
@user_builder.attributes "Contact", :full_name, :title, :email, :html => {:class => "contact"}, :display_empty => true
|
101
|
+
actual = @template.output_buffer.to_s
|
102
|
+
assert_equal expected, actual
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAttrtastic < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_fixtures
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_attrtastic_verbose
|
10
|
+
expected = html <<-EOHTML
|
11
|
+
<div class="attrtastic user">
|
12
|
+
<div class="attributes">
|
13
|
+
<div class="legend">User</div>
|
14
|
+
<ol>
|
15
|
+
<li class="attribute strong">
|
16
|
+
<span class="label">First name</span>
|
17
|
+
<span class="value">John</span>
|
18
|
+
</li>
|
19
|
+
<li class="attribute">
|
20
|
+
<span class="label">Last name</span>
|
21
|
+
<span class="value">Doe</span>
|
22
|
+
</li>
|
23
|
+
</ol>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="attributes">
|
27
|
+
<div class="legend">Contact</div>
|
28
|
+
<ol>
|
29
|
+
<li class="attribute">
|
30
|
+
<span class="label">Email</span>
|
31
|
+
<span class="value">john@doe.com</span>
|
32
|
+
</li>
|
33
|
+
</ol>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
EOHTML
|
37
|
+
|
38
|
+
@template.semantic_attributes_for(@user) do |attr|
|
39
|
+
attr.attributes "User" do
|
40
|
+
@template.output_buffer << (attr.attribute :first_name, :html => {:class => :strong}).to_s
|
41
|
+
@template.output_buffer << (attr.attribute :last_name).to_s
|
42
|
+
@template.output_buffer << (attr.attribute :title).to_s
|
43
|
+
end
|
44
|
+
attr.attributes "Contact" do
|
45
|
+
@template.output_buffer << (attr.attribute :email).to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
actual = @template.output_buffer.to_s
|
50
|
+
assert_equal expected, actual
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_attrtastic_compct
|
54
|
+
expected = html <<-EOHTML
|
55
|
+
<div class="attrtastic user">
|
56
|
+
<div class="attributes">
|
57
|
+
<div class="legend">User</div>
|
58
|
+
<ol>
|
59
|
+
<li class="attribute">
|
60
|
+
<span class="label">First name</span>
|
61
|
+
<span class="value">John</span>
|
62
|
+
</li>
|
63
|
+
<li class="attribute">
|
64
|
+
<span class="label">Last name</span>
|
65
|
+
<span class="value">Doe</span>
|
66
|
+
</li>
|
67
|
+
</ol>
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<div class="attributes">
|
71
|
+
<div class="legend">Contact</div>
|
72
|
+
<ol>
|
73
|
+
<li class="attribute">
|
74
|
+
<span class="label">Email</span>
|
75
|
+
<span class="value">john@doe.com</span>
|
76
|
+
</li>
|
77
|
+
</ol>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
EOHTML
|
81
|
+
|
82
|
+
@template.semantic_attributes_for(@user) do |attr|
|
83
|
+
attr.attributes "User", :first_name, :last_name, :title
|
84
|
+
attr.attributes "Contact", :email
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSemanticAttributesHelper < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_fixtures
|
7
|
+
end
|
8
|
+
|
9
|
+
def test__semantic_attributes_for__output_with_no_block
|
10
|
+
expected = html <<-EOHTML
|
11
|
+
<div class="attrtastic user">
|
12
|
+
</div>
|
13
|
+
EOHTML
|
14
|
+
|
15
|
+
@template.semantic_attributes_for(@user)
|
16
|
+
actual = @template.output_buffer.to_s
|
17
|
+
assert_equal expected, actual
|
18
|
+
|
19
|
+
@template.output_buffer.clear
|
20
|
+
|
21
|
+
expected = html <<-EOHTML
|
22
|
+
<div class="attrtastic blog">
|
23
|
+
</div>
|
24
|
+
EOHTML
|
25
|
+
|
26
|
+
@template.semantic_attributes_for(@blog)
|
27
|
+
actual = @template.output_buffer.to_s
|
28
|
+
assert_equal expected, actual
|
29
|
+
end
|
30
|
+
|
31
|
+
def test__semantic_attributes_for__should_run_block
|
32
|
+
block_run = false
|
33
|
+
@template.semantic_attributes_for(@user) do |attr|
|
34
|
+
block_run = true
|
35
|
+
end
|
36
|
+
|
37
|
+
assert block_run
|
38
|
+
end
|
39
|
+
|
40
|
+
def test__semantic_attributes_for__with_options
|
41
|
+
expected = html <<-EOHTML
|
42
|
+
<div class="attrtastic user simple show">
|
43
|
+
</div>
|
44
|
+
EOHTML
|
45
|
+
|
46
|
+
@template.semantic_attributes_for(@user, :html => {:class => 'simple show'})
|
47
|
+
actual = @template.output_buffer.to_s
|
48
|
+
assert_equal expected, actual
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attrtastic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Boruta Miroslaw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-03 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yard
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: description
|
26
|
+
email: boruta.miroslaw@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- LICENSE
|
39
|
+
- README
|
40
|
+
- README.rdoc
|
41
|
+
- Rakefile
|
42
|
+
- VERSION
|
43
|
+
- attrtastic.gemspec
|
44
|
+
- lib/attrtastic.rb
|
45
|
+
- rails/init.rb
|
46
|
+
- test/helper.rb
|
47
|
+
- test/test_attribute.rb
|
48
|
+
- test/test_attributes.rb
|
49
|
+
- test/test_attrtastic.rb
|
50
|
+
- test/test_semantic_attributes_helper.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/MBO/attrtastic
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: summary
|
79
|
+
test_files:
|
80
|
+
- test/helper.rb
|
81
|
+
- test/test_attrtastic.rb
|
82
|
+
- test/test_attribute.rb
|
83
|
+
- test/test_semantic_attributes_helper.rb
|
84
|
+
- test/test_attributes.rb
|