active_admin_simple_life 0.0.14 → 0.1.0

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: ec370d39c1fce84d4b123e3982d8580b7661ce49
4
- data.tar.gz: 6c07a7aa138f48521a33ccb1355d5db513ae44d2
3
+ metadata.gz: a707c7ee7d8b8facfdc140848aead03ded07e871
4
+ data.tar.gz: 14d81f1d3a363d39503b6677c90dfa4c606effab
5
5
  SHA512:
6
- metadata.gz: 1665c975a59f4f4193af1fe98351d15e93739e7ca1a922fc56c00fc2111bf5dd852cc89c49fa95c08e9d619c9e376617dff3ee0ea9052c1294b04945abd3dc5d
7
- data.tar.gz: 1487d207ab79a3b19ddc455a357ecdb1fe9b35f3581a180bbf3d5a552405fcbfbad03ac641f58de7f35a0a79fb72ab2b511b4c10a6aaf5993acc72e800bd2160
6
+ metadata.gz: 1e450b90589c8eba50b914f24cbfb70f6af6460cdf6588b079896355def766bdf878f464fa555e1b13885539b6132dc90548ff1d8471eab26d18336d85ddb851
7
+ data.tar.gz: f872f029753ebf20010d70ecdaf578bf76391fe7553b3aaeb78f3ef2fd287f8c541b94a606ee281ebbe14149c19d05046895de5423cc7dced8a7e27e859f8010
data/README.md CHANGED
@@ -11,22 +11,9 @@ put in `Gemfile`
11
11
 
12
12
  `gem 'active_admin_simple_life'`
13
13
 
14
- in `config/initializers/active_admin.rb` change header like this:
15
-
16
- ```
17
- # frozen_string_literal: true
18
- include ActiveAdminSimpleLife
19
- ActiveAdmin.setup do |config|
20
- include ActiveAdminSimpleLife::SimpleElements
21
- # your settings
22
- ```
23
-
24
- I had to include `simple_menu_for` method bacause it must be in the main
25
- namespace, so it is not a bug ;)
26
-
27
14
  ###Usage
28
15
 
29
- For all gem methods you need to present class method(NOT scope!) `main fields`,
16
+ For all gem methods you need to present class method(NOT scope!) `main_fields`,
30
17
  where you provide columns, which you would like to manage. Example:
31
18
 
