awesome_tables 0.0.3 → 0.0.4

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.
data/Manifest CHANGED
@@ -2,8 +2,13 @@ MIT-LICENSE
2
2
  Manifest
3
3
  README
4
4
  Rakefile
5
+ lib/app/views/awesome_tables/_base.html.erb
5
6
  lib/awesome_tables.rb
7
+ lib/awesome_tables/awesome_table.rb
8
+ lib/awesome_tables/formatters.rb
9
+ lib/awesome_tables/formatters/html.rb
6
10
  lib/awesome_tables/railtie.rb
11
+ lib/awesome_tables/scrap.rb
7
12
  lib/awesome_tables/view_helpers/action_view.rb
8
13
  test/awesome_tables_test.rb
9
14
  test/test_helper.rb
data/README CHANGED
@@ -1,13 +1,55 @@
1
1
  AwesomeTables
2
2
  =============
3
3
 
4
- Introduction goes here.
4
+ This rails gem is used to easily display, consistently styled tables. It is still very much a work in progress.
5
5
 
6
6
 
7
7
  Example
8
8
  =======
9
9
 
10
- Example goes here.
10
+ In order to use an awesome_table, first you must register it in a helper. Two examples are below.
11
11
 
12
+ AwesomeTables::AwesomeTable::register :posts do |t|
13
+ t.set_caption "Posts"
14
+ t.column :published_at, :display_published_at
15
+ t.column :post, :partial => 'awesome_tables/posts/body'
16
+ t.column :comment_count, :comment_counter, :with_image => 'comment-grey-bubble.png'
17
+ end
12
18
 
13
- Copyright (c) 2010 [name of plugin creator], released under the MIT license
19
+ AwesomeTables::AwesomeTable::register :users do |t|
20
+ t.set_caption "Users"
21
+ t.column :full_name
22
+ t.column :login
23
+ t.column :email
24
+ t.column :state
25
+ end
26
+
27
+ Now you can use them in your views
28
+
29
+ <%= awesome_table :users, @users %>
30
+ <%= awesome_table :posts, @posts %>
31
+
32
+ There are currently 3 different ways to declare a column.
33
+ 1. t.column(:method) A plain td can be created by passing in an object attribute. The header will be a titlized version of the method name.
34
+ 2. t.column(:header_text, :method) If you want the header text to be different than the method.
35
+ 3. t.column(:header_text, :partial => 'path/to/partial) If your td data is more complex than a method name, add a partial option.
36
+
37
+ Eventually, I want to be able to create columns that use view_helpers, but I haven't spent enough time investigating how to get that working.
38
+ 4. t.column(:header_text, link_to(obj.name, obj))
39
+
40
+ The :with_image option will use the image as the column header instead header text. That code and the way it is used needs some attention. Things have changed a little bit since I put that in there.
41
+
42
+ You'll need to make sure that you create an awesome tables view folder. There is a base example table contained in lib/app/views/awesome_tables.
43
+
44
+ TODO
45
+ ====
46
+
47
+ * create a generator that creates awesome_tables view folder and copies a base table into it.
48
+ * tests, tests, tests
49
+ * allow use of helpers in column calls
50
+ * figure out how to change the templates so that they don't have column loops inside of the object loop
51
+ * add more and better options support. Currently there is only a :class (and :with_image) option for columns and the way the :class option is implemented looks nasty.
52
+ * have awesome_tables infer objects the way will_paginate does. That was working, I changed it for some reason to work around something that I can't currently remember.
53
+ * create different formatters so awesome_tables can be used to output tables in formats other than html tables.
54
+
55
+ Copyright (c) 2010 Dan Engle, released under the MIT license
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.3') do |p|
5
+ Echoe.new('awesome_tables', '0.0.4') do |p|
6
6
  p.description = "A gem for some awesome tables"
7
7
  p.url = "http://github.com/danengle/awesome_tables"
8
8
  p.author = "Dan Engle"
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{awesome_tables}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
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-10}
10
+ s.date = %q{2010-10-24}
11
11
  s.description = %q{A gem for some awesome tables}
12
12
  s.email = %q{engle.68 @nospam@ gmail.com}
