Permalink
Browse files

Gemify.

  • Loading branch information...
1 parent 1292618 commit f017c86c90ff2352a7c18317e548e18a507fe871 @uu committed Jan 14, 2012
Showing with 248 additions and 113 deletions.
  1. +13 −0 Gemfile
  2. +21 −0 LICENSE.txt
  3. +4 −6 README.md
  4. +39 −14 Rakefile
  5. +1 −0 VERSION
  6. +1 −1 init.rb
  7. +109 −92 lib/rails_datatables.rb
  8. +1 −0 rails/init.rb
  9. +56 −0 rails_datatables.gemspec
  10. +3 −0 test/helper.rb
  11. 0 test/test_rails_datatables.rb
View
13 Gemfile
@@ -0,0 +1,13 @@
+source "http://rubygems.org"
+# Add dependencies required to use your gem here.
+# Example:
+# gem "activesupport", ">= 2.3.5"
+
+# Add dependencies to develop your gem here.
+# Include everything needed to run rake, tests, features, etc.
+group :development do
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.5.2"
+ gem "rcov", ">= 0"
+end
View
21 LICENSE.txt
@@ -0,0 +1,21 @@
+Copyright (c) 2010 [Phronos](http://phronos.com)
+Copyright (c) 2011 Jon Bringhurst <jon@bringhurst.org>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
10 README.md
@@ -50,24 +50,21 @@ Activate using <%= datatable() %>, passing in the columns, how to filter them (s
:persist_state - boolean, remember the sorting and page of the tables for the user. Defaults to true.
:additional_data - hash, pass along additional data, such as filter values. Default is none.
:table_dom_id - string, the ID of the table to alter. If nothing is passed, it will look for a class of 'datatable'. Necessary if you want to have multiple DataTables on a single page.
+ :jqueryui - enable the JQuery UI element styling (ThemeRoller support). Default is false.
:per_page - the number of rows to show per page (renamed from display_length)
:append - functions to all at the end of the dataTable() call. Useful for [Datatables plugins](http://www.datatables.net/plug-ins/api)
:no_records_message - Message to display if no records are found, whether on load or after searching
:auto_width - Automatically adjust the width of the columns. Defaults to true.
:row_callback - a function to run on each row in the table. Inserted in to "'fnRowCallback': function( nRow, aData, iDisplayIndex ) { }". See [documentation for fnRowCallback](http://www.datatables.net/usage/callbacks) for more information.
- :jquery_ui - boolean, set true if you want to enable jQueryUI for this datatable
- :dom - string, configuration for layout of additional table controls (see datatables documentation for sDom)
+ :pagination - boolean, turn pagination on or off. Defaults to true.
#### Column Options
:class - string, the class to assign to the table cell. Default is none.
:type - string, the type of content in the column, for non-Ajax tables. 'html' will strip all HTML and sort on the inner value, as a string. Default is string.
:sortable - boolean, allow this column to be sorted on. Default is true.
:searchable - boolean, allow this column to be searched, for non-Ajax tables. Default is true.
- :datasort - integer, use the indicated (0-indexed) column for sorting on this column
- :visible - boolean, set false to hide this column
- :sorting - array, controls the default sorting direction, and even alter the behaviour of the sort handler (i.e. only allow ascending sorting etc) using this parameter.
-
+
#### AJAX Options
When you're working with large datasets it's not reasonable to load everything on page load. Use an :ajax_source to load just the records that are being displayed, do custom searching (DB, Solr, etc).
@@ -141,3 +138,4 @@ There is a more functionality offered by DataTables than this plugin currently p
### Credits
Copyright (c) 2009 [Phronos](http://phronos.com), released under the MIT license
+Copyright (c) 2011 Jon Bringhurst <jon@bringhurst.org>, released under the MIT license
View
53 Rakefile
@@ -1,23 +1,48 @@
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ gem.name = "rails_datatables"
+ gem.homepage = "http://github.com/fintler/rails_datatables"
+ gem.license = "MIT"
+ gem.summary = %Q{Rails plugin for the jQuery Datatables library }
+ gem.description = %Q{A simpler, Rails-friendly interface to using the DataTables jQuery library.}
+ gem.email = "jon@bringhurst.org"
+ gem.authors = ["Jon Bringhurst"]
+end
+Jeweler::RubygemsDotOrgTasks.new
+
require 'rake/testtask'
-require 'rake/rdoctask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+require 'rcov/rcovtask'
+Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
-desc 'Default: run unit tests.'
task :default => :test
-desc 'Test the rails_datatables plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
-desc 'Generate documentation for the rails_datatables plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'RailsDatatables'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
+ rdoc.title = "rails_datatables #{version}"
+ rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
View
1 VERSION
@@ -0,0 +1 @@
+0.0.0
View
2 init.rb
@@ -1 +1 @@
-ActionView::Base.send :include, RailsDatatables
+ActionView::Base.send :include, RailsDatatables
View
201 lib/rails_datatables.rb
@@ -1,101 +1,118 @@
module RailsDatatables
- def datatable(columns, opts={})
- sort_by = opts[:sort_by] || nil
- additional_data = opts[:additional_data] || {}
- search = opts.has_key?(:search) ? opts[:search].to_s : "true"
- search_label = opts[:search_label] || "Search"
- processing = opts[:processing] || image_tag('throbber.gif')
- persist_state = opts.has_key?(:persist_state) ? opts[:persist_state].to_s : "true"
- table_dom_id = opts[:table_dom_id] ? "##{opts[:table_dom_id]}" : ".datatable"
- per_page = opts[:per_page] || opts[:display_length]|| 25
- no_records_message = opts[:no_records_message] || nil
- auto_width = opts.has_key?(:auto_width) ? opts[:auto_width].to_s : "true"
- row_callback = opts[:row_callback] || nil
- infinite_scrolling = opts[:infinite_scrolling] || nil
- infinite_scrolling_margin = opts[:infinite_scrolling_margin] || '200px'
- column_search = opts[:column_search] || nil
+ def datatable(columns, opts={})
+ sort_by = opts[:sort_by] || nil
+ additional_data = opts[:additional_data] || {}
+ search = opts[:search].present? ? opts[:search].to_s : "true"
+ search_label = opts[:search_label] || "Search"
+ processing = opts[:processing] || "Processing"
+ persist_state = opts[:persist_state].present? ? opts[:persist_state].to_s : "true"
+ table_dom_id = opts[:table_dom_id] ? "##{opts[:table_dom_id]}" : ".datatable"
+ per_page = opts[:per_page] || opts[:display_length]|| 25
+ no_records_message = opts[:no_records_message] || nil
+ auto_width = opts[:auto_width].present? ? opts[:auto_width].to_s : "true"
+ row_callback = opts[:row_callback] || nil
+ length_change = opts.key?(:length_change) ? opts[:length_change].to_s : "true"
+ jqueryui = opts.key?(:jqueryui) ? opts[:jqueryui].to_s : "false"
+ paginate = opts[:paginate].present? ? opts[:pagintate].to_s : "true"
- append = opts[:append] || nil
+ length_menu = opts[:length_menu] || nil
+ empty_table = opts[:empty_table] || nil
+ info = opts[:info] || nil
+ info_empty = opts[:info_empty] || nil
+ info_filtered = opts[:info_filtered] || nil
+ pfirst = opts[:pfirst] || nil
+ pprevious = opts[:pprevious] || nil
+ pnext = opts[:pnext] || nil
+ plast = opts[:plast] || nil
- ajax_source = opts[:ajax_source] || nil
- server_side = opts.has_key?(:ajax_source)
- jquery_ui = opts[:jquery_ui] || nil
- dom = opts[:dom] || nil
-
- additional_data_string = ""
- additional_data.each_pair do |name,value|
- additional_data_string = additional_data_string + ", " if !additional_data_string.blank? && value
- additional_data_string = additional_data_string + "{'name': '#{name}', 'value':'#{value}'}" if value
+ append = opts[:append] || nil
+
+ ajax_source = opts[:ajax_source] || nil
+ server_side = opts[:ajax_source].present?
+
+ additional_data_string = ""
+ additional_data.each_pair do |name,value|
+ additional_data_string = additional_data_string + ", " if !additional_data_string.blank? && value
+ additional_data_string = additional_data_string + "{'name': '#{name}', 'value':'#{value}'}" if value
+ end
+
+ %Q{
+ <script type="text/javascript">
+ $(function() {
+ $('#{table_dom_id}').dataTable({
+ "oLanguage": {
+ "sSearch": "#{search_label}",
+
+ "sLengthMenu": "#{length_menu}",
+ "sEmptyTable": "#{empty_table}",
+ "sInfo": "#{info}",
+ "sInfoEmpty": "#{info_empty}",
+ "sInfoFiltered": "#{info_filtered}",
+ "sInfoPostFix": "",
+ "sUrl": "",
+ "oPaginate": {
+ "sFirst": "#{pfirst}",
+ "sPrevious": "#{pprevious}",
+ "sNext": "#{pnext}",
+ "sLast": "#{plast}"
+ },
+
+ #{"'sZeroRecords': '#{no_records_message}'," if no_records_message}
+ "sProcessing": '#{processing}'
+ },
+ "bPaginate": #{paginate},
+ "sPaginationType": "full_numbers",
+ "iDisplayLength": #{per_page},
+ "bJQueryUI": #{jqueryui},
+ "bProcessing": true,
+ "bServerSide": #{server_side},
+ "bLengthChange": #{length_change},
+ "bStateSave": #{persist_state},
+ "bFilter": #{search},
+ "bAutoWidth": #{auto_width},
+ #{"'aaSorting': [#{sort_by}]," if sort_by}
+ #{"'sAjaxSource': '#{ajax_source}'," if ajax_source}
+ "aoColumns": [
+ #{formatted_columns(columns)}
+ ],
+ #{"'fnRowCallback': function( nRow, aData, iDisplayIndex ) {
+ #{row_callback}
+ }," if row_callback}
+ "fnServerData": function ( sSource, aoData, fnCallback ) {
+ aoData.push( #{additional_data_string} );
+ $.getJSON( sSource, aoData, function (json) {
+ fnCallback(json);
+ });
+ }
+ })#{append};
+ });
+ </script>
+ }.html_safe
end
- %Q{
- <script type="text/javascript">
- jQuery(document).ready(function () {
- if ( !window.DatatableStore ) {
- window.DatatableStore = {}
- }
+ private
- DatatableStore['#{table_dom_id.gsub('#','')}'] = jQuery('#{table_dom_id}').dataTable({
- "oLanguage": {
- "sSearch": "#{search_label}",
- #{"'sZeroRecords': '#{no_records_message}'," if no_records_message}
- "sProcessing": '#{processing}'
- },
- "sPaginationType": "full_numbers",
- "iDisplayLength": #{per_page},
- "bProcessing": true,
- "bServerSide": #{server_side},
- "bLengthChange": false,
- "bStateSave": #{persist_state},
- "bFilter": #{search},
- "bAutoWidth": #{auto_width},
- #{"'aoSearchCols': #{column_search.to_json}" if column_search},
- #{"'bScrollInfinite': '#{infinite_scrolling}'," if infinite_scrolling}
- #{"'bScrollCollapse': true," if infinite_scrolling}
- #{"'sScrollY': '#{infinite_scrolling_margin}'," if infinite_scrolling}
- #{"'sDom': '#{dom}'," if dom}
- #{"'aaSorting': [#{sort_by}]," if sort_by}
- #{"'sAjaxSource': '#{ajax_source}'," if ajax_source}
- #{"'bJQueryUI': #{jquery_ui}," if jquery_ui}
- "aoColumns": [
- #{formatted_columns(columns)}
- ],
- #{"'fnRowCallback': function( nRow, aData, iDisplayIndex ) { #{row_callback} }," if row_callback}
- "fnServerData": function ( sSource, aoData, fnCallback ) {
- aoData.push( #{additional_data_string} );
- jQuery.getJSON( sSource, aoData, function (json) {
- fnCallback(json);
- } );
- }
- })#{append};
- });
+ def formatted_columns(columns)
+ i = 0
+ columns.map {|c|
+ i += 1
+ if c.nil? or c.empty?
+ "null"
+ else
+ searchable = c[:searchable].to_s.present? ? c[:searchable].to_s : "true"
+ sortable = c[:sortable].to_s.present? ? c[:sortable].to_s : "true"
+
+ "{
+ 'sType': '#{c[:type] || "string"}',
+ 'bSortable':#{sortable},
+ 'bSearchable':#{searchable}
+ #{",'sClass':'#{c[:class]}'" if c[:class]}
+ }"
+
+ end
+ }.join(",")
+ end
- </script>
- }
end
- private
- def formatted_columns(columns)
- i = 0
- columns.map {|c|
- i += 1
- if c.nil? or c.empty?
- "null"
- else
- searchable = c.has_key?(:searchable) ? c[:searchable].to_s : "true"
- sortable = c.has_key?(:sortable) ? c[:sortable].to_s : "true"
- "{
- 'sType': '#{c[:type] || "string"}',
- 'bSortable':#{sortable},
- 'bSearchable':#{searchable},
- #{"'asSorting':#{c[:sorting].inspect}," if c[:sorting]}
- #{"'bVisible':'#{c[:visible]}'," if c[:visible]}
- #{"'iDataSort':#{c[:datasort]}," if c[:datasort]}
- #{"'sClass':'#{c[:class]}'," if c[:class]}
- #{"'sWidth':'#{c[:width]}'," if c[:width]}
- #{"'sName':'#{c[:name]}'" if c[:name]}
- }"
- end
- }.join(",")
- end
-end
+# EOF
View
1 rails/init.rb
@@ -0,0 +1 @@
+require 'rails_datatables'
View
56 rails_datatables.gemspec
@@ -0,0 +1,56 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{rails_datatables}
+ s.version = "0.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Jon Bringhurst"]
+ s.date = %q{2011-04-22}
+ s.description = %q{A simpler, Rails-friendly interface to using the DataTables jQuery library.}
+ s.email = %q{jon@bringhurst.org}
+ s.extra_rdoc_files = [
+ "LICENSE.txt",
+ "README.md"
+ ]
+ s.files = [
+ "README.md",
+ "Rakefile",
+ "VERSION",
+ "lib/rails_datatables.rb"
+ ]
+ s.homepage = %q{http://github.com/fintler/rails_datatables}
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.6.2}
+ s.summary = %q{Rails plugin for the jQuery Datatables library}
+ s.test_files = [
+ "test/helper.rb",
+ "test/test_rails_datatables.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_development_dependency(%q<rcov>, [">= 0"])
+ else
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ end
+end
+
View
3 test/helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
View
0 test/test_rails_datatables.rb
No changes.

0 comments on commit f017c86

Please sign in to comment.