mighty_grid 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db3be8e4ea2ceb7203c275271ab2d2f0f13b97c1
4
- data.tar.gz: d31f8201be065f8ec4df6578fe31ed874e58c404
3
+ metadata.gz: 0a1b8f39980c43212fbbcaf1536e2885315b0d25
4
+ data.tar.gz: 3c3a494e5aa3765bb575138ce551d8e926c9c5c7
5
5
  SHA512:
6
- metadata.gz: 5e2284003412c988caa41624d339790fb8d675e48abf96df115f128bedc7a51055ec0fd75942708b12e2d006dfacdb2f8913dbb8f06703799eb100fad8d0341b
7
- data.tar.gz: 1e953d518c34a8542c6047c6371ae10c8fa3de792d345dc18555f506ebed6fcce499a9b438c6bfb20ba847d880f70515b4a79ff67c1d769d58701d9bc05a3b9b
6
+ metadata.gz: 8a6873ec703fa7b3f069aa39a781914c696ce7f67fda8d64da8b25a4a04301665525bebae0bead8424de7f6627c23f9c78cd4883535f3101d9d54f17a37aa6e9
7
+ data.tar.gz: d6fed277c241aa679c1b194566e3bcbda77c4d41bab23c6473fb6a58b47ac0bccb447c79a36320cac69d09328cb40571c2e5f5e3178eae568d6d3f62e850e16a
data/README.md CHANGED
@@ -54,7 +54,7 @@ pagination_theme # 'mighty_grid' by default
54
54
  There's a handy generator that generates the default configuration file into config/initializers directory.
55
55
  Run the following generator command, then edit the generated file.
56
56
 
57
- $ rails g mighty_grid:config
57
+ $ rails g mighty_grid:install
58
58
 
59
59
  ## Contributing
60
60
 
@@ -0,0 +1,5 @@
1
+ en:
2
+ mighty_grid:
3
+ filters:
4
+ submit: Apply changes
5
+ reset: Reset changes
@@ -0,0 +1,17 @@
1
+ module MightyGrid
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc "Copies MightyGrid configuration and locale files to your application."
7
+
8
+ def copy_config_file
9
+ template 'mighty_grid_config.rb', 'config/initializers/mighty_grid_config.rb'
10
+ end
11
+
12
+ def copy_locale_file
13
+ copy_file '../../../../config/locales/en.yml', 'config/locales/mighty_grid.en.yml'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -44,10 +44,10 @@ module MightyGrid
44
44
  def apply_filters
45
45
  filter_params.each do |filter_name, filter_value|
46
46
  next if filter_value.blank? || !klass.column_names.include?(filter_name)
47
- if @filters.has_key?(filter_name.to_sym) && Array === @filters[filter_name.to_sym] ||
48
- klass.columns_hash[filter_name].type == :boolean
47
+ field_type = klass.columns_hash[filter_name].type
48
+ if @filters.has_key?(filter_name.to_sym) && Array === @filters[filter_name.to_sym] || field_type == :boolean
49
49
  @relation = @relation.where(filter_name => filter_value)
50
- elsif [:string, :text].include?(klass.columns_hash[filter_name].type)
50
+ elsif [:string, :text].include?(field_type)
51
51
  @relation = @relation.where("\"#{klass.table_name}\".\"#{filter_name}\" #{like_operator} ?", "%#{filter_value}%")
52
52
  end
53
53
  end
@@ -1,6 +1,10 @@
1
1
  require 'active_support/configurable'
2
2
 
3
3
  module MightyGrid
4
+ # Configures global settings for MightyGrid
5
+ # MightyGrid.configure do |config|
6
+ # config.grid_name = 'g'
7
+ # end
4
8
  def self.configure(&block)
5
9
  yield @config ||= MightyGrid::Configuration.new
6
10
  end
@@ -7,7 +7,8 @@ module MightyGrid
7
7
  end
8
8
 
9
9
  def label(name, content_or_options = nil, options = nil, &block)
10
- label_tag(name, content_or_options, options, &block)
10
+ filter_name = @grid.get_filter_name(name).parameterize('_')
11
+ label_tag(filter_name, content_or_options, options, &block)
11
12
  end
12
13
 
13
14
  def text_field(name, options={})
@@ -31,12 +32,14 @@ module MightyGrid
31
32
  check_box_tag(@grid.get_filter_name(name), value, checked, options)
