datagrid 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -158,55 +158,20 @@ create app/views/skills/index.html.erb
158
158
  route resources :skills
159
159
  ```
160
160
 
161
- ### Manually
162
161
 
163
- If you want to be a true ninja you can build everything from scratch on your own.
162
+ ### Customize Built-in partials
164
163
 
165
- In order to create form for your report you can use all set of rails built-in tools.
166
- More over Datagrid provides you two additional form helpers:
164
+ In order to get a control on datagrid built-in partials run:
167
165
 
168
- * datagrid\_label
169
- * datagrid\_filter
170
-
171
-
172
- The easiest way to create a report form (haml for readablity):
173
-
174
- ``` haml
175
- # Method `GET` is recommended for all report forms by default.
176
- - form_for @report, :html => {:method => :get} do |f|
177
- - @report.filters.each do |filter|
178
- %div
179
- = f.datagrid_label filter
180
- = f.datagrid_filter filter
181
- = f.submit
166
+ ``` sh
167
+ rake datagrid:copy_partials
182
168
  ```
183
169
 
184
- Your controller:
185
-
186
- ``` ruby
187
- map.resources :simple_reports, :only => [:index]
188
-
189
- class SimpleReportsController < ApplicationController
190
- def index
191
- @report = SimpleReport.new(params[:simple_report])
192
- end
193
- end
194
- ```
195
-
196
- There is a simple helper set of helpers that allows you display report:
197
- (require any pagination gem, will\_paginate is used as an example)
198
-
199
- ``` haml
200
- - assets = @report.assets.paginate(:page => params[:page])
201
-
202
- %div== Total #{assets.total_entries}
203
- = datagrid_table(@report, assets)
204
- = will_paginate assets
205
- ```
170
+ ### Advanced frontend
206
171
 
207
- If you need a custom interface for your report you should probably build it yourself with datagrid helpers.
172
+ All advanced frontend things are described in:
208
173
 
209
- [More about frontend](https://github.com/bogdan/datagrid/wiki/Frontend)
174
+ [Frontend section on wiki](https://github.com/bogdan/datagrid/wiki/Frontend)
210
175
 
211
176
  ## Self-Promotion
212
177
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
@@ -0,0 +1,9 @@
1
+ <%= form_for grid, options do |f| -%>
2
+ <% grid.filters.each do |filter| %>
3
+ <div class="filter">
4
+ <%= f.datagrid_label filter %>
5
+ <%= f.datagrid_filter filter %>
6
+ </div>
7
+ <% end %>
8
+ <%= f.submit I18n.t("datgrid.form.submit", :default => "Search").html_safe %>
9
+ <% end -%>
@@ -2,9 +2,9 @@
2
2
  <%= link_to(
3
3
  I18n.t("datagrid.table.order.asc", :default => "&uarr;".html_safe).html_safe,
4
4
  url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => false)),
5
- :class => "order asc") %>
5
+ :class => "asc") %>
6
6
  <%= link_to(
7
7
  I18n.t("datagrid.table.order.desc", :default => "&darr;".html_safe).html_safe,
8
8
  url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => true )),
9
- :class => "order desc") %>
9
+ :class => "desc") %>
10
10
  </div>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "datagrid"
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = "2013-04-28"
12
+ s.date = "2013-05-15"
13
13
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
14
14
  s.email = "agresso@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "Readme.markdown",
25
25
  "VERSION",
26
+ "app/views/datagrid/_form.html.erb",
26
27
  "app/views/datagrid/_head.html.erb",
27
28
  "app/views/datagrid/_order_for.html.erb",
28
29
  "app/views/datagrid/_row.html.erb",
@@ -32,6 +33,7 @@ Gem::Specification.new do |s|
32
33
  "lib/datagrid/active_model.rb",
33
34
  "lib/datagrid/columns.rb",
34
35
  "lib/datagrid/columns/column.rb",
36
+ "lib/datagrid/configuration.rb",
35
37
  "lib/datagrid/core.rb",
36
38
  "lib/datagrid/drivers.rb",
37
39
  "lib/datagrid/drivers/abstract_driver.rb",
@@ -94,7 +96,7 @@ Gem::Specification.new do |s|
94
96
  s.homepage = "http://github.com/bogdan/datagrid"
95
97
  s.licenses = ["MIT"]
96
98
  s.require_paths = ["lib"]
97
- s.rubygems_version = "1.8.24"
99
+ s.rubygems_version = "1.8.25"
98
100
  s.summary = "Ruby gem to create datagrids"
99
101
 
