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 +5 -5
- data/app/controllers/action_admin/shortcodes_controller.rb +2 -1
- data/app/helpers/action_admin/markup_helper.rb +2 -2
- data/app/inputs/action_admin/attachment_input.rb +14 -1
- data/app/inputs/action_admin/attachments_input.rb +20 -7
- data/app/inputs/action_admin/textarea_input.rb +13 -0
- data/app/views/action_admin/shortcodes/form.html.slim +2 -2
- data/app/views/admin/templates/_settings.html.slim +6 -18
- data/lib/action_admin.rb +1 -0
- data/lib/action_admin/shortcode.rb +53 -0
- data/lib/action_admin/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c77406bd753e915216a297463d96665a366cc77a3b11fa90062fee7effeea727
|
4
|
+
data.tar.gz: b5f009f61c75d7c09306116c785e36d2cf063868f00949499290e9c01a18af03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb6f0321c070337c08ac66251e9ad6a0a315218a06098bd7224c16450579b45b1b77744d8b1bd253722699a291825900ba59a4531c97fdbfacb78a68d6b9606
|
7
|
+
data.tar.gz: b9cc52e4b2941a03044d13482fa7b495f0bca6bde4a9c85e9419ca8289a46b8e4870c3ce1a411e3b81eff4e5ea2d6c235fe8e50409c072c63c46fd41674c5361
|
@@ -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
|
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
|
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
|
-
|
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
|
-
|
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,
|
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(
|
2
|
-
=
|
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
|
-
|
5
|
-
|
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
|
-
|
22
|
-
|
7
|
+
.content
|
8
|
+
= f.error_notification
|
9
|
+
= admin_present(current_record).render_panels(form: f)
|
10
|
+
= f.button :submit
|
data/lib/action_admin.rb
CHANGED
@@ -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
|
data/lib/action_admin/version.rb
CHANGED
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.
|
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:
|
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.
|
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
|