32
33
  end
33
34
 
34
- def submit(content = "Apply changes", options = {})
35
+ def submit(content = nil, options = {})
36
+ content = I18n.t("mighty_grid.filters.submit", default: 'Apply changes') if content.blank?
35
37
  options.merge!(type: :submit)
36
38
  content_tag(:button, content, options)
37
39
  end
38
40
 
39
- def reset(content = "Reset changes", options = {})
41
+ def reset(content = nil, options = {})
42
+ content = I18n.t("mighty_grid.filters.reset", default: 'Reset changes') if content.blank?
40
43
  options.merge!(type: :reset)
41
44
  content_tag(:button, content, options)
42
45
  end
@@ -3,6 +3,7 @@ module MightyGrid
3
3
  attr_reader :columns, :th_columns, :total_columns, :blank_slate_handler
4
4
 
5
5
  def initialize(grid, view)
6
+ @grid = grid
6
7
  @columns = []
7
8
  @th_columns = []
8
9
  @blank_slate_handler = nil
@@ -16,7 +17,7 @@ module MightyGrid
16
17
  attribute = attr_or_options.to_sym
17
18
  options = {} unless options.is_a?(Hash)
18
19
  opts = {
19
- title: attr_or_options.to_s.titleize,
20
+ title: @grid.klass.human_attribute_name(attribute),
20
21
  ordering: true,
21
22
  attribute: attribute
22
23
  }.merge!(options)
@@ -25,7 +26,7 @@ module MightyGrid
25
26
  @total_columns = @columns.count
26
27
  end
27
28
 
28
- def blank_slate(html_or_opts, &block)
29
+ def blank_slate(html_or_opts = nil, &block)
29
30
  if (html_or_opts.is_a?(Hash) && html_or_opts.has_key?(:partial) || html_or_opts.is_a?(String)) && !block_given?
30
31
  @blank_slate_handler = html_or_opts
31
32
  elsif html_or_opts.nil? && block_given?
@@ -36,6 +36,7 @@ module MightyGrid
36
36
  grid.output_buffer.html_safe
37
37
  end
38
38
 
39
+ # Creates a form to filter the data in the target grid.
39
40
  def mighty_filter_for(grid, options={}, &block)
40
41
  html_options = options[:html] ||= {}
41
42
  html_options = MightyGrid::MgHTML.join_html_classes(html_options, 'mighty-grid-filter')
@@ -1,3 +1,3 @@
1
1
  module MightyGrid
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/mighty_grid.rb CHANGED
@@ -14,7 +14,7 @@ require 'mighty_grid/helpers/mighty_grid_view_helpers'
14
14
  require 'mighty_grid/mighty_grid_controller'
15
15
 
16
16
  # GENERATORS
17
- require 'generators/mighty_grid/config_generator'
17
+ require 'generators/mighty_grid/install_generator'
18
18
 
19
19
  require 'mighty_grid/engine'
20
20
  require 'mighty_grid/base'
@@ -29,11 +29,7 @@ class ApplicationController < ActionController::Base; end
29
29
  class ProductsController < ApplicationController
30
30
  def index
31
31
  @products_grid = init_grid(Product)
32
- render :inline => <<-ERB
33
- <%= grid @products_grid do |g| %>
34
- <% g.column :name %>
35
- <% end %>
36
- ERB
32
+ render 'spec/fake_app/views/index', layout: false
37
33
  end
38
34
  end
39
35
 
@@ -0,0 +1,8 @@
1
+ <%= mighty_filter_for @products_grid do |filter| %>
2
+ <%= filter.text_field :name %>
3
+ <%= filter.submit %>
4
+ <% end %>
5
+
6
+ <%= grid @products_grid do |g| %>
7
+ <% g.column :name %>
8
+ <% end %>
@@ -110,4 +110,16 @@ describe MightyGrid::Base do
110
110
  after(:all){ @controller.params = {} }
111
111
  end
112
112
 
113
+ describe '#like_operator' do
114
+ subject { MightyGrid::Base.new(Product, @controller) }
115
+ context "when DB is #{ENV['DB']}" do
116
+ case ENV['DB']
117
+ when 'postgresql'
118
+ it{ subject.like_operator.should == 'ILIKE' }
119
+ when 'sqlite', 'mysql'
120
+ it{ subject.like_operator.should == 'LIKE' }
121
+ end
122
+ end
123
+ end
124
+
113
125
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require "generator_spec"
4
4
 
