camaleon_cms 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of camaleon_cms might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d114547f428656d17fdf58ce3a7d1096a01e413
4
- data.tar.gz: 3b994b5712f74b98f58942d1fa7de814a042c8ab
3
+ metadata.gz: 418b31e8a9007f20ed7e54b748b16b7edd8b0c6d
4
+ data.tar.gz: a7f16254d383c954d350d7f23b6f1d56bc16e0ae
5
5
  SHA512:
6
- metadata.gz: 1a8b1bad326b7d06e0051a93b2962c98f0e0ee8e0ac0b7d41950c580891e11948f0cb94e09d6adbcab52c4024a604f1d951b7f9d89208fb73cfe613e436fa969
7
- data.tar.gz: ad8f732b2820f70fc2e994eb8499d2502243c014d7eee187874166954b1b04d7d693449f8ba57e6a8f7751c16b0d8e5327ab2b1f35a701eb17483db32b6d86b7
6
+ metadata.gz: 6b550adda1b21074dd7118693739e0a87c72ed76edafe9ac7fc7ab361882c035bbfd61eab6c545eff7311a016d13ca1317e17d898abbf05c135d5e6ecef09b7b
7
+ data.tar.gz: 9f89b6a54b89da1e76db22ea6d45a425304cdfacb859f6be332c78d2a3f2feb4bf1903b5fd13b367d23107df96c63c85657bc3721ae0555a3e0cdeff73f6825d
@@ -342,4 +342,8 @@ margin-right: 0;
342
342
  }
343
343
  .item-custom-field{
344
344
  margin-bottom: 15px;
345
+ }
346
+ i.fa {
347
+ font-size: 15px;
348
+ &.large{ font-size: 20px; }
345
349
  }
@@ -27,6 +27,14 @@ class Admin::PluginsController < AdminController
27
27
  redirect_to action: :index
28
28
  end
29
29
 
30
+ # permit to upgrade a plugin for a new version
31
+ def upgrade
32
+ plugin = plugin_upgrade(params[:plugin_id])
33
+ flash[:notice] = "Plugin \"#{plugin.title}\" #{t('admin.message.was_upgraded')}"
34
+ PluginRoutes.reload
35
+ redirect_to action: :index
36
+ end
37
+
30
38
  def destroy
31
39
  plugin = plugin_destroy(params[:id])
32
40
  if plugin.error
@@ -72,6 +72,14 @@ class PostDecorator < ApplicationDecorator
72
72
  h.edit_admin_post_type_post_url(object.post_type.id, object)
73
73
  end
74
74
 
75
+ # create the html link with edit link
76
+ # return html link
77
+ # attrs: Hash of link tag attributes, sample: {id: "myid", class: "sss" }
78
+ def the_edit_link(title = nil, attrs = { })
79
+ attrs = {target: "_blank", style: "font-size:11px !important;cursor:pointer;"}.merge(attrs)
80
+ h.link_to("&rarr; #{title || h.ct("edit")}", the_edit_url, *attrs)
81
+ end
82
+
75
83
  # show thumbnail image as html
76
84
  def the_thumb(img_args = {})
77
85
  r = {image: h.image_tag(the_thumb_url, img_args), post: object}
@@ -77,6 +77,14 @@ class TermTaxonomyDecorator < ApplicationDecorator
77
77
  link
78
78
  end
79
79
 
80
+ # create the html link with edit link
81
+ # return html link
82
+ # attrs: Hash of link tag attributes, sample: {id: "myid", class: "sss" }
83
+ def the_edit_link(title = nil, attrs = { })
84
+ attrs = {target: "_blank", style: "font-size:11px !important;cursor:pointer;"}.merge(attrs)
85
+ h.link_to("&rarr; #{title || h.ct("edit")}", the_edit_url, *attrs)
86
+ end
87
+
80
88
  # cache identifier, the format is: [current-site-prefix]/[object-id]-[object-last_updated]/[current locale]
81
89
  # key: additional key for the model
82
90
  def cache_prefix(key = "")
@@ -21,11 +21,23 @@ module PluginsHelper
21
21
  (klass || self).send :extend, mod
22
22
  end
23
23
 
24
+ # upgrade installed plugin in current site for a new version
25
+ # plugin_key: key of the plugin
26
+ # trigger hook "on_upgrade"
27
+ # return model of the plugin
28
+ def plugin_upgrade(plugin_key)
29
+ plugin_model = current_site.plugins.where(slug: plugin_key).first!
30
+ hook_run(plugin_model.settings, "on_upgrade", plugin_model)
31
+ plugin_model.installed_version= plugin_model.settings["version"]
32
+ plugin_model
33
+ end
34
+
24
35
  # install a plugin for current site
25
36
  # plugin_key: key of the plugin
26
37
  # return model of the plugin
27
38
  def plugin_install(plugin_key)
28
39
  plugin_model = current_site.plugins.where(slug: plugin_key).first_or_create!
40
+ plugin_model.installed_version= plugin_model.settings["version"]
29
41
  return plugin_model if plugin_model.active?
30
42
  plugin_model.active
31
43
  PluginRoutes.reload
@@ -51,6 +63,7 @@ module PluginsHelper
51
63
  # plugin_key: key of the plugin
52
64
  # return model of the plugin removed
53
65
  def plugin_destroy(plugin_key)
66
+ # return
54
67
  plugin_model = current_site.plugins.where(slug: plugin_key).first_or_create
55
68
  if !plugin_can_be_deleted?(params[:id]) || true
56
69
  plugin_model.error = false
data/app/models/plugin.rb CHANGED
@@ -41,6 +41,27 @@ class Plugin < TermTaxonomy
41
41
  PluginRoutes.plugin_info(self.slug)
42
42
  end
43
43
 
