simple_form_ransack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 781739fc7f7beb87f714cb073fa707767882a5fe
4
+ data.tar.gz: 6af4ced0c336d9c2203fea2fdcef3462957dd632
5
+ SHA512:
6
+ metadata.gz: d0972f003f2bd7cd4e54194b47cfbe018b3663d1249367ddc362f448d5a2db0e83a5117639a27a831dc2ab87e1c70b4af611f1e765698c72fef97a004748a85e
7
+ data.tar.gz: 74a14b896ba796baf969c126e63731bcef0a71e2cbc3845b9ec8f0b3c9495b9d033133c884e5bf45932d2b85e7c3564e76ab782cbe3cce9f010537729fa18828
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SimpleFormRansack'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,26 @@
1
+ module SimpleFormRansackHelper
2
+ def simple_search_form_for(resource, params, *args)
3
+ if args.last.is_a?(Hash)
4
+ opts = args.pop
5
+ else
6
+ opts = {}
7
+ end
8
+
9
+ opts[:url] = request.original_url unless opts[:url]
10
+ opts[:method] = "get" unless opts[:method]
11
+ args << opts
12
+
13
+ model_class = resource.klass
14
+ sample_model = model_class.new
15
+
16
+ simple_form_for(sample_model, *args) do |form|
17
+ form_proxy = SimpleFormRansack::FormProxy.new(
18
+ :resource => resource,
19
+ :form => form,
20
+ :params => params,
21
+ )
22
+
23
+ yield form_proxy
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module SimpleFormRansack
2
+ end
3
+
4
+ require_relative "../app/helpers/simple_form_ransack_helper"
5
+ require_relative "simple_form_ransack/form_proxy"
@@ -0,0 +1,40 @@
1
+ class SimpleFormRansack::FormProxy
2
+ def initialize(args)
3
+ @resource = args[:resource]
4
+ @object = @resource.object
5
+ @class = @resource.klass
6
+ @params = args[:params]
7
+ @form = args[:form]
8
+
9
+ raise "No params given in arguments: #{args.keys}" unless @params
10
+ end
11
+
12
+ def input(name, *args)
13
+ if args.last.is_a?(Hash)
14
+ opts = args.last
15
+ else
16
+ opts = {}
17
+ end
18
+
19
+ match = name.to_s.match(/^(.+)_(eq|cont|eq_any)$/)
20
+ if match
21
+ attribute_name = match[1]
22
+ else
23
+ raise "Couldn't figure out attribute name from: #{name}"
24
+ end
25
+
26
+ input_html = opts.delete(:input_html) || {}
27
+ input_html[:name] = "q[#{name}]" unless input_html.key?(:name)
28
+ input_html[:value] = @params[name] if !input_html.key?(:value) && @params[name]
29
+
30
+ opts[:input_html] = input_html
31
+ opts[:required] = false unless opts.key?(:required)
32
+
33
+ args << opts
34
+ return @form.input(attribute_name, *args)
35
+ end
36
+
37
+ def method_missing(method_name, *args, &blk)
38
+ @form.__send__(method_name, *args, &blk)
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormRansack
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_form_ransack do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_ransack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Johansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
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: factory_girl_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: forgery
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ransack
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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: haml-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simple_form
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Makes it easy to use SimpleForm::FormBuilder with Ransack without constantly
126
+ having to supply labels and other pains.
127
+ email:
128
+ - k@spernj.org
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - app/helpers/simple_form_ransack_helper.rb
134
+ - lib/simple_form_ransack.rb
135
+ - lib/tasks/simple_form_ransack_tasks.rake
136
+ - lib/simple_form_ransack/version.rb
137
+ - lib/simple_form_ransack/form_proxy.rb
138
+ - MIT-LICENSE
139
+ - Rakefile
140
+ homepage: https://www.github.com/kaspernj/simple_form_ransack
141
+ licenses: []
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.0.7
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Ransack and SimpleForm combined.
163
+ test_files: []