tablesorter 0.0.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Tablesorter
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Tablesorter'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Tablesorter
2
+ require 'tablesorter/railtie' if defined?(Rails)
3
+ end
@@ -0,0 +1,9 @@
1
+ module Tablesorter
2
+ module ActiveRecord
3
+ def table_sort(sort_attr, dir, default_attr, default_dir)
4
+ sort_attr ||= default_attr
5
+ dir ||= default_attr
6
+ self.order("#{sort_attr} #{dir}")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'tablesorter/view_helpers'
2
+ require 'tablesorter/active_record'
3
+
4
+ module Tablesorter
5
+ class Railtie < Rails::Railtie
6
+
7
+ initializer 'tablesorter.view_helpers' do
8
+ ActionView::Base.send :include, ViewHelpers
9
+ end
10
+
11
+ initializer 'tablesorter.active_record' do
12
+ ActionView::Base.extend ActiveRecord
13
+
14
+ klasses = [::ActiveRecord::Relation]
15
+ if defined? ::ActiveRecord::Associations::CollectionProxy
16
+ klasses << ::ActiveRecord::Associations::CollectionProxy
17
+ else
18
+ klasses << ::ActiveRecord::Associations::AssociationCollection
19
+ end
20
+
21
+ klasses.each { |klass| klass.send(:include, ActiveRecord) }
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Tablesorter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ module Tablesorter
2
+ module ViewHelpers
3
+ def sortable_column_headings(columns, options={})
4
+
5
+ current_sort = params[:sort]
6
+ if current_sort.present?
7
+ current_sort = current_sort.to_sym
8
+ end
9
+
10
+ current_dir = params[:dir]
11
+ if current_dir.present?
12
+ current_dir = current_dir.to_sym
13
+ end
14
+
15
+ columns.inject('') do |acc, col|
16
+ sym = col.to_sym
17
+ dir = (current_sort==sym && current_dir==:asc) ? 'desc' : 'asc'
18
+ title = I18n.t(('tablesorter.'+sym.to_s).to_sym, :default => sym.to_s.humanize)
19
+ css_classes = []
20
+ css_classes << 'selected' if current_sort==sym
21
+ css_classes << dir.to_s if current_sort==sym
22
+
23
+ acc +
24
+ '<th>' +
25
+ "<a #{css_class_attribute(css_classes)} href='?" +
26
+ options.merge(sort:sym.to_s, dir:dir).to_query +
27
+ "'>" +
28
+ "#{title}<span></span></a>" +
29
+ '</th>'
30
+ end.html_safe
31
+ end
32
+
33
+ def css_class_attribute(css_classes)
34
+ css_classes.present? ? "class='#{css_classes.join(' ')}'" : ''
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tablesorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Luke Roberts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: ! "This gem provides helpers for building sortable column headings in
31
+ a table with links. \n It also monkey patches (for better or for
32
+ worse) ActiveRecord and provides a more \n succinct api for sorting
33
+ based on the table column links. It is the intention to \n expand
34
+ this API to provide default and secondary sorts. \n It's very
35
+ basic but I have built this functionality enough times to warrant gemification\n
36
+ \ Features via pull requests welcome"
37
+ email: luke@llamadigital.net
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/tablesorter/active_record.rb
43
+ - lib/tablesorter/railtie.rb
44
+ - lib/tablesorter/version.rb
45
+ - lib/tablesorter/view_helpers.rb
46
+ - lib/tablesorter.rb
47
+ - MIT-LICENSE
48
+ - Rakefile
49
+ - README.rdoc
50
+ homepage: http://github.com/lukeroberts1990/tablesorter
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.24
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: A gem for creating sortable tables in rails applications
74
+ test_files: []