th_simple_data_presentation 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmYyOTExNDlkZjhkNzg1MmFhMjlhYWY5MGRkYzY3NjdhYjI4NDc0OQ==
4
+ NDM0MTkzMGNmNjlkYTZkMTRlOGI5NjA3MDMxNzYzODU3Y2RhNjUzMA==
5
5
  data.tar.gz: !binary |-
6
- YmZkYTQ0MjhiNjNmMTNkNzQyYTA3NDY1NGYyMGUzOGQ4NWRkZWFmMA==
6
+ YTMxNjBkMTg4YWNjMTIzNjViNWQ4ZWFkMTNmOGY1MmY3YjdhY2YxOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTJhYWYyNTNhZmRkMTI2NmM4ZDU4Mjk2Yjg1OWM5YzM2ZDVmMzVkMTM0ZmU0
10
- N2IzZjYxMWU2NjljOTRlOGJhNTRiMTk2Mjc4MTYyZmVhOTg3ZjI1NjE3Yzdj
11
- NGIxM2IwNThhZDk3OGMyZjZkNjMxZTE1YWRhYjNkOGQ3MGQyZjc=
9
+ NDhjZDVkMzkyNDAzYzIxMmE0YTg2NTE2ZmNkZWVjOTE3YzljNTUwZjM5N2Zm
10
+ NGRiZjQyNjcyMTdmYzliZTcyNzg4MDI3MTRjMmFmMzkyMzlkNWQ2ZmIzNzUx
11
+ MDk4ZDc5NzQ1ZmI5ZjliM2QwZGU0YTczZDU4MTg0MTllNWVlYTc=
12
12
  data.tar.gz: !binary |-
13
- MGZmOWM2MjQ5MzEyOTI5OWNjYjQyNGY5NjU3MTc3YTEwNmI0MjAxNmI3ZmJk
14
- OTRjZDk5YWFlNjFhMTUwZjk2NGMzNGViMzZlMzA2NjZhOWI4OTA0OWQwMmRi
15
- MTBmNDEyNWE5YmM1ZDBkOTAyNDg2ODJmZGZlOGJkMzVkOTY0NTM=
13
+ ZGIzMmU3ZTVlODcyMDQ0OWFlZDIxYTNhODY1NjI5MzFjOTcyMWViOTMxOTFl
14
+ YmIyNzY4YmY5MDllZjk0ZmQ5MDNmZjQyNTNhMGM2Nzg3ZDhlYTFhYTE2ZThl
15
+ ZWQyZDUwOTk0ZDdiYjJjNDk2ZDQ5MDVlNTdiMWM4YTFkZjAxN2Q=
@@ -1,12 +1,12 @@
1
1
  class SimpleDataPresentation::SimpleDataList::Base
2
- def initialize(context, collection, options = {}, &content_block)
2
+ def initialize(context, resource, options = {}, &content_block)
3
3
  @context = context
4
- @collection = collection
4
+ @resource = resource
5
5
  @options = options
6
6
  @content_block = content_block
7
- @resource_class = @options.delete(:resource_class) || @collection.first.class
7
+ @resource_class = @options.delete(:resource_class) || @resource.class
8
8
  @html_options = SimpleDataPresentation::HtmlOptions.new(@options.delete(:html) || {})
9
- @html_options[:class] = "list"
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
- content = if as_formatter.respond_to?(:call)
41
- case as_formatter.arity
42
- when 1; as_formatter.call content
43
- when 2; as_formatter.call @resource, content
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 :td, content, options[:html]
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[:html]
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(collection, options = {}, &content_block)
3
- SimpleDataPresentation::SimpleDataList::Base.new(self, collection, options, &content_block).render!
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] = "list"
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
- elsif args.any?
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
- else
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
- content = if as_formatter.respond_to?(:call)
18
- case as_formatter.arity
19
- when 1; as_formatter.call content
20
- when 2; as_formatter.call @resource, content
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!
@@ -1,3 +1,3 @@
1
1
  module SimpleDataPresentation
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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-03-26 00:00:00.000000000 Z
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Collection of visual helpers
14
14
  email: