administrate-field-list 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 303f3e89962aeef52297980acdc98f7e1259ddfa
4
+ data.tar.gz: 2bedd7501b0e88ff3a82bfb4b1030aaebcef80b5
5
+ SHA512:
6
+ metadata.gz: 8d8b1b66699bcd20417194093632da30a75857b46d13230ef88610e1c6d97501c76d5ed237c01f2e442890d69a8744527e2bdc23685909f566ad4b5ba3df38eb
7
+ data.tar.gz: 6dc7fb41fc123298e29a0ecb851e22e46f4d88524eee5f28fa7b2415a4611177604181384aa4d793e7dadff03b3e47c7be02ac4488dcbc557eecc0c02be3bed2
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 potato2003
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Administrate::Field::List
2
+
3
+ simple plugin in order to be able to view and edit serialized list within Administrate
4
+
5
+ ![screenshot](screenshot/screenshot_1.png "screenshot_1")
6
+
7
+ support serialization type
8
+ - JSON
9
+
10
+ ```ruby
11
+ class Project < ApplicationRecord
12
+ serialize :admin_group, JSON
13
+ serialize :editor_group, JSON
14
+ ```
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'administrate-field-list'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle install
27
+
28
+ ## Usage
29
+
30
+ In your Dashboard `ATTRIBUTE_TYPES` use the field type `Field::List`. i.e.
31
+ ```ruby
32
+ ATTRIBUTE_TYPES = {
33
+ tags: Field::List
34
+ }
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/potato2003/administrate-field-list
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "administrate-field-list"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["potato2003"]
8
+ spec.email = ["potato2003@gmail.com"]
9
+
10
+ spec.summary = "simple plugin in order to be able to view and edit serialized list within Administrate."
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/potato2003/administrate-field-list"
13
+ spec.licenses = ['MIT']
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'administrate'
23
+ spec.add_runtime_dependency 'rails', '>= 5.0', '< 6.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,52 @@
1
+ <div class="field-unit__label">
2
+ <%= f.label field.attribute %>
3
+ </div>
4
+ <div class="field-unit__field">
5
+ <%= f.hidden_field field.attribute %>
6
+
7
+ <% _group_id = "gid_#{SecureRandom.alphanumeric}" %>
8
+ <% field.values.each do |v| %>
9
+
10
+ <%= text_field_tag(
11
+ nil,
12
+ v,
13
+ class: _group_id,
14
+ )
15
+ %>
16
+
17
+ <% end %>
18
+
19
+ <%= text_field_tag(
20
+ nil,
21
+ '',
22
+ class: _group_id,
23
+ )
24
+ %>
25
+
26
+ <%= button_tag(
27
+ '+',
28
+ onclick: 'var $l = $(".' + _group_id + '").last(); $l.clone(false).insertAfter($l).val(""); return false;',
29
+ )
30
+ %>
31
+
32
+ <script>
33
+ (function() {
34
+ var hiddens = document.querySelectorAll('input[type=hidden]');
35
+ var hidden = hiddens[hiddens.length - 1];
36
+ var group_selector = '.<%= _group_id %>'
37
+
38
+ document.addEventListener("DOMContentLoaded", function(evt) {
39
+
40
+ var $f = $(hidden).parents('form');
41
+ $f.on('submit', function() {
42
+ var vals = $(group_selector).map(function() {
43
+ return $(this).val();
44
+ }).toArray();
45
+ vals = vals.filter(function(v) { return v !== '' && v != null });
46
+
47
+ $(hidden).val(JSON.stringify(vals));
48
+ });
49
+ });
50
+ })()
51
+ </script>
52
+ </div>
@@ -0,0 +1 @@
1
+ <%= field.to_s %>
@@ -0,0 +1 @@
1
+ <%= field.to_s %>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "administrate-field-list"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require "administrate/field/base"
2
+ require 'rails'
3
+
4
+ module Administrate
5
+ module Field
6
+ class List < Administrate::Field::Base
7
+ def to_s
8
+ return '-' unless data
9
+
10
+ pretty
11
+ end
12
+
13
+ def pretty
14
+ return unless data
15
+
16
+ data.to_s
17
+ end
18
+
19
+ def values
20
+ return [] unless data
21
+ return data if data.is_a? Array
22
+
23
+ JSON.parse(data)
24
+ end
25
+
26
+ class Engine < ::Rails::Engine; end
27
+ end
28
+ end
29
+ end
Binary file
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - potato2003
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: administrate
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
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '5.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: simple plugin in order to be able to view and edit serialized list within
90
+ Administrate.
91
+ email:
92
+ - potato2003@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - Gemfile
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - administrate-field-list.gemspec
103
+ - app/views/fields/list/_form.html.erb
104
+ - app/views/fields/list/_index.html.erb
105
+ - app/views/fields/list/_show.html.erb
106
+ - bin/console
107
+ - bin/setup
108
+ - lib/administrate/field/list.rb
109
+ - screenshot/screenshot_1.png
110
+ homepage: https://github.com/potato2003/administrate-field-list
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.11
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: simple plugin in order to be able to view and edit serialized list within
134
+ Administrate.
135
+ test_files: []