bolter 0.1.1 → 0.2.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: ec99ab0f4a566eef9a9aaba790dd683cf37cb95b
4
- data.tar.gz: e6de1200f625cd5a8427158cca89ed5556a0aab4
3
+ metadata.gz: d60b846bd7d86bed20c7abcb1ade4ace715e683d
4
+ data.tar.gz: 452b092a56b399b074096dc3d5af6ca904adeedd
5
5
  SHA512:
6
- metadata.gz: b2c784b730edb31276812828518889f92eda958ad58027e4b15f83689ca3dd1eae36bf68db48d56c3e70893fc00dbe84c1141f297a80b4ba507bb25d67dba65d
7
- data.tar.gz: 815bdc59eadb6cc3fac23f8061d425914c2b60f772e4406e7fbdb2aec521a6c5191210c0fd64fb36c87b405ecc87f5f48618173f67c81872aebe0dc25c3bd52b
6
+ metadata.gz: 5e137b77848fa81ab8f0af2e8d9857f8ebb9e5400d2469beb08eb383cb27c77abda285b5d53c1567e29390523272d460741990660809a7e07b1a281e9e9e8d47
7
+ data.tar.gz: 72a94638d5a86b8c6cc5927d7033349ec7a8804dd59216e0d20353c19dd927d239a038f937f058a5e90d21218b5c18668c6f28de0c4a0e3dcef65f560ad5be57
data/README.md CHANGED
@@ -34,10 +34,10 @@ end
34
34
  View:
35
35
  ```haml
36
36
  .search
37
- = form_tag books_path, method: :get, id: :search do
38
- = fields_for :filters, OpenStruct.new(params[:filters]) do |f|
39
- = f.label :with_name, Book.human_attribute_name(:name)
40
- = f.text_field :with_name
37
+ = search_form books_path, id: :search do |f|
38
+ = f.label :with_name, Book.human_attribute_name(:name)
39
+ = f.text_field :with_name
40
+ = f.submit 'Search'
41
41
  .index
42
42
  %table
43
43
  %tr
data/bolter.gemspec CHANGED
@@ -11,14 +11,15 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = %q{This gem include sorting and filtering methods}
12
12
  spec.homepage = 'http://github.com/jpascal/bolter'
13
13
  spec.license = 'MIT'
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
15
15
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
16
  spec.require_paths = ['lib']
17
17
 
18
18
  spec.add_development_dependency 'bundler', '~> 1.8'
19
19
  spec.add_development_dependency 'rake', '~> 10.0'
20
- spec.add_development_dependency 'rails'
20
+ spec.add_development_dependency 'activerecord'
21
+ spec.add_development_dependency 'sqlite3'
21
22
  spec.add_development_dependency 'mongoid'
22
-
23
- spec.add_dependency 'activesupport'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'activesupport'
24
25
  end
@@ -1,19 +1,33 @@
1
1
  module Bolter
2
- module UrlHelpers
3
- def sort_link(scope_name, text = nil)
4
- sorting = params[:sorting] || "#{scope_name}:asc"
2
+ module SortHelper
3
+ def sort_link(scope_name, text = nil, options = {})
4
+ as = options.fetch(:as, :sorting)
5
+ sorting = params[as] || "#{scope_name}:asc"
5
6
  current_field, direction = sorting.split(':', 2).map(&:to_s)
6
7
  direction = direction == 'asc' ? 'desc' : 'asc'
7
8
  title = text || scope
8
- title = title + "#{direction == 'asc' ? '▲' : '▼'}" if scope_name.to_s == current_field and params[:sorting].present?
9
- link_to title.html_safe, url_for(params.merge({:sorting => "#{scope_name}:#{direction}"}))
9
+ title = title + "#{direction == 'asc' ? '▲' : '▼'}" if scope_name.to_s == current_field and params[as].present?
10
+ link_to title.html_safe, url_for(params.merge(Hash[as, "#{scope_name}:#{direction}"]))
10
11
  end
11
12
  end
12
- module FormHelpers
13
- def self.field_for_filters(name, options = {}, &block)
14
- record_object = OpenStruct.new(params[name])
15
- builder = instantiate_builder(name, record_object, options)
16
- silence(builder, &block)
13
+ module FormHelper
14
+ def search_form(url, options = {}, &block)
15
+ raise ArgumentError, 'Missing block' unless block_given?
16
+ as = options.fetch(:as, :search)
17
+ object = OpenStruct.new(params[as])
18
+ builder = default_form_builder.new(as, object, self, options)
19
+
20
+ html_options = options.fetch(:html, {})
21
+ html_options[:data] = options.delete(:data)
22
+ html_options[:remote] = options.fetch(:remote, false)
23
+ html_options[:method] = options.fetch(:method, :get)
24
+ html_options[:enforce_utf8] = options.fetch(:enforce_utf8, nil)
25
+ html_options[:authenticity_token] = options.delete(:authenticity_token)
26
+ html_options = html_options_for_form(url, html_options)
27
+
28
+ output = form_tag_html(html_options)
29
+ output << capture(builder, &block)
30
+ output.safe_concat('</form>')
17
31
  end
18
32
  end
19
33
  end
@@ -7,8 +7,8 @@ module Bolter
7
7
  class Railtie < Rails::Railtie
8
8
  initializer 'bolter.initialization' do
9
9
  ActiveSupport.on_load(:action_view) do
10
- ActionView::Base.send :include, Bolter::FormHelpers
11
- ActionView::Base.send :include, Bolter::UrlHelpers
10
+ ActionView::Base.send :include, Bolter::FormHelper
11
+ ActionView::Base.send :include, Bolter::SortHelper
12
12
  end
13
13
 
14
14
  ActiveSupport.on_load(:active_record) do
@@ -24,8 +24,6 @@ module Bolter
24
24
  search.each do |name, value|
25
25
  if enabled_filters.include?(name.to_s)
26
26
  result = result.send(name.to_s, value)
27
- else
28
- logger.warn "Unknown filter #{self}.#{name}(#{value.inspect})"
29
27
  end
30
28
  end
31
29
  result
@@ -1,3 +1,3 @@
1
1
  module Bolter
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Shurmin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rails
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: activesupport
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +101,7 @@ dependencies:
73
101
  - - ">="
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
- type: :runtime
104
+ type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
@@ -120,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
148
  version: '0'
121
149
  requirements: []
122
150
  rubyforge_project:
123
- rubygems_version: 2.4.5
151
+ rubygems_version: 2.2.0
124
152
  signing_key:
125
153
  specification_version: 4
126
154
  summary: This gem include sorting and filtering methods
127
155
  test_files: []
128
- has_rdoc: