tablette 0.1.0 → 0.1.1
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 +4 -0
- data/lib/tablette/action_view.rb +33 -0
- data/lib/tablette/html_renderer.rb +11 -9
- data/lib/tablette/table.rb +1 -1
- data/lib/tablette/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad91df010ec079aed48cd6c6b43ba4128195c51
|
4
|
+
data.tar.gz: da719c435e44e76d2fd7cbff9011c88acf7949ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e15e536e9c4cb16139b48a349dffbf06bf8d444fb77998c4d9d8bbf5775d7e7d5808c4dd28ada95af273862c22f191e1028e23bf57708a9fd21353872caf07eb
|
7
|
+
data.tar.gz: 9219a4a6c0ae292f64539d9946e5c3c5a3c404818eda6461ed92fc11e0cb72207cb18af195a5e7da53a232b10afb863190ec93461ca05edcc53a3c55895704a0
|
data/lib/tablette.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tablette
|
2
|
+
class ActionViewRenderer < HTMLRenderer
|
3
|
+
def initialize(template)
|
4
|
+
super()
|
5
|
+
|
6
|
+
@template = template
|
7
|
+
end
|
8
|
+
|
9
|
+
def wrap_content(proc)
|
10
|
+
->(*args) do
|
11
|
+
@template.capture(*args, &proc)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_html(node)
|
16
|
+
super(node).html_safe
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ActionViewHelper
|
21
|
+
def tablette_for(objects, options = {}, &block)
|
22
|
+
default_options = {
|
23
|
+
:renderer => ActionViewRenderer.new(self),
|
24
|
+
:helper => self
|
25
|
+
}
|
26
|
+
|
27
|
+
table = Tablette::Table.new(options.merge(default_options), &block)
|
28
|
+
table.to_html(objects)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ActionView::Base.send :include, Tablette::ActionViewHelper
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Tablette
|
2
|
-
|
3
|
-
def
|
2
|
+
class HTMLRenderer
|
3
|
+
def element=(element)
|
4
4
|
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
7
|
+
def produce_element(tag, attributes, content)
|
8
8
|
content = content.join if content.kind_of? Array
|
9
9
|
|
10
|
-
"<#{tag} #{
|
10
|
+
"<#{tag} #{to_html_args(attributes)}>#{content}</#{tag}>"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def to_html(root)
|
14
14
|
if root.kind_of? Array
|
15
15
|
root.join
|
16
16
|
else
|
@@ -18,20 +18,22 @@ module Tablette
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def wrap_content(proc)
|
22
22
|
proc
|
23
23
|
end
|
24
24
|
|
25
|
+
private
|
26
|
+
|
25
27
|
# Translates html_options to HTML attributes string. Accepts nested
|
26
28
|
# data-attributes.
|
27
29
|
#
|
28
30
|
# Example:
|
29
|
-
#
|
30
|
-
def
|
31
|
+
# to_html_args(ref: true, data: { id: 1 }) # ref="true" data-id="1"
|
32
|
+
def to_html_args(options, prepend = nil)
|
31
33
|
options = options || {}
|
32
34
|
html_args = options.map do |key, value|
|
33
35
|
if value.is_a?(Hash)
|
34
|
-
|
36
|
+
to_html_args(value, key)
|
35
37
|
else
|
36
38
|
key = "#{prepend}-#{key}" if prepend.present?
|
37
39
|
%{#{key}="#{value}"}
|
data/lib/tablette/table.rb
CHANGED
data/lib/tablette/version.rb
CHANGED
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.1
|
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-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- lib/tablette.rb
|
86
|
+
- lib/tablette/action_view.rb
|
86
87
|
- lib/tablette/columns.rb
|
87
88
|
- lib/tablette/element.rb
|
88
89
|
- lib/tablette/element/configuration.rb
|