Skip to content

Commit 0588e89

Browse files
author
Joel Quenneville
committed
Merge pull request jbox-web#2 from JoelQ/generators
Generators
2 parents 7d3588c + 6b74f52 commit 0588e89

File tree

5 files changed

+62
-29
lines changed

5 files changed

+62
-29
lines changed

.rvmrc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
4+
# development environment upon cd'ing into the directory
5+
6+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7+
# Only full ruby name is supported here, for short names use:
8+
# echo "rvm use 1.9.3" > .rvmrc
9+
environment_id="ruby-1.9.3-p125@ajax-datatables-rails"
10+
11+
# Uncomment the following lines if you want to verify rvm version per project
12+
# rvmrc_rvm_version="1.11.0-pre" # 1.10.1 seams as a safe start
13+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15+
# return 1
16+
# }
17+
18+
# First we attempt to load the desired environment directly from the environment
19+
# file. This is very fast and efficient compared to running through the entire
20+
# CLI and selector. If you want feedback on which environment was used then
21+
# insert the word 'use' after --create as this triggers verbose mode.
22+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24+
then
25+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28+
else
29+
# If the environment file has not yet been created, use the RVM CLI to select.
30+
rvm --create "$environment_id" || {
31+
echo "Failed to create RVM environment '${environment_id}'."
32+
return 1
33+
}
34+
fi
35+
36+
# If you use bundler, this might be useful to you:
37+
# if [[ -s Gemfile ]] && {
38+
# ! builtin command -v bundle >/dev/null ||
39+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40+
# }
41+
# then
42+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43+
# gem install bundler
44+
# fi
45+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46+
# then
47+
# bundle install | grep -vE '^Using|Your bundle is complete'
48+
# fi

ajax-datatables-rails.gemspec

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ Gem::Specification.new do |gem|
1414
gem.name = "ajax-datatables-rails"
1515
gem.require_paths = ["lib"]
1616
gem.version = AjaxDatatablesRails::VERSION
17-
18-
gem.add_runtime_dependency 'jquery-datatables-rails', '~> 1.9.1'
1917
end

lib/ajax-datatables-rails.rb

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
require 'rails'
1+
# require 'rails'
22

33
class AjaxDatatablesRails
44

55
VERSION = '0.0.1'
66

7-
class << self
8-
9-
def columns(column_array)
10-
@@columns ||= column_array
11-
end
12-
13-
def model_name(model_name)
14-
@@model_name ||= model_name
15-
end
16-
17-
def searchable_columns(columns_array)
18-
@@searchable_columns ||= columns_array
19-
end
20-
21-
end
22-
237
def initialize(view)
248
@view = view
259
end
10+
11+
attr_reader :columns, :model_name, :searchable_columns
2612

2713
def method_missing(meth, *args, &block)
2814
@view.send(meth, *args, &block)
@@ -31,7 +17,7 @@ def method_missing(meth, *args, &block)
3117
def as_json(options = {})
3218
{
3319
sEcho: params[:sEcho].to_i,
34-
iTotalRecords: @@model_name.count,
20+
iTotalRecords: @model_name.count,
3521
iTotalDisplayRecords: get_raw_records.count,
3622
aaData: data
3723
}
@@ -57,7 +43,7 @@ def sort_records(records)
5743

5844
def search_records(records)
5945
if params[:sSearch].present?
60-
query = @@searchable_columns.map do |column|
46+
query = @searchable_columns.map do |column|
6147
"#{column} LIKE :search"
6248
end.join(" OR ")
6349
records = records.where(query, search: "%#{params[:sSearch]}%")
@@ -74,7 +60,7 @@ def per_page
7460
end
7561

7662
def sort_column
77-
@@columns[params[:iSortCol_0].to_i]
63+
@columns[params[:iSortCol_0].to_i]
7864
end
7965

8066
def sort_direction

lib/generators/ajaxdatatable/templates/datatable.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
class <%= model.classify %>Datatable < AjaxDatatableRails
2-
model_name <%= model.classify %>
3-
columns # insert array of column names here
4-
searchable_columns #insert array of columns that will be searched
1+
class <%= model.classify.pluralize %>Datatable < AjaxDatatablesRails
2+
3+
def initialize(view)
4+
@model_name = <%= model.classify %>
5+
@columns = # insert array of column names here
6+
@searchable_columns = #insert array of columns that will be searched
7+
super(view)
8+
end
59

610
private
711

lib/generators/datatable_generator.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)