action_admin 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a9012703a5f2b71c90cf819ea615adc7a01b4962
4
- data.tar.gz: 04d2c416ffd490f115d0a2355c4ca992dd4c7868
2
+ SHA256:
3
+ metadata.gz: c77406bd753e915216a297463d96665a366cc77a3b11fa90062fee7effeea727
4
+ data.tar.gz: b5f009f61c75d7c09306116c785e36d2cf063868f00949499290e9c01a18af03
5
5
  SHA512:
6
- metadata.gz: 4a2515331cca4dc5faddff423557a13ccffc09270efb4b88422c27747091d1676727cca40c89a11161a9e930885f3759ef54b64864ddc87b4a828d497c54144b
7
- data.tar.gz: f8e510880908c0c62abd7a73e5416dc8b268d5ecda0dbc051498406f96817ef011c5fff8b4ce5f15ca3f66c55be0c53ad3098c5bc4956db9da05841410b121be
6
+ metadata.gz: 4eb6f0321c070337c08ac66251e9ad6a0a315218a06098bd7224c16450579b45b1b77744d8b1bd253722699a291825900ba59a4531c97fdbfacb78a68d6b9606
7
+ data.tar.gz: b9cc52e4b2941a03044d13482fa7b495f0bca6bde4a9c85e9419ca8289a46b8e4870c3ce1a411e3b81eff4e5ea2d6c235fe8e50409c072c63c46fd41674c5361
@@ -13,7 +13,8 @@ module ActionAdmin
13
13
  end
14
14
 
15
15
  def form
16
- @shortcode = params[:id]
16
+ @presenter = helpers.admin_shortcode_present(params[:id])
17
+ @shortcode = ActionAdmin::Shortcode.new(params, @presenter.fields)
17
18
  end
18
19
 
19
20
  def preview
@@ -29,7 +29,7 @@ module ActionAdmin
29
29
 
30
30
  def admin_settings_menu(records, label_method=:id)
31
31
  options = {
32
- menu_class: 'menu horizontal',
32
+ menu_class: 'vertical menu icons icon-left',
33
33
  active_class: 'active',
34
34
  keep_defaults: false
35
35
  }
@@ -38,7 +38,7 @@ module ActionAdmin
38
38
  label = record.send(label_method)
39
39
  url = edit_record_url(record)
40
40
 
41
- [:"#{label.downcase.underscore}", { label: label, url: url, html: { class: 'padding-1' } }]
41
+ [:"#{label.downcase.underscore}", { label: label, url: url }]
42
42
  end
43
43
 
44
44
  smart_navigation_for Hash[items], options
@@ -43,7 +43,20 @@ module ActionAdmin
43
43
  end
44
44
 
45
45
  def attachment_url
46
- object.try(attribute_name).try(:file_url, :preview)
46
+ medium = nil
47
+
48
+ if object.is_a? ::ActiveRecord::Base
49
+ medium = object.try(attribute_name)
50
+ elsif options[:model_name]
51
+ media_model = "#{options[:model_name]}".safe_constantize
52
+
53
+ if media_model.present?
54
+ attval = object.send(attribute_name) rescue nil
55
+ medium = media_model.find_by_id(attval)
56
+ end
57
+ end
58
+
59
+ medium.try(:file_url, :preview)
47
60
  end
48
61
 
49
62
  def attachment(image_url=nil)
@@ -30,13 +30,13 @@ module ActionAdmin
30
30
  @builder.hidden_field(final_attribute_name, value: '', id: nil, multiple: true)
31
31
  end
32
32
 
33
- def hidden_input
33
+ def hidden_input(image_id=nil)
34
34
  input_options = input_html_options
35
35
 
36
36
  input_options[:data] ||= {}
37
37
  input_options[:data][:value] = :id
38
38
 
39
- @builder.hidden_field(final_attribute_name, input_options.merge(multiple: true))
39
+ @builder.hidden_field(final_attribute_name, input_options.merge(multiple: true, value: image_id))
40
40
  end
41
41
 
42
42
  def input_html_id
@@ -44,20 +44,33 @@ module ActionAdmin
44
44
  end
45
45
 
46
46
  def attachment_urls
47
- Array(object.try(attribute_name)).map { |a| a.try(:file_url, :small) }
47
+ media = nil
48
+
49
+ if object.is_a? ::ActiveRecord::Base
50
+ media = object.try(attribute_name)
51
+ elsif options[:model_name]
52
+ media_model = "#{options[:model_name]}".safe_constantize
53
+
54
+ if media_model.present?
55
+ attval = object.send(attribute_name) rescue nil
56
+ media = media_model.where(id: attval)
57
+ end
58
+ end
59
+
60
+ Array(media).map { |a| [a.try(:id), a.try(:file_url, :small), a.try(:name)] }
48
61
  end
49
62
 
50
63
  def attachments(urls=[])
51
- urls.map { |u| attachment(u) }.join.html_safe
64
+ urls.map { |u| attachment(*u) }.join.html_safe
52
65
  end
53
66
 
54
- def attachment(image_url=nil)
67
+ def attachment(image_id=nil, image_url=nil, image_name=nil)
55
68
  image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: 'file.small.url', url: "#{template.root_url.chomp('/')}[src]" }
56
- filename = content_tag :span, nil, class: 'filename', data: { text: 'name' }
69
+ filename = content_tag :span, image_name, class: 'filename', data: { text: 'name' }
57
70
  remove = content_tag :span, nil, class: 'remove-button mdi mdi-close', data: { remove: '' }
58
71
  thumb = content_tag :div, image + filename + remove, class: 'thumbnail'