44
+ # check if current installation version is older
45
+ # return boolean
46
+ def old_version?
47
+ self.installed_version.to_s != self.settings["version"].to_s
48
+ end
49
+
50
+ # set a new installation version for this plugin
51
+ def installed_version=(version)
52
+ self.set_option("version_installed", version)
53
+ end
54
+
55
+ # return gem installed version
56
+ def installed_version
57
+ res = self.get_option("version_installed")
58
+ unless res.present? # fix for old installations
59
+ res = self.settings["version"]
60
+ self.installed_version= res
61
+ end
62
+ res
63
+ end
64
+
44
65
  def title
45
66
  PluginRoutes.plugin_info(self.slug)["title"]
46
67
  end
@@ -13,12 +13,12 @@
13
13
  </tr>
14
14
  </thead>
15
15
  <tbody>
16
- <% plugins.each do |plugin| status = enabled_plugins.include?(plugin); r = {links: []}; %>
16
+ <% plugins.each do |plugin| status = enabled_plugins.include?(plugin); r = {links: ["Version: #{plugin["version"]}"]}; %>
17
17
  <tr>
18
18
  <td>
19
- <%= plugin["title"] %>
19
+ <b><%= plugin["title"] %></b>
20
20
  <br>
21
- <% r[:links] << (link_to("#{t('admin.sidebar.information')}", "http://camaleon.tuzitio.com/store/plugins/info/#{plugin["key"]}", target: "_blank", title: "#{plugin["title"]}")) %>
21
+ <% r[:links] << (link_to("#{t('admin.sidebar.information')}", "http://camaleon.tuzitio.com/store/plugins/info/#{plugin["key"]}", target: "_blank", title: "Plugin #{t('admin.sidebar.information')}")) %>
22
22
  <% hook_run(plugin, "plugin_options", r) if status %>
23
23
  <%= raw r[:links].join(" | ") %>
24
24
  </td>
@@ -26,7 +26,8 @@
26
26
  <td><%= plugin["version"] %></td>
27
27
  <td><%= t("admin.plugins.status_#{status}") %></td>
28
28
  <td>