5
- describe MightyGrid::Generators::ConfigGenerator do
5
+ describe MightyGrid::Generators::InstallGenerator do
6
6
  destination File.expand_path("../../tmp", __FILE__)
7
7
 
8
8
  before(:all) do
@@ -13,4 +13,9 @@ describe MightyGrid::Generators::ConfigGenerator do
13
13
  it "creates config initializer" do
14
14
  assert_file "config/initializers/mighty_grid_config.rb"
15
15
  end
16
+
17
+ it "creates locale file" do
18
+ assert_file "config/locales/mighty_grid.en.yml"
19
+ end
20
+
16
21
  end
@@ -5,11 +5,27 @@ feature 'Product' do
5
5
 
6
6
  subject { page }
7
7
 
8
- describe "Index Page" do
8
+ describe 'Index Page' do
9
9
  before { visit '/products' }
10
10
 
11
- it { should have_selector('table.mighty-grid') }
12
- it { should have_selector('ul.pagination') }
11
+ it { should have_selector 'form.mighty-grid-filter' }
12
+ it { should have_selector 'table.mighty-grid' }
13
+ it { should have_selector 'ul.pagination' }
14
+ end
15
+
16
+ scenario 'filtering by fields' do
17
+ visit '/products'
18
+
19
+ product_name = Product.first.name
20
+
21
+ within '.mighty-grid-filter' do
22
+ fill_in "grid_f_name", :with => product_name
23
+ end
24
+
25
+ click_button "Apply changes"
26
+
27
+ expect(page).to have_content product_name
28
+ expect(page).to have_content '1 of 1'
13
29
  end
14
30
 
15
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mighty_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jurrick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,10 +102,11 @@ files:
102
102
  - app/views/kaminari/mighty_grid/_page.html.erb
103
103
  - app/views/kaminari/mighty_grid/_paginator.html.erb
104
104
  - app/views/kaminari/mighty_grid/_prev_page.html.erb
105
+ - config/locales/en.yml
105
106
  - gemfiles/rails_32.gemfile
106
107
  - gemfiles/rails_40.gemfile
107
108
  - gemfiles/rails_41.gemfile
108
- - lib/generators/mighty_grid/config_generator.rb
109
+ - lib/generators/mighty_grid/install_generator.rb
109
110
  - lib/generators/mighty_grid/templates/mighty_grid_config.rb
110
111
  - lib/mighty_grid.rb
111
112
  - lib/mighty_grid/base.rb
@@ -126,9 +127,10 @@ files:
126
127
  - spec/fake_app/models/active_record.rb
127
128
  - spec/fake_app/models/config.rb
128
129
  - spec/fake_app/rails_app.rb
130
+ - spec/fake_app/views/index.html.erb
129
131
  - spec/lib/base_spec.rb
130
132
  - spec/lib/column_spec.rb
131
- - spec/lib/generators/config_generator_spec.rb
133
+ - spec/lib/generators/install_generator_spec.rb
132
134
  - spec/requests/products_spec.rb
133
135
  - spec/spec_helper.rb
134
136
  - spec/support/capybara.rb
@@ -165,9 +167,10 @@ test_files:
165
167
  - spec/fake_app/models/active_record.rb
166
168
  - spec/fake_app/models/config.rb
167
169
  - spec/fake_app/rails_app.rb
170
+ - spec/fake_app/views/index.html.erb
168
171
  - spec/lib/base_spec.rb
169
172
  - spec/lib/column_spec.rb
170
- - spec/lib/generators/config_generator_spec.rb
173
+ - spec/lib/generators/install_generator_spec.rb
171
174
  - spec/requests/products_spec.rb
172
175
  - spec/spec_helper.rb
173
176
  - spec/support/capybara.rb
@@ -1,16 +0,0 @@
1
- module MightyGrid
2
- module Generators
3
- class ConfigGenerator < Rails::Generators::Base
4
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
-
6
- desc <<DESC
7
- Description:
8
- Copies MightyGrid configuration file to your application's initializer directory.
9
- DESC
10
-
11
- def copy_config_file
12
- template 'mighty_grid_config.rb', 'config/initializers/mighty_grid_config.rb'
13
- end
14
- end
15
- end
16
- end