activeadmin_addons 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activeadmin_addons/addons/bool_values.rb +27 -26
- data/lib/activeadmin_addons/addons/enum_tag.rb +9 -12
- data/lib/activeadmin_addons/addons/list.rb +47 -56
- data/lib/activeadmin_addons/addons/number.rb +19 -22
- data/lib/activeadmin_addons/addons/paperclip_attachment.rb +29 -32
- data/lib/activeadmin_addons/addons/paperclip_image.rb +10 -13
- data/lib/activeadmin_addons/engine.rb +1 -0
- data/lib/activeadmin_addons/support/custom_builder.rb +34 -0
- data/lib/activeadmin_addons/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642e1d8cf2a3405355d4ff9c633121f219d69041
|
4
|
+
data.tar.gz: 136a74147270d9fab01136edc717d8f7a358d143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b00492b0c016a1ff8191f227913ba2d1ed5ea3137614d1f673e37147456b420cdb85fb65386926961474e3f4b1876b3bbdcb6ac021bac5170a78d22b6f236dd0
|
7
|
+
data.tar.gz: ddd0f770ceeb567dfe2f942e23d7ec06160415bb61c743fd73f66d65456a6d239467e36e0099252d286dc247c49ae00294217a41338a5b4ac4292a66b47d370b
|
@@ -1,40 +1,41 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
|
-
|
3
|
-
|
2
|
+
class BoolBuilder < CustomBuilder
|
3
|
+
DEFAULT_BOOLEAN_TRUE = '✔'
|
4
|
+
DEFAULT_BOOLEAN_FALSE = '✗'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
i18n_lookup(model, attribute, 'false_value', DEFAULT_BOOLEAN_FALSE)
|
12
|
-
end
|
6
|
+
def render
|
7
|
+
if data
|
8
|
+
i18n_lookup('true_value', DEFAULT_BOOLEAN_TRUE)
|
9
|
+
else
|
10
|
+
i18n_lookup('false_value', DEFAULT_BOOLEAN_FALSE)
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
14
|
+
private
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
def i18n_lookup(key, last_default)
|
17
|
+
model_name = model.class.model_name.i18n_key
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
model_i18n = "activeadmin.addons.boolean.models.#{model_name}.#{key}"
|
20
|
+
default_i18n = "activeadmin.addons.boolean.default.#{key}"
|
22
21
|
|
23
|
-
|
24
|
-
end
|
22
|
+
I18n.t(model_i18n, default: I18n.t(default_i18n, default: last_default)).html_safe
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
module
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
module BoolValues
|
27
|
+
|
28
|
+
module ::ActiveAdmin
|
29
|
+
module Views
|
30
|
+
class TableFor
|
31
|
+
def bool_column(*args, &block)
|
32
|
+
column(*args) { |model| BoolBuilder.render(self, model, *args, &block) }
|
33
|
+
end
|
33
34
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
class AttributesTable
|
36
|
+
def bool_row(*args, &block)
|
37
|
+
row(*args) { |model| BoolBuilder.render(self, model, *args, &block) }
|
38
|
+
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -1,25 +1,22 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
raise 'you need to pass an enumerize attribute' unless state.is_a?('Enumerize::Value'.constantize)
|
8
|
-
context.status_tag(state.text, state)
|
9
|
-
end
|
2
|
+
class EnumBuilder < CustomBuilder
|
3
|
+
def render
|
4
|
+
raise 'you need to install enumerize gem first' unless defined? Enumerize::Value
|
5
|
+
raise 'you need to pass an enumerize attribute' unless data.is_a?('Enumerize::Value'.constantize)
|
6
|
+
context.status_tag(data.text, data)
|
10
7
|
end
|
11
8
|
end
|
12
9
|
|
13
10
|
module ::ActiveAdmin
|
14
11
|
module Views
|
15
12
|
class TableFor
|
16
|
-
def tag_column(
|
17
|
-
column(
|
13
|
+
def tag_column(*args, &block)
|
14
|
+
column(*args) { |model| EnumBuilder.render(self, model, *args, &block) }
|
18
15
|
end
|
19
16
|
end
|
20
17
|
class AttributesTable
|
21
|
-
def tag_row(
|
22
|
-
row(
|
18
|
+
def tag_row(*args, &block)
|
19
|
+
row(*args) { |model| EnumBuilder.render(self, model, *args, &block) }
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
@@ -1,70 +1,61 @@
|
|
1
|
-
|
2
|
-
module ListHelper
|
3
|
-
class << self
|
4
|
-
def localized_value(key, model, attribute)
|
5
|
-
I18n.t("addons_list.#{model.class.name.underscore}.#{attribute}.#{key}")
|
6
|
-
end
|
1
|
+
class ListBuilder < ActiveAdminAddons::CustomBuilder
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
items.each do |value|
|
12
|
-
value = localized_value(value, model, attribute) if !!options[:localize]
|
13
|
-
ctx.concat(ctx.content_tag(:li, value))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
3
|
+
def render
|
4
|
+
options[:localize] = options.fetch(:localize, false)
|
5
|
+
options[:list_type] = options.fetch(:list_type, :ul)
|
17
6
|
|
18
|
-
|
19
|
-
|
20
|
-
ctx.content_tag(options[:list_type]) do
|
21
|
-
items.keys.each do |key|
|
22
|
-
label = !!options[:localize] ? localized_value(key, model, attribute) : key
|
23
|
-
value = items[key]
|
24
|
-
ctx.concat(ctx.content_tag(:li) do
|
25
|
-
if value.blank?
|
26
|
-
ctx.content_tag(:span, label)
|
27
|
-
else
|
28
|
-
ctx.content_tag(:span) do
|
29
|
-
ctx.concat("#{label}: ".html_safe)
|
30
|
-
ctx.concat(ctx.content_tag(:span) do
|
31
|
-
ctx.content_tag(:i, value)
|
32
|
-
end)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
7
|
+
raise 'invalid list type (ul, ol)' unless [:ul, :ol].include?(options[:list_type])
|
8
|
+
raise "list must be Array or Hash" if !data.is_a?(Hash) && !data.is_a?(Array)
|
39
9
|
|
40
|
-
|
41
|
-
|
42
|
-
options[:list_type] = options.fetch(:list_type, :ul)
|
43
|
-
raise 'invalid list type (ul, ol)' unless [:ul, :ol].include?(options[:list_type])
|
10
|
+
data.is_a?(Array) ? render_array : render_hash
|
11
|
+
end
|
44
12
|
|
45
|
-
|
13
|
+
def localized_value(key, model, attribute)
|
14
|
+
I18n.t("addons_list.#{model.class.name.underscore}.#{attribute}.#{key}")
|
15
|
+
end
|
46
16
|
|
47
|
-
|
48
|
-
|
49
|
-
|
17
|
+
def render_array
|
18
|
+
context.content_tag(options[:list_type]) do
|
19
|
+
data.each do |value|
|
20
|
+
value = localized_value(value, model, attribute) if !!options[:localize]
|
21
|
+
context.concat(context.content_tag(:li, value))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
50
25
|
|
51
|
-
|
52
|
-
|
26
|
+
def render_hash
|
27
|
+
context.content_tag(options[:list_type]) do
|
28
|
+
data.keys.each do |key|
|
29
|
+
label = !!options[:localize] ? localized_value(key, model, attribute) : key
|
30
|
+
value = data[key]
|
31
|
+
context.concat(context.content_tag(:li) do
|
32
|
+
if value.blank?
|
33
|
+
context.content_tag(:span, label)
|
34
|
+
else
|
35
|
+
context.content_tag(:span) do
|
36
|
+
context.concat("#{label}: ".html_safe)
|
37
|
+
context.concat(context.content_tag(:span) do
|
38
|
+
context.content_tag(:i, value)
|
39
|
+
end)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end)
|
53
43
|
end
|
54
44
|
end
|
55
45
|
end
|
56
46
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
47
|
+
end
|
48
|
+
|
49
|
+
module ::ActiveAdmin
|
50
|
+
module Views
|
51
|
+
class TableFor
|
52
|
+
def list_column(*args, &block)
|
53
|
+
column(*args) { |model| ::ListBuilder.new(self, model, *args, &block).render }
|
63
54
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
55
|
+
end
|
56
|
+
class AttributesTable
|
57
|
+
def list_row(*args, &block)
|
58
|
+
row(*args) { |model| ::ListBuilder.new(self, model, *args, &block).render }
|
68
59
|
end
|
69
60
|
end
|
70
61
|
end
|
@@ -1,37 +1,34 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
2
|
+
class NumberBuilder < CustomBuilder
|
3
|
+
NUMBER_TYPES = {
|
4
|
+
currency: :number_to_currency,
|
5
|
+
human: :number_to_human,
|
6
|
+
human_size: :number_to_human_size,
|
7
|
+
percentage: :number_to_percentage,
|
8
|
+
phone: :number_to_phone,
|
9
|
+
delimiter: :number_with_delimiter,
|
10
|
+
precision: :number_with_precision
|
11
|
+
}
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
number = model.send(attribute)
|
20
|
-
context.send(NUMBER_TYPES[options[:as]], number, options)
|
13
|
+
def render
|
14
|
+
options[:as] = options.fetch(:as, :delimiter)
|
15
|
+
if !NUMBER_TYPES.keys.include?(options[:as])
|
16
|
+
raise "Invalid number type. Options are: #{NUMBER_TYPES.keys.to_s}"
|
21
17
|
end
|
18
|
+
context.send(NUMBER_TYPES[options[:as]], data, options)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
22
|
module ::ActiveAdmin
|
26
23
|
module Views
|
27
24
|
class TableFor
|
28
|
-
def number_column(
|
29
|
-
column(
|
25
|
+
def number_column(*args, &block)
|
26
|
+
column(*args) { |model| NumberBuilder.render(self, model, *args, &block) }
|
30
27
|
end
|
31
28
|
end
|
32
29
|
class AttributesTable
|
33
|
-
def number_row(
|
34
|
-
row(
|
30
|
+
def number_row(*args, &block)
|
31
|
+
row(*args) { |model| NumberBuilder.render(self, model, *args, &block) }
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -1,56 +1,53 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
|
-
|
3
|
-
|
4
|
-
KNOWN_EXTENSIONS = %w{
|
2
|
+
class PaperclipAttachmentBuilder < CustomBuilder
|
3
|
+
KNOWN_EXTENSIONS = %w{
|
5
4
|
3gp 7z ace ai aif aiff amr asf asx bat bin bmp bup cab cbr cda cdl cdr chm
|
6
5
|
dat divx dll dmg doc docx dss dvf dwg eml eps exe fla flv gif gz hqx htm html
|
7
6
|
ifo indd iso jar jpeg jpg lnk log m4a m4b m4p m4v mcd mdb mid mov mp2 mp4
|
8
7
|
mpeg mpg msi mswmm ogg pdf png pps ppt pptx ps psd pst ptb pub qbb qbw qxd ram
|
9
8
|
rar rm rmvb rtf sea ses sit sitx ss swf tgz thm tif tmp torrent ttf txt
|
10
9
|
vcd vob wav wma wmv wps xls xlsx xpi zip
|
11
|
-
|
10
|
+
}
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def for_ext file_extension
|
18
|
-
ext = file_extension.start_with?('.') ? file_extension[1..-1] : file_extension
|
19
|
-
ext.downcase!
|
20
|
-
ext = "unknown" unless KNOWN_EXTENSIONS.include?(ext)
|
21
|
-
"fileicons/file_extension_#{ext}.png"
|
22
|
-
end
|
12
|
+
def icon_for_filename filename
|
13
|
+
for_ext File.extname(filename)
|
14
|
+
end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
def for_ext file_extension
|
17
|
+
ext = file_extension.start_with?('.') ? file_extension[1..-1] : file_extension
|
18
|
+
ext.downcase!
|
19
|
+
ext = "unknown" unless KNOWN_EXTENSIONS.include?(ext)
|
20
|
+
"fileicons/file_extension_#{ext}.png"
|
21
|
+
end
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
label = context.content_tag(:span) do
|
35
|
-
context.concat(icon_img)
|
36
|
-
context.safe_concat(label_text)
|
37
|
-
end
|
23
|
+
def render
|
24
|
+
options[:truncate] = options.fetch(:truncate, true)
|
25
|
+
return nil if data.nil?
|
26
|
+
raise 'you need to pass a paperclip attribute' unless data.respond_to?(:url)
|
38
27
|
|
39
|
-
|
28
|
+
icon = icon_for_filename(data.original_filename)
|
29
|
+
icon_img = context.image_tag(icon, width: "20", height: "20", style: "margin-right: 5px; vertical-align: middle;")
|
30
|
+
file_name = (options[:truncate] == true) ? context.truncate(data.original_filename) : data.original_filename
|
31
|
+
label_text = options.fetch(:label, file_name)
|
32
|
+
label = context.content_tag(:span) do
|
33
|
+
context.concat(icon_img)
|
34
|
+
context.safe_concat(label_text)
|
40
35
|
end
|
36
|
+
|
37
|
+
context.link_to(label, data.url, { target: "_blank" }) if data.exists?
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
41
|
module ::ActiveAdmin
|
45
42
|
module Views
|
46
43
|
class TableFor
|
47
|
-
def attachment_column(
|
48
|
-
column(
|
44
|
+
def attachment_column(*args, &block)
|
45
|
+
column(*args) { |model| PaperclipAttachmentBuilder.render(self, model, *args, &block) }
|
49
46
|
end
|
50
47
|
end
|
51
48
|
class AttributesTable
|
52
|
-
def attachment_row(
|
53
|
-
row(
|
49
|
+
def attachment_row(*args, &block)
|
50
|
+
row(*args) { |model| PaperclipAttachmentBuilder.render(self, model, *args, &block) }
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
@@ -1,26 +1,23 @@
|
|
1
1
|
module ActiveAdminAddons
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
style = options.fetch(:style, :original)
|
9
|
-
context.image_tag(img.url(style)) if img.exists?
|
10
|
-
end
|
2
|
+
class PaperclipImageBuilder < CustomBuilder
|
3
|
+
def render
|
4
|
+
return nil if data.nil?
|
5
|
+
raise 'you need to pass a paperclip image attribute' unless data.respond_to?(:url)
|
6
|
+
style = options.fetch(:style, :original)
|
7
|
+
context.image_tag(data.url(style)) if data.exists?
|
11
8
|
end
|
12
9
|
end
|
13
10
|
|
14
11
|
module ::ActiveAdmin
|
15
12
|
module Views
|
16
13
|
class TableFor
|
17
|
-
def image_column(
|
18
|
-
column(
|
14
|
+
def image_column(*args, &block)
|
15
|
+
column(*args) { |model| PaperclipImageBuilder.render(self, model, *args, &block) }
|
19
16
|
end
|
20
17
|
end
|
21
18
|
class AttributesTable
|
22
|
-
def image_row(
|
23
|
-
row(
|
19
|
+
def image_row(*args, &block)
|
20
|
+
row(*args) { |model| PaperclipImageBuilder.render(self, model, *args, &block) }
|
24
21
|
end
|
25
22
|
end
|
26
23
|
end
|
@@ -3,6 +3,7 @@ module ActiveAdminAddons
|
|
3
3
|
class Engine < ::Rails::Engine
|
4
4
|
require 'select2-rails'
|
5
5
|
initializer "set boolean values addon" do |app|
|
6
|
+
require_relative './support/custom_builder'
|
6
7
|
require_relative './addons/bool_values'
|
7
8
|
require_relative './addons/paperclip_image'
|
8
9
|
require_relative './addons/paperclip_attachment'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveAdminAddons
|
2
|
+
class CustomBuilder
|
3
|
+
attr_accessor :context, :model, :args, :block
|
4
|
+
|
5
|
+
def initialize(context, model, *args, &block)
|
6
|
+
@context = context
|
7
|
+
@model = model
|
8
|
+
@args = *args
|
9
|
+
@block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.render(context, model, *args, &block)
|
16
|
+
new(context, model, *args, &block).render
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def data
|
22
|
+
@data ||= block ? block.call(model) : model.send(attribute)
|
23
|
+
end
|
24
|
+
|
25
|
+
def options
|
26
|
+
@options ||= args.last.is_a?(Hash) ? args.last : {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def attribute
|
30
|
+
@attribute ||= args[1] || args[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platanus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/activeadmin_addons/addons/paperclip_attachment.rb
|
217
217
|
- lib/activeadmin_addons/addons/paperclip_image.rb
|
218
218
|
- lib/activeadmin_addons/engine.rb
|
219
|
+
- lib/activeadmin_addons/support/custom_builder.rb
|
219
220
|
- lib/activeadmin_addons/support/enumerize_formtastic_support.rb
|
220
221
|
- lib/activeadmin_addons/support/set_datepicker.rb
|
221
222
|
- lib/activeadmin_addons/version.rb
|