13
- s.extra_rdoc_files = ["README", "lib/awesome_tables.rb", "lib/awesome_tables/railtie.rb", "lib/awesome_tables/view_helpers/action_view.rb"]
14
- s.files = ["MIT-LICENSE", "Manifest", "README", "Rakefile", "lib/awesome_tables.rb", "lib/awesome_tables/railtie.rb", "lib/awesome_tables/view_helpers/action_view.rb", "test/awesome_tables_test.rb", "test/test_helper.rb", "awesome_tables.gemspec"]
13
+ s.extra_rdoc_files = ["README", "lib/app/views/awesome_tables/_base.html.erb", "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"]
14
+ s.files = ["MIT-LICENSE", "Manifest", "README", "Rakefile", "lib/app/views/awesome_tables/_base.html.erb", "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", "test/awesome_tables_test.rb", "test/test_helper.rb", "awesome_tables.gemspec"]
15
15
  s.homepage = %q{http://github.com/danengle/awesome_tables}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Awesome_tables", "--main", "README"]
17
17
  s.require_paths = ["lib"]
@@ -0,0 +1,35 @@
1
+ <table>
2
+ <% if table.caption? %>
3
+ <caption class="medium_round_top"><%= table.caption %></caption>
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? %>
11
+ <tr><td colspan="<%= table.columns.size %>">0 results</td></tr>
12
+ <% 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 %>
26
+ <% if table.paginate? %>
27
+ <tr>
28
+ <td class="pagination_links" colspan="<%= table.columns.size %>">
29
+ <div class="pagination_info"><%= page_entries_info table.data %></div>
30
+ <%= will_paginate table.data %>
31
+ </td>
32
+ </tr>
33
+ <% end %>
34
+ <% end %>
35
+ </table>
@@ -0,0 +1,53 @@
1
+ module AwesomeTables
2
+ class AwesomeTable
3
+ @@tables = {}
4
+
5
+ attr_accessor :data, :columns, :partial, :caption
6
+
7
+ def self.register(table_type, &block)
8
+ raise AwesomeTables::NoBlockGivenException unless block_given?
9
+ @@tables[table_type] = block
10
+ end
11
+
12
+ def initialize(table_type, data = [], options = {})
13
+ @data = data
14
+ @paginate = true if @data.is_a? WillPaginate::Collection
15
+ @columns = []
16
+ @template = options[:template] ||= 'awesome_tables/base'
17
+ # is this the best way to do this?
18
+ raise AwesomeTables::UnknownTableTypeException if @@tables[table_type].blank?
19
+ @@tables[table_type].call(self)
20
+ end
21
+
22
+ def caption?
23
+ !@caption.blank?
24
+ end
25
+
26
+ def paginate?
27
+ @paginate
28
+ end
29
+
30
+ def set_caption(caption)
31
+ @caption = caption
32
+ end
33
+ # example column colls
34
+ # t.column :created_at, :display_created_at
35
+ # t.column :body, :partial => 'awesome_tables/posts/body'
36
+ # t.column :comments, :comment_count, :with_image => 'comments.png'
37
+ # t.column :full_name
38
+ def column(*args)
39
+ name = args[0].to_s.titleize
40
+ if args[1].nil?
41
+ method = args[0]
42
+ elsif args[1].is_a? Symbol
43
+ method = args[1]
44
+ options = args[2]
45
+ else
46
+ raise AwesomeTables::NoPartialProvidedException unless args[1].keys.include?(:partial)
47
+ method = args[1].delete(:partial)
48
+ options = args[1]
49
+ end
50
+ @columns << { :header => name, :method => method, :options => options ||= {} }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ =begin
2
+ require 'awesome_tables/formatters'
3
+
4
+ module AwesomeTables
5
+ module Formatters
6
+ class Html < Formatter
7
+ def self.output
8
+ end
9
+ end
10
+ end
11
+ =end
@@ -0,0 +1,13 @@
1
+ =begin
2
+ require 'awesome_tables/formatters/html'
3
+
4
+ module AwesomeTables
5
+ class Formatter
6
+ class << self
7
+ def output(type, awesome_table)
8
+ case type
9
+ end
10
+ end
11
+ end
12
+ end
13
+ =end
@@ -1,4 +1,5 @@
1
1
  require 'awesome_tables'
2
+ require 'awesome_tables/awesome_table'
2
3
 
3
4
  module AwesomTables
4
5
  class Railtie < Rails::Railtie
@@ -0,0 +1,3 @@
1
+ def test(*args)
2
+ puts "1. #{args}"
3
+ end
@@ -1,8 +1,13 @@
1
1
  module AwesomeTables
2
2
  module ViewHelpers
3
3
  module ActionView
4
- def awesome_table(table_type, data = [])
5
- "awesome_table: #{table_type}, #{data.size}"
4
+ # TODO make this only need table_type and infer objects by name
5
+ # TODO add a render method so calling partial is not needed here
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)
10
+ render :partial => awesome_table.template, :locals => { :table => awesome_table }
6
11
  end
7
12
  end
8
13
  end
@@ -1,4 +1,13 @@
1
1
  module AwesomeTables
2
+
3
+ class NoBlockGivenException < Exception
4
+ end
5
+
6
+ class UnknownTableTypeException < Exception
7
+ end
8
+
9
+ class NoPartialException < Exception
10
+ end
2
11
  end
3
12
 
4
13
  if defined?(::Rails::Railtie)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
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-10 00:00:00 -05:00
38
+ date: 2010-10-24 00:00:00 -05:00
39
39
  default_executable:
40
40
  dependencies: []
41
41
 
@@ -47,16 +47,26 @@ extensions: []
47
47
 
48
48
  extra_rdoc_files:
49
49
  - README
50
+ - lib/app/views/awesome_tables/_base.html.erb
50
51
  - lib/awesome_tables.rb
52
+ - lib/awesome_tables/awesome_table.rb
53
+ - lib/awesome_tables/formatters.rb
54
+ - lib/awesome_tables/formatters/html.rb
51
55
  - lib/awesome_tables/railtie.rb
56
+ - lib/awesome_tables/scrap.rb
52
57
  - lib/awesome_tables/view_helpers/action_view.rb
53
58
  files:
54
59
  - MIT-LICENSE
55
60
  - Manifest
56
61
  - README
57
62
  - Rakefile
63
+ - lib/app/views/awesome_tables/_base.html.erb
58
64
  - lib/awesome_tables.rb
65
+ - lib/awesome_tables/awesome_table.rb
66
+ - lib/awesome_tables/formatters.rb
67
+ - lib/awesome_tables/formatters/html.rb
59
68
  - lib/awesome_tables/railtie.rb
69
+ - lib/awesome_tables/scrap.rb
60
70
  - lib/awesome_tables/view_helpers/action_view.rb
61
71
  - test/awesome_tables_test.rb
62
72
  - test/test_helper.rb
metadata.gz.sig CHANGED
Binary file