trusty-cms 4.1.0 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +98 -98
- data/README.md +1 -1
- data/Rakefile +7 -7
- data/app/assets/javascripts/admin/assets.js +1 -1
- data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
- data/app/assets/javascripts/rad_social/rad_email.js +0 -1
- data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
- data/app/assets/stylesheets/admin/partials/_forms.scss +1 -1
- data/app/assets/stylesheets/admin/partials/_messages.scss +7 -2
- data/app/assets/stylesheets/admin/partials/_popup.scss +1 -1
- data/app/assets/stylesheets/rad_social/rad_screen.scss +0 -4
- data/app/controllers/admin/assets_controller.rb +21 -31
- data/app/controllers/admin/configuration_controller.rb +9 -11
- data/app/controllers/admin/extensions_controller.rb +3 -3
- data/app/controllers/admin/layouts_controller.rb +3 -4
- data/app/controllers/admin/page_attachments_controller.rb +5 -5
- data/app/controllers/admin/page_fields_controller.rb +3 -4
- data/app/controllers/admin/page_parts_controller.rb +4 -5
- data/app/controllers/admin/pages_controller.rb +55 -56
- data/app/controllers/admin/references_controller.rb +1 -1
- data/app/controllers/admin/resource_controller.rb +132 -130
- data/app/controllers/admin/sites_controller.rb +4 -4
- data/app/controllers/admin/snippets_controller.rb +3 -4
- data/app/controllers/admin/users_controller.rb +16 -16
- data/app/controllers/application_controller.rb +47 -48
- data/app/controllers/site_controller.rb +51 -48
- data/app/controllers/social_mailer_controller.rb +12 -22
- data/app/helpers/admin/configuration_helper.rb +19 -20
- data/app/helpers/admin/layouts_helper.rb +0 -1
- data/app/helpers/admin/node_helper.rb +27 -24
- data/app/helpers/admin/pages_helper.rb +2 -2
- data/app/helpers/admin/preferences_helper.rb +0 -1
- data/app/helpers/admin/references_helper.rb +9 -10
- data/app/helpers/admin/regions_helper.rb +3 -3
- data/app/helpers/application_helper.rb +32 -33
- data/app/helpers/rad_social_helper.rb +8 -11
- data/app/helpers/scoped_helper.rb +1 -3
- data/app/helpers/sites_helper.rb +4 -4
- data/app/mailers/devise_mailer.rb +3 -4
- data/app/mailers/rad_social_mailer.rb +8 -8
- data/app/models/asset.rb +62 -63
- data/app/models/asset_type.rb +38 -39
- data/app/models/deprecated_tags.rb +3 -4
- data/app/models/file_not_found_page.rb +1 -3
- data/app/models/haml_filter.rb +1 -1
- data/app/models/layout.rb +4 -5
- data/app/models/legacy_user.rb +2 -2
- data/app/models/menu_renderer.rb +16 -18
- data/app/models/page.rb +96 -93
- data/app/models/page_attachment.rb +1 -2
- data/app/models/page_context.rb +11 -12
- data/app/models/page_part.rb +3 -4
- data/app/models/rails_page.rb +10 -12
- data/app/models/site.rb +22 -21
- data/app/models/snippet.rb +6 -8
- data/app/models/snippet_finder.rb +3 -3
- data/app/models/snippet_tags.rb +4 -4
- data/app/models/standard_tags.rb +258 -252
- data/app/models/status.rb +8 -8
- data/app/models/trusty_cms/config.rb +25 -25
- data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
- data/app/models/user.rb +15 -14
- data/app/models/user_action_observer.rb +3 -3
- data/app/views/admin/assets/edit.html.haml +0 -9
- data/app/views/admin/assets/new.html.haml +0 -3
- data/app/views/admin/assets/remove.html.haml +1 -1
- data/app/views/admin/layouts/remove.html.haml +4 -3
- data/app/views/admin/page_parts/_page_part.html.haml +1 -1
- data/app/views/admin/pages/remove.html.haml +2 -1
- data/app/views/admin/sites/index.haml +3 -1
- data/app/views/admin/snippets/remove.html.haml +5 -4
- data/app/views/admin/users/remove.html.haml +2 -2
- data/app/views/rad_social_mailer/social_mail_form.html.haml +1 -3
- data/app/views/widget/_email_form.html.haml +0 -5
- data/bin/rails +4 -4
- data/bin/trusty_cms +3 -5
- data/config.ru +1 -1
- data/config/application.rb +14 -15
- data/config/boot.rb +1 -2
- data/config/environment.rb +1 -1
- data/config/environments/production.rb +0 -1
- data/config/environments/test.rb +1 -2
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/kraken.rb +2 -2
- data/config/initializers/tmp.rb +1 -1
- data/config/initializers/trusty_cms_config.rb +48 -48
- data/config/locales/en.yml +8 -8
- data/config/routes.rb +6 -7
- data/lib/active_record_extensions/active_record_extensions.rb +1 -2
- data/lib/annotatable.rb +3 -5
- data/lib/configuration_extensions/configuration_extensions.rb +1 -1
- data/lib/inheritable_class_attributes.rb +13 -9
- data/lib/login_system.rb +73 -73
- data/lib/method_observer.rb +13 -12
- data/lib/ostruct.rb +7 -10
- data/lib/simpleton.rb +0 -4
- data/lib/string_extensions/string_extensions.rb +3 -3
- data/lib/symbol_extensions/symbol_extensions.rb +1 -1
- data/lib/tasks/database.rake +28 -28
- data/lib/tasks/extensions.rake +18 -18
- data/lib/tasks/framework.rake +68 -68
- data/lib/tasks/radiant_config.rake +4 -4
- data/lib/tasks/snippets_extension_tasks.rake +11 -11
- data/lib/tasks/translate.rake +14 -14
- data/lib/tasks/upgrade_to_devise.rake +1 -1
- data/lib/translation_support.rb +22 -22
- data/lib/trusty_cms.rb +2 -2
- data/lib/trusty_cms/admin_ui.rb +19 -16
- data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
- data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
- data/lib/trusty_cms/available_locales.rb +2 -4
- data/lib/trusty_cms/config/definition.rb +11 -8
- data/lib/trusty_cms/engine.rb +13 -14
- data/lib/trusty_cms/extension.rb +14 -16
- data/lib/trusty_cms/extension_loader.rb +6 -6
- data/lib/trusty_cms/extension_migrator.rb +42 -41
- data/lib/trusty_cms/extension_path.rb +20 -19
- data/lib/trusty_cms/initializer.rb +5 -8
- data/lib/trusty_cms/pagination/controller.rb +7 -10
- data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
- data/lib/trusty_cms/resource_responses.rb +3 -3
- data/lib/trusty_cms/setup.rb +130 -132
- data/lib/trusty_cms/taggable.rb +19 -22
- data/lib/trusty_cms/task_support.rb +9 -6
- data/package.json +1 -1
- data/public/dispatch.fcgi +1 -1
- data/public/dispatch.rb +2 -2
- data/script/extension +1 -1
- data/script/rails +2 -2
- data/spec/dummy/package.json +1 -1
- data/spec/dummy/yarn.lock +3 -3
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/core.js +126 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/index.js +4 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/map.js +56 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/seq.js +43 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/string.js +28 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/index.js +36 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/json.js +76 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/options.js +23 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/binary.js +87 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/index.js +157 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/omap.js +142 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/pairs.js +81 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/set.js +114 -0
- data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/timestamp.js +97 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/core.js +114 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/index.js +17 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/map.js +37 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/seq.js +34 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/string.js +40 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/index.js +62 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/json.js +60 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/options.js +35 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/binary.js +97 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/index.js +131 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/omap.js +105 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/pairs.js +80 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/set.js +91 -0
- data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/timestamp.js +93 -0
- data/trusty_cms.gemspec +25 -25
- data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
- data/yarn.lock +7 -7
- metadata +7609 -105
- data/app/assets/javascripts/rad_social/captcha.js +0 -42
- data/app/views/admin/assets/refresh.html.haml +0 -14
@@ -20,26 +20,26 @@ module InheritableClassAttributes
|
|
20
20
|
|
21
21
|
def cattr_inheritable_reader(*symbols)
|
22
22
|
symbols.each do |symbol|
|
23
|
-
|
24
|
-
|
23
|
+
inheritable_cattr_readers << symbol
|
24
|
+
module_eval %{
|
25
25
|
def self.#{symbol}
|
26
26
|
@#{symbol}
|
27
27
|
end
|
28
28
|
}
|
29
29
|
end
|
30
|
-
|
30
|
+
inheritable_cattr_readers.uniq!
|
31
31
|
end
|
32
32
|
|
33
33
|
def cattr_inheritable_writer(*symbols)
|
34
34
|
symbols.each do |symbol|
|
35
|
-
|
36
|
-
|
35
|
+
inheritable_cattr_writers << symbol
|
36
|
+
module_eval %{
|
37
37
|
def self.#{symbol}=(value)
|
38
38
|
@#{symbol} = value
|
39
39
|
end
|
40
40
|
}
|
41
41
|
end
|
42
|
-
|
42
|
+
inheritable_cattr_writers.uniq!
|
43
43
|
end
|
44
44
|
|
45
45
|
def cattr_inheritable_accessor(*symbols)
|
@@ -52,12 +52,16 @@ module InheritableClassAttributes
|
|
52
52
|
|
53
53
|
readers = inheritable_cattr_readers.dup
|
54
54
|
writers = inheritable_cattr_writers.dup
|
55
|
-
inheritables = [
|
55
|
+
inheritables = %i[inheritable_cattr_readers inheritable_cattr_writers]
|
56
56
|
|
57
57
|
(readers + writers + inheritables).uniq.each do |attr|
|
58
58
|
var = "@#{attr}"
|
59
|
-
old_value =
|
60
|
-
new_value = (
|
59
|
+
old_value = module_eval(var)
|
60
|
+
new_value = (begin
|
61
|
+
old_value.dup
|
62
|
+
rescue StandardError
|
63
|
+
old_value
|
64
|
+
end)
|
61
65
|
klass.module_eval("#{var} = new_value")
|
62
66
|
end
|
63
67
|
end
|
data/lib/login_system.rb
CHANGED
@@ -2,93 +2,94 @@ module LoginSystem
|
|
2
2
|
def self.included(base)
|
3
3
|
base.extend ClassMethods
|
4
4
|
base.class_eval do
|
5
|
-
#prepend_before_action :authenticate
|
6
|
-
#prepend_before_action :authorize
|
7
|
-
#helper_method :current_user
|
5
|
+
# prepend_before_action :authenticate
|
6
|
+
# prepend_before_action :authorize
|
7
|
+
# helper_method :current_user
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
-
|
13
|
+
# def current_user
|
14
|
+
# end
|
15
|
+
|
16
|
+
# def current_user=(value=nil)
|
17
|
+
# if value && value.is_a?(User)
|
18
|
+
# @current_user = value
|
19
|
+
# session['user_id'] = value.id
|
20
|
+
# else
|
21
|
+
# @current_user = nil
|
22
|
+
# session['user_id'] = nil
|
23
|
+
# end
|
24
|
+
# @current_user
|
25
|
+
# end
|
26
|
+
|
27
|
+
def authenticate
|
28
|
+
# puts _process_action_callbacks.map(&:filter)
|
29
|
+
# if current_user
|
30
|
+
# session['user_id'] = current_user.id
|
31
|
+
# true
|
32
|
+
# else
|
33
|
+
# session[:return_to] = request.original_url
|
34
|
+
# respond_to do |format|
|
35
|
+
# format.html { redirect_to login_url }
|
36
|
+
# format.any(:xml,:json) { request_http_basic_authentication }
|
37
|
+
# end
|
38
|
+
# false
|
14
39
|
# end
|
40
|
+
true
|
41
|
+
end
|
15
42
|
|
16
|
-
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
43
|
+
def authorize
|
44
|
+
# puts _process_action_callbacks.map(&:filter)
|
45
|
+
# action = action_name.to_s.intern
|
46
|
+
# if user_has_access_to_action?(action)
|
47
|
+
# true
|
48
|
+
# else
|
49
|
+
# permissions = self.class.controller_permissions[action]
|
50
|
+
# flash[:error] = permissions[:denied_message] || 'Access denied.'
|
51
|
+
# respond_to do |format|
|
52
|
+
# format.html { redirect_to(permissions[:denied_url] || { :action => :index }) }
|
53
|
+
# format.any(:xml, :json) { head :forbidden }
|
23
54
|
# end
|
24
|
-
#
|
55
|
+
# false
|
25
56
|
# end
|
57
|
+
true
|
58
|
+
end
|
26
59
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# session['user_id'] = current_user.id
|
31
|
-
# true
|
32
|
-
# else
|
33
|
-
# session[:return_to] = request.original_url
|
34
|
-
# respond_to do |format|
|
35
|
-
# format.html { redirect_to login_url }
|
36
|
-
# format.any(:xml,:json) { request_http_basic_authentication }
|
37
|
-
# end
|
38
|
-
# false
|
39
|
-
# end
|
40
|
-
true
|
41
|
-
end
|
42
|
-
|
43
|
-
def authorize
|
44
|
-
#puts _process_action_callbacks.map(&:filter)
|
45
|
-
# action = action_name.to_s.intern
|
46
|
-
# if user_has_access_to_action?(action)
|
47
|
-
# true
|
48
|
-
# else
|
49
|
-
# permissions = self.class.controller_permissions[action]
|
50
|
-
# flash[:error] = permissions[:denied_message] || 'Access denied.'
|
51
|
-
# respond_to do |format|
|
52
|
-
# format.html { redirect_to(permissions[:denied_url] || { :action => :index }) }
|
53
|
-
# format.any(:xml, :json) { head :forbidden }
|
54
|
-
# end
|
55
|
-
# false
|
56
|
-
# end
|
57
|
-
true
|
58
|
-
end
|
59
|
-
|
60
|
-
def user_has_access_to_action?(action)
|
61
|
-
self.class.user_has_access_to_action?(current_user, action, self)
|
62
|
-
end
|
60
|
+
def user_has_access_to_action?(action)
|
61
|
+
self.class.user_has_access_to_action?(current_user, action, self)
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
def login_from_session
|
65
|
+
User.unscoped.find(session['user_id'])
|
66
|
+
rescue StandardError
|
67
|
+
nil
|
68
|
+
end
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
70
|
+
def login_from_cookie
|
71
|
+
if !cookies[:session_token].blank? && user = User.find_by_session_token(cookies[:session_token]) # don't find by empty value
|
72
|
+
user.remember_me
|
73
|
+
set_session_cookie(user)
|
74
|
+
user
|
74
75
|
end
|
76
|
+
end
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
78
|
+
def login_from_http
|
79
|
+
if [Mime[:xml], Mime[:json]].include?(request.format)
|
80
|
+
authenticate_with_http_basic do |user_name, password|
|
81
|
+
User.authenticate(user_name, password)
|
81
82
|
end
|
82
83
|
end
|
84
|
+
end
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
def set_session_cookie(user = current_user)
|
87
|
+
cookies[:session_token] = { value: user.session_token, expires: (Time.now + (TrustyCms::Config['session_timeout'].to_i / 86400).days).utc }
|
88
|
+
end
|
87
89
|
|
88
90
|
module ClassMethods
|
89
|
-
|
90
91
|
def login_required?
|
91
|
-
filter_chain.any? {|f| f.method == :authenticate || f.method == :authorize }
|
92
|
+
filter_chain.any? { |f| f.method == :authenticate || f.method == :authorize }
|
92
93
|
end
|
93
94
|
|
94
95
|
def login_required
|
@@ -99,7 +100,7 @@ module LoginSystem
|
|
99
100
|
|
100
101
|
def only_allow_access_to(*args)
|
101
102
|
options = {}
|
102
|
-
options = args.pop.dup if args.last.
|
103
|
+
options = args.pop.dup if args.last.is_a?(Hash)
|
103
104
|
options.symbolize_keys!
|
104
105
|
actions = args.map { |a| a.to_s.intern }
|
105
106
|
actions.each do |action|
|
@@ -108,16 +109,15 @@ module LoginSystem
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def controller_permissions
|
111
|
-
@controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new }
|
112
|
+
@controller_permissions ||= Hash.new { |h, k| h[k.to_s.intern] = Hash.new }
|
112
113
|
end
|
113
114
|
|
114
|
-
def user_has_access_to_action?(user, action, instance=new)
|
115
|
+
def user_has_access_to_action?(user, action, instance = new)
|
115
116
|
permissions = controller_permissions[action.to_s.intern]
|
116
|
-
|
117
|
-
when allowed_roles = permissions[:when]
|
117
|
+
if allowed_roles = permissions[:when]
|
118
118
|
allowed_roles = [allowed_roles].flatten
|
119
119
|
user.present? ? allowed_roles.any? { |role| user.has_role?(role) } : false
|
120
|
-
|
120
|
+
elsif condition_method = permissions[:if]
|
121
121
|
instance.send(condition_method)
|
122
122
|
else
|
123
123
|
true
|
data/lib/method_observer.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class MethodObserver
|
2
|
-
|
3
2
|
attr_reader :target
|
4
3
|
attr_accessor :result
|
5
4
|
|
@@ -11,6 +10,7 @@ class MethodObserver
|
|
11
10
|
|
12
11
|
def observe(target)
|
13
12
|
raise ObserverCannotObserveTwiceError if @target
|
13
|
+
|
14
14
|
@target = target
|
15
15
|
make_observable(target)
|
16
16
|
end
|
@@ -26,25 +26,26 @@ class MethodObserver
|
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
|
30
|
+
def make_observable(target)
|
31
|
+
methods_to_observe.each do |method|
|
32
|
+
target.instance_eval %{
|
32
33
|
def #{method}(*args, &block)
|
33
|
-
observer = #{self.class}.instances[#{
|
34
|
+
observer = #{self.class}.instances[#{object_id}]
|
34
35
|
observer.send(:before_#{method}, *args, &block) if observer.respond_to? :before_#{method}
|
35
36
|
observer.result = super
|
36
37
|
observer.send(:after_#{method}, *args, &block) if observer.respond_to? :after_#{method}
|
37
38
|
observer.result
|
38
39
|
end
|
39
40
|
}
|
40
|
-
end
|
41
41
|
end
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def methods_to_observe
|
45
|
+
(methods_for(:before) + methods_for(:after)).uniq
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def methods_for(name)
|
49
|
+
methods.grep(/^#{name}_/).map { |n| n.to_s.gsub(/^#{name}_/, '').intern }
|
50
|
+
end
|
50
51
|
end
|
data/lib/ostruct.rb
CHANGED
@@ -2,22 +2,19 @@
|
|
2
2
|
# See more here: http://stackoverflow.com/questions/39278864/openstruct-issue-with-ruby-2-3-1/39280374#39280374
|
3
3
|
|
4
4
|
class OpenStruct
|
5
|
-
|
6
|
-
def initialize(hash=nil)
|
5
|
+
def initialize(hash = nil)
|
7
6
|
@table = {}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
new_ostruct_member(k)
|
13
|
-
end
|
7
|
+
hash&.each_pair do |k, v|
|
8
|
+
k = k.to_sym
|
9
|
+
@table[k] = v
|
10
|
+
new_ostruct_member(k)
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
14
|
def modifiable
|
18
15
|
begin
|
19
16
|
@modifiable = true
|
20
|
-
rescue
|
17
|
+
rescue StandardError
|
21
18
|
raise RuntimeError, "can't modify frozen #{self.class}", caller(3)
|
22
19
|
end
|
23
20
|
@table
|
@@ -41,6 +38,7 @@ class OpenStruct
|
|
41
38
|
if len != 1
|
42
39
|
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
|
43
40
|
end
|
41
|
+
|
44
42
|
modifiable[new_ostruct_member(mname)] = args[0]
|
45
43
|
elsif len == 0
|
46
44
|
@table[mid]
|
@@ -50,5 +48,4 @@ class OpenStruct
|
|
50
48
|
raise err
|
51
49
|
end
|
52
50
|
end
|
53
|
-
|
54
51
|
end
|
data/lib/simpleton.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module Simpleton
|
2
|
-
|
3
2
|
def self.included(base)
|
4
3
|
base.extend(ClassMethods)
|
5
4
|
end
|
6
5
|
|
7
6
|
module ClassMethods
|
8
|
-
|
9
7
|
def instance(&block)
|
10
8
|
@instance ||= new
|
11
9
|
block.call(@instance) if block_given?
|
@@ -15,7 +13,5 @@ module Simpleton
|
|
15
13
|
def method_missing(method, *args, &block)
|
16
14
|
instance.respond_to?(method) ? instance.send(method, *args, &block) : super
|
17
15
|
end
|
18
|
-
|
19
16
|
end
|
20
|
-
|
21
17
|
end
|
@@ -2,15 +2,15 @@ require 'stringex'
|
|
2
2
|
|
3
3
|
class String
|
4
4
|
def symbolize
|
5
|
-
|
5
|
+
gsub(/[^A-Za-z0-9]+/, '_').gsub(/(^_+|_+$)/, '').underscore.to_sym
|
6
6
|
end
|
7
7
|
|
8
8
|
def titlecase
|
9
|
-
|
9
|
+
gsub(/((?:^|\s)[a-z])/) { $1.to_s.upcase }
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_name(last_part = '')
|
13
|
-
|
13
|
+
underscore.gsub('/', ' ').humanize.titlecase.gsub(/\s*#{last_part}$/, '')
|
14
14
|
end
|
15
15
|
|
16
16
|
unless methods.include?('parameterize')
|
data/lib/tasks/database.rake
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
namespace :db do
|
2
|
-
desc
|
3
|
-
task :
|
2
|
+
desc 'Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!'
|
3
|
+
task remigrate: :environment do
|
4
4
|
require 'highline/import'
|
5
|
-
if ENV['OVERWRITE'].to_s.downcase == 'true'
|
5
|
+
if (ENV['OVERWRITE'].to_s.downcase == 'true') || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [yn] ")
|
6
6
|
|
7
7
|
# Migrate downward
|
8
8
|
ActiveRecord::Migrator.migrate("#{TRUSTY_CMS_ROOT}/db/migrate/", 0)
|
9
9
|
|
10
10
|
# Migrate upward
|
11
|
-
Rake::Task[
|
11
|
+
Rake::Task['db:migrate'].invoke
|
12
12
|
|
13
13
|
# Dump the schema
|
14
|
-
Rake::Task[
|
14
|
+
Rake::Task['db:schema:dump'].invoke
|
15
15
|
else
|
16
|
-
say
|
16
|
+
say 'Task cancelled.'
|
17
17
|
exit
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
task :
|
21
|
+
task remigrate: :environment do
|
22
22
|
require 'highline/import'
|
23
|
-
if ENV['OVERWRITE'].to_s.downcase == 'true'
|
23
|
+
if (ENV['OVERWRITE'].to_s.downcase == 'true') || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [yn] ")
|
24
24
|
|
25
25
|
# Migrate downward
|
26
26
|
ActiveRecord::Migrator.migrate("#{TRUSTY_CMS_ROOT}/db/migrate/", 0)
|
27
27
|
|
28
28
|
# Migrate upward
|
29
|
-
Rake::Task[
|
29
|
+
Rake::Task['db:migrate'].invoke
|
30
30
|
|
31
31
|
# Dump the schema
|
32
|
-
Rake::Task[
|
32
|
+
Rake::Task['db:schema:dump'].invoke
|
33
33
|
else
|
34
|
-
say
|
34
|
+
say 'Task cancelled.'
|
35
35
|
exit
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
task :
|
39
|
+
task initialize: :environment do
|
40
40
|
require 'highline/import'
|
41
|
-
if ENV['OVERWRITE'].to_s.downcase == 'true'
|
41
|
+
if (ENV['OVERWRITE'].to_s.downcase == 'true') || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [yn] ")
|
42
42
|
|
43
43
|
# We need to erase and remove all existing trusty-cms tables, but we don't want to
|
44
44
|
# assume that the administrator has access to drop and create the database.
|
@@ -48,21 +48,21 @@ namespace :db do
|
|
48
48
|
ActiveRecord::Base.connection.tables.each do |table|
|
49
49
|
ActiveRecord::Migration[5.2].drop_table table
|
50
50
|
end
|
51
|
-
Rake::Task[
|
51
|
+
Rake::Task['db:migrate'].invoke
|
52
52
|
else
|
53
|
-
say
|
53
|
+
say 'Task cancelled.'
|
54
54
|
exit
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
desc
|
59
|
-
task :
|
58
|
+
desc 'Bootstrap your database for TrustyCms.'
|
59
|
+
task bootstrap: :initialize do
|
60
60
|
require 'trusty_cms/setup'
|
61
61
|
TrustyCms::Setup.bootstrap(
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
62
|
+
admin_name: ENV['ADMIN_NAME'],
|
63
|
+
admin_username: ENV['ADMIN_USERNAME'],
|
64
|
+
admin_password: ENV['ADMIN_PASSWORD'],
|
65
|
+
database_template: ENV['DATABASE_TEMPLATE'],
|
66
66
|
)
|
67
67
|
puts %{
|
68
68
|
Your TrustyCms application is ready to use. Run `rails s -e production` to
|
@@ -78,16 +78,16 @@ To add more extensions just add them to your Gemfile and run `bundle install`.
|
|
78
78
|
}
|
79
79
|
end
|
80
80
|
|
81
|
-
desc
|
82
|
-
task :
|
83
|
-
ActiveRecord::Migration[5.2].verbose = ENV[
|
84
|
-
Rake::Task[
|
81
|
+
desc 'Migrate the database through all available migration scripts (looks for db/migrate/* in trusty-cms, in extensions and in your site) and update db/schema.rb by invoking db:schema:dump. Turn off output with VERBOSE=false.'
|
82
|
+
task migrate: [:environment, 'db:migrate:trusty_cms', 'db:migrate:extensions'] do
|
83
|
+
ActiveRecord::Migration[5.2].verbose = ENV['VERBOSE'] ? ENV['VERBOSE'] == 'true' : true
|
84
|
+
Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
|
85
85
|
end
|
86
86
|
|
87
87
|
namespace :migrate do
|
88
|
-
desc
|
89
|
-
task :
|
90
|
-
ActiveRecord::Migration[5.2].verbose = ENV[
|
88
|
+
desc 'Migrates the database through steps defined in the core trusty-cms distribution. Usual db:migrate options can apply.'
|
89
|
+
task trusty_cms: :environment do
|
90
|
+
ActiveRecord::Migration[5.2].verbose = ENV['VERBOSE'] ? ENV['VERBOSE'] == 'true' : true
|
91
91
|
Rake::Task['db:migrate'].invoke
|
92
92
|
end
|
93
93
|
end
|