tablette 0.1.3 → 0.1.4
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 +4 -4
- data/lib/tablette.rb +1 -0
- data/lib/tablette/columns.rb +4 -6
- data/lib/tablette/element.rb +3 -7
- data/lib/tablette/element/nesting.rb +12 -8
- data/lib/tablette/html_renderer.rb +8 -1
- data/lib/tablette/table.rb +59 -2
- data/lib/tablette/version.rb +1 -1
- data/spec/grid_spec.rb +8 -10
- data/spec/support/sample_table.rb +5 -10
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 550320b22ddde53a83685fb4dd811f40eb8a40c6
|
|
4
|
+
data.tar.gz: 09e6070ab5d3c1c51c6b0d249959699069ec38d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc38e73adf2b70043862e62e308823d806450967f41bcf3fe84a1634457e6f31c1e136e356f0fbcaa5337c16ba17a022d2f2aad7e37fd054997b96f1c11ed20b
|
|
7
|
+
data.tar.gz: 8999b0e49499c5abddcb6da1dcbd48d07c976775a78ac3d9b0d0023e9b38ed9ca3fdba5184b9cf40f50f29fcf8d911becebe4fbe0ec4677f4056bfeb17e54ee6
|
data/lib/tablette.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'active_support/core_ext/object/blank'
|
|
|
2
2
|
require 'active_support/core_ext/object/inclusion'
|
|
3
3
|
require 'active_support/core_ext/string/inflections'
|
|
4
4
|
require 'active_support/core_ext/object/try'
|
|
5
|
+
require 'active_support/core_ext/array/wrap'
|
|
5
6
|
require 'active_support/configurable'
|
|
6
7
|
|
|
7
8
|
require 'tablette/version'
|
data/lib/tablette/columns.rb
CHANGED
|
@@ -40,8 +40,10 @@ module Tablette
|
|
|
40
40
|
options[:colspan]
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
attr_reader :key, :value
|
|
44
|
+
|
|
43
45
|
protected
|
|
44
|
-
|
|
46
|
+
attr_writer :key, :value
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
class BodyColumn < Column
|
|
@@ -64,11 +66,7 @@ module Tablette
|
|
|
64
66
|
protected
|
|
65
67
|
def html_content(collection, resource_class = nil)
|
|
66
68
|
return @renderer.wrap_content(value).call(collection, resource_class) if value.is_a?(Proc)
|
|
67
|
-
|
|
68
|
-
resource_class.human_attribute_name(key)
|
|
69
|
-
else
|
|
70
|
-
key
|
|
71
|
-
end
|
|
69
|
+
key
|
|
72
70
|
end
|
|
73
71
|
end
|
|
74
72
|
|
data/lib/tablette/element.rb
CHANGED
|
@@ -6,13 +6,9 @@ module Tablette
|
|
|
6
6
|
|
|
7
7
|
def initialize(*args, &definition)
|
|
8
8
|
options = args.extract_options!
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if options.include? :helper
|
|
14
|
-
@helper = options.delete :helper
|
|
15
|
-
end
|
|
9
|
+
@renderer = options.delete(:renderer) { @renderer }
|
|
10
|
+
@helper = options.delete(:helper) { @helper }
|
|
11
|
+
@header_builder = options.delete(:header_builder) { @header_builder }
|
|
16
12
|
|
|
17
13
|
instance_exec(&definition) if block_given?
|
|
18
14
|
config.merge!(options)
|
|
@@ -24,16 +24,11 @@ module Tablette
|
|
|
24
24
|
items = instance_variable_get("@#{ivar_name}") || []
|
|
25
25
|
return items if args.blank? && block.blank?
|
|
26
26
|
|
|
27
|
-
inherited_config = {
|
|
28
|
-
:renderer => @renderer,
|
|
29
|
-
:helper => @helper
|
|
30
|
-
}
|
|
31
|
-
|
|
32
27
|
if args.last.kind_of? Hash
|
|
33
28
|
last = args.pop
|
|
34
|
-
args << last.merge(inherited_config)
|
|
29
|
+
args << last.merge(self.inherited_config)
|
|
35
30
|
else
|
|
36
|
-
args << inherited_config
|
|
31
|
+
args << self.inherited_config
|
|
37
32
|
end
|
|
38
33
|
|
|
39
34
|
value = klass.new(*args, &block)
|
|
@@ -45,7 +40,6 @@ module Tablette
|
|
|
45
40
|
instance_variable_set("@#{ivar_name}", items)
|
|
46
41
|
value
|
|
47
42
|
end
|
|
48
|
-
protected accessor_name
|
|
49
43
|
end
|
|
50
44
|
|
|
51
45
|
# Defines top-level shortcut DSL method.
|
|
@@ -73,6 +67,16 @@ module Tablette
|
|
|
73
67
|
end
|
|
74
68
|
end
|
|
75
69
|
|
|
70
|
+
protected
|
|
71
|
+
|
|
72
|
+
def inherited_config
|
|
73
|
+
{
|
|
74
|
+
:renderer => @renderer,
|
|
75
|
+
:helper => @helper,
|
|
76
|
+
:header_builder => @header_builder
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
76
80
|
private
|
|
77
81
|
def _get_chained(context, chain, *args, &block)
|
|
78
82
|
key = chain.shift
|
|
@@ -7,7 +7,14 @@ module Tablette
|
|
|
7
7
|
def produce_element(tag, attributes, content)
|
|
8
8
|
content = content.join if content.kind_of? Array
|
|
9
9
|
|
|
10
|
-
"<#{tag}
|
|
10
|
+
buffer = "<#{tag}"
|
|
11
|
+
if attributes.any?
|
|
12
|
+
buffer << " #{to_html_args(attributes)}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
buffer << ">#{content}</#{tag}>"
|
|
16
|
+
|
|
17
|
+
buffer
|
|
11
18
|
end
|
|
12
19
|
|
|
13
20
|
def to_html(root)
|
data/lib/tablette/table.rb
CHANGED
|
@@ -14,6 +14,8 @@ module Tablette
|
|
|
14
14
|
def initialize(*args, &block)
|
|
15
15
|
@renderer = HTMLRenderer.new
|
|
16
16
|
@helper = nil
|
|
17
|
+
@header_builder = nil
|
|
18
|
+
@cached_autoheader = nil
|
|
17
19
|
|
|
18
20
|
super
|
|
19
21
|
end
|
|
@@ -33,7 +35,8 @@ module Tablette
|
|
|
33
35
|
def to_html(*args)
|
|
34
36
|
columns = 0
|
|
35
37
|
|
|
36
|
-
all_sections = [ self.header!, self.body, self.footer! ].flatten
|
|
38
|
+
all_sections = [ self.header!, build_autoheader(args), self.body, self.footer! ].flatten!
|
|
39
|
+
|
|
37
40
|
all_sections.each do |section|
|
|
38
41
|
section_columns = section.columns_for_section args
|
|
39
42
|
columns = section_columns if section_columns > columns
|
|
@@ -43,7 +46,61 @@ module Tablette
|
|
|
43
46
|
section.update_auto_colspan! columns, args
|
|
44
47
|
end
|
|
45
48
|
|
|
46
|
-
@
|
|
49
|
+
@sections_to_render = all_sections
|
|
50
|
+
begin
|
|
51
|
+
@renderer.to_html(super)
|
|
52
|
+
ensure
|
|
53
|
+
@sections_to_render = nil
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def html_content(*args)
|
|
60
|
+
buffer = ""
|
|
61
|
+
|
|
62
|
+
@sections_to_render.each do |e|
|
|
63
|
+
buffer << e.to_html(*args)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
buffer
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def build_autoheader(args)
|
|
70
|
+
if !nonempty_table_section?(self.header!, args) && !@header_builder.nil?
|
|
71
|
+
body = self.body
|
|
72
|
+
|
|
73
|
+
auto_header = Header.new(inherited_config) do
|
|
74
|
+
body.each do |body_section|
|
|
75
|
+
body_section.row.each do |body_row|
|
|
76
|
+
row do
|
|
77
|
+
body_row.column.each do |body_column|
|
|
78
|
+
options = { :html_options => { :colspan => body_column.colspan(args) } }
|
|
79
|
+
|
|
80
|
+
builder_options, block = @header_builder.build body_column.key
|
|
81
|
+
options.merge! builder_options
|
|
82
|
+
|
|
83
|
+
column options, &block
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
[ auto_header ]
|
|
91
|
+
else
|
|
92
|
+
[ ]
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def nonempty_table_section?(section, args)
|
|
97
|
+
section.any? do |entry|
|
|
98
|
+
entry.row.any? do |row|
|
|
99
|
+
row.column.any? do |column|
|
|
100
|
+
column.colspan(args) != "auto"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
47
104
|
end
|
|
48
105
|
end
|
|
49
106
|
end
|
data/lib/tablette/version.rb
CHANGED
data/spec/grid_spec.rb
CHANGED
|
@@ -59,18 +59,16 @@ describe 'Grid' do
|
|
|
59
59
|
with_tag 'tr', count: 4
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context 'with active record objects' do
|
|
65
|
-
subject { sample_table_active_record }
|
|
66
62
|
|
|
67
|
-
it 'should
|
|
68
|
-
subject.should have_tag '
|
|
69
|
-
with_tag '
|
|
70
|
-
with_tag '
|
|
63
|
+
it 'should have automatically generated header' do
|
|
64
|
+
subject.should have_tag 'table', count: 1 do
|
|
65
|
+
with_tag 'tbody', count: 1
|
|
66
|
+
with_tag 'thead', count: 1 do
|
|
67
|
+
with_tag 'th', text: 'id header', count: 1
|
|
68
|
+
with_tag 'th', text: 'age header', count: 1
|
|
69
|
+
end
|
|
70
|
+
with_tag 'tr', count: 4
|
|
71
71
|
end
|
|
72
|
-
|
|
73
|
-
subject.should_not have_tag 'tfoot'
|
|
74
72
|
end
|
|
75
73
|
end
|
|
76
74
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'ostruct'
|
|
2
2
|
|
|
3
|
-
class
|
|
4
|
-
def
|
|
5
|
-
"
|
|
3
|
+
class TestHeaderBuilder
|
|
4
|
+
def build(key)
|
|
5
|
+
[ {}, proc { "#{key} header" } ]
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -74,12 +74,7 @@ def sample_table_full_described
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def sample_table_short
|
|
77
|
-
table = Tablette::Table.new do
|
|
78
|
-
header do
|
|
79
|
-
column 'Id'
|
|
80
|
-
column 'Age'
|
|
81
|
-
end
|
|
82
|
-
|
|
77
|
+
table = Tablette::Table.new(:header_builder => TestHeaderBuilder.new) do
|
|
83
78
|
column :id
|
|
84
79
|
column :age
|
|
85
80
|
end
|
|
@@ -99,5 +94,5 @@ def sample_table_active_record
|
|
|
99
94
|
column :id
|
|
100
95
|
column :age
|
|
101
96
|
end
|
|
102
|
-
table.to_html(sample_collection
|
|
97
|
+
table.to_html(sample_collection)
|
|
103
98
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tablette
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Sokolov
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-09-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|