Browse files

initial commit

  • Loading branch information...
0 parents commit 667fe5c8f114aec393ec17a43a7a718da9203c66 @benwyrosdick benwyrosdick committed Aug 21, 2009
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 [name of plugin creator]
+
+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.
13 README
@@ -0,0 +1,13 @@
+Gridzilla
+=========
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2009 [name of plugin creator], released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the gridzilla plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the gridzilla plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Gridzilla'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1 install.rb
@@ -0,0 +1 @@
+# Install hook code here
5 lib/gridzilla.rb
@@ -0,0 +1,5 @@
+require 'gridzilla/constants'
+require 'gridzilla/delegate'
+require 'gridzilla/gobbler'
+require 'gridzilla/pagination_link_renderer'
+require 'gridzilla/dsl'
22 lib/gridzilla/constants.rb
@@ -0,0 +1,22 @@
+module Gridzilla
+
+ module Css
+ Title = 'gz_title'
+ Table = 'gz_table'
+ Panel = 'gz_panel'
+ Loading = 'gz_loading'
+ Checkbox = 'gz_checkbox'
+ RadioButton = 'gz_radio_button'
+ Empty = 'gz_empty'
+ Sortable = 'gz_sortable'
+ SortAsc = 'gz_sort_asc'
+ SortDesc = 'gz_sort_desc'
+ PanelAction = 'gz_action'
+ end
+
+ module Message
+ DefaultEmptySelection = "You must select an item"
+ DefaultSingleSelection = "You must select only one item"
+ end
+
+end
30 lib/gridzilla/delegate.rb
@@ -0,0 +1,30 @@
+module Gridzilla
+
+ module ViewDsl
+
+ class Base
+ def initialize(dsl, context)
+ @dsl = dsl
+ @chain = [@dsl, context]
+ end
+
+ def method_missing(name, *args, &block)
+ result = nil
+ @chain.each do |receiver|
+ begin
+ if receiver.respond_to?(name) or receiver.respond_to?(:method_missing)
+ result = receiver.send(name, *args, &block)
+ break
+ end
+ rescue Exception => e
+ next
+ end
+ end
+
+ result
+ end
+ end
+
+ end
+
+end
562 lib/gridzilla/dsl.rb
@@ -0,0 +1,562 @@
+module Gridzilla
+ module Controller
+ def self.included(base)
+ base.send :extend, ClassMethods
+ end
+
+ module ClassMethods
+ def gridzilla(&block)
+ grid_builder = GridBuilder.new(self)
+ block.bind(grid_builder).call
+ end
+ end
+
+ class GridBuilder
+ attr_accessor :context_object
+
+ def initialize(context_object)
+ @context_object = context_object
+ end
+
+ def method_missing(name, *args, &block)
+ raise "No block given" unless block
+
+ create_action("#{name}_grid") do
+ block.bind(self).call
+ unless performed?
+ render :layout => false
+ end
+ end
+ end
+
+ private
+ def create_action(name, &block)
+ context_object.send(:define_method, name.to_sym, &block)
+ end
+ end
+ end
+
+ module View
+ module InstanceMethods
+
+ def grid(name, *args, &block)
+ options = args.extract_options!
+ collection = args.shift
+
+ raise ArgumentError, "Missing collection in grid definition" if !collection and block_given?
+
+ grid_controller = params[:controller]
+
+ if name =~ /\//
+ name_parts = name.split(/\//)
+ grid_controller = name_parts.first
+ name = name_parts.last
+ end
+ grid_class = options[:class] || "gridzilla"
+ data = options[:data] || {}
+
+ unless @gridzilla_script_loaded
+ concat(content_tag(:script, <<-SCRIPT))
+ if (!gridzilla) {
+ var gridzilla = {};
+
+ (function(){
+
+ var gridzilla_data = {};
+ gridzilla.get_data = function(grid_name) {
+ return gridzilla_data[grid_name];
+ }
+ gridzilla.set_data = function(grid_name, data) {
+ gridzilla_data[grid_name] = data;
+ }
+
+ var gridzilla_is_loaded = {};
+ gridzilla.is_loaded = function(grid_name) {
+ return gridzilla_is_loaded[grid_name];
+ }
+ gridzilla.set_loaded = function(grid_name) {
+ gridzilla_is_loaded[grid_name] = true;
+ }
+
+ var gridzilla_options = {};
+ gridzilla.get_option = function(grid_name, option_name) {
+ if (gridzilla_options[grid_name]) {
+ return gridzilla_options[grid_name][option_name];
+ }
+ }
+ gridzilla.set_option = function(grid_name, option_name, value) {
+ if (!gridzilla_options[grid_name]) {
+ gridzilla_options[grid_name] = {};
+ }
+ gridzilla_options[grid_name][option_name] = value;
+ }
+
+ gridzilla.setup = function(grid_name) {
+ //Handle Check Boxes
+ $("#"+grid_name+"_select_all").click(function() {
+ if ($("#"+grid_name+" thead:first tr.ui-selected").length == 0) {
+ $("#"+grid_name+" tr").addClass("ui-selected").removeClass("ui-partial");
+ } else {
+ $("#"+grid_name+" tr").removeClass("ui-selected ui-partial");
+ }
+ });
+
+ if (gridzilla.get_option(grid_name, 'height') && $("#"+grid_name).is(":not(div > .#{Gridzilla::Css::Empty})")) {
+ if ($("#"+grid_name+" .#{Gridzilla::Css::Table}:first").height() > gridzilla.get_option(grid_name, 'height')) {
+ $("#"+grid_name+" .#{Gridzilla::Css::Table}:first").Scrollable(gridzilla.get_option(grid_name, 'height'));
+ }
+ }
+
+ $("#"+grid_name+" .#{Gridzilla::Css::Table}:first thead:first .#{Gridzilla::Css::Sortable}").click(function() {
+ if ($(this).hasClass("#{Gridzilla::Css::SortAsc}")) {
+ gridzilla.load(grid_name, {data: {sort_key: $("input[name=sort_key]", this).val(), sort_order: "DESC", page: 1}, keep_params: true});
+ } else if ($(this).hasClass("#{Gridzilla::Css::SortDesc}")) {
+ gridzilla.load(grid_name, {data: {page: 1, sort_key: "", sort_order: ""}, keep_params: true});
+ } else {
+ gridzilla.load(grid_name, {data: {sort_key: $("input[name=sort_key]", this).val(), sort_order: "ASC", page: 1}, keep_params: true});
+ }
+ });
+
+ gridzilla.set_loaded(grid_name);
+ };
+
+ gridzilla.row_click = function(element) {
+ if ($(element).is("tr:has(.#{Gridzilla::Css::RadioButton})")) {
+ $(element).closest('.gridzilla').find("tr").removeClass("ui-selected");
+ $(element).addClass("ui-selected");
+ } else {
+ $(element).toggleClass('ui-selected');
+ gridzilla.select_all_adorning($(element).closest('.gridzilla'));
+ }
+ };
+
+ gridzilla.select_all_adorning = function(grid_jqo) {
+ if ($("tbody td .#{Gridzilla::Css::Checkbox}", grid_jqo).length == $("tbody tr.ui-selected td .#{Gridzilla::Css::Checkbox}", grid_jqo).length) {
+ $("thead tr", grid_jqo).addClass('ui-selected');
+ $("thead tr", grid_jqo).removeClass('ui-partial');
+ } else if ($("tbody tr.ui-selected td .#{Gridzilla::Css::Checkbox}", grid_jqo).length == 0) {
+ $("thead tr", grid_jqo).removeClass('ui-selected');
+ $("thead tr", grid_jqo).removeClass('ui-partial');
+ } else {
+ $("thead tr", grid_jqo).removeClass('ui-selected');
+ $("thead tr", grid_jqo).addClass('ui-partial');
+ }
+ };
+
+ gridzilla.selected_values = function(grid_name, attribute) {
+ return $.map($("#"+grid_name+" tr.ui-selected input[name="+grid_name+"_select]"), function(d) {
+ eval("var val = "+$(d).val());
+ if (attribute) {
+ return [val[attribute]];
+ } else {
+ return [val];
+ }
+ });
+ };
+
+ gridzilla.values = function(grid_name, attribute) {
+ return gridzilla.selected_values(grid_name, attribute);
+ };
+
+ gridzilla.unload = function(grid_name) {
+ $('#'+grid_name).html('');
+ };
+
+ gridzilla.load = function(grid_name, options, callback) {
+ if (!gridzilla.get_option(grid_name, "controller")) return;
+
+ if (grid_name && $("#"+grid_name).length > 0) {
+ options = options || {};
+ var reload = true;
+
+ if (options.passive) {
+ if (gridzilla.is_loaded(grid_name)) {
+ reload = false;
+ } else {
+ reload = true;
+ }
+ }
+
+ if (reload) {
+ $("#"+grid_name).block({
+ css: {
+ border: 'none',
+ padding: '10px',
+ backgroundColor: '#000',
+ '-webkit-border-radius': '5px',
+ '-moz-border-radius': '5px',
+ opacity: .7,
+ color: '#fff'
+ },
+ message: '<div class="gz_load"><img src="/images/gridzilla/black_loader.gif"/><h2>Loading</h2></div>'
+
+ });
+ var grid_data = options.data || {};
+
+ if (options.keep_params) {
+ grid_data = merge(gridzilla.get_option(grid_name, "params"), grid_data);
+ }
+
+ for (attribute in gridzilla.get_data(grid_name)) {
+ if (grid_data[attribute] == undefined) {
+ grid_data[attribute] = gridzilla.get_data(grid_name)[attribute];
+ }
+ }
+
+ $.get('/gridzilla/'+gridzilla.get_option(grid_name, "controller")+'/'+grid_name+'_grid', grid_data, function(data) {
+ $('#'+grid_name).html(data);
+ gridzilla.setup(grid_name);
+ if (callback) callback();
+ });
+ }
+ }
+ };
+
+ gridzilla.action_function = function(function_name, grid_name, attribute, options) {
+ var selected_ids = gridzilla.values(grid_name, attribute);
+
+ var constraint_range = [1, Infinity];
+ if (options.selection_constraint == 'single') {
+ constraint_range = [1, 1];
+ } else if (options.selection_constraint instanceof Array) {
+ constraint_range = options.selection_constraint;
+ }
+
+ if (selected_ids.length < constraint_range[0] || selected_ids.length > constraint_range[1]) {
+ if (selected_ids.length == 0) {
+ alert(options.empty_message);
+ } else if (options.selection_constraint == 'single') {
+ alert(options.single_message);
+ } else if (constraint_range[1] == Infinity) {
+ alert('You must select ' + constraint_range[0] + ' or more items.');
+ } else {
+ alert('You must select ' + constraint_range[0] + '..' + constraint_range[1] + ' items.');
+ }
+ } else if (constraint_range[1] == 1) {
+ window[function_name](selected_ids[0]);
+ } else {
+ window[function_name](selected_ids);
+ }
+ };
+
+ gridzilla.add_class = function(element, css_class) {
+ $(element).addClass(css_class);
+ };
+
+ gridzilla.remove_class = function(element, css_class) {
+ $(element).removeClass(css_class);
+ };
+
+ var clone = function(obj) {
+ var copy = {};
+
+ for (attribute in obj) {
+ copy[attribute] = obj[attribute];
+ }
+
+ return copy;
+ };
+
+ var merge = function(first, second) {
+ var result = clone(first);
+
+ for (attribute in second) {
+ result[attribute] = second[attribute];
+ }
+
+ return result;
+ };
+
+ })();
+ }
+ SCRIPT
+
+ @gridzilla_script_loaded = true
+ end
+
+ concat(content_tag(:script, <<-SCRIPT, nil, false))
+ gridzilla.set_data('#{name}', #{data.to_json});
+ #{"gridzilla.set_option('#{name}', 'height', #{options[:height].to_json});" if options[:height]}
+ SCRIPT
+
+ if block_given?
+ @gridzilla ||= []
+ @gridzilla.push({})
+ @gridzilla.last[:grid_name] = name
+ @gridzilla.last[:grid_controller] = grid_controller
+ @gridzilla.last[:collection] = collection.compact
+ @gridzilla.last[:selected_items] = options[:selected_items]
+
+ concat(tag(:div, {:id => name, :class => grid_class}, true))
+ view_dsl = Gridzilla::ViewDsl::Base.new(Gridzilla::View::Grid.new(self), self)
+ view_dsl.instance_eval(&block)
+ concat('</div>')
+
+ concat(content_tag(:script, <<-SCRIPT))
+ gridzilla.setup('#{name}');
+ gridzilla.set_option('#{name}', 'controller', #{grid_controller.to_json});
+ gridzilla.set_option('#{name}', 'params', #{request.query_parameters.to_json});
+ gridzilla.set_option('#{name}', 'single_select', #{(!!@gridzilla.last[:single_select]).to_json});
+ SCRIPT
+
+ @gridzilla.pop
+ else
+ concat(content_tag(:div, "", :id => name, :class => grid_class))
+ if options[:lazy]
+ concat(content_tag(:script, <<-SCRIPT, nil, false))
+ $(function() {
+ gridzilla.set_option('#{name}', 'controller', #{grid_controller.to_json});
+ });
+ SCRIPT
+ else
+ concat(content_tag(:script, <<-SCRIPT, nil, false))
+ $(function() {
+ gridzilla.set_option('#{name}', 'controller', #{grid_controller.to_json});
+ gridzilla.load('#{name}');
+ });
+ SCRIPT
+ end
+
+ if RAILS_ENV == 'development'
+ concat(content_tag(:div, content_tag(:a, 'reload grid', :href => '#', :onclick => "gridzilla.load('#{name}')"), :id => "#{name}_reloader"))
+ end
+ end
+ end
+
+ def ajax_grid(collection, *args, &block)
+ options = args.extract_options!
+
+ raise ArgumentError, "Missing block in ajax_grid definition" unless block_given?
+
+ @gridzilla ||= []
+ @gridzilla.push({})
+ @gridzilla.last[:grid_controller] = params[:controller]
+ @gridzilla.last[:grid_name] = params[:action][0..-6] # MAGIC_NUMBER(-6) removes the _grid on the action name
+ @gridzilla.last[:collection] = collection.compact
+ @gridzilla.last[:selected_items] = options[:selected_items]
+
+ view_dsl = Gridzilla::ViewDsl::Base.new(Gridzilla::View::AjaxGrid.new(self), self)
+ view_dsl.instance_eval(&block)
+
+ concat(content_tag(:script, <<-SCRIPT))
+ gridzilla.set_option('#{@gridzilla.last[:grid_name]}', 'controller', #{@gridzilla.last[:grid_controller].to_json});
+ gridzilla.set_option('#{@gridzilla.last[:grid_name]}', 'params', #{request.query_parameters.to_json});
+ gridzilla.set_option('#{@gridzilla.last[:grid_name]}', 'single_select', #{(!!@gridzilla.last[:single_select]).to_json});
+ SCRIPT
+
+ @gridzilla.pop
+ end
+
+ end
+
+ class Grid
+ def initialize(view)
+ @view = view
+ @gridzilla = @view.instance_variable_get('@gridzilla')
+ end
+
+ def title(*args, &block)
+ options = args.extract_options!
+ text = args.shift
+
+ raise ArgumentError, "Missing block or text in title definition" unless block_given? or text
+
+ options[:class] = "#{Gridzilla::Css::Title} #{options[:class]}".strip
+
+ if block_given?
+ @view.concat(@view.tag(:div, options, true))
+ yield
+ @view.concat("</div>")
+ else
+ @view.concat(@view.content_tag(:div, @view.content_tag(:h4, text), options))
+ end
+ end
+
+ def panel(*args, &block)
+ options = args.extract_options!
+
+ options[:class] = "#{Gridzilla::Css::Panel} #{options[:class]}".strip
+
+ raise ArgumentError, "Missing block in panel definition" unless block_given?
+
+ view_dsl = Gridzilla::ViewDsl::Base.new(Gridzilla::View::Panel.new(@view), @view)
+
+ @view.concat(@view.tag(:div, options, true))
+ view_dsl.instance_eval(&block)
+ @view.concat("</div>")
+ end
+
+ def rows(*args, &block)
+ options = args.extract_options!
+
+ raise ArgumentError, "Missing block in rows definition" unless block_given?
+
+ view_dsl = Gridzilla::ViewDsl::Base.new(Gridzilla::View::Row.new(@view), @view)
+ @gridzilla.last[:row_number] = 0
+
+ @view.concat("<table class='#{Gridzilla::Css::Table}'>")
+ @view.concat("<thead>")
+ @view.concat("<tr>")
+ @gridzilla.last[:row_data] = nil
+ view_dsl.instance_exec(Gridzilla::Gobbler.new, &block)
+ @view.concat("</tr>")
+ @view.concat("</thead>")
+
+ @view.concat("<tbody>")
+ row_css_class_option = options[:class]
+ options[:onmouseover] = "gridzilla.add_class(this, 'over');#{options[:onmouseover]}"
+ options[:onmouseout] = "gridzilla.remove_class(this, 'over');#{options[:onmouseout]}"
+ options[:onclick] = "gridzilla.row_click(this);#{options[:onclick]}"
+ @gridzilla.last[:collection].each do |item|
+ row_css_class = row_css_class_option.is_a?(Proc) ? row_css_class_option.call(item) : row_css_class_option
+ if @gridzilla.last[:selected_items] and @gridzilla.last[:selected_items].include?(item)
+ options[:class] = "#{row_css_class} ui-selected"
+ else
+ options[:class] = row_css_class
+ end
+ options[:class] = options[:class].to_s + @view.cycle(" alt", "")
+ @view.concat(@view.tag(:tr, options, true))
+ @gridzilla.last[:row_data] = item
+ view_dsl.instance_exec(item, &block)
+ @view.concat("</tr>")
+ end
+ @view.concat("</tbody>")
+ @view.concat("</table>")
+ if @gridzilla.last[:collection].empty? and @gridzilla.last[:empty_block]
+ empty_options = @gridzilla.last[:empty_block_options] || {}
+ empty_options[:class] = "#{Gridzilla::Css::Empty} #{empty_options[:class]}".strip
+
+ @view.concat(@view.tag(:div, empty_options, true))
+ @view.instance_eval &@gridzilla.last[:empty_block]
+ @view.concat("</div>")
+ end
+ end
+ end
+
+ class AjaxGrid < Gridzilla::View::Grid
+ end
+
+ class Panel
+ def initialize(view)
+ @view = view
+ @gridzilla = @view.instance_variable_get('@gridzilla')
+ end
+
+ def action_function(name, function_name, *args, &block)
+ options = args.extract_options!
+
+ options[:class] = "#{Gridzilla::Css::PanelAction} #{options[:class]}".strip
+
+ json_options = {
+ :empty_message => options.delete(:empty_message) || Message::DefaultEmptySelection,
+ :single_message => options.delete(:single_message) || Message::DefaultSingleSelection,
+ :selection_constraint => options.delete(:selection_constraint) || :multiple
+ }
+
+ attribute_name = args.first
+
+ @view.link_to_function name, "gridzilla.action_function(#{function_name.to_json}, #{@gridzilla.last[:grid_name].to_json}, #{attribute_name.to_json}, #{json_options.to_json})", options
+ end
+
+ def pagination_links(*args)
+ options = args.extract_options!
+
+ if @gridzilla.last[:collection].is_a?(WillPaginate::Collection)
+ @view.will_paginate(@gridzilla.last[:collection], :renderer => PaginationLinkRenderer)
+ end
+ end
+ end
+
+ class Row
+ def initialize(view)
+ @view = view
+ @gridzilla = @view.instance_variable_get('@gridzilla')
+ end
+
+ def if_empty(*args, &block)
+ options = args.extract_options!
+
+ if @gridzilla.last[:row_data].nil?
+ @gridzilla.last[:empty_block_options] = options
+ @gridzilla.last[:empty_block] = block
+ end
+ end
+
+ def single_select_column(attribute, *args, &block)
+ options = args.extract_options!
+ options.merge!({:style => 'width: 12px;'})
+
+ if @gridzilla.last[:row_data].nil?
+ @view.concat(@view.tag(:th))
+ @gridzilla.last[:single_select] = true
+ elsif attribute.is_a?(Symbol)
+ @view.concat(@view.content_tag(:td, @view.tag(:input, :type => "hidden", :name => "#{@gridzilla.last[:grid_name]}_select", :value => @gridzilla.last[:row_data].send(attribute).to_json, :id => nil)+@view.tag(:div, :class => Gridzilla::Css::RadioButton), options))
+ else
+ @view.concat(@view.content_tag(:td, @view.tag(:input, :type => "hidden", :name => "#{@gridzilla.last[:grid_name]}_select", :value => attribute.to_json, :id => nil)+@view.tag(:div, :class => Gridzilla::Css::RadioButton), options))
+ end
+ end
+
+ def select_column(attribute, *args, &block)
+ options = args.extract_options!
+ options.merge!({:style => 'width: 12px;'})
+
+ if @gridzilla.last[:row_data].nil?
+ @view.concat(@view.content_tag(:th, @view.tag(:div, :class => Gridzilla::Css::Checkbox, :id => "#{@gridzilla.last[:grid_name]}_select_all")))
+ elsif attribute.is_a?(Symbol)
+ @view.concat(@view.content_tag(:td, @view.tag(:input, :type => "hidden", :name => "#{@gridzilla.last[:grid_name]}_select", :value => @gridzilla.last[:row_data].send(attribute).to_json, :id => nil)+@view.tag(:div, :class => Gridzilla::Css::Checkbox), options))
+ else
+ @view.concat(@view.content_tag(:td, @view.tag(:input, :type => "hidden", :name => "#{@gridzilla.last[:grid_name]}_select", :value => attribute.to_json, :id => nil)+@view.tag(:div, :class => Gridzilla::Css::Checkbox), options))
+ end
+ end
+
+ def row_number_column(*args, &block)
+ options = args.extract_options!
+
+ if @gridzilla.last[:row_data].nil?
+ @view.concat(@view.content_tag(:th, nil, options))
+ else
+ @view.concat(@view.tag(:td, options, true))
+ @view.concat("#{@gridzilla.last[:row_number] += 1}")
+ @view.concat("</td>")
+ end
+ end
+
+ def column(name = "", *args, &block)
+ options = args.extract_options!
+ attribute = args.shift
+
+ sort_key = options.delete(:sort_key)
+
+ raise ArgumentError, "Missing block or attribute in column definition" unless block_given? or attribute
+
+ if @gridzilla.last[:row_data].nil?
+ header_content = name
+ if sort_key
+ options[:class] = "#{Gridzilla::Css::Sortable} #{options[:class]}".strip
+ header_content << @view.hidden_field_tag("sort_key", sort_key)
+
+ if @view.params[:sort_key] == sort_key
+ if @view.params[:sort_order] == "DESC"
+ options[:class] = "#{Gridzilla::Css::SortDesc} #{options[:class]}".strip
+ else
+ options[:class] = "#{Gridzilla::Css::SortAsc} #{options[:class]}".strip
+ end
+ end
+ end
+ @view.concat(@view.content_tag(:th, header_content, options))
+ else
+ @view.concat(@view.tag(:td, options, true))
+ if block_given?
+ yield
+ else
+ @view.concat(@gridzilla.last[:row_data].send(attribute).to_s)
+ end
+ @view.concat("</td>")
+ end
+ end
+ end
+ end
+end
+
+ActionController::Base.send :include, Gridzilla::Controller
+ActionView::Base.send :include, Gridzilla::View::InstanceMethods
7 lib/gridzilla/gobbler.rb
@@ -0,0 +1,7 @@
+module Gridzilla
+ class Gobbler < BlankSlate
+ def method_missing(meth_name, *args, &block)
+ self
+ end
+ end
+end
14 lib/gridzilla/pagination_link_renderer.rb
@@ -0,0 +1,14 @@
+module Gridzilla
+ class PaginationLinkRenderer < WillPaginate::LinkRenderer
+ protected
+
+ def page_link(page, text, attributes = {})
+ extra_options = @template.instance_eval do
+ options = HashWithIndifferentAccess.new.merge(request.query_parameters.clone)
+ options[:page] = page
+ options.to_json
+ end
+ @template.link_to_function text, "gridzilla.load(#{@template.instance_eval("@gridzilla.last[:grid_name].to_json")}, {data: #{extra_options}})", attributes
+ end
+ end
+end
1 rails/init.rb
@@ -0,0 +1 @@
+require 'gridzilla'
4 tasks/gridzilla_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :gridzilla do
+# # Task goes here
+# end
8 test/gridzilla_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GridzillaTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
3 test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
1 uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit 667fe5c

Please sign in to comment.