hera_cms 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +67 -0
  4. data/Rakefile +22 -0
  5. data/app/assets/config/hera_cms_manifest.js +1 -0
  6. data/app/assets/images/hera_cms/hera_white.png +0 -0
  7. data/app/assets/javascripts/hera_cms/application.js +1 -0
  8. data/app/assets/stylesheets/hera_cms/application.css +154 -0
  9. data/app/assets/stylesheets/hera_cms/links.css +4 -0
  10. data/app/controllers/hera_cms/application_controller.rb +5 -0
  11. data/app/controllers/hera_cms/base_controller.rb +9 -0
  12. data/app/controllers/hera_cms/dashboard_controller.rb +6 -0
  13. data/app/controllers/hera_cms/links_controller.rb +56 -0
  14. data/app/helpers/hera_cms/application_helper.rb +4 -0
  15. data/app/helpers/hera_cms/links_helper.rb +4 -0
  16. data/app/helpers/hera_cms/tag_helper.rb +121 -0
  17. data/app/jobs/hera_cms/application_job.rb +4 -0
  18. data/app/mailers/hera_cms/application_mailer.rb +6 -0
  19. data/app/models/hera_cms/application_record.rb +31 -0
  20. data/app/models/hera_cms/image.rb +7 -0
  21. data/app/models/hera_cms/link.rb +8 -0
  22. data/app/models/hera_cms/text.rb +7 -0
  23. data/app/views/hera_cms/dashboard/home.html.erb +6 -0
  24. data/app/views/hera_cms/layouts/hera_cms/application.html.erb +15 -0
  25. data/app/views/hera_cms/shared/_hera_edit.js +302 -0
  26. data/app/views/hera_cms/shared/_navbar.html.erb +13 -0
  27. data/app/views/layouts/hera_cms/application.html.erb +15 -0
  28. data/config/routes.rb +5 -0
  29. data/db/migrate/20201202150007_create_hera_cms_links.rb +13 -0
  30. data/db/migrate/20201202152559_create_hera_cms_texts.rb +12 -0
  31. data/db/migrate/20201203104012_create_hera_cms_images.rb +13 -0
  32. data/lib/generators/hera_cms/install_generator.rb +22 -0
  33. data/lib/generators/hera_cms/templates/config.rb.tt +2 -0
  34. data/lib/generators/hera_cms/templates/install.rb.tt +38 -0
  35. data/lib/hera_cms.rb +28 -0
  36. data/lib/hera_cms/engine.rb +34 -0
  37. data/lib/hera_cms/railtie.rb +4 -0
  38. data/lib/hera_cms/version.rb +3 -0
  39. data/lib/tasks/hera_cms_tasks.rake +32 -0
  40. metadata +201 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9ab63c7e96a93e9b9bad69355b57d5379aa28d7f5d1728bdd0402bad5243658b
