cas-cms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +37 -0
- data/app/assets/config/cas_manifest.js +2 -0
- data/app/assets/images/cas/black-star.svg +4 -0
- data/app/assets/images/cas/check.svg +4 -0
- data/app/assets/images/cas/dropzone-in.svg +4 -0
- data/app/assets/images/cas/loading.gif +0 -0
- data/app/assets/images/cas/white-star.svg +4 -0
- data/app/assets/javascripts/cas/application.js +51 -0
- data/app/assets/javascripts/cas/fileupload_manifest.js +269 -0
- data/app/assets/javascripts/cas/plugins/cas_image_gallery.js +353 -0
- data/app/assets/javascripts/cas/vendor/file_upload/canvas-to-blob.min.js +2 -0
- data/app/assets/javascripts/cas/vendor/file_upload/jquery.fileupload-image.js +326 -0
- data/app/assets/javascripts/cas/vendor/file_upload/jquery.fileupload-process.js +178 -0
- data/app/assets/javascripts/cas/vendor/file_upload/jquery.fileupload.js +1482 -0
- data/app/assets/javascripts/cas/vendor/file_upload/jquery.iframe-transport.js +224 -0
- data/app/assets/javascripts/cas/vendor/file_upload/jquery.ui.widget.js +572 -0
- data/app/assets/javascripts/cas/vendor/file_upload/load-image.all.min.js +2 -0
- data/app/assets/javascripts/cas/vendor/jquery.ui.touch-punch.min.js +11 -0
- data/app/assets/javascripts/cas/vendor/selectize.min.js +3 -0
- data/app/assets/stylesheets/cas/application.sass +17 -0
- data/app/assets/stylesheets/cas/colors.sass +6 -0
- data/app/assets/stylesheets/cas/form.sass +99 -0
- data/app/assets/stylesheets/cas/layout.sass +68 -0
- data/app/assets/stylesheets/cas/mixins.sass +34 -0
- data/app/assets/stylesheets/cas/plugins/attachments_form.sass +16 -0
- data/app/assets/stylesheets/cas/plugins/image_gallery.sass +128 -0
- data/app/assets/stylesheets/cas/tables.sass +13 -0
- data/app/assets/stylesheets/cas/typography.sass +27 -0
- data/app/assets/stylesheets/cas/vendors/selectize.default.css +394 -0
- data/app/assets/stylesheets/cas/vendors/simplegrid.css +298 -0
- data/app/controllers/cas/api/files_controller.rb +88 -0
- data/app/controllers/cas/application_controller.rb +17 -0
- data/app/controllers/cas/devise/sessions_controller.rb +9 -0
- data/app/controllers/cas/file_uploads_controller.rb +14 -0
- data/app/controllers/cas/sections/application_controller.rb +23 -0
- data/app/controllers/cas/sections/categories_controller.rb +47 -0
- data/app/controllers/cas/sections/contents_controller.rb +144 -0
- data/app/controllers/cas/sections_controller.rb +7 -0
- data/app/controllers/cas/users_controller.rb +61 -0
- data/app/helpers/cas/application_helper.rb +4 -0
- data/app/helpers/cas/form_helper.rb +11 -0
- data/app/jobs/cas/application_job.rb +4 -0
- data/app/jobs/cas/images/delete_job.rb +11 -0
- data/app/jobs/cas/images/promote_job.rb +11 -0
- data/app/jobs/cas/increment_pageviews_job.rb +11 -0
- data/app/models/cas/application_record.rb +5 -0
- data/app/models/cas/category.rb +6 -0
- data/app/models/cas/content.rb +59 -0
- data/app/models/cas/media_file.rb +77 -0
- data/app/models/cas/section.rb +10 -0
- data/app/models/cas/site.rb +5 -0
- data/app/models/cas/user.rb +39 -0
- data/app/uploaders/file_uploader.rb +26 -0
- data/app/views/cas/devise/sessions/new.html.erb +24 -0
- data/app/views/cas/sections/categories/_form.html.erb +19 -0
- data/app/views/cas/sections/categories/edit.html.erb +5 -0
- data/app/views/cas/sections/categories/index.html.erb +28 -0
- data/app/views/cas/sections/categories/new.html.erb +5 -0
- data/app/views/cas/sections/contents/_form_attachments.html.erb +42 -0
- data/app/views/cas/sections/contents/_form_attachments_template.html.erb +11 -0
- data/app/views/cas/sections/contents/_form_for_content.html.erb +85 -0
- data/app/views/cas/sections/contents/_form_for_survey.html.erb +36 -0
- data/app/views/cas/sections/contents/_form_images.html.erb +86 -0
- data/app/views/cas/sections/contents/edit.html.erb +6 -0
- data/app/views/cas/sections/contents/index.html.erb +71 -0
- data/app/views/cas/sections/contents/new.html.erb +5 -0
- data/app/views/cas/sections/index.html.erb +21 -0
- data/app/views/cas/shared/_error_messages.html.erb +12 -0
- data/app/views/cas/users/_form.html.erb +11 -0
- data/app/views/cas/users/edit.html.erb +2 -0
- data/app/views/cas/users/index.html.erb +34 -0
- data/app/views/cas/users/new.html.erb +2 -0
- data/app/views/layouts/cas/application.html.erb +71 -0
- data/config/initializers/acts_as_taggable.rb +1 -0
- data/config/initializers/devise.rb +277 -0
- data/config/initializers/shrine.rb +50 -0
- data/config/initializers/simple_form.rb +169 -0
- data/config/locales/devise.en.yml +64 -0
- data/config/locales/pt-BR.yml +242 -0
- data/config/locales/simple_form.en.yml +31 -0
- data/config/routes.rb +31 -0
- data/db/migrate/20170129212144_create_cas_sites.rb +15 -0
- data/db/migrate/20170219172958_create_cas_sections.rb +12 -0
- data/db/migrate/20170219175007_create_cas_contents.rb +17 -0
- data/db/migrate/20170612204500_create_cas_users.rb +14 -0
- data/db/migrate/20170613174724_create_cas_media_files.rb +20 -0
- data/db/migrate/20170613175912_create_cas_categories.rb +14 -0
- data/db/migrate/20170614171928_add_columns_to_cas_contents.rb +12 -0
- data/db/migrate/20170614172904_add_column_to_cas_sections.rb +6 -0
- data/db/migrate/20170615235532_add_devise_to_cas_users.rb +49 -0
- data/db/migrate/20170616011202_remove_password_from_cas_users.rb +5 -0
- data/db/migrate/20170618014204_v3_migration_fields.rb +30 -0
- data/db/migrate/20170623182702_add_column_category_id_to_cas_content.rb +6 -0
- data/db/migrate/20170624024648_rename_url_to_path_in_files.rb +7 -0
- data/db/migrate/20170625192119_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +36 -0
- data/db/migrate/20170625192120_add_missing_unique_indices.acts_as_taggable_on_engine.rb +26 -0
- data/db/migrate/20170625192121_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +20 -0
- data/db/migrate/20170625192122_add_missing_taggable_index.acts_as_taggable_on_engine.rb +15 -0
- data/db/migrate/20170625192123_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +15 -0
- data/db/migrate/20170625192124_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb +23 -0
- data/db/migrate/20170713210101_add_location_to_cas_content.rb +5 -0
- data/db/migrate/20170714043036_add_url_to_content.rb +5 -0
- data/db/migrate/20170718201535_add_embedded_to_content.rb +5 -0
- data/db/migrate/20170801171952_categories_with_jsonb_metadata.rb +6 -0
- data/db/migrate/20170801173256_add_published_at_to_cas_contents.rb +6 -0
- data/db/migrate/20170801175407_add_description_to_cas_categories.rb +5 -0
- data/db/migrate/20170830000000_add_data_search_extensions.rb +17 -0
- data/db/migrate/20170830000001_add_search_index_to_cas_contents.rb +20 -0
- data/db/migrate/20170830000002_use_uuid_with_acts_as_taggable_references.rb +17 -0
- data/db/migrate/20170919181809_pageviews_default_to_zero.rb +9 -0
- data/db/migrate/20171201191059_add_domains_to_cas_site.rb +6 -0
- data/lib/cas.rb +22 -0
- data/lib/cas/config.rb +42 -0
- data/lib/cas/engine.rb +33 -0
- data/lib/cas/form_field.rb +54 -0
- data/lib/cas/remote_callbacks.rb +36 -0
- data/lib/cas/section_config.rb +84 -0
- data/lib/cas/setup.rb +43 -0
- data/lib/cas/version.rb +3 -0
- data/lib/devise/custom_failure.rb +16 -0
- data/lib/tasks/cas_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- metadata +560 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddDataSearchExtensions < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
execute <<-SQL
|
4
|
+
CREATE EXTENSION fuzzystrmatch;
|
5
|
+
CREATE EXTENSION pg_trgm;
|
6
|
+
CREATE EXTENSION unaccent;
|
7
|
+
SQL
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
execute <<-SQL
|
12
|
+
DROP EXTENSION pg_trgm;
|
13
|
+
DROP EXTENSION unaccent;
|
14
|
+
DROP EXTENSION fuzzystrmatch;
|
15
|
+
SQL
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class AddSearchIndexToCasContents < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
add_column :cas_contents, :tags_cache, :string
|
4
|
+
execute <<-SQL
|
5
|
+
CREATE INDEX cas_contents_search_with_fulltext ON cas_contents USING gist ((
|
6
|
+
to_tsvector('simple', coalesce("cas_contents"."title"::text, '')) ||
|
7
|
+
to_tsvector('simple', coalesce("cas_contents"."text"::text, '')) ||
|
8
|
+
to_tsvector('simple', coalesce("cas_contents"."location"::text, '')) ||
|
9
|
+
to_tsvector('simple', coalesce("cas_contents"."tags_cache"::text, ''))
|
10
|
+
));
|
11
|
+
SQL
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
execute <<-SQL
|
16
|
+
DROP INDEX cas_contents_search_with_fulltext;
|
17
|
+
SQL
|
18
|
+
remove_column :cas_contents, :tags_cache
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class UseUuidWithActsAsTaggableReferences < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
remove_column :taggings, :taggable_id
|
4
|
+
add_column :taggings, :taggable_id, :uuid
|
5
|
+
|
6
|
+
remove_column :taggings, :tagger_id
|
7
|
+
add_column :taggings, :tagger_id, :uuid
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
remove_column :taggings, :taggable_id
|
12
|
+
add_column :taggings, :taggable_id, :integer
|
13
|
+
|
14
|
+
remove_column :taggings, :tagger_id
|
15
|
+
add_column :taggings, :tagger_id, :integer
|
16
|
+
end
|
17
|
+
end
|
data/lib/cas.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "cas/engine"
|
2
|
+
require "cas/config"
|
3
|
+
require "cas/remote_callbacks"
|
4
|
+
require "cas/setup"
|
5
|
+
require "cas/section_config"
|
6
|
+
require "cas/form_field"
|
7
|
+
|
8
|
+
require 'devise'
|
9
|
+
require 'simple_form'
|
10
|
+
require 'friendly_id'
|
11
|
+
require 'jquery-rails'
|
12
|
+
require 'jquery-ui-rails'
|
13
|
+
require 'kaminari'
|
14
|
+
require 'acts-as-taggable-on'
|
15
|
+
require 'tinymce-rails'
|
16
|
+
require 'tinymce-rails-langs'
|
17
|
+
require 'shrine'
|
18
|
+
require 'sidekiq'
|
19
|
+
require 'pg_search'
|
20
|
+
|
21
|
+
module Cas
|
22
|
+
end
|
data/lib/cas/config.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Cas
|
4
|
+
class Config
|
5
|
+
|
6
|
+
def initialize(filename: nil)
|
7
|
+
@filename = filename
|
8
|
+
end
|
9
|
+
|
10
|
+
def uploads
|
11
|
+
uploads = config["uploads"] || {}
|
12
|
+
|
13
|
+
{
|
14
|
+
cache_directory_prefix: uploads["cache_directory_prefix"] || "cache",
|
15
|
+
store_directory_prefix: uploads["store_directory_prefix"] || "store"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def read_file
|
22
|
+
@file ||= YAML.load_file(filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
def filename
|
26
|
+
@filename ||= begin
|
27
|
+
if File.exists?("cas.yml")
|
28
|
+
"cas.yml"
|
29
|
+
elsif ENV['RAILS_ENV'] == 'test'
|
30
|
+
"spec/fixtures/cas.yml"
|
31
|
+
else
|
32
|
+
raise "cas.yml file is not defined."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def config
|
38
|
+
read_file["config"] || {}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/lib/cas/engine.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Cas
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Cas
|
4
|
+
|
5
|
+
initializer :append_migrations do |app|
|
6
|
+
unless app.root.to_s.match root.to_s
|
7
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
8
|
+
app.config.paths["db/migrate"] << expanded_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
config.after_initialize do
|
14
|
+
Dir.glob("#{config.root}/app/uploaders/**/*.rb").each do |c|
|
15
|
+
require_dependency(c)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config.assets.precompile += ["cas/fileupload_manifest.js"]
|
20
|
+
|
21
|
+
config.active_record.primary_key = :uuid
|
22
|
+
config.generators do |g|
|
23
|
+
g.test_framework :rspec
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.mounted_path
|
27
|
+
route = Rails.application.routes.routes.detect do |current_route|
|
28
|
+
current_route.app == self
|
29
|
+
end
|
30
|
+
route && route.path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Cas
|
2
|
+
class FormField
|
3
|
+
def initialize(section, field_name)
|
4
|
+
@section = section
|
5
|
+
@field_name = field_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(name, *args, &block)
|
9
|
+
load_field[name]
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def filename
|
15
|
+
if Rails.env.test?
|
16
|
+
"spec/fixtures/cas.yml"
|
17
|
+
else
|
18
|
+
"cas.yml"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_field
|
23
|
+
@config ||= begin
|
24
|
+
config_file = YAML.load_file(filename)
|
25
|
+
sites = config_file["sites"]
|
26
|
+
site = sites[@section.site.slug]
|
27
|
+
section = site["sections"]
|
28
|
+
fields = section.find { |key, value|
|
29
|
+
key == @section.slug
|
30
|
+
}[1]["fields"]
|
31
|
+
|
32
|
+
config = fields.find do |field|
|
33
|
+
if field.is_a?(Hash)
|
34
|
+
field[@field_name.to_s]
|
35
|
+
else
|
36
|
+
field == @field_name.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if config.is_a?(Hash)
|
41
|
+
config = config[@field_name.to_s]
|
42
|
+
config = config.deep_symbolize_keys
|
43
|
+
else
|
44
|
+
config = {}
|
45
|
+
end
|
46
|
+
|
47
|
+
config.merge(
|
48
|
+
format: (config[:format] || [:day, :month, :year]).map(&:to_sym)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Cas
|
2
|
+
class RemoteCallbacks
|
3
|
+
INITIAL_SETUP ||= {
|
4
|
+
# Process images here and return a hash
|
5
|
+
#
|
6
|
+
# {
|
7
|
+
# small: small_image,
|
8
|
+
# medium: medium_image,
|
9
|
+
# big: big_image
|
10
|
+
# }
|
11
|
+
#
|
12
|
+
# `original` should always be present. If it is not, we will merge it
|
13
|
+
# afterwards automatically.
|
14
|
+
uploaded_image_versions: ->(io, context) {
|
15
|
+
{}
|
16
|
+
},
|
17
|
+
|
18
|
+
# Class to be called after image was saved.
|
19
|
+
after_file_upload: ->(file) { }
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
@@callbacks ||= INITIAL_SETUP
|
23
|
+
|
24
|
+
def self.reset
|
25
|
+
@@callbacks ||= INITIAL_SETUP
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.callbacks=(callbacks_hash)
|
29
|
+
@@callbacks = INITIAL_SETUP.merge(callbacks_hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.callbacks
|
33
|
+
@@callbacks
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Cas
|
2
|
+
class SectionConfig
|
3
|
+
def initialize(section)
|
4
|
+
@section = section
|
5
|
+
end
|
6
|
+
|
7
|
+
def list_order_by
|
8
|
+
config = YAML.load_file(filename)
|
9
|
+
sites = config["sites"]
|
10
|
+
site = sites[@section.site.slug]
|
11
|
+
section = site["sections"]
|
12
|
+
|
13
|
+
order_field = section.find { |key, value|
|
14
|
+
key == @section.slug
|
15
|
+
}[1]['list_order_by']
|
16
|
+
|
17
|
+
order_field || ['created_at']
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_fields
|
21
|
+
config = YAML.load_file(filename)
|
22
|
+
sites = config["sites"]
|
23
|
+
site = sites[@section.site.slug]
|
24
|
+
section = site["sections"]
|
25
|
+
fields = section.find { |key, value|
|
26
|
+
key == @section.slug
|
27
|
+
}[1]["list_fields"]
|
28
|
+
fields || ['title', 'created_at']
|
29
|
+
end
|
30
|
+
|
31
|
+
def accessible_by_user?(user)
|
32
|
+
roles = user.roles.map(&:to_s)
|
33
|
+
accessible_roles = load_field["accessible_roles"]
|
34
|
+
|
35
|
+
if accessible_roles.present?
|
36
|
+
(accessible_roles.map(&:to_s) & roles).compact.present?
|
37
|
+
else
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def form_has_field?(field)
|
43
|
+
config = YAML.load_file(filename)
|
44
|
+
sites = config["sites"]
|
45
|
+
site = sites[@section.site.slug]
|
46
|
+
section = site["sections"]
|
47
|
+
section_fields = section.find { |key, value|
|
48
|
+
key == @section.slug
|
49
|
+
}[1]["fields"]
|
50
|
+
|
51
|
+
Array.wrap(section_fields).any? do |section_field|
|
52
|
+
if section_field.is_a?(Hash)
|
53
|
+
section_field.keys.map(&:to_s).include?(field.to_s)
|
54
|
+
else
|
55
|
+
section_field.to_s == field.to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def filename
|
63
|
+
if Rails.env.test?
|
64
|
+
"spec/fixtures/cas.yml"
|
65
|
+
else
|
66
|
+
"cas.yml"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_field
|
71
|
+
@config ||= begin
|
72
|
+
config_file = YAML.load_file(filename)
|
73
|
+
sites = config_file["sites"]
|
74
|
+
site = sites[@section.site.slug]
|
75
|
+
section = site["sections"]
|
76
|
+
field = section.find { |key, value|
|
77
|
+
key == @section.slug
|
78
|
+
}
|
79
|
+
(field && field[1]) || {}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
data/lib/cas/setup.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Cas
|
2
|
+
class Setup
|
3
|
+
def install
|
4
|
+
ActiveRecord::Base.transaction do
|
5
|
+
config = YAML.load_file(filename)
|
6
|
+
|
7
|
+
config["sites"].each do |site_slug, site_config|
|
8
|
+
site = ::Cas::Site.where(slug: site_slug).first_or_create
|
9
|
+
site.update!(
|
10
|
+
domains: site_config["domains"],
|
11
|
+
name: site_config["name"]
|
12
|
+
)
|
13
|
+
|
14
|
+
site_config["sections"].each do |key, section|
|
15
|
+
model = ::Cas::Section.where(
|
16
|
+
slug: key,
|
17
|
+
site_id: site.id
|
18
|
+
).first_or_create!(
|
19
|
+
name: section["name"],
|
20
|
+
section_type: section["type"],
|
21
|
+
)
|
22
|
+
|
23
|
+
model.update!(
|
24
|
+
name: section["name"],
|
25
|
+
section_type: section["type"],
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def filename
|
35
|
+
if Rails.env.test?
|
36
|
+
"spec/fixtures/cas.yml"
|
37
|
+
else
|
38
|
+
"cas.yml"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/lib/cas/version.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Devise
|
2
|
+
class CustomFailure < ::Devise::FailureApp
|
3
|
+
def redirect_url
|
4
|
+
cas.new_user_session_url
|
5
|
+
end
|
6
|
+
|
7
|
+
# You need to override respond to eliminate recall
|
8
|
+
def respond
|
9
|
+
if http_auth?
|
10
|
+
http_auth
|
11
|
+
else
|
12
|
+
redirect
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|