hera_cms 0.3.0 → 0.4.0

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
2
  SHA256:
3
- metadata.gz: 5aa9efe0f53f57f3455978481d5b469a58b470f651db6c9b9de10167bdd6910e
4
- data.tar.gz: b5ed7cb6d61b33f38d40448a12737ccc95aa577f240f2970872edd95de9814e2
3
+ metadata.gz: 7f4470fe55d225d68aa2bf7acc64e51bde8313ff8a8ab980fbf3ed026d984d32
4
+ data.tar.gz: 459ba30e104ccb91cc80e1496467e315655933d2cb6f1a5cde8c43e35f56410e
5
5
  SHA512:
6
- metadata.gz: 6f1d9b6b41a4e272cb4df3e1a84aba88d10ec26f10458c42206f12af256c7db0451642e0767720d6eb1d5e0ffffc56bf77feef62b9a498526c41102ba568e1ed
7
- data.tar.gz: '0798a46a9aa7ed5d8dd557e1cd37a82be450d17fbc852cacf89fa4071248a396672376581d3120f1ed12ea84f51c966490a1222f2318f8028c84772037a6687f'
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 'media_index':
155
- form = imageForm(form, editable);
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 imageForm = (form, editable) => {
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', "media[upload]");
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', "media[upload_cache]");
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
@@ -82,7 +82,7 @@
82
82
  .hera-highlight-layer{
83
83
  position: relative;
84
84
  z-index: 6;
85
- background: #F5F5F5;
85
+ background: #F5F5F5 !important;
86
86
  transition: .5s;
87
87
  padding: 5px;
88
88
  border-radius: 3px;
@@ -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 hera_media_banner(identifier, args={}, &block)
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.include?("hera-editable"))
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.include?("hera-editable") || !editable.editable?
118
+ classes += " hera-editable" unless args[:editable] == false || editable.classes&.include?("hera-editable") || !editable.editable?
118
119
  end
119
120
 
120
121
  end
@@ -1,6 +1,10 @@
1
1
  module HeraCms
2
2
  class Image < ApplicationRecord
3
3
  validates :identifier, presence: true, uniqueness: true
4
-
4
+ if HeraCms.active_storage?
5
+ has_one_attached :upload
6
+ else
7
+ validates :url, presence: true
8
+ end
5
9
  end
6
10
  end
data/config/routes.rb CHANGED
@@ -3,4 +3,5 @@ HeraCms::Engine.routes.draw do
3
3
 
4
4
  resources :links, only: :update
5
5
  resources :texts, only: :update
6
+ resources :images, only: :update
6
7
  end
@@ -1,2 +1,6 @@
1
- # see https://github.com/horta-tech/iris_cms for more info
1
+ # see https://github.com/horta-tech/hera_cms for more info
2
2
 
3
+ HeraCms.setup do |config|
4
+ # config.image_upload = true
5
+ # config.upload_service = :active_storage
6
+ end
data/lib/hera_cms.rb CHANGED
@@ -22,8 +22,8 @@ module HeraCms
22
22
  yield self
23
23
  end
24
24
 
25
- def self.test
26
- return "Successful"
25
+ def self.active_storage?
26
+ self.image_upload && ["active_storage", :active_storage].include?(self.upload_service&.downcase)
27
27
  end
28
28
  end
29
29
 
@@ -1,3 +1,3 @@
1
1
  module HeraCms
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
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.3.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-23 00:00:00.000000000 Z
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