4
+ data.tar.gz: c1d924cd2a13543552fb3b64e61c6cab530a6b5e404dbba9b8c9a66c752b6245
5
+ SHA512:
6
+ metadata.gz: f4846dfa4cbdd921f78b0ae60ac1cbdfff6f6416d71afbe16225b065082844b4c6ac531e30c7e1b5378e5610eaee234c6f1d188f9f5e2f295dc6387e1dc2eaea
7
+ data.tar.gz: 2defba654284916930c0b0e98ab892a6193d23927a68eecdf29a4fd8ec27ee8187b8358fa97ff6a9659e6366ed777479829931cc67b3a28dcb954e7069a47bec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Rayan Castro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ ---- STILL IN DEVELOPMENT ----
2
+ ---- If you want to contribute, feel free to open an issue or contact me at rayan@hortatech.com.br ----
3
+
4
+ # HeraCms
5
+
6
+ Hera aims to enable you to easily add Content Managment to your Rails projects, with a very friendly user interface.
7
+
8
+ ## Usage
9
+ We use some tables to store the editable content of your website, in order for it to be updatable dynamically by the website owner.
10
+
11
+ ## Installation
12
+
13
+ 1. Add this line to your application's Gemfile:
14
+ ```ruby
15
+ gem 'hera_cms'
16
+ ```
17
+ 2. Execute:
18
+ ```bash
19
+ $ bundle
20
+ ```
21
+
22
+ 3. The Hera Installer will generate some migrations, that you need to run:
23
+ ```bash
24
+ $ rails hera_cms:install
25
+ $ rails db:migrate
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ First, you need to add the Hera routes. Its highly recommended that you add some authentication logic (with devise or another library) to the routes level. Example with Devise:
31
+
32
+ ```ruby
33
+ # config/routes.rb
34
+ authenticate :user, lambda { |u| u.admin? } do
35
+ mount HeraCms::Engine => "/hera_cms"
36
+ end
37
+
38
+ ```
39
+
40
+ Then, you need to add the Hera navbar to your layout. Here is also highly recommended to add authentication logic, in order to restrict who is able to update the content of your website. Example with Devise:
41
+
42
+ ```html
43
+ # app/views/layouts/application.html.erb
44
+ <!DOCTYPE html>
45
+ <html>
46
+ <head>
47
+ <!-- ... -->
48
+ </head>
49
+
50
+ <body>
51
+ <!-- ... -->
52
+ <% if current_user&.admin? %>
53
+ <%= hera_admin_navbar %>
54
+ <% end %>
55
+ <%= yield %>
56
+ <!-- ... -->
57
+ </body>
58
+ </html>
59
+
60
+
61
+ ```
62
+
63
+ ## Contributing
64
+ Contribution directions go here.
65
+
66
+ ## License
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'HeraCms'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/hera_cms .css
@@ -0,0 +1 @@
1
+ // Hera edit JS is located at app/views/hera_cms/shared/_hera_edit.js
@@ -0,0 +1,154 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+
17
+ .hera-navbar {
18
+ top: 70px;
19
+ right: 35px;
20
+ position: fixed;
21
+ justify-content: space-between;
22
+ height: 200px;
23
+ width: 250px;
24
+ display: flex;
25
+ flex-direction: column;
26
+ padding: 2%;
27
+ z-index: 100;
28
+ background-color: #333333;
29
+ color: white;
30
+ }
31
+
32
+ .hera-navbar img {
33
+ object-fit: contain;
34
+ /*margin: -65px 0 -25px 0;*/
35
+ }
36
+ .hera-navbar a {
37
+ color: white;
38
+ }
39
+
40
+ .hera-navbar .margin-auto-center {
41
+ margin: 0 auto;
42
+ }
43
+
44
+ #hera-edit-button {
45
+ padding: 8px 16px;
46
+ transition: background 0.3s ease;
47
+ background-color: #EE5F5B;
48
+ font-size: 0.9em;
49
+ font-weight: bold;
50
+ text-align: center;
51
+ border-radius: 3px;
52
+ border-width: 0px;
53
+ font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
54
+ }
55
+
56
+ .hera-edit-button-on {
57
+ background-color: #f1cf00 !important;
58
+ }
59
+
60
+
61
+ .hera-background-layer{
62
+ position: fixed;
63
+ top: 0;
64
+ left: 0;
65
+ right: 0;
66
+ bottom: 0;
67
+ background: rgba(0, 0, 0, 0.7);
68
+ pointer-events: none;
69
+ z-index: 3;
70
+ transition: .5s;
71
+ }
72
+
73
+ .hera-clickable {
74
+ pointer-events: all;
75
+ }
76
+
77
+ .hera-editable {
78
+ position: relative;
79
+ z-index: 1;
80
+ }
81
+
82
+ .hera-highlight-layer{
83
+ position: relative;
84
+ z-index: 6;
85
+ background: #F5F5F5;
86
+ transition: .5s;
87
+ padding: 5px;
88
+ border-radius: 3px;
89
+ cursor: pointer;
90
+ color: black !important;
91
+ }
92
+
93
+ .hera-edit-icon {
94
+ color: #EE5F5B;
95
+ position: absolute;
96
+ left: 0;
97
+ bottom: 0;
98
+ }
99
+
100
+ .hera-form-destroy {
101
+ color: white;
102
+ font-size: 1.2em;
103
+ padding: 0px 16px;
104
+ transition: .5s;
105
+ background-color: black;
106
+ }
107
+ .hera-form-destroy:hover{
108
+ color: #EE5F5B;
109
+ transition: .5s;
110
+ cursor: pointer;
111
+ }
112
+
113
+ .hera-editable-wrapper{
114
+ position: relative;
115
+ border-radius: 8px;
116
+ }
117
+
118
+ .hera-form-box {
119
+ position: absolute;
120
+ background: #F5F5F5;
121
+ width: 300px !important;
122
+ height: auto;
123
+ z-index: 6;
124
+ padding: 8px !important;
125
+ border-radius: 3px;
126
+ top: 30px;
127
+ left: 30px;
128
+ font-size: 20px !important;
129
+ font-weight: normal !important;
130
+ border: 1px solid white;
131
+ }
132
+
133
+ .hera-form-box form {
134
+ display: flex;
135
+ flex-direction: column;
136
+ height: 100%;
137
+ }
138
+ .hera-form-box textarea {
139
+ flex: 1 0 auto;
140
+ }
141
+ .hera-form-box input {
142
+ flex: 1 0 auto;
143
+ }
144
+ .hera-form-box input:last-of-type{
145
+ flex: 0 1 auto;
146
+ font-family: Helvetica;
147
+ font-size: 1rem !important;
148
+ }
149
+ .hera-form-box .form-destroy {
150
+ position: absolute;
151
+ top: -9px;
152
+ right: 13px;
153
+ font-size: 1rem;
154
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module HeraCms
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module HeraCms
2
+ class BaseController < ApplicationController
3
+ filters = _process_action_callbacks.map(&:filter) - [:activate_authlogic]
4
+ skip_before_action(*filters, raise: false)
5
+ skip_after_action(*filters, raise: false)
6
+ skip_around_action(*filters, raise: false)
7
+
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module HeraCms
2
+ class DashboardController < BaseController
3
+ def home
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,56 @@
1
+ require_dependency "hera_cms/application_controller"
2
+ require 'json'
3
+
4
+ module HeraCms
5
+ class LinksController < ApplicationController
6
+ # layout "admin"
7
+
8
+ # def index
9
+ # link_json = HeraCms::Link.read_json
10
+ # @seed_link = JSON.pretty_generate(link_json)
11
+ # @links = HeraCms::Link.all.order(created_at: :desc)
12
+ # end
13
+
14
+ # def edit
15
+ # @link = HeraCms::Link.find(params[:id])
16
+ # end
17
+
18
+ def update
19
+ @link = HeraCms::Link.find(params[:id])
20
+
21
+ if @link.update(link_params)
22
+ render json: { redirect: URI(request.referer).path }, status: 200
23
+ else
24
+ render json: { errors: @link.errors.full_messages }, status: 422
25
+ end
26
+ end
27
+
28
+ # def new
29
+ # @link = HeraCms::Link.new
30
+ # end
31
+
32
+ # def create
33
+ # @link = HeraCms::Link.new(link_params)
34
+
35
+ # @link[:translated_text] << translate_service.mount_translation(params[:link]["inner_text"])
36
+
37
+ # if @HeraCms::link.save
38
+ # redirect_to URI(request.referer).path
39
+ # else
40
+ # render :new
41
+ # end
42
+ # end
43
+
44
+ # def destroy
45
+ # @link = HeraCms::Link.find(params[:id])
46
+ # @HeraCms::link.destroy
47
+ # redirect_to URI(request.referer).path
48
+ # end
49
+
50
+ private
51
+
52
+ def link_params
53
+ params.require(:link).permit(:identifier, :classes, :style, :path)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module HeraCms
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module HeraCms
2
+ module LinksHelper
3
+ end
4
+ end
@@ -0,0 +1,121 @@
1
+ module HeraCms
2
+ module TagHelper
3
+
4
+ def hera_admin_navbar
5
+ render 'hera_cms/shared/navbar'
6
+ end
7
+
8
+ def hera_link(identifier, args = {}, &block)
9
+ link = HeraCms::Link.identify(identifier)
10
+ inner_text, style, identifier, path = link.inner_text, link.style, link.identifier, link.path
11
+ classes = set_classes(args, link)
12
+
13
+ html_options = {
14
+ class: classes,
15
+ style: style,
16
+ id: identifier,
17
+ data: { editable_id: link.id, editable_type: link.model_name.route_key}
18
+ }
19
+
20
+ args[:attributes]&.each do |key, value|
21
+ html_options[key] = value
22
+ end
23
+
24
+ if block_given?
25
+ link_to(path, html_options, &block)
26
+ else
27
+ link_to(inner_text, path, html_options)
28
+ end
29
+ end
30
+
31
+ # BANNER
32
+ def hera_media_banner(identifier, args={}, &block)
33
+ media = HeraCms::Image.identify(identifier)
34
+ identifier, upload, style = media.identifier, media.upload, media.style
35
+ classes = set_classes(args, media)
36
+
37
+ url = upload.url.to_s
38
+ html_options = {
39
+ class: classes,
40
+ style: "background: url(\"#{url}\"); width: 100vw;, padding: 0; height: calc(100vh - 80px); background-position: center center; background-size: cover;",
41
+ id: identifier,
42
+ data: { editable_id: media.id, editable_type: media.model_name.route_key}
43
+ }
44
+ if block_given?
45
+ content_tag(:div, "", html_options, &block)
46
+ else
47
+ content_tag(:div, "", html_options)
48
+ end
49
+ end
50
+
51
+ # 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
+
73
+ # Generate HTML tag
74
+ def hera_text(identifier, args = {})
75
+ text = Text.identify(identifier)
76
+ inner_text, style, identifier = translate_service.translate(text), text.style, text.identifier
77
+ classes = set_classes(args, text)
78
+ args[:html_tag] ||= "div"
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
+ # Generate Form Tag
90
+ def hera_form(identifier, args = {})
91
+ form = Form.identify(identifier)
92
+ set_editable(form) unless args[:editable] == false
93
+ identifier, send_to, classes, style = form.identifier, form.send_to, form.classes, form.style
94
+ html_options = {
95
+ class: classes,
96
+ style: style,
97
+ id: identifier,
98
+ data: { editable_id: form.id, editable_type: form.model_name.route_key, mail: form.send_to}
99
+ }
100
+ form_tag("/contact", html_options ) do
101
+ concat hidden_field_tag("form_id", form.id)
102
+ concat text_field_tag('name',"", placeholder: "Nome")
103
+ concat text_field_tag('email',"", placeholder: "E-mail")
104
+ concat text_field_tag('phone',"", placeholder: "Telefone")
105
+ concat text_area_tag('message',"", placeholder: "Digite sua mensagem aqui")
106
+ concat submit_tag('Enviar')
107
+ end
108
+ end
109
+
110
+ def set_editable(editable)
111
+ editable.classes += " hera-editable" if editable.editable? && (editable.classes && !editable.classes.include?("hera-editable"))
112
+ end
113
+
114
+ def set_classes(args, editable)
115
+ args[:add_class] ||= ""
116
+ classes = "#{ args[:class] || editable.classes } #{args[:add_class]}"
117
+ classes += " hera-editable" unless args[:editable] == false || editable.classes.include?("hera-editable") || !editable.editable?
118
+ end
119
+
120
+ end
121
+ end