html_table_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in html_table_rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # TableRails
2
+
3
+ Provides a view helper for [html_table](https://github.com/tomkurt/html_table).
4
+
5
+ ## Features
6
+
7
+ * you can call view helpers on the row object
8
+ * localizes the table headers using human_attribute_name
9
+
10
+ ## Example
11
+
12
+ ### HAML
13
+
14
+ ```haml
15
+ = %table do |row|
16
+ = row.column :description, :value => some_view_helper(row.object)
17
+ = row.column :description, :value => render(:partial => "employee", :collection => row.object.employees)
18
+ ```
19
+
20
+ ### ERB
21
+
22
+ ```erb
23
+ <%= %table do |row|
24
+ row.column(:description, :value => some_view_helper(row.object)) +
25
+ row.column(:description, :value => render(:partial => "employee", :collection => row.object.employees))
26
+ end %>
27
+ ```
28
+
29
+ ## Installation
30
+
31
+ gem install html_table_rails
32
+
33
+ Copyright (c) 2011 Tom Maeckelberghe, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "html_table_rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "html_table_rails"
7
+ s.version = HtmlTableRails::VERSION
8
+ s.authors = ["Tom Maeckelberghe"]
9
+ s.email = ["tom.maeckelberghe@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{This allows the user to call view helpers from inside html_table.}
12
+ s.description = %q{This will add rails templating to html_table}
13
+
14
+ s.rubyforge_project = "html_table_rails"
15
+ s.add_dependency "html_table"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
@@ -0,0 +1,3 @@
1
+ module HtmlTableRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,61 @@
1
+ require "html_table_rails/version"
2
+ require "html_table"
3
+
4
+ class HtmlTable::TableBuilder::ColumnHeaders
5
+ def column_translation column
6
+ model_class.human_attribute_name(column) rescue column
7
+ end
8
+
9
+ def model_class
10
+ row.object.class
11
+ end
12
+ end
13
+
14
+ class HtmlTable::TableBuilder
15
+ def initialize(collection, template, options={}, &block)
16
+ init_instance_vars(options)
17
+ collection.each do |object|
18
+ @rows << HtmlTable::TableRowBuilder.new(object, template, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ class HtmlTable::TableRowBuilder
24
+ def initialize(object, template)
25
+ @object = object
26
+ @columns = []
27
+ @html_columns = []
28
+ @template = template
29
+ capture_method = (template.respond_to?(:is_haml?) && template.is_haml?) ? :capture_haml : :capture
30
+ @output = template.send(capture_method) do
31
+ yield(self)
32
+ end
33
+ end
34
+
35
+ def to_s
36
+ "<tr>#{@output}</tr>"
37
+ end
38
+
39
+ def value_with_localization column_name, options
40
+ if column_name &&
41
+ object.respond_to?(column_name) &&
42
+ (
43
+ object.send(column_name).is_a?(Time) ||
44
+ object.send(column_name).is_a?(Date)
45
+ )
46
+ @template.l(object.send(column_name))
47
+ else
48
+ value_without_localization(column_name, options)
49
+ end
50
+ end
51
+
52
+ alias_method_chain :value, :localization
53
+ end
54
+
55
+ module ::HtmlTable
56
+ def set_table_builder(collection, options, &block)
57
+ @table_builder = TableBuilder.new(collection, self, options, &block)
58
+ end
59
+ end
60
+
61
+ ActionView::Base.send :include, ::HtmlTable
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_table_rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tom Maeckelberghe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-12 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: html_table
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: This will add rails templating to html_table
35
+ email:
36
+ - tom.maeckelberghe@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - html_table_rails.gemspec
49
+ - lib/html_table_rails.rb
50
+ - lib/html_table_rails/version.rb
51
+ homepage: ""
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: html_table_rails
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: This allows the user to call view helpers from inside html_table.
84
+ test_files: []
85
+