display_for 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/display_for.gemspec +5 -3
- data/lib/display_for/builder/list.rb +40 -0
- data/lib/display_for/builder.rb +1 -0
- data/lib/display_for/helper.rb +4 -0
- data/spec/lib/builder/list_spec.rb +26 -0
- data/spec/lib/builder/table_spec.rb +2 -2
- metadata +6 -4
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.homepage = "http://github.com/mateomurphy/display_for"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Rails library for displaying data}
|
21
|
-
gem.description = %Q{A Rails library for
|
21
|
+
gem.description = %Q{A Rails library for displaying data, in tabular and other formats}
|
22
22
|
gem.email = "mateo.murphy@gmail.com"
|
23
23
|
gem.authors = ["Mateo Murphy"]
|
24
24
|
# dependencies defined in Gemfile
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/display_for.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "display_for"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mateo Murphy"]
|
12
|
-
s.date = "2012-
|
13
|
-
s.description = "A Rails library for
|
12
|
+
s.date = "2012-11-21"
|
13
|
+
s.description = "A Rails library for displaying data, in tabular and other formats"
|
14
14
|
s.email = "mateo.murphy@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/display_for/builder/base.rb",
|
32
32
|
"lib/display_for/builder/collection_base.rb",
|
33
33
|
"lib/display_for/builder/csv.rb",
|
34
|
+
"lib/display_for/builder/list.rb",
|
34
35
|
"lib/display_for/builder/resource_base.rb",
|
35
36
|
"lib/display_for/builder/table.rb",
|
36
37
|
"lib/display_for/builder/view.rb",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"lib/display_for/element/base.rb",
|
41
42
|
"lib/display_for/element/html.rb",
|
42
43
|
"lib/display_for/helper.rb",
|
44
|
+
"spec/lib/builder/list_spec.rb",
|
43
45
|
"spec/lib/builder/table_spec.rb",
|
44
46
|
"spec/spec_helper.rb",
|
45
47
|
"spec/support/test_model.rb",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module DisplayFor
|
2
|
+
module Builder
|
3
|
+
class List < CollectionBase
|
4
|
+
|
5
|
+
def build_row(resource)
|
6
|
+
result = ''
|
7
|
+
@attributes.each do |attribute|
|
8
|
+
result << content_tag(:span, attribute.content(resource), attribute.html_options)
|
9
|
+
end
|
10
|
+
result << content_tag(:span, build_actions(resource)) if @actions.any?
|
11
|
+
|
12
|
+
options = {}
|
13
|
+
options[:id] = "#{@resource_class}_#{resource.id}".underscore if resource
|
14
|
+
content_tag(:li, result.html_safe, options) << "\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_actions(resource)
|
18
|
+
result = []
|
19
|
+
|
20
|
+
@actions.each do |action|
|
21
|
+
result << action.content(resource)
|
22
|
+
end
|
23
|
+
|
24
|
+
result.join(" ").html_safe
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
result = ''.html_safe
|
29
|
+
|
30
|
+
@collection.each do |resource|
|
31
|
+
result << build_row(resource)
|
32
|
+
end
|
33
|
+
|
34
|
+
html_options[:class] ||= "list #{@resource_class.to_s.underscore}-list"
|
35
|
+
content_tag(:ul, result, html_options).html_safe
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/display_for/builder.rb
CHANGED
@@ -3,6 +3,7 @@ module DisplayFor
|
|
3
3
|
autoload :Base, 'display_for/builder/base'
|
4
4
|
autoload :CollectionBase, 'display_for/builder/collection_base'
|
5
5
|
autoload :Csv, 'display_for/builder/csv'
|
6
|
+
autoload :List, 'display_for/builder/list'
|
6
7
|
autoload :ResourceBase, 'display_for/builder/resource_base'
|
7
8
|
autoload :Table, 'display_for/builder/table'
|
8
9
|
autoload :View, 'display_for/builder/view'
|
data/lib/display_for/helper.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module DisplayFor
|
2
2
|
module Helper
|
3
|
+
def list_for(resource_class, collection, html_options={}, &block)
|
4
|
+
Builder::List.new(resource_class, collection, html_options, self, &block).to_s
|
5
|
+
end
|
6
|
+
|
3
7
|
def table_for(resource_class, collection, html_options={}, &block)
|
4
8
|
Builder::Table.new(resource_class, collection, html_options, self, &block).to_s
|
5
9
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
LIST_OUTPUT = %q|<ul class="list test_model-list"><li id="test_model_1"><span>1</span><span>foo</span><span>bar</span></li>
|
4
|
+
</ul>|
|
5
|
+
|
6
|
+
module DisplayFor
|
7
|
+
module Builder
|
8
|
+
describe List, :focus => true do
|
9
|
+
|
10
|
+
subject :table do
|
11
|
+
List.new(TestModel, [TestModel.new(1, 'foo', 'bar')], {}, TestTemplate.new) do |t|
|
12
|
+
t.attribute :id
|
13
|
+
t.attribute :first_name
|
14
|
+
t.attribute :last_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_s' do
|
19
|
+
it 'renders the table' do
|
20
|
+
table.to_s.should eq(LIST_OUTPUT)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
TABLE_OUTPUT = %q|<table class="table table-bordered table-striped test_model-table"><thead><tr><th class="col_id">id</th><th class="col_first_name">first_name</th><th class="col_last_name">last_name</th></tr></thead>
|
4
4
|
<tbody><tr id="test_model_1"><td>1</td><td>foo</td><td>bar</td></tr>
|
5
5
|
</tbody><tfoot><tr><td colspan="3"> </td></tr>
|
6
6
|
</tfoot></table>|
|
@@ -24,7 +24,7 @@ module DisplayFor
|
|
24
24
|
|
25
25
|
describe '#to_s' do
|
26
26
|
it 'renders the table' do
|
27
|
-
table.to_s.should eq(
|
27
|
+
table.to_s.should eq(TABLE_OUTPUT)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: display_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
description: A Rails library for
|
110
|
+
description: A Rails library for displaying data, in tabular and other formats
|
111
111
|
email: mateo.murphy@gmail.com
|
112
112
|
executables: []
|
113
113
|
extensions: []
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/display_for/builder/base.rb
|
130
130
|
- lib/display_for/builder/collection_base.rb
|
131
131
|
- lib/display_for/builder/csv.rb
|
132
|
+
- lib/display_for/builder/list.rb
|
132
133
|
- lib/display_for/builder/resource_base.rb
|
133
134
|
- lib/display_for/builder/table.rb
|
134
135
|
- lib/display_for/builder/view.rb
|
@@ -138,6 +139,7 @@ files:
|
|
138
139
|
- lib/display_for/element/base.rb
|
139
140
|
- lib/display_for/element/html.rb
|
140
141
|
- lib/display_for/helper.rb
|
142
|
+
- spec/lib/builder/list_spec.rb
|
141
143
|
- spec/lib/builder/table_spec.rb
|
142
144
|
- spec/spec_helper.rb
|
143
145
|
- spec/support/test_model.rb
|
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
version: '0'
|
158
160
|
segments:
|
159
161
|
- 0
|
160
|
-
hash: -
|
162
|
+
hash: -3990301534027286697
|
161
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
164
|
none: false
|
163
165
|
requirements:
|