29
- <%= link_to raw("<i class='fa fa-#{status ? "check-square" : "square"}'></i>"), {action: :toggle, id: plugin["key"], status: status }, class: "btn btn-default btn-xs", title: "#{status ? t('admin.button.disable_plugin') : t('admin.button.activate_plugin') }" %>
29
+ <%= link_to raw("<i class='fa fa-#{status ? "check-square" : "square"}'></i>"), {action: :toggle, id: plugin["key"], status: status }, class: "btn btn-default btn-xs", title: "#{status ? t('admin.button.disable_plugin') : t('admin.button.activate_plugin') }", data: { confirm: "#{"#{status ? t('admin.button.disable_plugin') : t('admin.button.activate_plugin') }"}?" } %>
30
+ <%= link_to("<i class='fa fa-arrow-circle-o-up'></i>".html_safe, admin_plugin_upgrade_path(plugin["key"]), class: "btn btn-info btn-xs", title: "#{t("admin.plugins.upgrade_to")} #{plugin["version"]}") if status && current_site.get_plugin(plugin["key"]).old_version? %>
30
31
  </td>
31
32
  </tr>
32
33
  <% end %>
@@ -32,6 +32,8 @@
32
32
  </div>
33
33
  <script>
34
34
  jQuery(function(){
35
- $("#table-plugins-list table").sieve();
35
+ var table = $("#table-plugins-list table")
36
+ table.sieve();
37
+ table.find("a[title!='']").tooltip();
36
38
  })
37
39
  </script>
@@ -19,18 +19,15 @@ if loaded_rufus
19
19
  system("rake camaleon_cms:sitemap")
20
20
  end
21
21
 
22
- # run all custom cron jobs
23
- begin
24
- Site.all.each do |site|
25
- # hooks
26
- c = CamaleonController.new
27
- c.instance_eval do
28
- @current_site = site
29
- @_hooks_skip = []
30
- end
31
- r = {site: site, eval: nil}; c.hooks_run("cron", r)
32
- r[:eval].call(r) if r[:eval].present? # evaluate the cron job created by plugin or theme
22
+ sites = Site.all rescue []
23
+ sites.each do |site|
24
+ # triggering cron hooks
25
+ c = CamaleonController.new
26
+ c.instance_eval do
27
+ @current_site = site
28
+ @_hooks_skip = []
33
29
  end
34
- rescue #ActiveRecord::RecordNotFound # skipping pending migrations
30
+ r = {site: site, eval: nil}; c.hooks_run("cron", r)
31
+ r[:eval].call(r) if r[:eval].present? # evaluate the cron job created by plugin or theme
35
32
  end
36
33
  end
@@ -177,6 +177,7 @@ en:
177
177
  quick_info: 'Some quick info about this user'
178
178
  was_inactivated: 'was inactivated.'
179
179
  was_activated: 'was activated.'
180
+ was_upgraded: 'was updated.'
180
181
  can_not_be_removed: 'can not be removed.'
181
182
  was_removed: 'was removed.'
182
183
  processing: 'Procesando...'
@@ -273,6 +274,7 @@ en:
273
274
  status_false: 'Inactive'
274
275
  status_true: 'Active'
275
276
  type_contents: 'Type Contents'
277
+ upgrade_to: "Upgrade to"
276
278
  settings:
277
279
  activate_create_account: 'Activate Create Account'
278
280
  activate_login_social_networks: 'Activate Login Social Networks'
@@ -177,6 +177,7 @@ es:
177
177
  quick_info: 'Algo de información rápida acerca de este usuario'
178
178
  was_inactivated: 'fue desactivado.'
179
179
  was_activated: 'fue activado.'
180
+ was_upgraded: 'fue actualizado.'
180
181
  can_not_be_removed: 'no puede ser eliminado.'
181
182
  was_removed.: 'fue eliminado.'
182
183
  processing: 'Processing...'
@@ -273,6 +274,7 @@ es:
273
274
  status_false: 'Inactivo'
274
275
  status_true: 'Activo'
275
276
  type_contents: 'Tipo de Contenidos'
277
+ upgrade_to: "Actualizar a"
276
278
  settings:
277
279
  activate_create_account: 'Activar Crear Cuenta'
278
280
  activate_login_social_networks: 'Activar Iniciar sesión con Redes Sociales'
@@ -178,6 +178,7 @@ it:
178
178
  quick_info: "Informazioni veloci sull'utente"
179
179
  was_inactivated: 'è stato disattivato.'
180
180
  was_activated: 'è stato attivato.'
181
+ was_upgraded: "E 'stato aggiornato."
181
182
  can_not_be_removed: 'Non può essere rimosso.'
182
183
  was_removed: 'è stato rimosso.'
183
184
  processing: 'Caricamento...'
@@ -274,6 +275,7 @@ it:
274
275
  status_false: 'Inattivo'
275
276
  status_true: 'Attivo'
276
277
  type_contents: 'Type Contents'
278
+ upgrade_to: "Aggiornamento a"
277
279
  settings:
278
280
  activate_create_account: 'Attiva account creato'
279
281
  activate_login_social_networks: 'Attiva i Login con i Social Network'
@@ -20,6 +20,7 @@ en:
20
20
  comment_saved: "Your comment was saved"
21
21
  comment_error: "An error was occurred on save comment"
22
22
  comment_reply: "Reply"
23
+ edit: "Edit"
23
24
 
24
25
  recent_posts: "Recent Posts"
25
26
 
@@ -81,6 +82,7 @@ es:
81
82
  comment_saved: "Su comentario se a guardado"
82
83
  comment_error: "Ocurrió un error al enviar su comentario"
83
84
  comment_reply: "Respuesta"
85
+ edit: "Editar"
84
86
 
85
87
  recent_posts: "Artículos Recientes"
86
88
 
@@ -142,6 +144,7 @@ it:
142
144
  comment_saved: "Il tuo commento è stato salvato"
143
145
  comment_error: "C'è stato un errore durante il salvataggio del commento"
144
146
  comment_reply: "Rispondi"
147
+ edit: "Modifica"
145
148
 
146
149
  recent_posts: "Articoli recenti"
147
150
 
@@ -102,6 +102,7 @@ Rails.application.routes.draw do
102
102
 
103
103
  resources :plugins, only: [:index, :destroy] do
104
104
  get "toggle", on: :collection
105
+ get "upgrade"
105
106
  end
106
107
 
107
108
  # installer
@@ -1,4 +1,5 @@
1
1
  $camaleon_engine_dir = File.expand_path("../../../", __FILE__)
2
+ require File.join($camaleon_engine_dir, "lib", "plugin_routes").to_s
2
3
  Dir[File.join($camaleon_engine_dir, "lib", "ext", "**", "*.rb")].each{ |f| require f }
3
4
  module CamaleonCms
4
5
  class Engine < ::Rails::Engine
@@ -6,43 +7,38 @@ module CamaleonCms
6
7
  if app.respond_to?(:console)
7
8
  app.console do
8
9
  puts "******** Camaleon CMS: To use custom models and helpers of installed plugins, write this: ********"
9
- puts "include SiteHelper; site_console_switch(Site.first.decorate);"
10
- puts "*********** To change current site, use: site_console_switch(site) *************"
10
+ puts "- include SiteHelper"
11
+ puts "- site_console_switch(Site.first.decorate)"
11
12
  end
12
13
  end
13
14
  end
14
15
 
15
16
  initializer :append_migrations do |app|
16
- unless defined?(PluginRoutes)
17
- require File.join($camaleon_engine_dir, "lib", "generators", "camaleon_cms", "install_template", "plugin_routes").to_s
18
- Rails.logger.info "Please copy plugin_routes.rb file in lib/"
19
- else
20
- engine_dir = File.expand_path("../../../", __FILE__)
21
- app.config.i18n.load_path += Dir[File.join($camaleon_engine_dir, 'config', 'locales', '**', '*.{rb,yml}')]
22
- app.config.i18n.enforce_available_locales = false
23
- PluginRoutes.all_apps.each{ |info| app.config.i18n.load_path += Dir[File.join(info["path"], "config", "locales", '*.{rb,yml}')] }
17
+ engine_dir = File.expand_path("../../../", __FILE__)
18
+ app.config.i18n.load_path += Dir[File.join($camaleon_engine_dir, 'config', 'locales', '**', '*.{rb,yml}')]
19
+ app.config.i18n.enforce_available_locales = false
20
+ PluginRoutes.all_apps.each{ |info| app.config.i18n.load_path += Dir[File.join(info["path"], "config", "locales", '*.{rb,yml}')] }
24
21
 
25
- # assets
26
- app.config.assets.paths << Rails.root.join("app", "apps")
27
- app.config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
28
- app.config.assets.paths << File.join($camaleon_engine_dir, "app", "apps")
29
- app.config.assets.paths << File.join($camaleon_engine_dir, 'app', 'assets', 'fonts')
30
- app.config.encoding = "utf-8"
22
+ # assets
23
+ app.config.assets.paths << Rails.root.join("app", "apps")
24
+ app.config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
25
+ app.config.assets.paths << File.join($camaleon_engine_dir, "app", "apps")
26
+ app.config.assets.paths << File.join($camaleon_engine_dir, 'app', 'assets', 'fonts')
27
+ app.config.encoding = "utf-8"
31
28
 
32
- #multiple route files
33
- app.routes_reloader.paths.push(File.join(engine_dir, "config", "routes", "admin.rb"))
34
- app.routes_reloader.paths.push(File.join(engine_dir, "config", "routes", "frontend.rb"))
35
- # Dir[File.join(engine_dir, "config", "routes", "*.rb")].each{|r| app.routes_reloader.paths.unshift(r) }
29
+ #multiple route files
30
+ app.routes_reloader.paths.push(File.join(engine_dir, "config", "routes", "admin.rb"))
31
+ app.routes_reloader.paths.push(File.join(engine_dir, "config", "routes", "frontend.rb"))
32
+ # Dir[File.join(engine_dir, "config", "routes", "*.rb")].each{|r| app.routes_reloader.paths.unshift(r) }
36
33
 
37
- # extra configuration for plugins
38
- app.config.autoload_paths += %W{#{app.config.root}/app/apps/**/}
39
- PluginRoutes.all_plugins.each{ |plugin| app.config.paths["db/migrate"] << File.join(plugin["path"], "migrate") if Dir.exist?(File.join(plugin["path"], "migrate")) }
34
+ # extra configuration for plugins
35
+ app.config.autoload_paths += %W{#{app.config.root}/app/apps/**/}
36
+ PluginRoutes.all_plugins.each{ |plugin| app.config.paths["db/migrate"] << File.join(plugin["path"], "migrate") if Dir.exist?(File.join(plugin["path"], "migrate")) }
40
37
 
41
- # migrations checking
42
- unless app.root.to_s.match root.to_s
43
- config.paths["db/migrate"].expanded.each do |expanded_path|
44
- app.config.paths["db/migrate"] << expanded_path
45
- end
38
+ # migrations checking
39
+ unless app.root.to_s.match root.to_s
40
+ config.paths["db/migrate"].expanded.each do |expanded_path|
41
+ app.config.paths["db/migrate"] << expanded_path
46
42
  end
47
43
  end
48
44
  end
@@ -1,3 +1,3 @@
1
1
  module CamaleonCms
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/ext/string.rb CHANGED
@@ -16,6 +16,10 @@ class String
16
16
  return /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.match(self).present?
17
17
  end
18
18
 
19
+ def is_float?
20
+ self.to_f.to_s == self.to_s
21
+ end
22
+
19
23
  def is_number?
20
24
  self.to_f.to_s == self.to_s || self.to_i.to_s == self.to_s
21
25
  end
@@ -25,7 +29,9 @@ class String
25
29
  end
26
30
 
27
31
  def to_var
28
- if is_number?
32
+ if is_float?
33
+ self.to_f
34
+ elsif is_number?
29
35
  self.to_i
30
36
  elsif is_bool?
31
37
  self.to_bool
@@ -1,239 +1,23 @@
1
1
  require 'json'
2
2
  class PluginRoutes
3
- @@_vars = []
4
- # load plugin routes if it is enabled
5
- def self.load(env = "admin")
6
- plugins = all_enabled_plugins
7
- res = ""
8
- if env == "front"
9
- res << "namespace :plugins do \n"
10
- plugins.each do |plugin|
11
- res << "namespace '#{plugin["key"]}' do \n"
12
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
13
- res << "end\n"
14
- end
15
- res << "end\n"
16
-
17
- elsif env == "admin" # admin
18
- res << "scope 'admin', as: 'admin' do \n"
19
- res << "namespace :plugins do \n"
20
- plugins.each do |plugin|
21
- res << "namespace '#{plugin["key"]}' do \n"
22
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
23
- res << "end\n"
24
- end
25
- res << "end\n"
26
- res << "end\n"
27
- else # main
28
- plugins.each do |plugin|
29
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
30
- end
31
- end
32
- res + load_themes(env)
33
- end
34
-
35
- def self.load_themes(env = "admin")
36
- plugins = all_enabled_themes
37
- res = ""
38
- if env == "front"
39
- res << "namespace :themes do \n"
40
- plugins.each do |plugin|
41
- res << "namespace '#{plugin["key"]}' do \n"
42
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
43
- res << "end\n"
44
- end
45
- res << "end\n"
46
-
47
- elsif env == "admin" # admin
48
- res << "scope 'admin', as: 'admin' do \n"
49
- res << "namespace :themes do \n"
50
- plugins.each do |plugin|
51
- res << "namespace '#{plugin["key"]}' do \n"
52
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
53
- res << "end\n"
54
- end
55
- res << "end\n"
56
- res << "end\n"
57
- else # main
58
- plugins.each do |plugin|
59
- res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
60
- end
61
- end
62
- res
63
- end
64
-
65
- # return plugin information
66
- def self.plugin_info(plugin_key)
67
- self.all_plugins.each{|p| return p if p["key"] == plugin_key }
68
- nil
69
- end
70
-
71
- # return theme information
72
- # if theme_name is nil, the use current site theme
73
- def self.theme_info(theme_name)
74
- self.all_themes.each{|p| return p if p["key"] == theme_name }
75
- nil
76
- end
77
-
78
- # return system information
79
- def self.system_info
80
- camaleon_gem = get_gem('camaleon_cms')
81
- return {} if !camaleon_gem
82
- r = cache_variable("system_info"); return r unless r.nil?
83
- res = JSON.parse(File.read(File.join(camaleon_gem.gem_dir, "config", "system.json")))
84
- res = res.with_indifferent_access rescue res
85
- return cache_variable("system_info", res) unless File.exist?(system_file = File.join(apps_dir, "..", '..', "config", "system.json"))
86
- res = res.merge(JSON.parse(File.read(system_file)).with_indifferent_access).with_indifferent_access
87
- res["key"] = "system"
88
- res["path"] = ''
89
- res["kind"] = "system"
90
- res["hooks"] = {} unless res["hooks"].present?
91
- res["hooks"]["on_notification"] = (res["hooks"]["on_notification"] || []) + ["admin_system_notifications"]
92
- cache_variable("system_info", res)
93
- end
94
-
95
- # update a system value
96
- # key: attribute name
97
- # value: new value for attribute
98
- def self.system_info_set(key, val)
99
- ff = File.read(File.join(apps_dir, "..", '..', "config", "system.json"))
100
- File.open(File.join(apps_dir, "..", '..', "config", "system.json"), "w") do |f|
101
- f.write(ff.sub(/"#{key}": ?\"(.*)\"/, "\"#{key}\": \"#{val}\""))
102
- end
103
- self.reload
104
- end
105
-
106
- # reload routes
107
- def self.reload
108
- @@_vars.each {|v| class_variable_set("@@cache_#{v}", nil) }
109
- # WPRails::Application.routes_reloader.reload!
110
- Rails.application.reload_routes!
111
- end
112
-
113
- # return all enabled plugins []
114
- def self.enabled_plugins(site)
115
- r = cache_variable("enable_plugins_site_#{site.id}"); return r unless r.nil?
116
- res = []
117
- enabled_ps = site.plugins.active.pluck(:slug)
118
- all_plugins.each do |plugin|
119
- res << plugin if enabled_ps.include?(plugin["key"])
120
- end
121
- res = res.sort_by{|e| e["position"] || 10 }
122
- cache_variable("enable_plugins_site_#{site.id}", res)
123
- end
124
-
125
- # return all enabled apps for site (themes + system + plugins) []
126
- # theme_slug: current theme slug
127
- def self.enabled_apps(site, theme_slug = nil)
128
- theme_slug = theme_slug || site.get_theme_slug
129
- r = cache_variable("enabled_apps_#{site.id}_#{theme_slug}"); return r unless r.nil?
130
- res = [system_info()] + enabled_plugins(site) + [theme_info(theme_slug)]
131
- cache_variable("enabled_apps_#{site.id}_#{theme_slug}", res)
132
- end
133
-
134
- # return all enabled apps as []: system, themes, plugins
135
- def self.all_enabled_apps
136
- [system_info()] + all_enabled_themes + all_enabled_plugins
137
- end
138
-
139
- # return all enabled themes (a theme is enabled if at least one site is assigned)
140
- def self.all_enabled_themes
141
- r = cache_variable("all_enabled_themes"); return r unless r.nil?
142
- res = []
143
- get_sites.each do |site|
144
- i = theme_info(site.get_theme_slug)
145
- res << i if i.present?
146
- end
147
- cache_variable("all_enabled_themes", res)
148
- end
149
-
150
- # return all enabled plugins (a theme is enabled if at least one site has installed)
151
- def self.all_enabled_plugins
152
- r = cache_variable("all_enabled_plugins"); return r unless r.nil?
153
- res, enabled_ps = [], []
154
- get_sites.each { |site| enabled_ps += site.plugins.active.pluck(:slug) }
155
- all_plugins.each do |plugin|
156
- if enabled_ps.include?(plugin["key"])
157
- res << plugin
158
- end
159
- end
160
- cache_variable("all_enabled_plugins", res)
161
- end
162
-
163
- # all helpers of enabled plugins for site
164
- def self.site_plugin_helpers(site)
165
- r = cache_variable("site_plugin_helpers"); return r unless r.nil?
166
- res = []
167
- enabled_apps(site).each do |settings|
168
- res += settings["helpers"] if settings["helpers"].present?
169
- end
170
- cache_variable("site_plugin_helpers", res)
171
- end
172
-
173
- # all helpers of enabled plugins
174
- def self.plugin_helpers
175
- r = cache_variable("plugins_helper"); return r unless r.nil?
176
- res = []
177
- all_enabled_apps.each do |settings|
178
- res += settings["helpers"] if settings["helpers"].present?
179
- end
180
- cache_variable("plugins_helper", res)
181
- end
182
-
183
- # destroy plugin
184
- def self.destroy_plugin(plugin_key)
185
- FileUtils.rm_r(Rails.root.join("app", "apps", "plugins", plugin_key)) rescue ""
186
- PluginRoutes.reload
187
- end
188
-
189
- # destroy theme
190
- def self.destroy_theme(theme_key)
191
- FileUtils.rm_r(Rails.root.join("app", "apps", "themes", theme_key)) rescue ""
192
- PluginRoutes.reload
193
- end
194
-
195
- def self.cache_variable(var_name, value=nil)
196
- @@_vars.push(var_name).uniq
197
- cache = class_variable_get("@@cache_#{var_name}") rescue nil
198
- return cache if value.nil?
199
- class_variable_set("@@cache_#{var_name}", value)
200
- value
201
- end
202
-
203
- # return all sites registered for Plugin routes
204
- def self.get_sites
205
- r = cache_variable("site_get_sites"); return r unless r.nil?
206
- res = {}
207
- begin
208
- res = Site.eager_load(:metas).order(term_group: :desc).all
209
- rescue
210
- end
211
- cache_variable("site_get_sites", res)
212
- end
213
-
214
- # return all locales for all sites joined by |
215
- def self.all_locales
216
- r = cache_variable("site_all_locales"); return r unless r.nil?
217
- res = []
218
- get_sites.each do |s|
219
- res += s.get_languages
220
- end
221
- cache_variable("site_all_locales", res.uniq.join("|"))
222
- end
223
-
224
3
  # draw "all" gems registered for the plugins or themes and camaleon gems
225
4
  def self.draw_gems
226
5
  res = []
6
+ dirs = [] + Dir["#{apps_dir}/plugins/*"] + Dir["#{apps_dir}/themes/*"]
227
7
  # recovering gem dependencies
228
8
  if camaleon_gem = get_gem('camaleon_cms')
229
- res << File.read(File.join(camaleon_gem.gem_dir, "lib", "Gemfile")).gsub("source 'https://rubygems.org'", "")
9
+ gem_file = File.join(camaleon_gem.gem_dir, "lib", "Gemfile")
10
+ res << File.read(gem_file).gsub("source 'https://rubygems.org'", "") if File.exist?(gem_file)
230
11
  else
231
- puts "******** Warning: You need to install camaleon_cms gem. *********"
232
- return ""
12
+ # recover cached gemfile
13
+ gem_file = File.join(apps_dir, "..", "..", "lib", "Gemfile_camaleon")
14
+ res << File.read(gem_file).gsub("source 'https://rubygems.org'", "") if File.exist?(gem_file)
233
15
  end
234
- (self.all_themes + self.all_plugins).each do |item|
235
- f = File.join(item["path"], "config", "Gemfile")
236
- res << File.read(f) if File.exist?(f)
16
+
17
+ dirs.each do |path|
18
+ next if [".", ".."].include?(path)
19
+ g = File.join(path, "config", "Gemfile")
20
+ res << File.read(g) if File.exist?(g)
237
21
  end
238
22
  res.join("\n")
239
23
  end
@@ -245,56 +29,6 @@ class PluginRoutes
245
29
  dir.join("/")+ '/app/apps'
246
30
  end
247
31
 
248
- # return all plugins located in cms and in this project
249
- def self.all_plugins
250
- camaleon_gem = get_gem('camaleon_cms')
251
- return [] if !camaleon_gem
252
- r = cache_variable("all_plugins"); return r unless (r.nil? || r == [])
253
- res = []
254
- entries = [".", ".."]
255
- (Dir["#{apps_dir}/plugins/*"] + Dir["#{camaleon_gem.gem_dir}/app/apps/plugins/*"]).each do |path|
256
- entry = path.split("/").last
257
- config = File.join(path, "config", "config.json")
258
- next if entries.include?(entry) || !File.directory?(path) || !File.exist?(config)
259
- p = JSON.parse(File.read(config))
260
- p = p.with_indifferent_access rescue p
261
- p["key"] = entry
262
- p["path"] = path
263
- p["kind"] = "plugin"
264
- res << p
265
- entries << entry
266
- end
267
- cache_variable("all_plugins", res)
268
- end
269
-
270
- # return an array of all themes installed for all sites
271
- def self.all_themes
272
- camaleon_gem = get_gem('camaleon_cms')
273
- return [] if !camaleon_gem
274
- r = cache_variable("all_themes"); return r unless (r.nil? || r == [])
275
- res = []
276
- entries = [".", ".."]
277
- (Dir["#{apps_dir}/themes/*"] + Dir["#{camaleon_gem.gem_dir}/app/apps/themes/*"]).each do |path|
278
- entry = path.split("/").last
279
- config = File.join(path, "config", "config.json")
280
- next if entries.include?(entry) || !File.directory?(path) || !File.exist?(config)
281
- p = JSON.parse(File.read(config))
282
- p = p.with_indifferent_access rescue p
283
- p["key"] = entry
284
- p["path"] = path
285
- p["kind"] = "theme"
286
- p["title"] = p["name"]
287
- res << p
288
- entries << entry
289
- end
290
- cache_variable("all_themes", res)
291
- end
292
-
293
- # return all apps loaded
294
- def self.all_apps
295
- all_plugins+all_themes
296
- end
297
-
298
32
  # check if a gem is available or not
299
33
  # Arguemnts:
300
34
  # name: name of the gem
@@ -12,6 +12,9 @@
12
12
  ],
13
13
  "on_inactive": [
14
14
  "pluginKey_on_inactive"
15
+ ],
16
+ "on_upgrade": [
17
+ "pluginKey_on_upgrade"
15
18
  ]
16
19
  //here you can add all your hooks (read documentation)
17
20
  }
@@ -14,4 +14,9 @@ module Plugins::PluginClass::MainHelper
14
14
  # plugin: plugin model
15
15
  def pluginKey_on_inactive(plugin)
16
16
  end
17
+
18
+ # here all actions to upgrade for a new version
19
+ # plugin: plugin model
20
+ def pluginKey_on_upgrade(plugin)
21
+ end
17
22
  end
@@ -0,0 +1,290 @@
1
+ require 'json'
2
+ class PluginRoutes
3
+ @@_vars = []
4
+ # load plugin routes if it is enabled
5
+ def self.load(env = "admin")
6
+ plugins = all_enabled_plugins
7
+ res = ""
8
+ if env == "front"
9
+ res << "namespace :plugins do \n"
10
+ plugins.each do |plugin|
11
+ res << "namespace '#{plugin["key"]}' do \n"
12
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
13
+ res << "end\n"
14
+ end
15
+ res << "end\n"
16
+
17
+ elsif env == "admin" # admin
18
+ res << "scope 'admin', as: 'admin' do \n"
19
+ res << "namespace :plugins do \n"
20
+ plugins.each do |plugin|
21
+ res << "namespace '#{plugin["key"]}' do \n"
22
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
23
+ res << "end\n"
24
+ end
25
+ res << "end\n"
26
+ res << "end\n"
27
+ else # main
28
+ plugins.each do |plugin|
29
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
30
+ end
31
+ end
32
+ res + load_themes(env)
33
+ end
34
+
35
+ def self.load_themes(env = "admin")
36
+ plugins = all_enabled_themes
37
+ res = ""
38
+ if env == "front"
39
+ res << "namespace :themes do \n"
40
+ plugins.each do |plugin|
41
+ res << "namespace '#{plugin["key"]}' do \n"
42
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
43
+ res << "end\n"
44
+ end
45
+ res << "end\n"
46
+
47
+ elsif env == "admin" # admin
48
+ res << "scope 'admin', as: 'admin' do \n"
49
+ res << "namespace :themes do \n"
50
+ plugins.each do |plugin|
51
+ res << "namespace '#{plugin["key"]}' do \n"
52
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
53
+ res << "end\n"
54
+ end
55
+ res << "end\n"
56
+ res << "end\n"
57
+ else # main
58
+ plugins.each do |plugin|
59
+ res << "#{File.open(File.join(plugin["path"], "config", "routes_#{env}.txt")).read}\n" rescue ""
60
+ end
61
+ end
62
+ res
63
+ end
64
+
65
+ # return plugin information
66
+ def self.plugin_info(plugin_key)
67
+ self.all_plugins.each{|p| return p if p["key"] == plugin_key }
68
+ nil
69
+ end
70
+
71
+ # return theme information
72
+ # if theme_name is nil, the use current site theme
73
+ def self.theme_info(theme_name)
74
+ self.all_themes.each{|p| return p if p["key"] == theme_name }
75
+ nil
76
+ end
77
+
78
+ # return system information
79
+ def self.system_info
80
+ camaleon_gem = get_gem('camaleon_cms')
81
+ return {} if !camaleon_gem
82
+ r = cache_variable("system_info"); return r unless r.nil?
83
+ res = JSON.parse(File.read(File.join(camaleon_gem.gem_dir, "config", "system.json")))
84
+ res = res.with_indifferent_access rescue res
85
+ return cache_variable("system_info", res) unless File.exist?(system_file = File.join(apps_dir, "..", '..', "config", "system.json"))
86
+ res = res.merge(JSON.parse(File.read(system_file)).with_indifferent_access).with_indifferent_access
87
+ res["key"] = "system"
88
+ res["path"] = ''
89
+ res["kind"] = "system"
90
+ res["hooks"] = {} unless res["hooks"].present?
91
+ res["hooks"]["on_notification"] = (res["hooks"]["on_notification"] || []) + ["admin_system_notifications"]
92
+ cache_variable("system_info", res)
93
+ end
94
+
95
+ # update a system value
96
+ # key: attribute name
97
+ # value: new value for attribute
98
+ def self.system_info_set(key, val)
99
+ ff = File.read(File.join(apps_dir, "..", '..', "config", "system.json"))
100
+ File.open(File.join(apps_dir, "..", '..', "config", "system.json"), "w") do |f|
101
+ f.write(ff.sub(/"#{key}": ?\"(.*)\"/, "\"#{key}\": \"#{val}\""))
102
+ end
103
+ self.reload
104
+ end
105
+
106
+ # reload routes
107
+ def self.reload
108
+ @@_vars.each {|v| class_variable_set("@@cache_#{v}", nil) }
109
+ # WPRails::Application.routes_reloader.reload!
110
+ Rails.application.reload_routes!
111
+ end
112
+
113
+ # return all enabled plugins []
114
+ def self.enabled_plugins(site)
115
+ r = cache_variable("enable_plugins_site_#{site.id}"); return r unless r.nil?
116
+ res = []
117
+ enabled_ps = site.plugins.active.pluck(:slug)
118
+ all_plugins.each do |plugin|
119
+ res << plugin if enabled_ps.include?(plugin["key"])
120
+ end
121
+ res = res.sort_by{|e| e["position"] || 10 }
122
+ cache_variable("enable_plugins_site_#{site.id}", res)
123
+ end
124
+
125
+ # return all enabled apps for site (themes + system + plugins) []
126
+ # theme_slug: current theme slug
127
+ def self.enabled_apps(site, theme_slug = nil)
128
+ theme_slug = theme_slug || site.get_theme_slug
129
+ r = cache_variable("enabled_apps_#{site.id}_#{theme_slug}"); return r unless r.nil?
130
+ res = [system_info()] + enabled_plugins(site) + [theme_info(theme_slug)]
131
+ cache_variable("enabled_apps_#{site.id}_#{theme_slug}", res)
132
+ end
133
+
134
+ # return all enabled apps as []: system, themes, plugins
135
+ def self.all_enabled_apps
136
+ [system_info()] + all_enabled_themes + all_enabled_plugins
137
+ end
138
+
139
+ # return all enabled themes (a theme is enabled if at least one site is assigned)
140
+ def self.all_enabled_themes
141
+ r = cache_variable("all_enabled_themes"); return r unless r.nil?
142
+ res = []
143
+ get_sites.each do |site|
144
+ i = theme_info(site.get_theme_slug)
145
+ res << i if i.present?
146
+ end
147
+ cache_variable("all_enabled_themes", res)
148
+ end
149
+
150
+ # return all enabled plugins (a theme is enabled if at least one site has installed)
151
+ def self.all_enabled_plugins
152
+ r = cache_variable("all_enabled_plugins"); return r unless r.nil?
153
+ res, enabled_ps = [], []
154
+ get_sites.each { |site| enabled_ps += site.plugins.active.pluck(:slug) }
155
+ all_plugins.each do |plugin|
156
+ if enabled_ps.include?(plugin["key"])
157
+ res << plugin
158
+ end
159
+ end
160
+ cache_variable("all_enabled_plugins", res)
161
+ end
162
+
163
+ # all helpers of enabled plugins for site
164
+ def self.site_plugin_helpers(site)
165
+ r = cache_variable("site_plugin_helpers"); return r unless r.nil?
166
+ res = []
167
+ enabled_apps(site).each do |settings|
168
+ res += settings["helpers"] if settings["helpers"].present?
169
+ end
170
+ cache_variable("site_plugin_helpers", res)
171
+ end
172
+
173
+ # all helpers of enabled plugins
174
+ def self.plugin_helpers
175
+ r = cache_variable("plugins_helper"); return r unless r.nil?
176
+ res = []
177
+ all_enabled_apps.each do |settings|
178
+ res += settings["helpers"] if settings["helpers"].present?
179
+ end
180
+ cache_variable("plugins_helper", res)
181
+ end
182
+
183
+ # destroy plugin
184
+ def self.destroy_plugin(plugin_key)
185
+ FileUtils.rm_r(Rails.root.join("app", "apps", "plugins", plugin_key)) rescue ""
186
+ PluginRoutes.reload
187
+ end
188
+
189
+ # destroy theme
190
+ def self.destroy_theme(theme_key)
191
+ FileUtils.rm_r(Rails.root.join("app", "apps", "themes", theme_key)) rescue ""
192
+ PluginRoutes.reload
193
+ end
194
+
195
+ def self.cache_variable(var_name, value=nil)
196
+ @@_vars.push(var_name).uniq
197
+ cache = class_variable_get("@@cache_#{var_name}") rescue nil
198
+ return cache if value.nil?
199
+ class_variable_set("@@cache_#{var_name}", value)
200
+ value
201
+ end
202
+
203
+ # return all sites registered for Plugin routes
204
+ def self.get_sites
205
+ r = cache_variable("site_get_sites"); return r unless r.nil?
206
+ res = {}
207
+ begin
208
+ res = Site.eager_load(:metas).order(term_group: :desc).all
209
+ rescue
210
+ end
211
+ cache_variable("site_get_sites", res)
212
+ end
213
+
214
+ # return all locales for all sites joined by |
215
+ def self.all_locales
216
+ r = cache_variable("site_all_locales"); return r unless r.nil?
217
+ res = []
218
+ get_sites.each do |s|
219
+ res += s.get_languages
220
+ end
221
+ cache_variable("site_all_locales", res.uniq.join("|"))
222
+ end
223
+
224
+ # return apps directory path
225
+ def self.apps_dir
226
+ Rails.root.join("app", "apps").to_s
227
+ end
228
+
229
+ # return all plugins located in cms and in this project
230
+ def self.all_plugins
231
+ camaleon_gem = get_gem('camaleon_cms')
232
+ return [] if !camaleon_gem
233
+ r = cache_variable("all_plugins"); return r unless (r.nil? || r == [])
234
+ res = []
235
+ entries = [".", ".."]
236
+ (Dir["#{apps_dir}/plugins/*"] + Dir["#{camaleon_gem.gem_dir}/app/apps/plugins/*"]).each do |path|
237
+ entry = path.split("/").last
238
+ config = File.join(path, "config", "config.json")
239
+ next if entries.include?(entry) || !File.directory?(path) || !File.exist?(config)
240
+ p = JSON.parse(File.read(config))
241
+ p = p.with_indifferent_access rescue p
242
+ p["key"] = entry
243
+ p["path"] = path
244
+ p["kind"] = "plugin"
245
+ res << p
246
+ entries << entry
247
+ end
248
+ cache_variable("all_plugins", res)
249
+ end
250
+
251
+ # return an array of all themes installed for all sites
252
+ def self.all_themes
253
+ camaleon_gem = get_gem('camaleon_cms')
254
+ return [] if !camaleon_gem
255
+ r = cache_variable("all_themes"); return r unless (r.nil? || r == [])
256
+ res = []
257
+ entries = [".", ".."]
258
+ (Dir["#{apps_dir}/themes/*"] + Dir["#{camaleon_gem.gem_dir}/app/apps/themes/*"]).each do |path|
259
+ entry = path.split("/").last
260
+ config = File.join(path, "config", "config.json")
261
+ next if entries.include?(entry) || !File.directory?(path) || !File.exist?(config)
262
+ p = JSON.parse(File.read(config))
263
+ p = p.with_indifferent_access rescue p
264
+ p["key"] = entry
265
+ p["path"] = path
266
+ p["kind"] = "theme"
267
+ p["title"] = p["name"]
268
+ res << p
269
+ entries << entry
270
+ end
271
+ cache_variable("all_themes", res)
272
+ end
273
+
274
+ # return all apps loaded
275
+ def self.all_apps
276
+ all_plugins+all_themes
277
+ end
278
+
279
+ # check if a gem is available or not
280
+ # Arguemnts:
281
+ # name: name of the gem
282
+ # return (Boolean) true/false
283
+ def self.get_gem(name)
284
+ Gem::Specification.find_by_name(name)
285
+ rescue Gem::LoadError
286
+ false
287
+ rescue
288
+ Gem.available?(name)
289
+ end
290
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camaleon_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen Peredo Diaz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Camaleon CMS is a dynamic and advanced content management system based
14
14
  on Ruby on Rails 4 as an alternative to Wordpress.
@@ -653,6 +653,7 @@ files:
653
653
  - lib/generators/ctheme_template/app/apps/themes/my_theme/views/index.html.erb
654
654
  - lib/generators/ctheme_template/app/apps/themes/my_theme/views/layouts/index.html.erb
655
655
  - lib/generators/ctheme_template/app/apps/themes/my_theme/views/partials/readme.txt
656
+ - lib/plugin_routes.rb
656
657
  - lib/tasks/camaleon_cms_tasks.rake
657
658
  - test/camaleon_cms_test.rb
658
659
  - test/integration/navigation_test.rb
@@ -669,13 +670,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
669
670
  requirements:
670
671
  - - ">="
671
672
  - !ruby/object:Gem::Version
672
- version: '0'
673
+ version: 1.9.3
673
674
  required_rubygems_version: !ruby/object:Gem::Requirement
674
675
  requirements:
675
676
  - - ">="
676
677
  - !ruby/object:Gem::Version
677
678
  version: '0'
678
- requirements: []
679
+ requirements:
680
+ - rails >= 4.1
681
+ - ruby >= 1.9.3
682
+ - imagemagick
679
683
  rubyforge_project:
680
684
  rubygems_version: 2.4.8
681
685
  signing_key: