table-for 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -51,7 +51,7 @@ begin
51
51
  gemspec.email = "hunterae@gmail.com"
52
52
  gemspec.homepage = "http://github.com/hunterae/table-for"
53
53
  gemspec.authors = ["Andrew Hunter"]
54
- gemspec.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"] - FileList["**/*.log"]
54
+ gemspec.files = FileList["[A-Z]*", "{lib,spec,app,rails}/**/*"] - FileList["**/*.log"]
55
55
  end
56
56
  Jeweler::GemcutterTasks.new
57
57
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -0,0 +1,22 @@
1
+ module TableFor
2
+ module HelperMethods
3
+ def table_for_options(options={}, parameters={})
4
+ evaluated_options = {}
5
+ options.each_pair { |k, v| evaluated_options[k] = (v.is_a?(Proc) ? v.call(parameters) : v)}
6
+ evaluated_options
7
+ end
8
+
9
+ def table_for(records, options={}, &block)
10
+ options[:view] = self
11
+ options[:records] = records
12
+ options[:block] = block
13
+ options[:row_html] = {:class => lambda { |parameters| cycle('odd', 'even')}} if options[:row_html].nil?
14
+ options[:template] = "table_for/table_for"
15
+ options[:templates_folder] = "table_for"
16
+ options[:record_variable] = "records"
17
+ options[:variable] = "table"
18
+
19
+ TableFor::Base.new(options).render
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,105 @@
1
+ <%= table.define :thead do %>
2
+ <thead>
3
+ <%= table.use :header_row %>
4
+ </thead>
5
+ <% end %>
6
+
7
+ <%= table.define :header_row do %>
8
+ <tr>
9
+ <%= table.use :header_columns %>
10
+ </tr>
11
+ <% end %>
12
+
13
+ <%= table.define :header_columns do |options| %>
14
+ <% table.columns.each do |column| %>
15
+ <% header_html = options.merge(column.options)[:header_html] %>
16
+ <% if options.merge(column.options)[:sortable] %>
17
+ <% order = column.options[:order] ? column.options[:order].to_s : column.name.to_s %>
18
+
19
+ <% sort_class = params[:order] != order ? "sorting" : (params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc") %>
20
+ <% header_html = {} if header_html.nil? %>
21
+ <% header_html[:class] ||= "" %>
22
+ <% header_html[:class] += " #{sort_class}" %>
23
+ <% end %>
24
+
25
+ <%= content_tag :th, header_html do %>
26
+ <%= table.use "#{column.name.to_s}_header", options.merge(column.options) %>
27
+ <% end %>
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <% table.columns.each do |column| %>
32
+ <%= table.define "#{column.name.to_s}_header", :column => column do |options| %>
33
+ <% if options[:sortable] %>
34
+ <%= table.use "#{options[:column].name.to_s}_header_sortable_link", options %>
35
+ <% else %>
36
+ <%= options[:label] ? options[:label] : options[:column].name.to_s.titleize %>
37
+ <% end %>
38
+ <% end %>
39
+
40
+ <%= table.define "#{column.name.to_s}_header_sortable_link", :column => column do |options| %>
41
+ <%= table.use :header_sortable_link, options %>
42
+ <% end %>
43
+ <% end %>
44
+
45
+ <%= table.define :header_sortable_link do |options| %>
46
+ <% order = options[:order] ? options[:order].to_s : options[:column].name.to_s %>
47
+ <% label = (options[:label] ? options[:label] : options[:column].name.to_s.titleize) %>
48
+ <% sort_mode = ((params[:order] != order or params[:sort_mode] == "desc") ? "asc" : "desc") %>
49
+ <% parameters = params.merge({:order => (options[:order] ? options[:order] : options[:column].name), :sort_mode => sort_mode}) %>
50
+ <% parameters.delete(:action); parameters.delete(:controller) %>
51
+ <% url = options[:sort_url] ? options[:sort_url] : "" %>
52
+
53
+ <%= link_to label, "#{url}?#{parameters.to_query}" %>
54
+ <% end %>
55
+
56
+ <%= table.define :tbody do %>
57
+ <tbody>
58
+ <%= table.use :rows %>
59
+ </tbody>
60
+ <% end %>
61
+
62
+ <%= table.define :rows do %>
63
+ <% records.each do |record| %>
64
+ <%= table.use :row, record %>
65
+ <% end %>
66
+ <% end %>
67
+
68
+ <%= table.define :row do |record, options| %>
69
+ <%= content_tag :tr, table_for_options(options[:row_html], options) do %>
70
+ <%= table.use :data_columns, record, options %>
71
+ <% end %>
72
+ <% end %>
73
+
74
+ <%= table.define :data_columns do |record, options| %>
75
+ <% table.columns.each do |column| %>
76
+ <%= content_tag :td, options.merge(column.options)[:column_html] do %>
77
+ <%= table.use column, record, options.merge(:column => column) %>
78
+ <% end %>
79
+ <% end %>
80
+ <% end %>
81
+
82
+ <%= table.define :edit, :action => :edit do |record, options| %>
83
+ <%= link_to "Edit", [options[:action], options[:scope], record].flatten, options[:link_html] %>
84
+ <% end %>
85
+
86
+ <%= table.define :show, :action => nil do |record, options| %>
87
+ <%= link_to "Show", [options[:action], options[:scope], record].flatten, options[:link_html] %>
88
+ <% end %>
89
+
90
+ <%= table.define :delete, :link_html => {} do |record, options| %>
91
+ <%= link_to "Delete", [options[:scope], record].flatten, {:method => "delete", :confirm => "Are you sure you want to delete this #{record.class.to_s.humanize}?"}.merge(options[:link_html]) %>
92
+ <% end %>
93
+
94
+ <% table.columns.each do |column| %>
95
+ <%= table.define column.name, :column => column do |record, options| %>
96
+ <%= record.send(options[:column].name) %>
97
+ <% end %>
98
+ <% end %>
99
+
100
+ <%= table.use :table do |options| %>
101
+ <%= content_tag :table, options[:table_html] do %>
102
+ <%= table.use :thead %>
103
+ <%= table.use :tbody %>
104
+ <% end %>
105
+ <% end %>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table-for
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Hunter
@@ -98,10 +98,11 @@ extra_rdoc_files:
98
98
  - README.rdoc
99
99
  files:
100
100
  - Gemfile
101
- - Gemfile.lock
102
101
  - README.rdoc
103
102
  - Rakefile
104
103
  - VERSION
104
+ - app/helpers/table_for/helper_methods.rb
105
+ - app/views/table_for/_table_for.html.erb
105
106
  - lib/table-for.rb
106
107
  - lib/table_for/engine.rb
107
108
  - lib/table_for/table_for.rb
data/Gemfile.lock DELETED
@@ -1,96 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.0.beta3)
6
- actionpack (= 3.0.0.beta3)
7
- mail (~> 2.2.0)
8
- text-format (~> 1.0.0)
9
- actionpack (3.0.0.beta3)
10
- activemodel (= 3.0.0.beta3)
11
- activesupport (= 3.0.0.beta3)
12
- erubis (~> 2.6.5)
13
- rack (~> 1.1.0)
14
- rack-mount (~> 0.6.0)
15
- rack-test (~> 0.5.0)
16
- activemodel (3.0.0.beta3)
17
- activesupport (= 3.0.0.beta3)
18
- activerecord (3.0.0.beta3)
19
- activemodel (= 3.0.0.beta3)
20
- activesupport (= 3.0.0.beta3)
21
- arel (~> 0.3.3)
22
- activeresource (3.0.0.beta3)
23
- activemodel (= 3.0.0.beta3)
24
- activesupport (= 3.0.0.beta3)
25
- activesupport (3.0.0.beta3)
26
- builder (~> 2.1.2)
27
- i18n (~> 0.3.6)
28
- memcache-client (>= 1.7.5)
29
- tzinfo (~> 0.3.16)
30
- arel (0.3.3)
31
- activesupport (>= 3.0.0.beta)
32
- builder (2.1.2)
33
- building-blocks (0.0.1)
34
- jeweler
35
- rails
36
- rcov
37
- rspec
38
- erubis (2.6.6)
39
- abstract (>= 1.0.0)
40
- git (1.2.5)
41
- i18n (0.3.7)
42
- jeweler (1.6.0)
43
- bundler (~> 1.0.0)
44
- git (>= 1.2.5)
45
- rake
46
- mail (2.2.7)
47
- activesupport (>= 2.3.6)
48
- mime-types
49
- treetop (>= 1.4.5)
50
- memcache-client (1.8.5)
51
- mime-types (1.16)
52
- polyglot (0.3.1)
53
- rack (1.1.2)
54
- rack-mount (0.6.14)
55
- rack (>= 1.0.0)
56
- rack-test (0.5.7)
57
- rack (>= 1.0)
58
- rails (3.0.0.beta3)
59
- actionmailer (= 3.0.0.beta3)
60
- actionpack (= 3.0.0.beta3)
61
- activerecord (= 3.0.0.beta3)
62
- activeresource (= 3.0.0.beta3)
63
- activesupport (= 3.0.0.beta3)
64
- bundler (>= 0.9.19)
65
- railties (= 3.0.0.beta3)
66
- railties (3.0.0.beta3)
67
- actionpack (= 3.0.0.beta3)
68
- activesupport (= 3.0.0.beta3)
69
- rake (>= 0.8.3)
70
- thor (~> 0.13.4)
71
- rake (0.8.7)
72
- rcov (0.9.9)
73
- rspec (2.0.0.beta.8)
74
- rspec-core (= 2.0.0.beta.8)
75
- rspec-expectations (= 2.0.0.beta.8)
76
- rspec-mocks (= 2.0.0.beta.8)
77
- rspec-core (2.0.0.beta.8)
78
- rspec-expectations (2.0.0.beta.8)
79
- rspec-mocks (2.0.0.beta.8)
80
- text-format (1.0.0)
81
- text-hyphen (~> 1.0.0)
82
- text-hyphen (1.0.2)
83
- thor (0.13.8)
84
- treetop (1.4.9)
85
- polyglot (>= 0.3.1)
86
- tzinfo (0.3.27)
87
-
88
- PLATFORMS
89
- ruby
90
-
91
- DEPENDENCIES
92
- building-blocks
93
- jeweler
94
- rails
95
- rcov
96
- rspec