th_simple_data_presentation 0.0.1 → 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.
- checksums.yaml +8 -8
- data/lib/simple_data_presentation/simple_data_list/base.rb +11 -14
- data/lib/simple_data_presentation/simple_data_list/helper.rb +2 -2
- data/lib/simple_data_presentation/simple_table/base.rb +1 -1
- data/lib/simple_data_presentation/simple_table/head.rb +3 -3
- data/lib/simple_data_presentation/simple_table/row.rb +5 -8
- data/lib/simple_data_presentation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDM0MTkzMGNmNjlkYTZkMTRlOGI5NjA3MDMxNzYzODU3Y2RhNjUzMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTMxNjBkMTg4YWNjMTIzNjViNWQ4ZWFkMTNmOGY1MmY3YjdhY2YxOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDhjZDVkMzkyNDAzYzIxMmE0YTg2NTE2ZmNkZWVjOTE3YzljNTUwZjM5N2Zm
|
10
|
+
NGRiZjQyNjcyMTdmYzliZTcyNzg4MDI3MTRjMmFmMzkyMzlkNWQ2ZmIzNzUx
|
11
|
+
MDk4ZDc5NzQ1ZmI5ZjliM2QwZGU0YTczZDU4MTg0MTllNWVlYTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGIzMmU3ZTVlODcyMDQ0OWFlZDIxYTNhODY1NjI5MzFjOTcyMWViOTMxOTFl
|
14
|
+
YmIyNzY4YmY5MDllZjk0ZmQ5MDNmZjQyNTNhMGM2Nzg3ZDhlYTFhYTE2ZThl
|
15
|
+
ZWQyZDUwOTk0ZDdiYjJjNDk2ZDQ5MDVlNTdiMWM4YTFkZjAxN2Q=
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class SimpleDataPresentation::SimpleDataList::Base
|
2
|
-
def initialize(context,
|
2
|
+
def initialize(context, resource, options = {}, &content_block)
|
3
3
|
@context = context
|
4
|
-
@
|
4
|
+
@resource = resource
|
5
5
|
@options = options
|
6
6
|
@content_block = content_block
|
7
|
-
@resource_class = @options.delete(:resource_class) || @
|
7
|
+
@resource_class = @options.delete(:resource_class) || @resource.class
|
8
8
|
@html_options = SimpleDataPresentation::HtmlOptions.new(@options.delete(:html) || {})
|
9
|
-
@html_options[:class] = "
|
9
|
+
@html_options[:class] = "dl-horizontal"
|
10
10
|
end
|
11
11
|
|
12
12
|
def item(*args, &block)
|
@@ -26,7 +26,7 @@ class SimpleDataPresentation::SimpleDataList::Base
|
|
26
26
|
@resource_class.human_attribute_name args.join("_").to_sym
|
27
27
|
end
|
28
28
|
end
|
29
|
-
@context.content_tag :dt, content, options[:html]
|
29
|
+
@context.content_tag :dt, content, SimpleDataPresentation::HtmlOptions.new(options[:html] || {}).merge(options[:label_html] || {})
|
30
30
|
end
|
31
31
|
|
32
32
|
def value(*args, &block)
|
@@ -37,21 +37,18 @@ class SimpleDataPresentation::SimpleDataList::Base
|
|
37
37
|
content = value_for_method_chain *args
|
38
38
|
as_formatter = options[:as]
|
39
39
|
if as_formatter.present?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
elsif as_formatter.is_a?(Symbol) && @context.respond_to?(as_formatter)
|
46
|
-
@context.public_send as_formatter, content if !content.nil?
|
40
|
+
as_formatter = @context.method(as_formatter).to_proc if as_formatter.is_a?(Symbol)
|
41
|
+
content = case as_formatter.arity
|
42
|
+
when 1; as_formatter.call content
|
43
|
+
when 2; as_formatter.call @resource, content
|
47
44
|
end
|
48
45
|
end
|
49
46
|
end
|
50
|
-
@context.content_tag :
|
47
|
+
@context.content_tag :dd, content, SimpleDataPresentation::HtmlOptions.new(options[:html] || {}).merge(options[:value_html] || {})
|
51
48
|
end
|
52
49
|
|
53
50
|
def render!
|
54
|
-
@context.raw @context.content_tag :dl, @context.capture(self, &@content_block), @html_options
|
51
|
+
@context.raw @context.content_tag :dl, @context.capture(self, &@content_block), @html_options
|
55
52
|
end
|
56
53
|
|
57
54
|
protected
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SimpleDataPresentation::SimpleDataList::Helper
|
2
|
-
def data_list_for(
|
3
|
-
SimpleDataPresentation::SimpleDataList::Base.new(self,
|
2
|
+
def data_list_for(resource, options = {}, &content_block)
|
3
|
+
SimpleDataPresentation::SimpleDataList::Base.new(self, resource, options, &content_block).render!
|
4
4
|
end
|
5
5
|
end
|
@@ -6,7 +6,7 @@ class SimpleDataPresentation::SimpleTable::Base
|
|
6
6
|
@content_block = content_block
|
7
7
|
@resource_class = @options.delete(:resource_class) || @collection.first.class
|
8
8
|
@html_options = SimpleDataPresentation::HtmlOptions.new(@options.delete(:html) || {})
|
9
|
-
@html_options[:class] = "
|
9
|
+
@html_options[:class] = "table"
|
10
10
|
end
|
11
11
|
|
12
12
|
def item(*args, &block)
|
@@ -11,13 +11,13 @@ class SimpleDataPresentation::SimpleTable::Head < SimpleDataPresentation::Simple
|
|
11
11
|
options = args.extract_options!
|
12
12
|
content = if block.present?
|
13
13
|
@context.capture(@resource_class, &block)
|
14
|
-
|
15
|
-
sort_attribute = args.join("_").to_sym
|
14
|
+
else
|
15
|
+
sort_attribute = options[:sort_by] || (args.any? ? args.join("_").to_sym : nil)
|
16
16
|
label = if options[:label].is_a?(Symbol)
|
17
17
|
@resource_class.human_attribute_name options[:label]
|
18
18
|
elsif !options[:label].nil?
|
19
19
|
options[:label]
|
20
|
-
|
20
|
+
elsif sort_attribute.present?
|
21
21
|
@resource_class.human_attribute_name sort_attribute
|
22
22
|
end
|
23
23
|
!@search.nil? && options[:sortable] != false ? @context.sort_link(@search, sort_attribute, label) : label
|
@@ -14,17 +14,14 @@ class SimpleDataPresentation::SimpleTable::Row < SimpleDataPresentation::SimpleT
|
|
14
14
|
content = value_for_method_chain *args
|
15
15
|
as_formatter = options[:as]
|
16
16
|
if as_formatter.present?
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
elsif as_formatter.is_a?(Symbol) && @context.respond_to?(as_formatter)
|
23
|
-
@context.public_send as_formatter, content if !content.nil?
|
17
|
+
as_formatter = @context.method(as_formatter).to_proc if as_formatter.is_a?(Symbol)
|
18
|
+
content = case as_formatter.arity
|
19
|
+
when 1; as_formatter.call content
|
20
|
+
when 2; as_formatter.call @resource, content
|
24
21
|
end
|
25
22
|
end
|
26
23
|
end
|
27
|
-
@context.content_tag :td, content, options[:html]
|
24
|
+
@context.content_tag :td, content, (SimpleDataPresentation::HtmlOptions.new(options[:html] || {}).merge options[:row_html] || {})
|
28
25
|
end
|
29
26
|
|
30
27
|
def render!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: th_simple_data_presentation
|
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
|
- Toby Hinloopen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Collection of visual helpers
|
14
14
|
email:
|