hera_cms 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/hera_cms/application.js +22 -5
- data/app/assets/stylesheets/hera_cms/application.css +1 -1
- data/app/controllers/hera_cms/images_controller.rb +22 -0
- data/app/helpers/hera_cms/tag_helper.rb +39 -38
- data/app/models/hera_cms/image.rb +5 -1
- data/config/routes.rb +1 -0
- data/lib/generators/hera_cms/templates/config.rb.tt +5 -1
- data/lib/hera_cms.rb +2 -2
- data/lib/hera_cms/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4470fe55d225d68aa2bf7acc64e51bde8313ff8a8ab980fbf3ed026d984d32
|
4
|
+
data.tar.gz: 459ba30e104ccb91cc80e1496467e315655933d2cb6f1a5cde8c43e35f56410e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5131b9167e0854d426538322d39f97c3b5b05fee5a4a4f03a2699e45c0474655b6d0785390de74540069fafe1dc4a716bb2be13d1a4d93e9b4a292891e3753f0
|
7
|
+
data.tar.gz: a5813934ba73b6ef1874f2bbc48846caee3dac3a6dfdf50c0f7cc9773c7d448aead71d20f31d6a2d0177f539e4aa49851c09da44103c53641bb7456db4a14030
|
@@ -151,8 +151,12 @@ const createForm = (e) => {
|
|
151
151
|
case 'links':
|
152
152
|
form = linkForm(form, editable);
|
153
153
|
break;
|
154
|
-
case '
|
155
|
-
|
154
|
+
case 'images':
|
155
|
+
if (editable.dataset['editableUpload'] === "true") {
|
156
|
+
form = imageUploadForm(form, editable);
|
157
|
+
} else {
|
158
|
+
form = imageUrlForm(form, editable);
|
159
|
+
}
|
156
160
|
break;
|
157
161
|
case 'texts':
|
158
162
|
form = textForm(form, editable);
|
@@ -251,24 +255,37 @@ const linkForm = (form, editable) => {
|
|
251
255
|
return form;
|
252
256
|
}
|
253
257
|
|
254
|
-
const
|
258
|
+
const imageUploadForm = (form, editable) => {
|
255
259
|
|
256
260
|
// Creates text input for the content of the element and appends it to the form
|
257
261
|
i = document.createElement("input");
|
258
262
|
i.setAttribute('type', "file");
|
259
|
-
i.setAttribute('name', "
|
263
|
+
i.setAttribute('name', "image[upload]");
|
260
264
|
|
261
265
|
form.appendChild(i);
|
262
266
|
|
263
267
|
i = document.createElement("input");
|
264
268
|
i.setAttribute('type', "hidden");
|
265
|
-
i.setAttribute('name', "
|
269
|
+
i.setAttribute('name', "image[upload_cache]");
|
266
270
|
|
267
271
|
form.appendChild(i);
|
268
272
|
|
269
273
|
return form;
|
270
274
|
}
|
271
275
|
|
276
|
+
const imageUrlForm = (form, editable) => {
|
277
|
+
|
278
|
+
// Creates text input for the content of the element and appends it to the form
|
279
|
+
i = document.createElement("input");
|
280
|
+
i.setAttribute('type', "text");
|
281
|
+
i.setAttribute('name', "image[url]");
|
282
|
+
i.setAttribute('autocomplete', "off");
|
283
|
+
i.setAttribute('value', editable.querySelector('img').src);
|
284
|
+
form.appendChild(i);
|
285
|
+
|
286
|
+
return form;
|
287
|
+
}
|
288
|
+
|
272
289
|
const textForm = (form, editable) => {
|
273
290
|
|
274
291
|
// Creates text input for the content of the element and appends it to the form
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_dependency "hera_cms/application_controller"
|
2
|
+
|
3
|
+
module HeraCms
|
4
|
+
class ImagesController < ApplicationController
|
5
|
+
|
6
|
+
def update
|
7
|
+
@image = HeraCms::Image.find(params[:id])
|
8
|
+
|
9
|
+
if @image.update(image_params)
|
10
|
+
render json: { redirect: URI(request.referer).path }, status: 200
|
11
|
+
else
|
12
|
+
render json: { errors: @image.errors.full_messages }, status: 422
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def image_params
|
19
|
+
params.require(:image).permit(:identifier, :upload, :url, :classes, :style)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -28,8 +28,44 @@ module HeraCms
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def hera_text(identifier, args = {})
|
32
|
+
text = HeraCms::Text.identify(identifier)
|
33
|
+
inner_text, style, identifier = text.inner_text, text.style, text.identifier
|
34
|
+
classes = set_classes(args, text)
|
35
|
+
args[:html_tag] ||= "p"
|
36
|
+
|
37
|
+
html_options = {
|
38
|
+
class: classes,
|
39
|
+
style: style,
|
40
|
+
id: identifier,
|
41
|
+
data: { editable_id: text.id, editable_type: text.model_name.route_key}
|
42
|
+
}
|
43
|
+
return content_tag(args[:html_tag].to_sym, inner_text, html_options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def hera_image(identifier, args = {})
|
47
|
+
image = HeraCms::Image.identify(identifier)
|
48
|
+
identifier, upload, style = image.identifier, image.upload, image.style
|
49
|
+
classes = set_classes(args, image)
|
50
|
+
args[:type] ||= "image"
|
51
|
+
url = HeraCms.active_storage? ? url_for(upload) : image.url
|
52
|
+
|
53
|
+
html_options = {
|
54
|
+
class: classes,
|
55
|
+
style: style,
|
56
|
+
id: identifier,
|
57
|
+
data: { editable_id: image.id, editable_type: image.model_name.route_key, editable_upload: HeraCms.active_storage? }
|
58
|
+
}
|
59
|
+
|
60
|
+
if args[:type] == "video"
|
61
|
+
content_tag(:div, video_tag(url, style: "max-width: 100%; max-height: 100%;"), html_options)
|
62
|
+
else
|
63
|
+
content_tag(:div, image_tag(url, style: "max-width: 100%; max-height: 100%;"), html_options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
31
67
|
# BANNER
|
32
|
-
# def
|
68
|
+
# def hera_image_banner(identifier, args={}, &block)
|
33
69
|
# media = HeraCms::Image.identify(identifier)
|
34
70
|
# identifier, upload, style = media.identifier, media.upload, media.style
|
35
71
|
# classes = set_classes(args, media)
|
@@ -49,42 +85,7 @@ module HeraCms
|
|
49
85
|
# end
|
50
86
|
|
51
87
|
# Assign media to rails helpers for videos and images
|
52
|
-
# def hera_image_tag(identifier, args = {})
|
53
|
-
# media = HeraCms::Image.identify(identifier)
|
54
|
-
# identifier, upload, style = media.identifier, media.upload, media.style
|
55
|
-
# classes = set_classes(args, media)
|
56
|
-
# args[:type] ||= "image"
|
57
|
-
# url = upload.url if upload
|
58
|
-
|
59
|
-
# html_options = {
|
60
|
-
# class: classes,
|
61
|
-
# style: style,
|
62
|
-
# id: identifier,
|
63
|
-
# data: { editable_id: media.id, editable_type: media.model_name.route_key}
|
64
|
-
# }
|
65
|
-
|
66
|
-
# if args[:type] == "video"
|
67
|
-
# content_tag(:div, video_tag(url, style: "max-width: 100%; max-height: 100%;"), html_options)
|
68
|
-
# else
|
69
|
-
# content_tag(:div, image_tag(url, style: "max-width: 100%; max-height: 100%;"), html_options)
|
70
|
-
# end
|
71
|
-
# end
|
72
88
|
|
73
|
-
# Generate HTML tag
|
74
|
-
def hera_text(identifier, args = {})
|
75
|
-
text = Text.identify(identifier)
|
76
|
-
inner_text, style, identifier = text.inner_text, text.style, text.identifier
|
77
|
-
classes = set_classes(args, text)
|
78
|
-
args[:html_tag] ||= "p"
|
79
|
-
|
80
|
-
html_options = {
|
81
|
-
class: classes,
|
82
|
-
style: style,
|
83
|
-
id: identifier,
|
84
|
-
data: { editable_id: text.id, editable_type: text.model_name.route_key}
|
85
|
-
}
|
86
|
-
return content_tag(args[:html_tag].to_sym, inner_text, html_options)
|
87
|
-
end
|
88
89
|
|
89
90
|
# Generate Form Tag
|
90
91
|
# def hera_form(identifier, args = {})
|
@@ -108,13 +109,13 @@ module HeraCms
|
|
108
109
|
# end
|
109
110
|
|
110
111
|
def set_editable(editable)
|
111
|
-
editable.classes += " hera-editable" if editable.editable? && (editable.classes && !editable.classes
|
112
|
+
editable.classes += " hera-editable" if editable.editable? && (editable.classes && !editable.classes&.include?("hera-editable"))
|
112
113
|
end
|
113
114
|
|
114
115
|
def set_classes(args, editable)
|
115
116
|
args[:add_class] ||= ""
|
116
117
|
classes = "#{ args[:class] || editable.classes } #{args[:add_class]}"
|
117
|
-
classes += " hera-editable" unless args[:editable] == false || editable.classes
|
118
|
+
classes += " hera-editable" unless args[:editable] == false || editable.classes&.include?("hera-editable") || !editable.editable?
|
118
119
|
end
|
119
120
|
|
120
121
|
end
|
data/config/routes.rb
CHANGED
data/lib/hera_cms.rb
CHANGED
data/lib/hera_cms/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hera_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rayan Castro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- app/controllers/hera_cms/application_controller.rb
|
149
149
|
- app/controllers/hera_cms/base_controller.rb
|
150
150
|
- app/controllers/hera_cms/dashboard_controller.rb
|
151
|
+
- app/controllers/hera_cms/images_controller.rb
|
151
152
|
- app/controllers/hera_cms/links_controller.rb
|
152
153
|
- app/controllers/hera_cms/texts_controller.rb
|
153
154
|
- app/helpers/hera_cms/application_helper.rb
|