trusty-cms 4.1.1 → 4.1.6
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 +107 -107
- 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/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 +3 -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 +3 -2
- data/app/views/admin/page_parts/_page_part.html.haml +1 -1
- data/app/views/admin/snippets/remove.html.haml +3 -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 +5 -4
- 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
@@ -17,11 +17,11 @@ module TrustyCms
|
|
17
17
|
@config = rails_config
|
18
18
|
end
|
19
19
|
|
20
|
-
def before_clear(*
|
20
|
+
def before_clear(*_args) #:nodoc
|
21
21
|
ExtensionLoader.deactivate_extensions
|
22
22
|
end
|
23
23
|
|
24
|
-
def after_clear(*
|
24
|
+
def after_clear(*_args) #:nodoc
|
25
25
|
ExtensionLoader.load_extensions
|
26
26
|
ExtensionLoader.activate_extensions
|
27
27
|
end
|
@@ -77,7 +77,7 @@ module TrustyCms
|
|
77
77
|
extension.path = extension_path
|
78
78
|
extension
|
79
79
|
rescue LoadError, NameError => e
|
80
|
-
|
80
|
+
warn "Could not load extension: #{name}.\n#{e.inspect}"
|
81
81
|
nil
|
82
82
|
end
|
83
83
|
end
|
@@ -104,14 +104,14 @@ module TrustyCms
|
|
104
104
|
if configuration.extensions.first == :all
|
105
105
|
ordered_extensions = extensions
|
106
106
|
else
|
107
|
-
configuration.extensions.each {|name| ordered_extensions << select_extension(name)
|
107
|
+
configuration.extensions.each { |name| ordered_extensions << select_extension(name) }
|
108
108
|
end
|
109
109
|
ordered_extensions.flatten.each(&:activate)
|
110
110
|
Page.load_subclasses
|
111
111
|
end
|
112
112
|
|
113
113
|
def select_extension(name)
|
114
|
-
extensions.select {|ext| ext.extension_name.symbolize == name}
|
114
|
+
extensions.select { |ext| ext.extension_name.symbolize == name }
|
115
115
|
end
|
116
116
|
|
117
117
|
alias :reactivate :activate_extensions
|
@@ -122,7 +122,7 @@ module TrustyCms
|
|
122
122
|
# An extension name can be supplied in addition to the path. It will be processed in the usual way to
|
123
123
|
# remove trusty- and -extension and any verion numbering.
|
124
124
|
#
|
125
|
-
def record_path(path, name=nil)
|
125
|
+
def record_path(path, name = nil)
|
126
126
|
ExtensionPath.from_path(path, name)
|
127
127
|
end
|
128
128
|
|
@@ -13,7 +13,7 @@ module TrustyCms
|
|
13
13
|
|
14
14
|
def get_all_versions
|
15
15
|
ActiveRecord::Base.connection.select_values("SELECT version FROM #{sanitize(schema_migrations_table_name)}").
|
16
|
-
select { |version| version.starts_with?("#{@extension.extension_name}-")}.
|
16
|
+
select { |version| version.starts_with?("#{@extension.extension_name}-") }.
|
17
17
|
map { |version| version.sub("#{@extension.extension_name}-", '').to_i }.sort
|
18
18
|
end
|
19
19
|
end
|
@@ -25,58 +25,59 @@ module TrustyCms
|
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
|
-
def quote(s)
|
29
|
-
ActiveRecord::Base.connection.quote(s)
|
30
|
-
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def quote(s)
|
30
|
+
ActiveRecord::Base.connection.quote(s)
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
def extension_name
|
34
|
+
self.class.extension.extension_name
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
def version_string(version)
|
38
|
+
"#{extension_name}-#{version}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize_extension_schema_migrations
|
42
|
+
current_version = ActiveRecord::Base.connection.select_value("SELECT schema_version FROM extension_meta WHERE name = #{sanitize(quote(extension_name))}")
|
43
|
+
if current_version
|
44
|
+
assume_migrated_upto_version(current_version.to_i)
|
45
|
+
ActiveRecord::Base.connection.delete("DELETE FROM extension_meta WHERE name = #{sanitize(quote(extension_name))}")
|
46
46
|
end
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
def initialize_received_migrations
|
50
|
+
if donors = self.class.extension.migrates_from
|
51
|
+
donors.each do |extension_name, until_migration|
|
52
|
+
replaced = ActiveRecord::Base.connection.select_values("SELECT version FROM #{sanitize(ActiveRecord::Migrator.schema_migrations_table_name)} WHERE version LIKE '#{extension_name}-%'").map { |v| v.sub(/^#{extension_name}\-/, '').to_i }
|
53
|
+
replaced.delete_if { |v| v > until_migration.to_i } if until_migration
|
54
|
+
assume_migrated_upto_version(replaced.max) if replaced.any?
|
55
55
|
end
|
56
56
|
end
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def assume_migrated_upto_version(version)
|
60
|
+
version = version.to_i
|
61
|
+
sm_table = self.class.schema_migrations_table_name
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
migrated = self.class.get_all_versions
|
64
|
+
versions = Dir["#{@migrations_path}/[0-9]*_*.rb"].map do |filename|
|
65
|
+
filename.split('/').last.split('_').first.to_i
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
unless migrated.include?(version)
|
69
|
+
ActiveRecord::Base.connection.execute "INSERT INTO #{sm_table} (version) VALUES (#{sanitize(quote(version_string(version)))})"
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
72
|
+
inserted = Set.new
|
73
|
+
(versions - migrated).each do |v|
|
74
|
+
if inserted.include?(v)
|
75
|
+
raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict."
|
76
|
+
elsif v < version
|
77
|
+
ActiveRecord::Base.connection.execute "INSERT INTO #{sm_table} (version) VALUES (#{sanitize(quote(version_string(v)))})"
|
78
|
+
inserted << v
|
79
79
|
end
|
80
80
|
end
|
81
|
+
end
|
81
82
|
end
|
82
83
|
end
|
@@ -24,7 +24,8 @@ module TrustyCms
|
|
24
24
|
@@known_paths = {}
|
25
25
|
|
26
26
|
def initialize(options = {}) #:nodoc
|
27
|
-
@name
|
27
|
+
@name = options[:name].underscore
|
28
|
+
@path = options[:path]
|
28
29
|
@@known_paths[@name.to_sym] = self
|
29
30
|
end
|
30
31
|
|
@@ -43,10 +44,10 @@ module TrustyCms
|
|
43
44
|
#
|
44
45
|
# If two arguments are given, the second is taken to be the full extension name.
|
45
46
|
#
|
46
|
-
def self.from_path(path, name=nil)
|
47
|
+
def self.from_path(path, name = nil)
|
47
48
|
name = path if name.blank?
|
48
49
|
name = File.basename(name).gsub(/^trusty-|-extension(-[\d\.a-z]+|-[a-z\d]+)*$/, '')
|
49
|
-
new(:
|
50
|
+
new(name: name, path: path)
|
50
51
|
end
|
51
52
|
|
52
53
|
# Forgets all recorded extension paths.
|
@@ -77,7 +78,7 @@ module TrustyCms
|
|
77
78
|
# Call the class method ExtensionPath.plugin_paths to get a list of the plugin paths found in all enabled extensions.
|
78
79
|
#
|
79
80
|
def plugin_paths
|
80
|
-
check_subdirectory(
|
81
|
+
check_subdirectory('vendor/plugins')
|
81
82
|
end
|
82
83
|
|
83
84
|
# Returns a list of names of all the locale files found within this extension root.
|
@@ -85,8 +86,8 @@ module TrustyCms
|
|
85
86
|
# in reverse order so that locale definitions override one another correctly.
|
86
87
|
#
|
87
88
|
def locale_paths
|
88
|
-
if check_subdirectory(
|
89
|
-
Dir[File.join(
|
89
|
+
if check_subdirectory('config/locales')
|
90
|
+
Dir[File.join(path.to_s, 'config/locales', '*.{rb,yml}')]
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
@@ -94,21 +95,21 @@ module TrustyCms
|
|
94
95
|
# Call the class method ExtensionPath.helper_paths to get a list of the helper paths found in all enabled extensions.
|
95
96
|
#
|
96
97
|
def helper_paths
|
97
|
-
check_subdirectory(
|
98
|
+
check_subdirectory('app/helpers')
|
98
99
|
end
|
99
100
|
|
100
101
|
# Returns the app/models path if it is found within this extension root.
|
101
102
|
# Call the class method ExtensionPath.model_paths to get a list of the model paths found in all enabled extensions.
|
102
103
|
#
|
103
104
|
def model_paths
|
104
|
-
check_subdirectory(
|
105
|
+
check_subdirectory('app/models')
|
105
106
|
end
|
106
107
|
|
107
108
|
# Returns the app/controllers path if it is found within this extension root.
|
108
109
|
# Call the class method ExtensionPath.controller_paths to get a list of the controller paths found in all enabled extensions.
|
109
110
|
#
|
110
111
|
def controller_paths
|
111
|
-
check_subdirectory(
|
112
|
+
check_subdirectory('app/controllers')
|
112
113
|
end
|
113
114
|
|
114
115
|
# Returns the app/views path if it is found within this extension root.
|
@@ -116,21 +117,21 @@ module TrustyCms
|
|
116
117
|
# in reverse order so that views override one another correctly.
|
117
118
|
#
|
118
119
|
def view_paths
|
119
|
-
check_subdirectory(
|
120
|
+
check_subdirectory('app/views')
|
120
121
|
end
|
121
122
|
|
122
123
|
# Returns the app/metal path if it is found within this extension root.
|
123
124
|
# Call the class method ExtensionPath.metal_paths to get a list of the metal paths found in all enabled extensions.
|
124
125
|
#
|
125
126
|
def metal_paths
|
126
|
-
check_subdirectory(
|
127
|
+
check_subdirectory('app/metal')
|
127
128
|
end
|
128
129
|
|
129
130
|
# Returns a list of all the rake task files found within this extension root.
|
130
131
|
#
|
131
132
|
def rake_task_paths
|
132
|
-
if check_subdirectory(
|
133
|
-
Dir[File.join(
|
133
|
+
if check_subdirectory('lib/tasks')
|
134
|
+
Dir[File.join(path.to_s, 'lib/tasks/**', '*.rake')]
|
134
135
|
end
|
135
136
|
end
|
136
137
|
|
@@ -149,6 +150,7 @@ module TrustyCms
|
|
149
150
|
#
|
150
151
|
def find(name)
|
151
152
|
raise LoadError, "Cannot return path for unknown extension: #{name}" unless @@known_paths[name.to_sym]
|
153
|
+
|
152
154
|
@@known_paths[name.to_sym]
|
153
155
|
end
|
154
156
|
|
@@ -175,19 +177,19 @@ module TrustyCms
|
|
175
177
|
enabled.map(&:path)
|
176
178
|
end
|
177
179
|
|
178
|
-
[
|
180
|
+
%i[load_paths plugin_paths helper_paths model_paths controller_paths eager_load_paths].each do |m|
|
179
181
|
define_method(m) do
|
180
|
-
enabled.map{|ep| ep.send(m)}.flatten.compact
|
182
|
+
enabled.map { |ep| ep.send(m) }.flatten.compact
|
181
183
|
end
|
182
184
|
end
|
183
|
-
[
|
185
|
+
%i[locale_paths view_paths metal_paths rake_task_paths].each do |m|
|
184
186
|
define_method(m) do
|
185
|
-
enabled.map{|ep| ep.send(m)}.flatten.compact.reverse
|
187
|
+
enabled.map { |ep| ep.send(m) }.flatten.compact.reverse
|
186
188
|
end
|
187
189
|
end
|
188
190
|
end
|
189
191
|
|
190
|
-
|
192
|
+
private
|
191
193
|
|
192
194
|
# If the supplied path within the extension root exists and is a directory, its absolute path is returned. Otherwise, nil.
|
193
195
|
#
|
@@ -195,6 +197,5 @@ module TrustyCms
|
|
195
197
|
subdirectory = File.join(path, subpath)
|
196
198
|
subdirectory if File.directory?(subdirectory)
|
197
199
|
end
|
198
|
-
|
199
200
|
end
|
200
201
|
end
|
@@ -11,7 +11,7 @@ require 'trusty_cms/engine'
|
|
11
11
|
|
12
12
|
# This is a wild and probably terrible hack built to initialize extension engines.
|
13
13
|
# I have no idea what the repercussions will be. Revisit later.
|
14
|
-
Gem.loaded_specs.each_with_object([]) do |(gemname, gemspec),
|
14
|
+
Gem.loaded_specs.each_with_object([]) do |(gemname, gemspec), _found|
|
15
15
|
if gemname =~ /trusty-.*-extension$/
|
16
16
|
ep = TrustyCms::ExtensionLoader.record_path(gemspec.full_gem_path, gemname)
|
17
17
|
require "#{ep.name}/engine"
|
@@ -19,15 +19,12 @@ Gem.loaded_specs.each_with_object([]) do |(gemname, gemspec), found|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module TrustyCms
|
22
|
-
|
23
22
|
module Initializer
|
24
|
-
|
25
23
|
# Rails::Initializer is essentially a list of startup steps and we extend it here by:
|
26
24
|
# * overriding or extending some of those steps so that they use trusty and extension paths
|
27
25
|
# as well as (or instead of) the rails defaults.
|
28
26
|
# * appending some extra steps to set up the admin UI and activate extensions
|
29
27
|
|
30
|
-
|
31
28
|
# Returns true in the very unusual case where trusty has been deployed as a rails app itself, rather than
|
32
29
|
# loaded as a gem or from vendor/. This is only likely in situations where trusty is customised so heavily
|
33
30
|
# that extensions are not sufficient.
|
@@ -54,7 +51,8 @@ module TrustyCms
|
|
54
51
|
|
55
52
|
configuration.middleware.insert_before(
|
56
53
|
:"ActionController::ParamsParser",
|
57
|
-
Rails::Rack::Metal, :
|
54
|
+
Rails::Rack::Metal, if: Rails::Rack::Metal.metals.any?
|
55
|
+
)
|
58
56
|
end
|
59
57
|
|
60
58
|
# Extends the Rails initializer to add locale paths from TRUSTY_CMS_ROOT and from trusty extensions.
|
@@ -120,7 +118,7 @@ module TrustyCms
|
|
120
118
|
#
|
121
119
|
def after_initialize
|
122
120
|
super
|
123
|
-
extension_loader.activate_extensions
|
121
|
+
extension_loader.activate_extensions # also calls initialize_views
|
124
122
|
TrustyCms::Application.config.add_controller_paths(extension_loader.paths(:controller))
|
125
123
|
TrustyCms::Application.config.add_eager_load_paths(extension_loader.paths(:eager_load))
|
126
124
|
end
|
@@ -157,8 +155,7 @@ module TrustyCms
|
|
157
155
|
# Returns the ExtensionLoader singleton that will eventually load extensions.
|
158
156
|
#
|
159
157
|
def extension_loader
|
160
|
-
ExtensionLoader.instance {|l| l.initializer = self }
|
158
|
+
ExtensionLoader.instance { |l| l.initializer = self }
|
161
159
|
end
|
162
|
-
|
163
160
|
end
|
164
161
|
end
|
@@ -6,33 +6,30 @@ module TrustyCms
|
|
6
6
|
def configure_pagination
|
7
7
|
# unconfigured parameters remain at will_paginate defaults
|
8
8
|
# will_paginate controller options are not overridden by tag attribetus
|
9
|
-
WillPaginate::ViewHelpers.pagination_options[:param_name] = TrustyCms::Config[
|
10
|
-
WillPaginate::ViewHelpers.pagination_options[:per_page_param_name] = TrustyCms::Config[
|
9
|
+
WillPaginate::ViewHelpers.pagination_options[:param_name] = TrustyCms::Config['pagination.param_name'].to_sym unless TrustyCms::Config['pagination.param_name'].blank?
|
10
|
+
WillPaginate::ViewHelpers.pagination_options[:per_page_param_name] = TrustyCms::Config['pagination.per_page_param_name'].blank? ? :per_page : TrustyCms::Config['pagination.per_page_param_name'].to_sym
|
11
11
|
|
12
12
|
# will_paginate view options can be overridden by tag attributes
|
13
|
-
[
|
13
|
+
%i[class previous_label next_label inner_window outer_window separator container].each do |opt|
|
14
14
|
WillPaginate::ViewHelpers.pagination_options[opt] = TrustyCms::Config["pagination.#{opt}"] unless TrustyCms::Config["pagination.#{opt}"].blank?
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def pagination_parameters
|
19
19
|
{
|
20
|
-
:
|
21
|
-
:
|
20
|
+
page: params[WillPaginate::ViewHelpers.pagination_options[:param_name]] || 1,
|
21
|
+
per_page: params[WillPaginate::ViewHelpers.pagination_options[:per_page_param_name]] || TrustyCms::Config['pagination.per_page'] || 20,
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.included(base)
|
26
|
-
base.class_eval
|
26
|
+
base.class_eval do
|
27
27
|
helper_method :pagination_parameters
|
28
28
|
before_action :configure_pagination
|
29
|
-
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
33
|
end
|
37
34
|
|
38
35
|
|
@@ -23,10 +23,10 @@ module TrustyCms
|
|
23
23
|
linkclass = %{ class="#{attributes[:class]}"} if attributes[:class]
|
24
24
|
linkrel = %{ rel="#{attributes[:rel]}"} if attributes[:rel]
|
25
25
|
param_name = WillPaginate::ViewHelpers.pagination_options[:param_name]
|
26
|
-
%
|
26
|
+
%{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
|
27
27
|
end
|
28
28
|
|
29
|
-
def page_span(
|
29
|
+
def page_span(_page, text, attributes = {})
|
30
30
|
%{<span class="#{attributes[:class]}">#{text}</span>}
|
31
31
|
end
|
32
32
|
end
|
@@ -39,7 +39,7 @@ module TrustyCms
|
|
39
39
|
lambda do
|
40
40
|
# Ruby 1.9.2 yields self in instance_eval... see https://gist.github.com/479572
|
41
41
|
# lambdas are as strict as methods in 1.9.x, making sure that the args match, Procs are not.
|
42
|
-
if RUBY_VERSION =~ /^1\.9/
|
42
|
+
if RUBY_VERSION =~ /^1\.9/ && proc.lambda? && (proc.arity != 1)
|
43
43
|
raise "You can only pass a proc ('Proc.new') or a lambda that takes exactly one arg (for self) to the wrap method."
|
44
44
|
end
|
45
45
|
|
@@ -51,7 +51,7 @@ module TrustyCms
|
|
51
51
|
class Collector < OpenStruct
|
52
52
|
def initialize
|
53
53
|
super
|
54
|
-
@table = Hash.new {|h,k| h[k] = Response.new }
|
54
|
+
@table = Hash.new { |h, k| h[k] = Response.new }
|
55
55
|
end
|
56
56
|
|
57
57
|
def initialize_copy(orig)
|
@@ -90,7 +90,7 @@ module TrustyCms
|
|
90
90
|
if block_given?
|
91
91
|
@publish_block = block
|
92
92
|
else
|
93
|
-
raise ArgumentError,
|
93
|
+
raise ArgumentError, 'Block required to publish' unless @publish_block
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
data/lib/trusty_cms/setup.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'highline'
|
2
|
+
require 'forwardable'
|
3
3
|
|
4
4
|
module TrustyCms
|
5
5
|
class Setup
|
6
|
-
|
7
6
|
class << self
|
8
7
|
def bootstrap(config)
|
9
8
|
setup = new
|
@@ -19,24 +18,24 @@ module TrustyCms
|
|
19
18
|
@admin = create_admin_user(config[:admin_name], config[:admin_username], config[:admin_password])
|
20
19
|
load_default_configuration
|
21
20
|
# load_database_template(config[:database_template])
|
22
|
-
announce
|
21
|
+
announce 'Finished.'
|
23
22
|
end
|
24
23
|
|
25
24
|
def create_admin_user(name, username, password)
|
26
|
-
unless name
|
27
|
-
announce
|
28
|
-
name
|
29
|
-
username
|
30
|
-
password
|
25
|
+
unless name && username && password
|
26
|
+
announce 'Create the admin user (press enter for defaults).'
|
27
|
+
name ||= prompt_for_admin_name
|
28
|
+
username ||= prompt_for_admin_username
|
29
|
+
password ||= prompt_for_admin_password
|
31
30
|
end
|
32
31
|
attributes = {
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
32
|
+
name: name,
|
33
|
+
login: username,
|
34
|
+
password: password,
|
35
|
+
password_confirmation: password,
|
37
36
|
}
|
38
37
|
admin = User.find_by(login: username)
|
39
|
-
admin
|
38
|
+
admin ||= User.new
|
40
39
|
admin.update_attributes(attributes)
|
41
40
|
admin.admin = true
|
42
41
|
admin.save
|
@@ -45,11 +44,11 @@ module TrustyCms
|
|
45
44
|
|
46
45
|
def load_default_configuration
|
47
46
|
feedback "\nInitializing configuration" do
|
48
|
-
step { TrustyCms::Config['admin.title'
|
47
|
+
step { TrustyCms::Config['admin.title'] = 'TrustyCms CMS' }
|
49
48
|
step { TrustyCms::Config['admin.subtitle'] = 'Publishing for Small Teams' }
|
50
|
-
step { TrustyCms::Config['defaults.page.parts'
|
51
|
-
step { TrustyCms::Config['defaults.page.status'
|
52
|
-
step { TrustyCms::Config['defaults.page.filter'
|
49
|
+
step { TrustyCms::Config['defaults.page.parts'] = 'body, extended' }
|
50
|
+
step { TrustyCms::Config['defaults.page.status'] = 'Draft' }
|
51
|
+
step { TrustyCms::Config['defaults.page.filter'] = nil }
|
53
52
|
step { TrustyCms::Config['defaults.page.fields'] = 'Keywords, Description' }
|
54
53
|
step { TrustyCms::Config['session_timeout'] = 2.weeks }
|
55
54
|
step { TrustyCms::Config['default_locale'] = 'en' }
|
@@ -60,11 +59,11 @@ module TrustyCms
|
|
60
59
|
template = nil
|
61
60
|
if filename
|
62
61
|
name = find_template_in_path(filename)
|
63
|
-
|
62
|
+
if name
|
63
|
+
template = load_template_file(name)
|
64
|
+
else
|
64
65
|
announce "Invalid template name: #{filename}"
|
65
66
|
filename = nil
|
66
|
-
else
|
67
|
-
template = load_template_file(name)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
unless filename
|
@@ -88,141 +87,140 @@ module TrustyCms
|
|
88
87
|
|
89
88
|
private
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
username = "Administrator" if username.blank?
|
98
|
-
username
|
90
|
+
def prompt_for_admin_name
|
91
|
+
username = ask('Name (Administrator): ', String) do |q|
|
92
|
+
q.validate = /^.{0,100}$/
|
93
|
+
q.responses[:not_valid] = 'Invalid name. Must be under 100 characters long.'
|
94
|
+
q.whitespace = :strip
|
99
95
|
end
|
96
|
+
username = 'Administrator' if username.blank?
|
97
|
+
username
|
98
|
+
end
|
100
99
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
username = "admin" if username.blank?
|
108
|
-
username
|
100
|
+
def prompt_for_admin_username
|
101
|
+
username = ask('Username (admin): ', String) do |q|
|
102
|
+
q.validate = /^(|.{3,40})$/
|
103
|
+
q.responses[:not_valid] = 'Invalid username. Must be at least 3 characters long.'
|
104
|
+
q.whitespace = :strip
|
109
105
|
end
|
106
|
+
username = 'admin' if username.blank?
|
107
|
+
username
|
108
|
+
end
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
password = default_password if password.blank?
|
120
|
-
password
|
110
|
+
def prompt_for_admin_password
|
111
|
+
default_password = 'trusty'
|
112
|
+
password = ask("Password (#{default_password}): ", String) do |q|
|
113
|
+
q.echo = false unless defined?(::JRuby) # JRuby doesn't support stty interaction
|
114
|
+
q.validate = /^(|.{5,40})$/
|
115
|
+
q.responses[:not_valid] = 'Invalid password. Must be at least 5 characters long.'
|
116
|
+
q.whitespace = :strip
|
121
117
|
end
|
118
|
+
password = default_password if password.blank?
|
119
|
+
password
|
120
|
+
end
|
122
121
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
122
|
+
def find_template_in_path(filename)
|
123
|
+
(
|
124
|
+
[
|
125
|
+
filename,
|
126
|
+
"#{TRUSTY_CMS_ROOT}/#{filename}",
|
127
|
+
"#{TRUSTY_CMS_ROOT}/db/templates/#{filename}",
|
128
|
+
"#{Rails.root}/#{filename}",
|
129
|
+
"#{Rails.root}/db/templates/#{filename}",
|
130
|
+
"#{Dir.pwd}/#{filename}",
|
131
|
+
"#{Dir.pwd}/db/templates/#{filename}",
|
132
|
+
] +
|
133
|
+
Dir.glob("#{TRUSTY_CMS_ROOT}/vendor/extensions/**/db/templates/#{filename}") +
|
134
|
+
Dir.glob("#{Rails.root}/vendor/extensions/**/db/templates/#{filename}") +
|
135
|
+
TrustyCms::Extension.descendants.inject([]) do |r, d|
|
136
|
+
r << "#{d.root}/db/templates/#{filename}"
|
137
|
+
end
|
138
|
+
).find { |name| File.file?(name) }
|
139
|
+
end
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
def find_and_load_templates(glob)
|
142
|
+
templates = Dir[glob]
|
143
|
+
templates.map! { |template| load_template_file(template) }
|
144
|
+
templates.sort_by { |template| template['name'] }
|
145
|
+
end
|
147
146
|
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
def load_template_file(filename)
|
148
|
+
YAML.load_file(filename)
|
149
|
+
end
|
151
150
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
151
|
+
def create_records(template)
|
152
|
+
records = template['records']
|
153
|
+
if records
|
154
|
+
puts
|
155
|
+
records.keys.each do |key|
|
156
|
+
feedback "Creating #{key.to_s.underscore.humanize}" do
|
157
|
+
model = model(key)
|
158
|
+
model.reset_column_information
|
159
|
+
record_pairs = order_by_id(records[key])
|
160
|
+
step do
|
161
|
+
record_pairs.each do |_id, record|
|
162
|
+
model.new(record).save
|
165
163
|
end
|
166
164
|
end
|
167
165
|
end
|
168
166
|
end
|
169
167
|
end
|
168
|
+
end
|
170
169
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
def order_by_id(records)
|
176
|
-
records.map { |name, record| [record['id'], record] }.sort { |a, b| a[0] <=> b[0] }
|
177
|
-
end
|
170
|
+
def model(model_name)
|
171
|
+
model_name.to_s.singularize.constantize
|
172
|
+
end
|
178
173
|
|
179
|
-
|
180
|
-
|
174
|
+
def order_by_id(records)
|
175
|
+
records.map { |_name, record| [record['id'], record] }.sort { |a, b| a[0] <=> b[0] }
|
176
|
+
end
|
181
177
|
|
182
|
-
|
183
|
-
|
184
|
-
end
|
178
|
+
extend Forwardable
|
179
|
+
def_delegators :terminal, :agree, :ask, :choose, :say
|
185
180
|
|
186
|
-
|
187
|
-
|
188
|
-
|
181
|
+
def terminal
|
182
|
+
@terminal ||= HighLine.new
|
183
|
+
end
|
189
184
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
185
|
+
def output
|
186
|
+
terminal.instance_variable_get('@output')
|
187
|
+
end
|
194
188
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
189
|
+
def wrap(string)
|
190
|
+
string = terminal.send(:wrap, string) unless terminal.wrap_at.nil?
|
191
|
+
string
|
192
|
+
end
|
199
193
|
|
200
|
-
|
201
|
-
|
202
|
-
|
194
|
+
def print(string)
|
195
|
+
output.print(wrap(string))
|
196
|
+
output.flush
|
197
|
+
end
|
203
198
|
|
204
|
-
|
205
|
-
|
206
|
-
|
199
|
+
def puts(string = "\n")
|
200
|
+
say string
|
201
|
+
end
|
207
202
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
puts "OK"
|
212
|
-
true
|
213
|
-
else
|
214
|
-
puts "FAILED"
|
215
|
-
false
|
216
|
-
end
|
217
|
-
rescue Exception => e
|
218
|
-
puts "FAILED"
|
219
|
-
raise e
|
220
|
-
end
|
203
|
+
def announce(string)
|
204
|
+
puts "\n#{string}"
|
205
|
+
end
|
221
206
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
207
|
+
def feedback(process)
|
208
|
+
print "#{process}..."
|
209
|
+
if yield
|
210
|
+
puts 'OK'
|
211
|
+
true
|
212
|
+
else
|
213
|
+
puts 'FAILED'
|
214
|
+
false
|
215
|
+
end
|
216
|
+
rescue Exception => e
|
217
|
+
puts 'FAILED'
|
218
|
+
raise e
|
219
|
+
end
|
226
220
|
|
221
|
+
def step
|
222
|
+
yield if block_given?
|
223
|
+
print '.'
|
224
|
+
end
|
227
225
|
end
|
228
226
|
end
|