100
102
  if s.respond_to? :specification_version then
@@ -1,4 +1,5 @@
1
1
  require "action_view"
2
+ require "datagrid/configuration"
2
3
 
3
4
  module Datagrid
4
5
 
@@ -9,6 +10,7 @@ module Datagrid
9
10
  autoload :Filters
10
11
  autoload :Columns
11
12
  autoload :Ordering
13
+ autoload :Configuration
12
14
 
13
15
  autoload :Helper
14
16
  ActionView::Base.send(:include, Datagrid::Helper)
@@ -0,0 +1,13 @@
1
+ module Datagrid
2
+
3
+ def self.configuration
4
+ @configuration ||= Configuration.new
5
+ end
6
+
7
+ def self.configure
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration < Struct.new(:date_formats)
12
+ end
13
+ end
@@ -14,9 +14,16 @@ class Datagrid::Filters::DateFilter < Datagrid::Filters::BaseFilter
14
14
  def format(value)
15
15
  return nil if value.blank?
16
16
  return value if value.is_a?(Range)
17
+ if formats = Datagrid.configuration.date_formats
18
+ Array(formats).each do |format|
19
+ begin
20
+ return Date.strptime(value, format)
21
+ rescue ArgumentError
22
+ end
23
+ end
24
+ end
17
25
  return value.to_date if value.respond_to?(:to_date)
18
26
  return value unless value.is_a?(String)
19
- #TODO: more smart date normalizer
20
27
  Date.parse(value)
21
28
  rescue ArgumentError
22
29
  nil
@@ -24,6 +24,10 @@ module Datagrid
24
24
  datagrid_renderer.order_for(grid, column)
25
25
  end
26
26
 
27
+ def datagrid_form_for(grid, options = {})
28
+ datagrid_renderer.form_for(grid, options)
29
+ end
30
+
27
31
  protected
28
32
 
29
33
  def datagrid_renderer
@@ -43,10 +43,17 @@ module Datagrid
43
43
  end
44
44
  end
45
45
 
46
+ def form_for(grid, options = {})
47
+ options[:method] ||= :get
48
+ options[:html] ||= {}
49
+ options[:html][:class] ||= "datagrid-form #{html_class(grid)}"
50
+ @template.render :partial => "datagrid/form", :locals => {:grid => grid, :options => options}
51
+ end
52
+
46
53
  def table(grid, *args)
47
54
  options = args.extract_options!
48
55
  options[:html] ||= {}
49
- options[:html][:class] ||= "datagrid #{grid.class.to_s.underscore.demodulize}"
56
+ options[:html][:class] ||= "datagrid #{html_class(grid)}"
50
57
  assets = args.any? ? args.shift : grid.assets
51
58
  paginate = options[:paginate]
52
59
  if paginate
@@ -75,6 +82,9 @@ module Datagrid
75
82
  @template.render :partial => "datagrid/order_for", :locals => { :grid => grid, :column => column }
76
83
  end
77
84
 
85
+ def html_class(grid)
86
+ grid.class.to_s.underscore.demodulize
87
+ end
78
88
 
79
89
  def _safe(string)
80
90
  string.respond_to?(:html_safe) ? string.html_safe : string
@@ -3,18 +3,13 @@ namespace :datagrid do
3
3
  desc "Copy table partials into rails application"
4
4
  task :copy_partials do
5
5
  require "fileutils"
6
- def copy_template(path)
7
- gem_app = File.expand_path("../../../app", __FILE__)
8
- rails_app = (Rails.root + "app").to_s
9
- full_path = "#{rails_app}/#{File.dirname path}"
10
- puts "* copy #{full_path}"
11
- FileUtils.mkdir_p full_path
12
- FileUtils.cp "#{gem_app}/#{path}", full_path
6
+ views_path = "app/views/datagrid"
7
+ destination_dir = (Rails.root + views_path).to_s
8
+ pattern = File.expand_path(File.dirname(__FILE__) + "/../../#{views_path}") + "/*"
9
+ Dir[pattern].each do |template|
10
+ puts "* copy #{template} => #{destination_dir}"
11
+ FileUtils.mkdir_p destination_dir
12
+ FileUtils.cp template, destination_dir
13
13
  end
14
- copy_template "views/datagrid/_table.html.erb"
15
- copy_template "views/datagrid/_head.html.erb"
16
- copy_template "views/datagrid/_order_for.html.erb"
17
- copy_template "views/datagrid/_row.html.erb"
18
14
  end
19
-
20
15
  end