59
72
 
60
- content_tag :div, hidden_input + thumb, class: 'attachment', data: { list_item: '' }
73
+ content_tag :div, hidden_input(image_id) + thumb, class: 'attachment', data: { list_item: '' }
61
74
  end
62
75
 
63
76
  def input_template
@@ -0,0 +1,13 @@
1
+ module ActionAdmin
2
+ class TextareaInput < SimpleForm::Inputs::TextInput
3
+ def input(wrapper_options)
4
+ input_html_options[:data] ||= {}
5
+ input_html_options[:data].merge!({
6
+ textarea: '',
7
+ resize_icon: 'mce-ico mce-i-resize'
8
+ })
9
+
10
+ super
11
+ end
12
+ end
13
+ end
@@ -1,2 +1,2 @@
1
- = admin_form_for(:"#{@shortcode}", url: root_url, method: :get) do |f|
2
- = admin_shortcode_present(@shortcode).render_fields(f)
1
+ = admin_form_for(@shortcode, url: root_url, method: :get) do |f|
2
+ = @presenter.render_fields(f)
@@ -1,22 +1,10 @@
1
1
  = admin_form_for([:admin, current_record]) do |f|
2
- = f.error_notification
3
2
 
4
- / .page-content
5
- / .sidebar
6
- / .panel
7
- / .panel-header.border
8
- / = 'Menu'
9
- /
10
- / .panel-content
11
- / = admin_settings_menu collection, label_method
12
- /
13
- / .content
14
- / = admin_present(current_record).render_panels(form: f)
15
- / = f.button :submit
16
-
17
- .panel
18
- .panel-content.padding-0
3
+ .page-content
4
+ .sidebar
19
5
  = admin_settings_menu collection, label_method
20
6
 
21
- = admin_present(current_record).render_panels(form: f)
22
- = f.button :submit
7
+ .content
8
+ = f.error_notification
9
+ = admin_present(current_record).render_panels(form: f)
10
+ = f.button :submit
@@ -16,6 +16,7 @@ module ActionAdmin
16
16
  autoload :Form
17
17
  autoload :Header
18
18
  autoload :Table
19
+ autoload :Shortcode
19
20
 
20
21
  # Set attr accessors
21
22
  mattr_accessor :config
@@ -0,0 +1,53 @@
1
+ module ActionAdmin
2
+ class Shortcode
3
+ # Initializes the decorator
4
+ def initialize(params, attribs={})
5
+ attribs = Hash[attribs.map { |k, _v| [k, nil] }].symbolize_keys
6
+ string = URI.decode(params[:shortcode])
7
+
8
+ @field = params[:id]
9
+ @object = parse_shortcode_attr(string, attribs)
10
+ end
11
+
12
+ # Sets the model name
13
+ def model_name
14
+ ActiveModel::Name.new(self.class, nil, @field)
15
+ end
16
+
17
+ # Delegates to the wrapped object
18
+ def method_missing(method, *args, &block)
19
+ if @object.key? method
20
+ @object[method]
21
+ elsif @object.respond_to? method
22
+ @object.send(method, *args, &block)
23
+ end
24
+ end
25
+
26
+ # Check if attribute exists
27
+ def has_attribute?(attribute)
28
+ @object.key? attribute
29
+ end
30
+
31
+ private
32
+
33
+ # Checks if shortcode string is valid
34
+ def valid_shortcode?(string)
35
+ "#{string}".strip.match(/^\[(\w+) (.+?)\]$/).present? and
36
+ parse_shortcode_field(string) == "#{@field}"
37
+ end
38
+
39
+ # Parses shortcode string and returns field name
40
+ def parse_shortcode_field(string)
41
+ "#{string}".match(/^\[(\w+) /).captures.first
42
+ end
43
+
44
+ # Parses shortcode string and returns attributes
45
+ def parse_shortcode_attr(string, attribs)
46
+ found = Hash["#{string}".scan(/(\w+)="([^"]+)"/)].symbolize_keys
47
+ valid = found.select { |k, _v| k.in? attribs.keys }
48
+ valid = Hash[valid.map { |k, v| k == :ids ? [k, v.split(',').map(&:strip)] : [k, v] }]
49
+
50
+ valid_shortcode?(string) ? attribs.merge(valid) : attribs
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module ActionAdmin
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -204,6 +204,7 @@ files:
204
204
  - app/inputs/action_admin/seo_analysis_input.rb
205
205
  - app/inputs/action_admin/slug_input.rb
206
206
  - app/inputs/action_admin/tag_list_input.rb
207
+ - app/inputs/action_admin/textarea_input.rb
207
208
  - app/inputs/action_admin/tinymce_input.rb
208
209
  - app/inputs/action_admin/title_input.rb
209
210
  - app/inputs/action_admin/toggle_input.rb
@@ -263,6 +264,7 @@ files:
263
264
  - lib/action_admin/form/minimal_builder.rb
264
265
  - lib/action_admin/header.rb
265
266
  - lib/action_admin/routes.rb
267
+ - lib/action_admin/shortcode.rb
266
268
  - lib/action_admin/table.rb
267
269
  - lib/action_admin/version.rb
268
270
  - lib/tasks/action_admin_tasks.rake
@@ -286,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
288
  version: '0'
287
289
  requirements: []
288
290
  rubyforge_project:
289
- rubygems_version: 2.6.14
291
+ rubygems_version: 2.7.3
290
292
  signing_key:
291
293
  specification_version: 4
292
294
  summary: Ruby on Rails mountable engine to create admin interfaces