activeadmin_addons 0.1.0 → 0.2.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: beddbc0bff10eff87f32a88d3f39efb756dd82b1
4
- data.tar.gz: 0e49d15370800ab92548bc22518388dc98f5bb24
3
+ metadata.gz: 95f4ecae57fd54f1e3c6ebbbc25a870edaa609f6
4
+ data.tar.gz: 9a4e30551e31e85c7a87df7b681047ce572bdfea
5
5
  SHA512:
6
- metadata.gz: c0f94ca68da948c446ed8531493ea9fee5e89db4be300489e38347febad58c993545a5b2c56b868b6699f42cf1493d64b3be231c143a64361a0c14f3c139c1e2
7
- data.tar.gz: def44ec50b4acfb1734780c0f513a602098cb0baeecb6bfec99d765edf3bd099fd13263d5b3ddb64d7c98a7190213a46f8808a22ea8aa923830812ba938bdd28
6
+ metadata.gz: fce96305288148f953886678e488912961579ed2ede09f2eea92f7c661722e49c7010840a61ee12b6bc33b336be42973e3ee531aa499d353abf53bb6a274b70e
7
+ data.tar.gz: caa5401737347ebf0f2a820efcf643c4dd3885a41bc5e12183eccc51a488e8008f27992545850036df690492f8b20930fda973d56fc26f6a93c5edc0c5c31c6d
@@ -0,0 +1,71 @@
1
+ module ActiveAdminAddons
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
7
+
8
+ def array_list(ctx, model, attribute, options)
9
+ items = model.send(attribute)
10
+ ctx.content_tag(options[:list_type]) do
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
17
+
18
+ def hash_list(ctx, model, attribute, options)
19
+ items = model.send(attribute)
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}:&nbsp".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
39
+
40
+ def list(ctx, model, attribute, options)
41
+ options[:localize] = options.fetch(:localize, false)
42
+ options[:list_type] = options.fetch(:list_type, :ul)
43
+ raise 'invalid list type (ul, ol)' unless [:ul, :ol].include?(options[:list_type])
44
+
45
+ items = model.send(attribute)
46
+
47
+ if !items.is_a?(Hash) && !items.is_a?(Array)
48
+ rails "list must be Array or Hash"
49
+ end
50
+
51
+ return array_list(ctx, model, attribute, options) if items.is_a?(Array)
52
+ hash_list(ctx, model, attribute, options)
53
+ end
54
+ end
55
+ end
56
+
57
+ module ::ActiveAdmin
58
+ module Views
59
+ class TableFor
60
+ def list_column(attribute, options = {})
61
+ column(attribute) { |model| ListHelper.list(self, model, attribute, options) }
62
+ end
63
+ end
64
+ class AttributesTable
65
+ def list_row(attribute, options = {})
66
+ row(attribute) { |model| ListHelper.list(self, model, attribute, options) }
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,39 @@
1
+ module ActiveAdminAddons
2
+ module NumberHelper
3
+ class << self
4
+ NUMBER_TYPES = {
5
+ currency: :number_to_currency,
6
+ human: :number_to_human,
7
+ human_size: :number_to_human_size,
8
+ percentage: :number_to_percentage,
9
+ phone: :number_to_phone,
10
+ delimiter: :number_with_delimiter,
11
+ precision: :number_with_precision
12
+ }
13
+
14
+ def label(context, model, attribute, options)
15
+ options[:as] = options.fetch(:as, :delimiter)
16
+ if !NUMBER_TYPES.keys.include?(options[:as])
17
+ raise "Invalid number type. Options are: #{NUMBER_TYPES.keys.to_s}"
18
+ end
19
+ number = model.send(attribute)
20
+ context.send(NUMBER_TYPES[options[:as]], number, options)
21
+ end
22
+ end
23
+ end
24
+
25
+ module ::ActiveAdmin
26
+ module Views
27
+ class TableFor
28
+ def number_column(attribute, options = {})
29
+ column(attribute) { |model| NumberHelper.label(self, model, attribute, options) }
30
+ end
31
+ end
32
+ class AttributesTable
33
+ def number_row(attribute, options = {})
34
+ row(attribute) { |model| NumberHelper.label(self, model, attribute, options) }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -22,15 +22,17 @@ module ActiveAdminAddons
22
22
  end
