Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract order_for helper into partial

  • Loading branch information...
commit 024eab031ce8b4ca98fa6c427738795a24aabb05 1 parent 1d2b14e
@dmitry-ilyashevich dmitry-ilyashevich authored
View
10 app/views/datagrid/_order_for.html.erb
@@ -0,0 +1,10 @@
+<div class="order">
+ <%= link_to(
+ I18n.t("datagrid.table.order.asc", :default => "&uarr;".html_safe).html_safe,
+ url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => false)),
+ :class => "order asc") %>
+ <%= link_to(
+ I18n.t("datagrid.table.order.desc", :default => "&darr;".html_safe).html_safe,
+ url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => true )),
+ :class => "order desc") %>
+</div>
View
12 lib/datagrid/renderer.rb
@@ -72,17 +72,7 @@ def rows(grid, assets, options = {})
end
def order_for(grid, column)
- @template.content_tag(:div, :class => "order") do
- @template.link_to(
- I18n.t("datagrid.table.order.asc", :default => "&uarr;".html_safe).html_safe,
- @template.url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => false)),
- :class => "order asc"
- ) + " " + @template.link_to(
- I18n.t("datagrid.table.order.desc", :default => "&darr;".html_safe).html_safe,
- @template.url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => true )),
- :class => "order desc"
- )
- end
+ @template.render :partial => "datagrid/order_for", :locals => { :grid => grid, :column => column }
end
View
1  lib/tasks/datagrid_tasks.rake
@@ -13,6 +13,7 @@ namespace :datagrid do
end
copy_template "views/datagrid/_table.html.erb"
copy_template "views/datagrid/_head.html.erb"
+ copy_template "views/datagrid/_order_for.html.erb"
copy_template "views/datagrid/_row.html.erb"
end
View
3  spec/datagrid/helper_spec.rb
@@ -272,7 +272,8 @@ class OrderedGrid
grid = OrderedGrid.new(:descending => true, :order => :category)
subject.datagrid_order_for(grid, grid.column_by_name(:category)).should equal_to_dom(<<-HTML)
<div class="order">
-<a href="ordered_grid%5Bdescending%5D=false&amp;ordered_grid%5Border%5D=category" class="order asc">&uarr;</a> <a href="ordered_grid%5Bdescending%5D=true&amp;ordered_grid%5Border%5D=category" class="order desc">&darr;</a>
+ <a href="ordered_grid%5Bdescending%5D=false&amp;ordered_grid%5Border%5D=category" class="order asc">&uarr;</a>
+ <a href="ordered_grid%5Bdescending%5D=true&amp;ordered_grid%5Border%5D=category" class="order desc">&darr;</a>
</div>
HTML
end
View
11 spec/support/matchers.rb
@@ -34,17 +34,24 @@ def failure_message
class EqualToDom
def initialize(expectation)
- @expectation = Nokogiri::HTML::DocumentFragment.parse(expectation.strip).to_s
+ @expectation = Nokogiri::HTML::DocumentFragment.parse(force_encoding(expectation).strip).to_s
end
def matches?(text)
- @matcher = Nokogiri::HTML::DocumentFragment.parse(text.strip).to_s
+
+ @matcher = Nokogiri::HTML::DocumentFragment.parse(force_encoding(text).strip).to_s
@matcher == @expectation
end
def failure_message
"Expected dom #{@matcher} to match #{@expectation}, but it wasn't"
end
+
+ private
+
+ def force_encoding(text)
+ text.clone.force_encoding("UTF-8") if "1.9.3".respond_to? :force_encoding
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.