html_tables 0.0.4 → 0.0.5

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/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.0.5
2
+ -----
3
+ * New option for checkboxes: `checked`.
4
+ * New option for checkboxes and radio: `value_method`.
5
+ * Changed `#send` calls for `#public_send`.
6
+
1
7
  0.0.4
2
8
  -----
3
9
  * Added support for groups.
@@ -82,17 +82,16 @@ module HtmlTables
82
82
  end
83
83
 
84
84
  v = if opts[:checkbox]
85
- checked = nil
85
+ checked = opts[:checked]
86
86
  checked = opts[:block].call(item) if opts[:block]
87
- ck_opts = opts.select { |k, _| [:disabled].include?(k) }
88
- check_box_tag "#{column}[]", item.id, checked, ck_opts
87
+ check_box_tag "#{column}[]", item.public_send(opts.fetch(:value_method, :id)), checked, extract_check_box_tag_options(opts)
89
88
  elsif opts[:radio]
90
- radio_button_tag "#{column}[]", item.id
89
+ radio_button_tag "#{column}[]", item.public_send(opts.fetch(:value_method, :id))
91
90
  elsif opts[:block]
92
91
  capture(item, &opts[:block])
93
92
  else
94
- tmp = item.send(column)
95
- tmp = item.send("#{column}_text") rescue tmp if tmp.is_a?(Symbol)
93
+ tmp = item.public_send(column)
94
+ tmp = item.public_send("#{column}_text") rescue tmp if tmp.is_a?(Symbol)
96
95
  tmp
97
96
  end
98
97
 
@@ -115,5 +114,10 @@ module HtmlTables
115
114
 
116
115
  content_tag(:td, v, td_options)
117
116
  end
117
+
118
+ def extract_check_box_tag_options(opts)
119
+ valid_options = [:disabled]
120
+ opts.select { |k, _| valid_options.include?(k) }
121
+ end
118
122
  end
119
123
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module HtmlTables
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -10,12 +10,18 @@ module HtmlTables
10
10
 
11
11
  # Adds a checkbox column to the DataTable.
12
12
  # If a block is supplied, it is used to determine the initial state of the checkbox.
13
+ # @param [Hash] options the checkbox options
14
+ # @option options [TrueClass,FalseClass] checked the initial state of the checkbox.
15
+ # @option options [Proc] block a block which will be evaluated to define the initial state of the checkbox.
16
+ # @option options [String] value_method the method to be called to define the checkbox value. Default = :id
13
17
  def checkbox(id = nil, options = { }, &block)
14
18
  options[:block] = block if block_given?
15
19
  t.columns[id] = options.reverse_merge! checkbox: true, align: :center
16
20
  end
17
21
 
18
22
  # Adds a radio button column to the DataTable.
23
+ # @param [Hash] options the radio options
24
+ # @option options [String] value_method the method to be called to define the radio value. Default = :id
19
25
  def radio(id = nil, options = { })
20
26
  t.columns[id] = options.reverse_merge! radio: true, align: :center
21
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-18 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n