awesome_tables 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- |a�K[����n1�XaW�`��~W _����R �����0V;��� ��-y���A��z���h���i9H���uaOڂ�!�kă#S�g����� "��`��1�����v�W�cI�[��
2
- ��+�X��B�'{�AP������[�p�A?Q �Z�C*X�2*S����nH�;�9>���~秌��ZS:P��[.~�fh� �����2ȭ@����9�;
1
+ N� �����=�M|��r�J +�I��,�D���͒�QtoAE��ק�uC�>�zG�*V؞3~�q��9$�|G�.oc���39��&�����RZ���R݇f8<�)F��>�VHVo[͖ɒ[��=?���qM��`����Y�]d������߷l�gý�H��/�$���H�!�����0���gV\-%��
@@ -1,3 +1,9 @@
1
+ == 0.0.6, released 2010-11-07
2
+
3
+ * added blocks to available ways to pass to t.column
4
+ * cleaned up view helpers
5
+ * updated templates/_base.html.erb to reflect cleaned up helpers
6
+
1
7
  == 0.0.5, released 2010-10-24
2
8
 
3
9
  * added awesome_tables generator that copies the base template to app/view/awesome_tables/_base.html.erb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('awesome_tables', '0.0.5') do |p|
5
+ Echoe.new('awesome_tables', '0.0.6') do |p|
6
6
  p.description = "A gem for creating awesome, consistently styled tables"
7
7
  p.url = "http://github.com/danengle/awesome_tables"
8
8
  p.author = "Dan Engle"
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{awesome_tables}
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Dan Engle"]
9
9
  s.cert_chain = ["/Users/danengle/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-10-24}
10
+ s.date = %q{2010-11-07}
11
11
  s.description = %q{A gem for creating awesome, consistently styled tables}
12
12
  s.email = %q{engle.68 @nospam@ gmail.com}
13
13
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/awesome_tables.rb", "lib/awesome_tables/awesome_table.rb", "lib/awesome_tables/formatters.rb", "lib/awesome_tables/formatters/html.rb", "lib/awesome_tables/railtie.rb", "lib/awesome_tables/scrap.rb", "lib/awesome_tables/view_helpers/action_view.rb", "lib/generators/awesome_tables_generator.rb", "lib/generators/templates/_base.html.erb"]
@@ -1,12 +1,21 @@
1
1
  module AwesomeTables
2
2
 
3
- class NoBlockGivenException < Exception
4
- end
3
+ class Error < StandardError; end
4
+
5
+ class NoBlockGiven < Error; end
6
+
7
+ class UnknownTableType < Error; end
5
8
 
6
- class UnknownTableTypeException < Exception
7
- end
9
+ class NoPartial < Error; end
10
+
11
+ class BadData < Error; end
12
+
13
+ def self.register(table_type, &block)
14
+ AwesomeTables::AwesomeTable::register(table_type, &block)
15
+ end
8
16
 
9
- class NoPartialException < Exception
17
+ def self.new(table_type, collection = [], options = {})
18
+ AwesomeTables::AwesomeTable::new(table_type, collection, options)
10
19
  end
11
20
  end
12
21
 
@@ -2,20 +2,20 @@ module AwesomeTables
2
2
  class AwesomeTable
3
3
  @@tables = {}
4
4
 
5
- attr_accessor :data, :columns, :partial, :caption
5
+ attr_accessor :collection, :columns, :partial, :caption, :template
6
6
 
7
7
  def self.register(table_type, &block)
8
- raise AwesomeTables::NoBlockGivenException unless block_given?
8
+ raise AwesomeTables::NoBlockGiven unless block_given?
9
9
  @@tables[table_type] = block
10
10
  end
11
11
 
12
- def initialize(table_type, data = [], options = {})
13
- @data = data
14
- @paginate = true if @data.is_a? WillPaginate::Collection
12
+ def initialize(table_type, collection = [], options = {})
13
+ @collection = collection
14
+ @paginate = true if @collection.is_a? WillPaginate::Collection
15
15
  @columns = []
16
16
  @template = options[:template] ||= 'awesome_tables/base'
17
17
  # is this the best way to do this?
18
- raise AwesomeTables::UnknownTableTypeException if @@tables[table_type].blank?
18
+ raise AwesomeTables::UnknownTableType if @@tables[table_type].blank?
19
19
  @@tables[table_type].call(self)
20
20
  end
21
21
 
@@ -33,18 +33,37 @@ module AwesomeTables
33
33
  # example column colls
34
34
  # t.column :created_at, :display_created_at
35
35
  # t.column :body, :partial => 'awesome_tables/posts/body'
36
- # t.column :comments, :comment_count, :with_image => 'comments.png'
36
+ # t.column :comments, :comment_count, :with_header => 'comments.png'
37
37
  # t.column :full_name
38
- def column(*args)
38
+ # I can't figure out how to get content_tag and other helper methods to
39
+ # get used correctly when used inside blocks. For now, passing in reference
40
+ # to self that has those methods defined.
41
+ # t.column :full_name do |obj, c|
42
+ # obj.full_name +
43
+ # c.content_tag(:div, :class => 'actions') do
44
+ # c.link_to("Edit", c.edit_admin_user_path(obj))
45
+ # end
46
+ # end
47
+ def column(*args, &block)
39
48
  name = args[0].to_s.titleize
40
- if args[1].nil?
49
+ if block_given?
50
+ method = block
51
+ options = args[1]
52
+ # t.column :full_name
53
+ elsif args[1].nil?
41
54
  method = args[0]
55
+ # t.column :created_at, :display_created_at
42
56
  elsif args[1].is_a? Symbol
43
57
  method = args[1]
44
58
  options = args[2]
59
+ # t.column :body, :partial => 'awesome_tables/posts/body'
60
+ # t.column :comments, :with_header => 'comments.png'
45
61
  else
46
- raise AwesomeTables::NoPartialProvidedException unless args[1].keys.include?(:partial)
47
- method = args[1].delete(:partial)
62
+ method = if args[1].keys.include?(:partial)
63
+ args[1].delete(:partial)
64
+ else
65
+ args[0]
66
+ end
48
67
  options = args[1]
49
68
  end
50
69
  @columns << { :header => name, :method => method, :options => options ||= {} }
@@ -4,11 +4,65 @@ module AwesomeTables
4
4
  # TODO make this only need table_type and infer objects by name
5
5
  # TODO add a render method so calling partial is not needed here
6
6
  # e.g. AwesomeTables::AwesomeTable.new(table_type, data).render
7
- def awesome_table(table_type, data)
8
- raise "awesome_table data is not an Array" unless data.is_a? Array
9
- awesome_table = AwesomeTables::AwesomeTable.new(table_type, data)
7
+ def awesome_table(table_type, collection = nil)
8
+ if collection.nil?
9
+ collection_name = "@#{table_type}"
10
+ collection = instance_variable_get(collection_name)
11
+ end
12
+ raise AwesomeTables::BadData unless collection.is_a? Array
13
+ awesome_table = AwesomeTables.new(table_type, collection)
10
14
  render :partial => awesome_table.template, :locals => { :table => awesome_table }
11
15
  end
16
+
17
+ def table_headers(table)
18
+ content_tag :tr do
19
+ th_tags = []
20
+ table.columns.each do |column|
21
+ th_tags << th_tag(column)
22
+ end
23
+ th_tags.join('')
24
+ end
25
+ end
26
+
27
+ def th_tag(column)
28
+ content_tag(:th, :class => column[:options][:class]) do
29
+ if column[:options][:header_image]
30
+ image_tag(column[:options][:header_image], :border => 0)
31
+ else
32
+ column[:header]
33
+ end
34
+ end
35
+ end
36
+
37
+ def table_rows(table)
38
+ rows = []
39
+ table.collection.each do |object|
40
+ rows << table_row(object, table.columns)
41
+ end
42
+ raw(rows.join(''))
43
+ end
44
+
45
+ def table_row(object, columns)
46
+ content_tag :tr do
47
+ row = []
48
+ columns.each do |column|
49
+ row << td_tag(column, object)
50
+ end
51
+ row.join('')
52
+ end
53
+ end
54
+
55
+ def td_tag(column, object)
56
+ content_tag(:td) do
57
+ if column[:method].is_a?(Proc)
58
+ column[:method].call(object, self)
59
+ elsif object.respond_to? column[:method]
60
+ object.send(column[:method]).to_s
61
+ else
62
+ render :partial => column[:method], :locals => { :obj => object }
63
+ end
64
+ end
65
+ end
12
66
  end
13
67
  end
14
68
  end
@@ -1,33 +1,17 @@
1
- <table>
1
+ <table class="awesome_tables add_margin">
2
2
  <% if table.caption? %>
3
- <caption class="medium_round_top"><%= table.caption %></caption>
3
+ <caption><%= table.caption %></caption>
4
4
  <% end %>
5
- <tr>
6
- <% table.columns.each do |column| %>
7
- <th<%= " class=#{column[:class]}" unless column[:class].blank? %>><%= column[:image].blank? ? column[:header] : image_tag(column[:image]) %></th>
8
- <% end %>
9
- </tr>
10
- <% if table.data.blank? %>
5
+ <%= table_headers(table) %>
6
+ <% if table.collection.blank? %>
11
7
  <tr><td colspan="<%= table.columns.size %>">0 results</td></tr>
12
8
  <% else %>
13
- <% table.data.each do |object| %>
14
- <tr>
15
- <% table.columns.each do |column| %>
16
- <td<%= " class=#{column[:class]}" unless column[:class].blank? %>>
17
- <% if object.respond_to?(column[:method]) %>
18
- <%= object.send(column[:method]) %>
19
- <% else %>
20
- <%= render :partial => column[:method], :locals => { :obj => object } %>
21
- <% end %>
22
- </td>
23
- <% end %>
24
- </tr>
25
- <% end %>
9
+ <%= table_rows(table) %>
26
10
  <% if table.paginate? %>
27
11
  <tr>
28
12
  <td class="pagination_links" colspan="<%= table.columns.size %>">
29
- <div class="pagination_info"><%= page_entries_info table.data %></div>
30
- <%= will_paginate table.data %>
13
+ <div class="pagination_info"><%= page_entries_info table.collection %></div>
14
+ <%= will_paginate table.collection %>
31
15
  </td>
32
16
  </tr>
33
17
  <% end %>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Engle
@@ -35,7 +35,7 @@ cert_chain:
35
35
  2MS0NMYj
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2010-10-24 00:00:00 -05:00
38
+ date: 2010-11-07 01:00:00 -05:00
39
39
  default_executable:
40
40
  dependencies: []
41
41
 
metadata.gz.sig CHANGED
Binary file