@@ -93,4 +93,20 @@ describe Datagrid::Filters::DateFilter do
93
93
  report.assets.should include(Entry.create!(:created_at => DateTime.now))
94
94
  end
95
95
 
96
+ it "should have configurable date format" do
97
+ begin
98
+ Datagrid.configure do |config|
99
+ config.date_formats = "%m/%d/%Y"
100
+ end
101
+ report = test_report(:created_at => "10/01/2013") do
102
+ scope {Entry}
103
+ filter(:created_at, :date)
104
+ end
105
+ report.created_at.should == Date.new(2013,10,01)
106
+ ensure
107
+ Datagrid.configure do |config|
108
+ config.date_formats = nil
109
+ end
110
+ end
111
+ end
96
112
  end
@@ -272,11 +272,28 @@ describe Datagrid::Helper do
272
272
  grid = OrderedGrid.new(:descending => true, :order => :category)
273
273
  subject.datagrid_order_for(grid, grid.column_by_name(:category)).should equal_to_dom(<<-HTML)
274
274
  <div class="order">
275
- <a href="ordered_grid%5Bdescending%5D=false&amp;ordered_grid%5Border%5D=category" class="order asc">&uarr;</a>
276
- <a href="ordered_grid%5Bdescending%5D=true&amp;ordered_grid%5Border%5D=category" class="order desc">&darr;</a>
275
+ <a href="ordered_grid%5Bdescending%5D=false&amp;ordered_grid%5Border%5D=category" class="asc">&uarr;</a>
276
+ <a href="ordered_grid%5Bdescending%5D=true&amp;ordered_grid%5Border%5D=category" class="desc">&darr;</a>
277
277
  </div>
278
278
  HTML
279
279
  end
280
280
  end
281
+ describe ".datagrid_form_for" do
282
+ it "should render ordering layout" do
283
+ class FormForGrid
284
+ include Datagrid
285
+ scope { Entry }
286
+ filter(:category)
287
+ end
288
+ grid = FormForGrid.new(:category => "hello")
289
+ subject.datagrid_form_for(grid, :url => "/grid").should match_css_pattern(
290
+ "form.datagrid-form.form_for_grid[action='/grid']" => 1,
291
+ "form input[name=utf8]" => 1,
292
+ "form .filter label" => "Category",
293
+ "form .filter input.category.default_filter[name='form_for_grid[category]'][value=hello]" => 1,
294
+ "form input[name=commit][value=Search]" => 1
295
+ )
296
+ end
297
+ end
281
298
  end
282
299
  end
@@ -1,12 +1,4 @@
1
- <%%= form_for @grid, :method => :get, :url => <%= grid_route_name %> do |f| %>
2
- <%% @grid.filters.each do |filter| %>
3
- <div class="field">
4
- <%%= f.datagrid_label filter %>
5
- <%%= f.datagrid_filter filter %>
6
- </div>
7
- <%% end %>
8
- <%%= f.submit %>
9
- <%% end %>
1
+ <%%= datagrid_form_for @grid, :method => :get, :url => <%= grid_route_name %> %>
10
2
 
11
3
  <%%= <%=pagination_helper_code%> %>
12
4
  <%%= datagrid_table @grid, @assets %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -250,6 +250,7 @@ files:
250
250
  - Rakefile
251
251
  - Readme.markdown
252
252
  - VERSION
253
+ - app/views/datagrid/_form.html.erb
253
254
  - app/views/datagrid/_head.html.erb
254
255
  - app/views/datagrid/_order_for.html.erb
255
256
  - app/views/datagrid/_row.html.erb
@@ -259,6 +260,7 @@ files:
259
260
  - lib/datagrid/active_model.rb
260
261
  - lib/datagrid/columns.rb
261
262
  - lib/datagrid/columns/column.rb
263
+ - lib/datagrid/configuration.rb
262
264
  - lib/datagrid/core.rb
263
265
  - lib/datagrid/drivers.rb
264
266
  - lib/datagrid/drivers/abstract_driver.rb
@@ -332,7 +334,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
332
334
  version: '0'
333
335
  segments:
334
336
  - 0
335
- hash: 3628850104894180281
337
+ hash: 2130335005317540436
336
338
  required_rubygems_version: !ruby/object:Gem::Requirement
337
339
  none: false
338
340
  requirements:
@@ -341,7 +343,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
343
  version: '0'
342
344
  requirements: []
343
345
  rubyforge_project:
344
- rubygems_version: 1.8.24
346
+ rubygems_version: 1.8.25
345
347
  signing_key:
346
348
  specification_version: 3
347
349
  summary: Ruby gem to create datagrids