action_admin 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/action_admin/devise/registrations_controller.rb +2 -1
- data/app/controllers/action_admin/shortcodes_controller.rb +23 -0
- data/app/helpers/action_admin/admin_helper.rb +26 -0
- data/app/helpers/action_admin/markup_helper.rb +4 -0
- data/app/inputs/action_admin/attachment_input.rb +23 -10
- data/app/inputs/action_admin/attachments_input.rb +71 -0
- data/app/inputs/action_admin/tinymce_input.rb +5 -4
- data/app/presenters/action_admin/shortcode_presenter.rb +30 -0
- data/app/views/action_admin/shortcodes/form.html.slim +2 -0
- data/app/views/action_admin/shortcodes/preview.html.slim +2 -0
- data/app/views/admin/common/_media_modal.html.slim +1 -1
- data/app/views/admin/common/_shortcode_modal.html.slim +33 -0
- data/app/views/layouts/admin.html.slim +7 -4
- data/app/views/layouts/admin/devise.html.slim +1 -0
- data/app/views/layouts/shortcode.html.slim +7 -0
- data/config/routes.rb +6 -0
- data/lib/action_admin/config.rb +9 -4
- data/lib/action_admin/engine.rb +1 -1
- data/lib/action_admin/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9012703a5f2b71c90cf819ea615adc7a01b4962
|
4
|
+
data.tar.gz: 04d2c416ffd490f115d0a2355c4ca992dd4c7868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2515331cca4dc5faddff423557a13ccffc09270efb4b88422c27747091d1676727cca40c89a11161a9e930885f3759ef54b64864ddc87b4a828d497c54144b
|
7
|
+
data.tar.gz: f8e510880908c0c62abd7a73e5416dc8b268d5ecda0dbc051498406f96817ef011c5fff8b4ce5f15ca3f66c55be0c53ad3098c5bc4956db9da05841410b121be
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActionAdmin
|
2
|
+
class ShortcodesController < ActionController::Base
|
3
|
+
layout nil, except: :preview
|
4
|
+
layout ActionAdmin.config.shortcode_layout, only: :preview
|
5
|
+
|
6
|
+
def list
|
7
|
+
shortcodes = ActionAdmin.config.shortcodes
|
8
|
+
shortcodes.each do |key, value|
|
9
|
+
shortcodes[key][:icon] = "mdi mdi-#{value[:icon]}" if value[:icon].present?
|
10
|
+
end
|
11
|
+
|
12
|
+
render json: shortcodes
|
13
|
+
end
|
14
|
+
|
15
|
+
def form
|
16
|
+
@shortcode = params[:id]
|
17
|
+
end
|
18
|
+
|
19
|
+
def preview
|
20
|
+
@shortcode = params[:shortcode]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -61,5 +61,31 @@ module ActionAdmin
|
|
61
61
|
def admin_search_url
|
62
62
|
url_for merge_params({}, [:per_page, :filter, :sort], params.permit(:per_page, filter: {}, sort: {}).to_h)
|
63
63
|
end
|
64
|
+
|
65
|
+
def admin_shortcode_present(shortcode, presenter=nil)
|
66
|
+
class_name = shortcode.classify
|
67
|
+
presenter = presenter || "Admin::Shortcode::#{class_name}Presenter"
|
68
|
+
presenter = "#{presenter}".safe_constantize || 'ActionAdmin::ShortcodePresenter'.constantize
|
69
|
+
|
70
|
+
presenter.new(shortcode, self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def admin_render_shortcode(string)
|
74
|
+
method(ActionAdmin.config.shortcode_helper).call(string)
|
75
|
+
end
|
76
|
+
|
77
|
+
def admin_shortcode_assets
|
78
|
+
assets = ActionAdmin.config.shortcode_assets.map do |asset|
|
79
|
+
type = asset.split('.').last
|
80
|
+
type == 'css' ? stylesheet_link_tag(asset) : javascript_include_tag(asset)
|
81
|
+
end
|
82
|
+
|
83
|
+
packs = ActionAdmin.config.shortcode_packs.map do |asset|
|
84
|
+
type = asset.split('.').last
|
85
|
+
type == 'css' ? stylesheet_pack_tag(asset) : javascript_pack_tag(asset)
|
86
|
+
end
|
87
|
+
|
88
|
+
assets.join.html_safe + packs.join.html_safe
|
89
|
+
end
|
64
90
|
end
|
65
91
|
end
|
@@ -10,19 +10,32 @@ module ActionAdmin
|
|
10
10
|
def input_placeholder
|
11
11
|
span = content_tag :span, 'No thumbnail', class: 'margin-bottom-1'
|
12
12
|
icon = content_tag :i, nil, class: 'mdi mdi-camera-off'
|
13
|
-
button = content_tag :a, 'Add Thumbnail', data: { open: input_html_id }, class: 'button success small hollow
|
14
|
-
content = content_tag :div, empty_input + icon + span + button, class: 'no-content hide', data: { empty_state: '' }
|
13
|
+
button = content_tag :a, 'Add Thumbnail', data: { open: input_html_id }, class: 'button success small hollow'
|
14
|
+
content = content_tag :div, empty_input + icon + span + button, class: 'no-content panel-section expanded border first last hide', data: { empty_state: '' }
|
15
15
|
image = attachment(attachment_url) if attachment_url.present?
|
16
16
|
|
17
17
|
content + content_tag(:div, image, data: { list_remove: '' }, class: 'attachments')
|
18
18
|
end
|
19
19
|
|
20
|
+
def final_attribute_name
|
21
|
+
if object.is_a? ::ActiveRecord::Base
|
22
|
+
:"#{attribute_name}_id"
|
23
|
+
else
|
24
|
+
:"#{attribute_name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
20
28
|
def empty_input
|
21
|
-
@builder.hidden_field(
|
29
|
+
@builder.hidden_field(final_attribute_name, value: '', id: nil)
|
22
30
|
end
|
23
31
|
|
24
32
|
def hidden_input
|
25
|
-
|
33
|
+
input_options = input_html_options
|
34
|
+
|
35
|
+
input_options[:data] ||= {}
|
36
|
+
input_options[:data][:value] = :id
|
37
|
+
|
38
|
+
@builder.hidden_field(final_attribute_name, input_options)
|
26
39
|
end
|
27
40
|
|
28
41
|
def input_html_id
|
@@ -30,15 +43,15 @@ module ActionAdmin
|
|
30
43
|
end
|
31
44
|
|
32
45
|
def attachment_url
|
33
|
-
object.
|
46
|
+
object.try(attribute_name).try(:file_url, :preview)
|
34
47
|
end
|
35
48
|
|
36
49
|
def attachment(image_url=nil)
|
37
|
-
image
|
38
|
-
remove
|
39
|
-
change
|
40
|
-
remove
|
41
|
-
change
|
50
|
+
image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: 'file.preview.url', url: "#{template.root_url.chomp('/')}[src]" }
|
51
|
+
remove = content_tag :a, 'Remove', class: 'button alert small hollow margin-0', data: { remove: '' }
|
52
|
+
change = content_tag :a, 'Change', class: 'button success small hollow margin-0', data: { open: input_html_id }
|
53
|
+
remove = content_tag :div, remove, class: 'cell auto text-left'
|
54
|
+
change = content_tag :div, change, class: 'cell shrink'
|
42
55
|
buttons = content_tag :div, remove + change, class: 'panel-section expanded border last grid-x'
|
43
56
|
|
44
57
|
content_tag :div, hidden_input + image + buttons, class: 'attachment text-center', data: { list_item: '' }
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ActionAdmin
|
2
|
+
class AttachmentsInput < SimpleForm::Inputs::Base
|
3
|
+
def input(wrapper_options)
|
4
|
+
modal = options.fetch :modal, 'media-modal'
|
5
|
+
html = content_tag :div, input_placeholder, id: input_html_id, data: { media_attach: modal, media_multiple: true }
|
6
|
+
|
7
|
+
html + input_template
|
8
|
+
end
|
9
|
+
|
10
|
+
def input_placeholder
|
11
|
+
span = content_tag :span, 'No media attached', class: 'margin-bottom-1'
|
12
|
+
icon = content_tag :i, nil, class: 'mdi mdi-camera-off'
|
13
|
+
button = content_tag :a, 'Add media', data: { open: input_html_id }, class: 'button success small hollow margin-0'
|
14
|
+
content = content_tag :div, empty_input + icon + span, class: 'no-content hide', data: { empty_state: '' }
|
15
|
+
images = attachments(attachment_urls) if attachment_urls.present?
|
16
|
+
grid = content_tag(:div, images, data: { list_remove: '' }, class: 'attachments-grid removable')
|
17
|
+
|
18
|
+
content + grid + content_tag(:div, button, class: 'panel-section expanded border last')
|
19
|
+
end
|
20
|
+
|
21
|
+
def final_attribute_name
|
22
|
+
if object.is_a? ::ActiveRecord::Base
|
23
|
+
:"#{attribute_name}_ids"
|
24
|
+
else
|
25
|
+
:"#{attribute_name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def empty_input
|
30
|
+
@builder.hidden_field(final_attribute_name, value: '', id: nil, multiple: true)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hidden_input
|
34
|
+
input_options = input_html_options
|
35
|
+
|
36
|
+
input_options[:data] ||= {}
|
37
|
+
input_options[:data][:value] = :id
|
38
|
+
|
39
|
+
@builder.hidden_field(final_attribute_name, input_options.merge(multiple: true))
|
40
|
+
end
|
41
|
+
|
42
|
+
def input_html_id
|
43
|
+
hidden_input[/id=\"(.*)\"/, 1].dasherize
|
44
|
+
end
|
45
|
+
|
46
|
+
def attachment_urls
|
47
|
+
Array(object.try(attribute_name)).map { |a| a.try(:file_url, :small) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def attachments(urls=[])
|
51
|
+
urls.map { |u| attachment(u) }.join.html_safe
|
52
|
+
end
|
53
|
+
|
54
|
+
def attachment(image_url=nil)
|
55
|
+
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' }
|
57
|
+
remove = content_tag :span, nil, class: 'remove-button mdi mdi-close', data: { remove: '' }
|
58
|
+
thumb = content_tag :div, image + filename + remove, class: 'thumbnail'
|
59
|
+
|
60
|
+
content_tag :div, hidden_input + thumb, class: 'attachment', data: { list_item: '' }
|
61
|
+
end
|
62
|
+
|
63
|
+
def input_template
|
64
|
+
content_tag :script, attachment, id: "#{input_html_id}-item-template", type: 'text/template'
|
65
|
+
end
|
66
|
+
|
67
|
+
def label(wrapper_options)
|
68
|
+
''
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -5,10 +5,11 @@ module ActionAdmin
|
|
5
5
|
input_html_options[:data].merge!({
|
6
6
|
tiny_mce_editor: '',
|
7
7
|
content_css: template.asset_path('admin/tinymce-editor.css'),
|
8
|
-
media_handler: 'media-modal',
|
9
|
-
media_src: "file.large.url",
|
10
|
-
media_alt: "name",
|
11
|
-
media_url: "[src]",
|
8
|
+
# media_handler: 'media-modal',
|
9
|
+
# media_src: "file.large.url",
|
10
|
+
# media_alt: "name",
|
11
|
+
# media_url: "[src]",
|
12
|
+
shortcode_handler: 'shortcode-modal',
|
12
13
|
convert_urls: false
|
13
14
|
})
|
14
15
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActionAdmin
|
2
|
+
class ShortcodePresenter
|
3
|
+
include ActionAdmin::Presentable
|
4
|
+
|
5
|
+
def initialize(shortcode, context)
|
6
|
+
@shortcode = shortcode
|
7
|
+
@context = context
|
8
|
+
end
|
9
|
+
|
10
|
+
def fields
|
11
|
+
self.record_fields
|
12
|
+
end
|
13
|
+
|
14
|
+
def render_field(form, field, options={})
|
15
|
+
options = Hash(options)
|
16
|
+
|
17
|
+
options[:input_html] ||= {}
|
18
|
+
options[:input_html][:data] ||= {}
|
19
|
+
|
20
|
+
options[:input_html][:data][:attribute] = field
|
21
|
+
options[:input_html][:include_hidden] = false
|
22
|
+
|
23
|
+
form.input field, options
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_fields(form)
|
27
|
+
fields.map { |f, o| render_field(form, f, o) }.join.html_safe
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -9,7 +9,7 @@ ruby:
|
|
9
9
|
thumbnail_width: "300"
|
10
10
|
}
|
11
11
|
|
12
|
-
#media-modal.reveal.full.reveal-panel.media-reveal data-media-reveal="" data-media-url=admin_media_url(per_page: 10000, format: :json)
|
12
|
+
#media-modal.reveal.full.reveal-panel.media-reveal data-media-reveal="" data-multiple-opened="true" data-media-url=admin_media_url(per_page: 10000, format: :json)
|
13
13
|
.panel
|
14
14
|
.panel-header.border
|
15
15
|
= 'Add Media'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
ruby:
|
2
|
+
list_url = admin.shortcode_list_url
|
3
|
+
form_url = URI.unescape admin.shortcode_form_url(id: '[name]')
|
4
|
+
preview_url = URI.unescape admin.shortcode_preview_url(id: '[name]')
|
5
|
+
|
6
|
+
#shortcode-modal.reveal.full.reveal-panel.shortcode-reveal data-shortcode-reveal="" data-multiple-opened="true" data-form-url=form_url data-preview-url=preview_url data-shortcodes-url=list_url
|
7
|
+
.panel
|
8
|
+
.panel-header.border
|
9
|
+
= 'Add Shortcode'
|
10
|
+
button.close-button aria-label="Close modal" data-close="" type="button"
|
11
|
+
span aria-hidden="true" ×
|
12
|
+
|
13
|
+
.panel-content.border.padding-0
|
14
|
+
.shortcode-columns
|
15
|
+
.shortcode-menu data-menu=""
|
16
|
+
|
17
|
+
.shortcode-preview
|
18
|
+
.shortcode-inner
|
19
|
+
div.shortcode-content data-preview=""
|
20
|
+
.no-content data-empty=""
|
21
|
+
= admin_icon 'eye-off'
|
22
|
+
span = 'No preview available'
|
23
|
+
|
24
|
+
.shortcode-form
|
25
|
+
h4.shortcode-title = 'Customize'
|
26
|
+
div.shortcode-content data-form=""
|
27
|
+
|
28
|
+
.panel-footer
|
29
|
+
.grid-x
|
30
|
+
.cell.auto
|
31
|
+
button.button.hollow.alert.margin-0 aria-label="Close modal" data-close="" type="button" = 'Close'
|
32
|
+
.cell.shrink
|
33
|
+
button.button.margin-0 aria-label="Insert Shortcode" data-insert="" type="button" = 'Insert'
|
@@ -6,11 +6,12 @@ html
|
|
6
6
|
= csrf_meta_tags
|
7
7
|
= favicon_link_tag 'admin/favicon.png'
|
8
8
|
= stylesheet_link_tag 'admin/application', media: 'all'
|
9
|
+
script = '/** ActionAdmin **/'
|
9
10
|
|
10
11
|
body
|
11
|
-
.off-canvas-wrapper
|
12
|
+
.off-canvas-wrapper data-resize-watcher=""
|
12
13
|
.off-canvas-menu-wrapper.off-canvas-content data-off-canvas-content=""
|
13
|
-
#sidebar.off-canvas-menu.position-left data-off-canvas-menu=""
|
14
|
+
#sidebar.off-canvas-menu.position-left data-off-canvas-menu="" class=admin_sidebar_status
|
14
15
|
= render 'admin/common/sidebar'
|
15
16
|
|
16
17
|
.off-canvas-menu-content data-off-canvas-content=""
|
@@ -20,10 +21,12 @@ html
|
|
20
21
|
= render 'admin/common/header'
|
21
22
|
= yield
|
22
23
|
= render 'admin/common/footer'
|
23
|
-
= render 'admin/common/media_modal'
|
24
|
-
= render 'admin/common/dropzone_template'
|
25
24
|
|
26
25
|
#offcanvas.off-canvas.position-right data-off-canvas=""
|
27
26
|
= render 'admin/common/messagebar'
|
28
27
|
|
28
|
+
= render 'admin/common/media_modal'
|
29
|
+
= render 'admin/common/shortcode_modal'
|
30
|
+
= render 'admin/common/dropzone_template'
|
31
|
+
|
29
32
|
= javascript_include_tag 'admin/application'
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
1
|
ActionAdmin::Engine.routes.draw do
|
2
2
|
root 'action_admin/welcome#index'
|
3
|
+
|
4
|
+
scope :shortcodes do
|
5
|
+
get 'list', to: 'action_admin/shortcodes#list', as: :shortcode_list
|
6
|
+
get 'form/:id', to: 'action_admin/shortcodes#form', as: :shortcode_form
|
7
|
+
get 'preview/:id', to: 'action_admin/shortcodes#preview', as: :shortcode_preview
|
8
|
+
end
|
3
9
|
end
|
data/lib/action_admin/config.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
module ActionAdmin
|
2
2
|
class Config < Hashie::Dash
|
3
|
-
property :app_name,
|
4
|
-
property :app_urls,
|
5
|
-
property :admin_locale,
|
6
|
-
property :menus,
|
3
|
+
property :app_name, default: 'Action Admin'
|
4
|
+
property :app_urls, default: :web_url
|
5
|
+
property :admin_locale, default: :en
|
6
|
+
property :menus, default: Hashie::Mash.new
|
7
|
+
property :shortcodes, default: Hashie::Mash.new
|
8
|
+
property :shortcode_helper, default: :render_shortcode
|
9
|
+
property :shortcode_layout, default: 'shortcode'
|
10
|
+
property :shortcode_assets, default: ['application.css', 'application.js']
|
11
|
+
property :shortcode_packs, default: []
|
7
12
|
|
8
13
|
def menu(name, &block)
|
9
14
|
if self.menus.send(:"#{name}").nil?
|
data/lib/action_admin/engine.rb
CHANGED
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.7
|
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-
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- app/controllers/action_admin/devise/registrations_controller.rb
|
191
191
|
- app/controllers/action_admin/devise/sessions_controller.rb
|
192
192
|
- app/controllers/action_admin/devise/unlocks_controller.rb
|
193
|
+
- app/controllers/action_admin/shortcodes_controller.rb
|
193
194
|
- app/controllers/action_admin/welcome_controller.rb
|
194
195
|
- app/controllers/concerns/action_admin/actionable.rb
|
195
196
|
- app/controllers/concerns/action_admin/controller.rb
|
@@ -198,6 +199,7 @@ files:
|
|
198
199
|
- app/helpers/action_admin/form_helper.rb
|
199
200
|
- app/helpers/action_admin/markup_helper.rb
|
200
201
|
- app/inputs/action_admin/attachment_input.rb
|
202
|
+
- app/inputs/action_admin/attachments_input.rb
|
201
203
|
- app/inputs/action_admin/select_list_input.rb
|
202
204
|
- app/inputs/action_admin/seo_analysis_input.rb
|
203
205
|
- app/inputs/action_admin/slug_input.rb
|
@@ -207,6 +209,7 @@ files:
|
|
207
209
|
- app/inputs/action_admin/toggle_input.rb
|
208
210
|
- app/inputs/action_admin/upload_input.rb
|
209
211
|
- app/presenters/action_admin/presenter.rb
|
212
|
+
- app/presenters/action_admin/shortcode_presenter.rb
|
210
213
|
- app/presenters/concerns/action_admin/presentable.rb
|
211
214
|
- app/views/action_admin/devise/confirmations/new.html.slim
|
212
215
|
- app/views/action_admin/devise/passwords/edit.html.slim
|
@@ -216,6 +219,8 @@ files:
|
|
216
219
|
- app/views/action_admin/devise/sessions/new.html.slim
|
217
220
|
- app/views/action_admin/devise/shared/_links.html.slim
|
218
221
|
- app/views/action_admin/devise/unlocks/new.html.slim
|
222
|
+
- app/views/action_admin/shortcodes/form.html.slim
|
223
|
+
- app/views/action_admin/shortcodes/preview.html.slim
|
219
224
|
- app/views/action_admin/welcome/index.html.slim
|
220
225
|
- app/views/admin/common/_alerts.html.slim
|
221
226
|
- app/views/admin/common/_dropzone_template.html.slim
|
@@ -225,6 +230,7 @@ files:
|
|
225
230
|
- app/views/admin/common/_media_modal.html.slim
|
226
231
|
- app/views/admin/common/_messagebar.html.slim
|
227
232
|
- app/views/admin/common/_noresults.html.slim
|
233
|
+
- app/views/admin/common/_shortcode_modal.html.slim
|
228
234
|
- app/views/admin/common/_sidebar.html.slim
|
229
235
|
- app/views/admin/common/_topbar.html.slim
|
230
236
|
- app/views/admin/common/action.html.slim
|
@@ -244,6 +250,7 @@ files:
|
|
244
250
|
- app/views/admin/templates/_upload.html.slim
|
245
251
|
- app/views/layouts/admin.html.slim
|
246
252
|
- app/views/layouts/admin/devise.html.slim
|
253
|
+
- app/views/layouts/shortcode.html.slim
|
247
254
|
- config/initializers/admin_simple_form.rb
|
248
255
|
- config/initializers/simple_attribute.rb
|
249
256
|
- config/routes.rb
|