rails_admin_enum4 0.1.2

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: 91de64fcb67d3822fda5c588fde741b80f6339d8
4
+ data.tar.gz: 964e7a5223538b7495c7310e4938e6f197272535
5
+ SHA512:
6
+ metadata.gz: c3ee57aa50108349d73e3545ec0a54b8eaa1e44827a959bab7bd63c509c08441a802d9ed6f29856d225cda92ad48c0543458ec7eee4022dd362421cf8880e9f3
7
+ data.tar.gz: 0c6e89dff92b748e5f9c32390cc1b4d27ad12c3fddc846cde34dcd4b8e585abb6eb3e6dbf43049ddb2509655b25a48e5e8e440e12c2f480b2e7aa511ba562b6e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Sibext Ltd.
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.
data/Rakefile ADDED
@@ -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 = 'RailsAdminEnum4'
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,7 @@
1
+ - if field.values.count > 5
2
+ .btn-group.btn-group-xs{"data-toggle" => "buttons"}
3
+ = render 'form_enum4_values', field: field, form: form
4
+ - else
5
+ .btn-group{"data-toggle" => "buttons"}
6
+ = render 'form_enum4_values', field: field, form: form
7
+
@@ -0,0 +1,9 @@
1
+ - field.values.each do |v|
2
+ - if field.form_value == v[1]
3
+ %label.btn.btn-primary.active
4
+ = form.radio_button field.method_name, v[0], checked: true
5
+ = t "enum.values.#{v[0]}"
6
+ - else
7
+ %label.btn.btn-primary
8
+ = form.radio_button field.method_name, v[0]
9
+ = t "enum.values.#{v[0]}"
@@ -0,0 +1,64 @@
1
+ require "rails_admin_enum4/engine"
2
+
3
+ module RailsAdminEnum4
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ module RailsAdmin
10
+ module Config
11
+ module Fields
12
+ module Types
13
+ class Enum4 < RailsAdmin::Config::Fields::Base
14
+ RailsAdmin::Config::Fields::Types::register(self)
15
+
16
+ register_instance_option :enum_values do
17
+ data_name = name.to_s.pluralize(100)
18
+ @enum_values ||= bindings[:object].class.respond_to?(data_name) || bindings[:object].respond_to?(data_name) ? data_name : name
19
+ end
20
+
21
+ register_instance_option :values do
22
+ bindings[:object].class.respond_to?(enum_values) ? bindings[:object].class.send(enum_values) : bindings[:object].send(enum_values)
23
+ end
24
+
25
+ register_instance_option :partial do
26
+ :form_enum4
27
+ end
28
+
29
+ register_instance_option :pretty_value do
30
+ if value
31
+ I18n::t "enum.values.#{values.keys[value]}", default: values.keys[value].split('_').collect(&:capitalize).join(' ')
32
+ else
33
+ I18n::t "enum.none", default: 'None'
34
+ end
35
+ end
36
+
37
+ def self.data_for_name name
38
+ name.to_s.pluralize(100)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
48
+ model = parent.abstract_model.model
49
+ method_name = RailsAdmin::Config::Fields::Types::Enum4::data_for_name properties.name
50
+ puts "#{model} >>>>> #{properties.type} #{properties.name} #{method_name}\n"
51
+
52
+ if (not properties.name.to_s.eql? 'id') && \
53
+ properties.type.to_s.eql?('integer') &&
54
+ !Object.respond_to?(method_name) && \
55
+ model.respond_to?(method_name)
56
+ fields << RailsAdmin::Config::Fields::Types::Enum4.new(parent, properties.name, properties)
57
+ puts "ADDED"
58
+ true
59
+ else
60
+ false
61
+ end
62
+ end
63
+
64
+
@@ -0,0 +1,4 @@
1
+ module RailsAdminEnum4
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminEnum4
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_enum4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Moskvin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-25 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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ description: Makes enum field from ActiveRecord::Enum more easy use
28
+ email:
29
+ - moskvin@sibext.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - app/views/rails_admin/main/_form_enum4.html.haml
37
+ - app/views/rails_admin/main/_form_enum4_values.html.haml
38
+ - lib/rails_admin_enum4.rb
39
+ - lib/rails_admin_enum4/engine.rb
40
+ - lib/rails_admin_enum4/version.rb
41
+ homepage: https://github.com/sibext/rails_admin_enum4
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Enum from Rails 4 field for rails admin
65
+ test_files: []