peek-select 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/app/views/peek/views/_select.html.erb +4 -0
- data/lib/peek-select.rb +3 -0
- data/lib/peek-select/railtie.rb +6 -0
- data/lib/peek-select/version.rb +5 -0
- data/lib/peek/views/select.rb +40 -0
- data/peek-select.gemspec +21 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b6648410e8dcaa2cfec6f074093744ac46855919f45789d8680ec561fa34359
|
4
|
+
data.tar.gz: aa827705d7a210f9fd57ac90683901aafc98395fccbc79f9c88ed734baf17171
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a1748ff7b94f5a4e876e839227920978b5cb45a5619c200d3f6f9cee35b963ed802db2a3c84ff65e5878b72bfa47e9898a5e920adad3ef7e672b998d471c0b1
|
7
|
+
data.tar.gz: 8f1a2d12a4632cdc82235b6b70b451bbeb6aac49a684e83961a68aa347734220a39a41012452221d8ebd37b4bd1e4f54f1d1500d31d199932a7ab569927268af
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Garrett Bjerkhoel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Peek::Select
|
2
|
+
|
3
|
+
Peek into any collection in your app.
|
4
|
+
|
5
|
+
Things this peek view provides:
|
6
|
+
|
7
|
+
- Present options from a collection as a select list
|
8
|
+
- Run a piece of JavaScript code when an option is selected
|
9
|
+
|
10
|
+
An example use would be to list subdomains served by an application
|
11
|
+
and switch between them when a new option is selected, as in
|
12
|
+
[Usage](#usage) below.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'peek-select'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install peek-select
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Add something like the following to your `config/initializers/peek.rb`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Peek.into Peek::Views::Select,
|
34
|
+
collection: lambda { Site.order(:subdomain).pluck(:name, :subdomain) },
|
35
|
+
selected: lambda { |controller| controller.current_site.subdomain },
|
36
|
+
onchange: "window.location.hostname=" \
|
37
|
+
"window.location.hostname.replace(/^[^.]*\.?(?=mysite.com)/," \
|
38
|
+
"this.value+'.');"
|
39
|
+
```
|
40
|
+
|
41
|
+
The options are:
|
42
|
+
|
43
|
+
- `collection` - A collection or lambda returning a collection suitable
|
44
|
+
for passing to [options_for_select](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select).
|
45
|
+
Defaults to the empty array.
|
46
|
+
- `selected` - The value in `collection` that should be selected.
|
47
|
+
- `onchange` - JavaScript for the `<select>` element's `onchange` attribute.
|
48
|
+
- `name` - String used to generate the `<select>` element's `name` and `id`
|
49
|
+
attributes. The value used is `peek-select-#{@name}`
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/peek-select.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Peek
|
2
|
+
module Views
|
3
|
+
class Select < View
|
4
|
+
# A view to present a collection as a select list.
|
5
|
+
#
|
6
|
+
# name - Name inserted into the select element's name
|
7
|
+
# collection - A collection of labels and values
|
8
|
+
# selected - A lambda returning the currently selected value
|
9
|
+
# onchange - JavaScript for the select list onchange attribute
|
10
|
+
#
|
11
|
+
# Returns Peek::Views::Select
|
12
|
+
def parse_options
|
13
|
+
@name = @options.fetch(:name, "select")
|
14
|
+
@collection = @options.fetch(:collection, [])
|
15
|
+
@selected = @options.delete(:selected)
|
16
|
+
@onchange = @options.delete(:onchange)
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
"peek-select-#{@name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def collection
|
24
|
+
if @collection.respond_to?(:call)
|
25
|
+
@collection.call
|
26
|
+
else
|
27
|
+
@collection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def selected(controller)
|
32
|
+
if @selected.respond_to?(:call)
|
33
|
+
@selected.call(controller)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :onchange
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/peek-select.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'peek-select/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'peek-select'
|
8
|
+
gem.version = Peek::Select::VERSION
|
9
|
+
gem.authors = ['Mark Wilkinson']
|
10
|
+
gem.email = ['mhw@dangerous-techniques.com']
|
11
|
+
gem.description = %q{Take a peek into any collection in your Rails application. A view for https://github.com/peek/peek.}
|
12
|
+
gem.summary = %q{Take a peek into any collection in your Rails application. A view for https://github.com/peek/peek.}
|
13
|
+
gem.homepage = 'https://github.com/mhw/peek-select'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'peek'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peek-select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Wilkinson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: peek
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Take a peek into any collection in your Rails application. A view for
|
28
|
+
https://github.com/peek/peek.
|
29
|
+
email:
|
30
|
+
- mhw@dangerous-techniques.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- app/views/peek/views/_select.html.erb
|
42
|
+
- lib/peek-select.rb
|
43
|
+
- lib/peek-select/railtie.rb
|
44
|
+
- lib/peek-select/version.rb
|
45
|
+
- lib/peek/views/select.rb
|
46
|
+
- peek-select.gemspec
|
47
|
+
homepage: https://github.com/mhw/peek-select
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.1.4
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Take a peek into any collection in your Rails application. A view for https://github.com/peek/peek.
|
69
|
+
test_files: []
|