23
23
 
24
24
  def link(context, model, attribute, options)
25
+ options[:truncate] = options.fetch(:truncate, true)
25
26
  doc = model.send(attribute)
26
27
  raise 'you need to pass a paperclip attribute' unless doc.respond_to?(:url)
27
28
 
28
29
  icon = icon_for_filename(doc.original_filename)
29
30
  icon_img = context.image_tag(icon, width: "20", height: "20", style: "margin-right: 5px; vertical-align: middle;")
30
31
  file_name = (options[:truncate] == true) ? context.truncate(doc.original_filename) : doc.original_filename
32
+ label_text = options.fetch(:label, file_name)
31
33
  label = context.content_tag(:span) do
32
34
  context.concat(icon_img)
33
- context.safe_concat(file_name)
35
+ context.safe_concat(label_text)
34
36
  end
35
37
 
36
38
  context.link_to(label, doc.url, { target: "_blank" }) if doc.exists?
@@ -42,13 +44,11 @@ module ActiveAdminAddons
42
44
  module Views
43
45
  class TableFor
44
46
  def attachment_column(attribute, options = {})
45
- options[:truncate] = options.fetch(:truncate, true)
46
47
  column(attribute) { |model| PaperclipAttachment.link(self, model, attribute, options) }
47
48
  end
48
49
  end
49
50
  class AttributesTable
50
51
  def attachment_row(attribute, options = {})
51
- options[:truncate] = options.fetch(:truncate, false)
52
52
  row(attribute) { |model| PaperclipAttachment.link(self, model, attribute, options) }
53
53
  end
54
54
  end
@@ -3,11 +3,14 @@ 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 './set_datepicker'
7
6
  require_relative './addons/bool_values'
8
7
  require_relative './addons/paperclip_image'
9
8
  require_relative './addons/paperclip_attachment'
10
9
  require_relative './addons/enum_tag'
10
+ require_relative './addons/number'
11
+ require_relative './addons/list'
12
+ require_relative './support/enumerize_formtastic_support'
13
+ require_relative './support/set_datepicker'
11
14
  app.config.assets.precompile += %w(select.scss)
12
15
  end
13
16
  end
@@ -0,0 +1,24 @@
1
+ module ActiveAdminAddons
2
+ module RansackFormBuilderExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method_chain :input, :ransack
7
+ end
8
+
9
+ def input_with_ransack(method, options={})
10
+ if object.is_a?(::Ransack::Search)
11
+ klass = object.klass
12
+
13
+ if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[method])
14
+ options[:collection] ||= attr.options
15
+ options[:as] = :select
16
+ end
17
+ end
18
+
19
+ input_without_ransack(method, options)
20
+ end
21
+ end
22
+ end
23
+
24
+ ::Formtastic::FormBuilder.send :include, ActiveAdminAddons::RansackFormBuilderExtension
@@ -1,3 +1,3 @@
1
1
  module ActiveadminAddons
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platanus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-08 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -211,10 +211,13 @@ files:
211
211
  - app/inputs/tags_input.rb
212
212
  - lib/activeadmin_addons/addons/bool_values.rb
213
213
  - lib/activeadmin_addons/addons/enum_tag.rb
214
+ - lib/activeadmin_addons/addons/list.rb
215
+ - lib/activeadmin_addons/addons/number.rb
214
216
  - lib/activeadmin_addons/addons/paperclip_attachment.rb
215
217
  - lib/activeadmin_addons/addons/paperclip_image.rb
216
218
  - lib/activeadmin_addons/engine.rb
217
- - lib/activeadmin_addons/set_datepicker.rb
219
+ - lib/activeadmin_addons/support/enumerize_formtastic_support.rb
220
+ - lib/activeadmin_addons/support/set_datepicker.rb
218
221
  - lib/activeadmin_addons/version.rb
219
222
  - lib/activeadmin_addons.rb
220
223
  - lib/tasks/activeadmin_addons_tasks.rake