32
19
  ```
@@ -40,7 +27,7 @@ end
40
27
 
41
28
  ###Methods
42
29
 
43
- `simple_menu_for KlassName, [options]` which will make all dirty work, and just
30
+ `ActiveAdminSimpleLife.for KlassName, [options]` which will make all dirty work, and just
44
31
  give you simple menu, with only `main_fields` and `filters` in 1 line.
45
32
  method takes options like:
46
33
  * `:priority` = `ActiveAdmin` proxy menu `priority`
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  require "active_admin_simple_life/engine"
3
+ require "active_admin_simple_life/extensions"
3
4
  require "active_admin_simple_life/simple_menu"
4
- require "active_admin_simple_life/menu_elements"
5
+ require "active_admin_simple_life/simple_elements"
5
6
  module ActiveAdminSimpleLife
6
- include SimpleMenu
7
+ extend SimpleMenu
8
+ ActiveAdmin::ResourceDSL.send :include, ActiveAdminSimpleLife::SimpleElements
7
9
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module ActiveAdminSimpleLife
3
+ module Extensions
4
+ require "forwardable"
5
+ class ExtensionedSymbol < DelegateClass(Symbol)
6
+ def cut_id
7
+ to_s.sub(/_id$/, "").to_sym
8
+ end
9
+ end
10
+ end
11
+ end
12
+ module ActiveAdmin
13
+ module Views
14
+ class IndexAsTable < ActiveAdmin::Component
15
+ def span_true
16
+ Arbre::Context.new { span(class: "status_tag yes") { I18n.t("boolean.active") } }
17
+ end
18
+
19
+ def span_false
20
+ Arbre::Context.new { span(class: "status_tag no") { I18n.t "boolean.not_active" } }
21
+ end
22
+
23
+ def genders
24
+ [[I18n.t("active_admin.genders.male"), true],
25
+ [I18n.t("active_admin.genders.female"), false]]
26
+ end
27
+
28
+ def truncate_field(field, max_length = 50)
29
+ length = max_length || 50
30
+ truncate(field.to_s, length: length)
31
+ end
32
+
33
+ def fetch_path(field)
34
+ "edit_admin_#{field.class.to_s.underscore}_path"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveAdminSimpleLife
3
3
  module SimpleElements
4
+ ActiveAdmin.send :include, ActiveAdminSimpleLife::Extensions
5
+ include Extensions
4
6
  def index_for_main_fields(klass, options = {})
5
- max_length = options[:max_length]
7
+ max_length = options[:max_length]
6
8
  add_fields = [options[:add]].flatten.compact
7
9
  position = options[:position]
8
10
  index download_links: false do
@@ -10,7 +12,7 @@ module ActiveAdminSimpleLife
10
12
  id_column
11
13
  klass.main_fields.insert(position, *add_fields).each do |symbol|
12
14
  column(I18n.t("activerecord.attributes.#{klass.to_s.underscore}.#{symbol}"), sortable: symbol) do |current|
13
- field_value = current.send(symbol.cut_id)
15
+ field_value = current.send(ExtensionedSymbol.new(symbol).cut_id)
14
16
  case field_value
15
17
  when ActiveRecord::Base
16
18
  link_to truncate_field(field_value, max_length),
@@ -34,9 +36,9 @@ module ActiveAdminSimpleLife
34
36
  def filter_for_main_fields(klass)
35
37
  klass.main_fields.each do |f|
36
38
  if f == :gender
37
- filter f.cut_id, collection: genders
39
+ filter ExtensionedSymbol.new(f).cut_id, collection: genders
38
40
  else
39
- filter f.cut_id
41
+ filter ExtensionedSymbol.new(f).cut_id
40
42
  end
41
43
  end
42
44
  end
@@ -46,11 +48,11 @@ module ActiveAdminSimpleLife
46
48
  f.semantic_errors(*f.object.errors.keys)
47
49
  f.inputs do
48
50
  klass.main_fields.each do |ff|
49
- ff_cut_id = ff.cut_id
50
- if collection? ff
51
- f.input ff_cut_id, as: :select, member_label: :to_s
52
- else
51
+ ff_cut_id = ExtensionedSymbol.new(ff).cut_id
52
+ if ff == ff_cut_id
53
53
  f.input ff_cut_id
54
+ else
55
+ f.input ff_cut_id, as: :select, member_label: :to_s
54
56
  end
55
57
  end
56
58
  f.instance_eval(&block) if block_given?
@@ -65,44 +67,11 @@ module ActiveAdminSimpleLife
65
67
  nested_table_name = nested_klass.to_s.underscore.pluralize.to_sym
66
68
  main_model_name = klass.to_s.underscore.to_sym
67
69
  form_field.has_many nested_table_name, allow_destroy: true do |form|
68
- nested_klass.main_fields.map(&:cut_id).each do |nested_field|
70
+ nested_klass.main_fields.map { |f| ExtensionedSymbol.new(f).cut_id }.each do |nested_field|
69
71
  form.input(nested_field) unless nested_field == main_model_name
70
72
  end
71
73
  end
72
74
  end
73
75
  end
74
-
75
- def cut_id
76
- to_s.sub(/_id$/, "").to_sym
77
- end
78
-
79
- private
80
-
81
- def truncate_field(field, max_length = 50)
82
- length = max_length || 50
83
- truncate(field.to_s, length: length)
84
- end
85
-
86
- def fetch_path(field)
87
- "edit_admin_#{field.class.to_s.underscore}_path"
88
- end
89
-
90
- def collection?(symbol)
91
- return true if symbol.to_s =~ /_id$/
92
- false
93
- end
94
-
95
- def span_true
96
- Arbre::Context.new { span(class: "status_tag yes") { I18n.t("boolean.active") } }
97
- end
98
-
99
- def span_false
100
- Arbre::Context.new { span(class: "status_tag no") { I18n.t "boolean.not_active" } }
101
- end
102
-
103
- def genders
104
- [[I18n.t("active_admin.genders.male"), true],
105
- [I18n.t("active_admin.genders.female"), false]]
106
- end
107
76
  end
108
77
  end
@@ -9,7 +9,8 @@ module ActiveAdminSimpleLife
9
9
  # menu_parent:string
10
10
  # permitted_params:array for some additions to main_fields permitted params
11
11
 
12
- def simple_menu_for(klass, options = {})
12
+ # def simple_menu_for(klass, options = {})
13
+ def for(klass, options = {})
13
14
  ActiveAdmin.register klass do
14
15
  permitted_params = options.delete :permitted_params
15
16
  permit_params(*(klass.main_fields + (permitted_params || [])))
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveAdminSimpleLife
3
- VERSION = "0.0.14"
3
+ VERSION = "0.1.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_simple_life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kvokka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-29 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,7 +39,8 @@ files:
39
39
  - config/locales/ru.yml
40
40
  - lib/active_admin_simple_life.rb
41
41
  - lib/active_admin_simple_life/engine.rb
42
- - lib/active_admin_simple_life/menu_elements.rb
42
+ - lib/active_admin_simple_life/extensions.rb
43
+ - lib/active_admin_simple_life/simple_elements.rb
43
44
  - lib/active_admin_simple_life/simple_menu.rb
44
45
  - lib/active_admin_simple_life/version.rb
45
46
  - lib/generators/active_admin_simple_life/simple_config_generator.rb