tablette 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1ea4083f7a84daf2dc1cdd21a1fddce42ab0e08
4
- data.tar.gz: a194c4045ce19b05f0ec69c022c239cb7cef32a7
3
+ metadata.gz: 0ad91df010ec079aed48cd6c6b43ba4128195c51
4
+ data.tar.gz: da719c435e44e76d2fd7cbff9011c88acf7949ec
5
5
  SHA512:
6
- metadata.gz: 91950838b5802f5c25485d8bc1cb872d835501115cbc2b457105c12821898a3efa5dd157c2bd2900ad66e1f13bec45d1592fc1b4db9d1411945b78a5970e00fc
7
- data.tar.gz: 723deac30f5dcf8f06a6f9580ea607dd1c99eb4a7016f1b6005a31a1bb6f7311c1d301f094583932f0b2a80f17933ffe8c54f00f787cba3672661cbbf86451e0
6
+ metadata.gz: e15e536e9c4cb16139b48a349dffbf06bf8d444fb77998c4d9d8bbf5775d7e7d5808c4dd28ada95af273862c22f191e1028e23bf57708a9fd21353872caf07eb
7
+ data.tar.gz: 9219a4a6c0ae292f64539d9946e5c3c5a3c404818eda6461ed92fc11e0cb72207cb18af195a5e7da53a232b10afb863190ec93461ca05edcc53a3c55895704a0
@@ -14,3 +14,7 @@ require 'tablette/rows'
14
14
  require 'tablette/sections'
15
15
  require 'tablette/table'
16
16
  require 'tablette/html_renderer'
17
+
18
+ if defined? ActionView::Base
19
+ require 'tablette/action_view'
20
+ end
@@ -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
- module HTMLRenderer
3
- def self.element=(element)
2
+ class HTMLRenderer
3
+ def element=(element)
4
4
 
5
5
  end
6
6
 
7
- def self.produce_element(tag, attributes, content)
7
+ def produce_element(tag, attributes, content)
8
8
  content = content.join if content.kind_of? Array
9
9
 
10
- "<#{tag} #{_to_html_args(attributes)}>#{content}</#{tag}>"
10
+ "<#{tag} #{to_html_args(attributes)}>#{content}</#{tag}>"
11
11
  end
12
12
 
13
- def self.to_html(root)
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 self.wrap_content(proc)
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
- # _to_html_args(ref: true, data: { id: 1 }) # ref="true" data-id="1"
30
- def self._to_html_args(options, prepend = nil)
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
- _to_html_args(value, key)
36
+ to_html_args(value, key)
35
37
  else
36
38
  key = "#{prepend}-#{key}" if prepend.present?
37
39
  %{#{key}="#{value}"}
@@ -12,7 +12,7 @@ module Tablette
12
12
  nest_through :body, :row, :column
13
13
 
14
14
  def initialize(*args, &block)
15
- @renderer = HTMLRenderer
15
+ @renderer = HTMLRenderer.new
16
16
  @helper = nil
17
17
 
18
18
  super
@@ -1,3 +1,3 @@
1
1
  module Tablette
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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-03-28 00:00:00.000000000 Z
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