Skip to content

Commit

Permalink
Moves view objects into a View module and directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dball committed May 16, 2012
1 parent d088bb7 commit 86fcfd1
Show file tree
Hide file tree
Showing 25 changed files with 862 additions and 837 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.0.10

* Moves view objects into View module and directory

# v0.0.9

* Adds :model_label option to table description
Expand Down
46 changes: 0 additions & 46 deletions lib/paginated_table/column_description.rb

This file was deleted.

34 changes: 0 additions & 34 deletions lib/paginated_table/link_renderer.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/paginated_table/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ class Railtie < Rails::Railtie
initializer "paginated_table" do |app|
ActiveSupport.on_load(:action_view) do
require 'paginated_table/view_helpers'
require 'paginated_table/table_description'
require 'paginated_table/row_description'
require 'paginated_table/column_description'
require 'paginated_table/table_renderer'
require 'paginated_table/link_renderer'
end
ActiveSupport.on_load :action_controller do
require 'paginated_table/controller_helpers'
Expand Down
36 changes: 0 additions & 36 deletions lib/paginated_table/row_description.rb

This file was deleted.

46 changes: 0 additions & 46 deletions lib/paginated_table/table_description.rb

This file was deleted.

114 changes: 0 additions & 114 deletions lib/paginated_table/table_renderer.rb

This file was deleted.

48 changes: 48 additions & 0 deletions lib/paginated_table/view/column_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module PaginatedTable
module View
class ColumnDescription
attr_reader :name

def initialize(row, name, options = {}, &block)
@row = row
@name = name
@block = block
@options = options
end

def render_header
@options.fetch(:title, @name.to_s.titleize)
end

def render_cell(datum)
if @block
@block.call(datum)
else
datum.send(@name)
end
end

def sortable?
@options.fetch(:sortable, true)
end

def span
@options.fetch(:span, false)
end

def html_attributes
html_attributes = {}
if @options[:class]
html_attributes[:class] = Array(@options[:class]).join(' ')
end
if @options[:style]
html_attributes[:style] = @options[:style]
end
if span
html_attributes[:colspan] = @row.colspan(span)
end
html_attributes
end
end
end
end
36 changes: 36 additions & 0 deletions lib/paginated_table/view/link_renderer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module PaginatedTable
module View
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
def initialize(page)
super()
@paginated_table_page = page
end

def sort_link(text, sort_on)
@template.link_to(text, sort_url(sort_on), :remote => true)
end

def tag(name, value, attributes = {})
if name == :a
@template.link_to(value.to_s.html_safe, attributes.delete(:href), attributes.merge(:remote => true))
else
super
end
end

private

def sort_url(sort_on)
new_page = @paginated_table_page.page_for_sort_column(sort_on)
new_page_params = PageParams.to_params(new_page)
params = merge_get_params({})
symbolized_update(params, new_page_params)
@template.url_for(params)
end

def default_url_params
PageParams.to_params(@paginated_table_page)
end
end
end
end
Loading

0 comments on commit 86fcfd1

Please sign in to comment.