trusty-cms 4.0.2 → 4.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +89 -89
  4. data/Rakefile +7 -7
  5. data/app/assets/images/admin/spinner.gif +0 -0
  6. data/app/assets/javascripts/admin.js +3 -0
  7. data/app/assets/javascripts/admin/more-or-less.js +2 -2
  8. data/app/assets/javascripts/admin/tabcontrol.js.erb +1 -2
  9. data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
  10. data/app/assets/javascripts/rad_social/rad_email.js +0 -1
  11. data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
  12. data/app/assets/stylesheets/admin/_base.scss +22 -6
  13. data/app/assets/stylesheets/admin/_multi_site_main.scss +28 -29
  14. data/app/assets/stylesheets/admin/_reset.scss +5 -4
  15. data/app/assets/stylesheets/admin/_site_chooser.scss +44 -69
  16. data/app/assets/stylesheets/admin/assets.scss +138 -141
  17. data/app/assets/stylesheets/admin/main.scss +10 -12
  18. data/app/assets/stylesheets/admin/modules/_boxes.scss +0 -3
  19. data/app/assets/stylesheets/admin/modules/_buttons.scss +30 -0
  20. data/app/assets/stylesheets/admin/modules/_links.scss +1 -1
  21. data/app/assets/stylesheets/admin/partials/_actions.scss +29 -46
  22. data/app/assets/stylesheets/admin/partials/_avatars.scss +3 -2
  23. data/app/assets/stylesheets/admin/partials/_content.scss +15 -38
  24. data/app/assets/stylesheets/admin/partials/_dateinput.scss +23 -14
  25. data/app/assets/stylesheets/admin/partials/_drawer.scss +78 -0
  26. data/app/assets/stylesheets/admin/partials/_dropdown.scss +9 -12
  27. data/app/assets/stylesheets/admin/partials/_footer.scss +4 -3
  28. data/app/assets/stylesheets/admin/partials/_forms.scss +64 -493
  29. data/app/assets/stylesheets/admin/partials/_header.scss +9 -118
  30. data/app/assets/stylesheets/admin/partials/_layout.scss +26 -2
  31. data/app/assets/stylesheets/admin/partials/_login_form.scss +28 -0
  32. data/app/assets/stylesheets/admin/partials/_messages.scss +10 -5
  33. data/app/assets/stylesheets/admin/partials/_popup.scss +61 -50
  34. data/app/assets/stylesheets/admin/partials/_preferences.scss +37 -0
  35. data/app/assets/stylesheets/admin/partials/_sidebar.scss +55 -0
  36. data/app/assets/stylesheets/admin/partials/_tabcontrol.scss +24 -36
  37. data/app/assets/stylesheets/admin/partials/{_index.scss → _table.scss} +53 -84
  38. data/app/assets/stylesheets/admin/partials/_toolbar.scss +11 -6
  39. data/app/assets/stylesheets/admin/partials/_treetable.scss +1 -71
  40. data/app/assets/stylesheets/admin/partials/_typography.scss +30 -55
  41. data/app/assets/stylesheets/admin/partials/_validations.scss +6 -5
  42. data/app/assets/stylesheets/rad_social/rad_screen.scss +64 -67
  43. data/app/controllers/admin/assets_controller.rb +21 -31
  44. data/app/controllers/admin/configuration_controller.rb +9 -11
  45. data/app/controllers/admin/extensions_controller.rb +3 -3
  46. data/app/controllers/admin/layouts_controller.rb +3 -4
  47. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  48. data/app/controllers/admin/page_fields_controller.rb +3 -4
  49. data/app/controllers/admin/page_parts_controller.rb +4 -5
  50. data/app/controllers/admin/pages_controller.rb +55 -56
  51. data/app/controllers/admin/references_controller.rb +1 -1
  52. data/app/controllers/admin/resource_controller.rb +132 -130
  53. data/app/controllers/admin/sites_controller.rb +4 -4
  54. data/app/controllers/admin/snippets_controller.rb +3 -4
  55. data/app/controllers/admin/users_controller.rb +16 -16
  56. data/app/controllers/application_controller.rb +47 -48
  57. data/app/controllers/site_controller.rb +51 -48
  58. data/app/controllers/social_mailer_controller.rb +12 -22
  59. data/app/helpers/admin/configuration_helper.rb +19 -20
  60. data/app/helpers/admin/layouts_helper.rb +0 -1
  61. data/app/helpers/admin/node_helper.rb +27 -24
  62. data/app/helpers/admin/pages_helper.rb +2 -2
  63. data/app/helpers/admin/preferences_helper.rb +0 -1
  64. data/app/helpers/admin/references_helper.rb +9 -10
  65. data/app/helpers/admin/regions_helper.rb +3 -3
  66. data/app/helpers/application_helper.rb +34 -35
  67. data/app/helpers/rad_social_helper.rb +8 -11
  68. data/app/helpers/scoped_helper.rb +1 -3
  69. data/app/helpers/sites_helper.rb +4 -4
  70. data/app/mailers/devise_mailer.rb +3 -4
  71. data/app/mailers/rad_social_mailer.rb +8 -8
  72. data/app/models/asset.rb +62 -63
  73. data/app/models/asset_type.rb +38 -39
  74. data/app/models/deprecated_tags.rb +3 -4
  75. data/app/models/file_not_found_page.rb +1 -3
  76. data/app/models/haml_filter.rb +1 -1
  77. data/app/models/layout.rb +4 -5
  78. data/app/models/legacy_user.rb +2 -2
  79. data/app/models/menu_renderer.rb +16 -18
  80. data/app/models/page.rb +96 -93
  81. data/app/models/page_attachment.rb +1 -2
  82. data/app/models/page_context.rb +11 -12
  83. data/app/models/page_part.rb +3 -4
  84. data/app/models/rails_page.rb +10 -12
  85. data/app/models/site.rb +22 -21
  86. data/app/models/snippet.rb +6 -8
  87. data/app/models/snippet_finder.rb +3 -3
  88. data/app/models/snippet_tags.rb +4 -4
  89. data/app/models/standard_tags.rb +258 -252
  90. data/app/models/status.rb +8 -8
  91. data/app/models/trusty_cms/config.rb +25 -25
  92. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  93. data/app/models/user.rb +15 -14
  94. data/app/models/user_action_observer.rb +3 -3
  95. data/app/users/_choose_site.html.haml +3 -7
  96. data/app/views/admin/assets/_form.html.haml +2 -1
  97. data/app/views/admin/assets/_search.html.haml +2 -1
  98. data/app/views/admin/assets/edit.html.haml +2 -10
  99. data/app/views/admin/assets/index.html.haml +4 -2
  100. data/app/views/admin/assets/new.html.haml +4 -8
  101. data/app/views/admin/assets/remove.html.haml +2 -1
  102. data/app/views/admin/configuration/edit.html.haml +7 -7
  103. data/app/views/admin/configuration/show.html.haml +6 -8
  104. data/app/views/admin/layouts/_choose_site.html.haml +2 -3
  105. data/app/views/admin/layouts/_form.html.haml +13 -12
  106. data/app/views/admin/layouts/_site_chooser.html.haml +2 -2
  107. data/app/views/admin/layouts/index.html.haml +11 -4
  108. data/app/views/admin/layouts/remove.html.haml +6 -5
  109. data/app/views/admin/page_attachments/_attachment.html.haml +2 -2
  110. data/app/views/admin/page_fields/_page_field.html.haml +3 -3
  111. data/app/views/admin/page_parts/_page_part.html.haml +5 -6
  112. data/app/views/admin/pages/_asset_popups.html.haml +15 -16
  113. data/app/views/admin/pages/_assets.html.haml +8 -7
  114. data/app/views/admin/pages/_fields.html.haml +16 -13
  115. data/app/views/admin/pages/_node.html.haml +3 -3
  116. data/app/views/admin/pages/_popups.html.haml +11 -11
  117. data/app/views/admin/pages/edit.html.haml +2 -2
  118. data/app/views/admin/pages/index.html.haml +5 -2
  119. data/app/views/admin/pages/new.html.haml +3 -3
  120. data/app/views/admin/pages/remove.html.haml +4 -3
  121. data/app/views/admin/preferences/edit.html.haml +5 -5
  122. data/app/views/admin/references/filters.haml +1 -1
  123. data/app/views/admin/references/tags.haml +3 -3
  124. data/app/views/admin/removed/_assets_bucket.html.haml +3 -3
  125. data/app/views/admin/removed/_assets_container.html.haml +18 -18
  126. data/app/views/admin/removed/_bucket.html.haml +1 -1
  127. data/app/views/admin/removed/_bucket_asset.html.haml +3 -3
  128. data/app/views/admin/removed/_show_bucket_link.html.haml +1 -1
  129. data/app/views/admin/removed/_upload_to_page.html.haml +5 -5
  130. data/app/views/admin/sites/_form.haml +18 -18
  131. data/app/views/admin/sites/edit.haml +1 -1
  132. data/app/views/admin/sites/index.haml +8 -4
  133. data/app/views/admin/sites/new.haml +1 -1
  134. data/app/views/admin/snippets/_choose_site.html.haml +4 -5
  135. data/app/views/admin/snippets/_form.html.haml +8 -9
  136. data/app/views/admin/snippets/edit.html.haml +1 -1
  137. data/app/views/admin/snippets/index.html.haml +11 -4
  138. data/app/views/admin/snippets/new.html.haml +1 -1
  139. data/app/views/admin/snippets/remove.html.haml +7 -6
  140. data/app/views/admin/users/_avatar.html.haml +2 -2
  141. data/app/views/admin/users/_choose_site.html.haml +3 -7
  142. data/app/views/admin/users/_form.html.haml +18 -21
  143. data/app/views/admin/users/_password_fields.html.haml +6 -6
  144. data/app/views/admin/users/index.html.haml +13 -6
  145. data/app/views/admin/users/remove.html.haml +4 -4
  146. data/app/views/admin/welcome/login.html.haml +8 -8
  147. data/app/views/devise/passwords/edit.html.haml +6 -6
  148. data/app/views/devise/passwords/new.html.haml +3 -3
  149. data/app/views/devise/sessions/new.html.haml +8 -8
  150. data/app/views/devise/shared/_links.html.haml +2 -2
  151. data/app/views/layouts/application.html.haml +24 -19
  152. data/app/views/rad_social_mailer/social_mail_form.html.haml +15 -17
  153. data/app/views/widget/_email_form.html.haml +13 -18
  154. data/app/views/widget/_horizontal_widget.html.haml +5 -5
  155. data/bin/rails +4 -4
  156. data/bin/trusty_cms +3 -5
  157. data/config.ru +1 -1
  158. data/config/application.rb +14 -15
  159. data/config/boot.rb +1 -2
  160. data/config/environment.rb +1 -1
  161. data/config/environments/production.rb +0 -1
  162. data/config/environments/test.rb +1 -2
  163. data/config/initializers/devise.rb +1 -1
  164. data/config/initializers/kraken.rb +2 -2
  165. data/config/initializers/tmp.rb +1 -1
  166. data/config/initializers/trusty_cms_config.rb +48 -48
  167. data/config/locales/en.yml +8 -8
  168. data/config/routes.rb +6 -7
  169. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  170. data/lib/annotatable.rb +3 -5
  171. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  172. data/lib/inheritable_class_attributes.rb +13 -9
  173. data/lib/login_system.rb +73 -73
  174. data/lib/method_observer.rb +13 -12
  175. data/lib/ostruct.rb +7 -10
  176. data/lib/simpleton.rb +0 -4
  177. data/lib/string_extensions/string_extensions.rb +3 -3
  178. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  179. data/lib/tasks/database.rake +28 -28
  180. data/lib/tasks/extensions.rake +18 -18
  181. data/lib/tasks/framework.rake +68 -68
  182. data/lib/tasks/radiant_config.rake +4 -4
  183. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  184. data/lib/tasks/translate.rake +14 -14
  185. data/lib/tasks/upgrade_to_devise.rake +1 -1
  186. data/lib/translation_support.rb +22 -22
  187. data/lib/trusty_cms.rb +2 -2
  188. data/lib/trusty_cms/admin_ui.rb +19 -16
  189. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  190. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  191. data/lib/trusty_cms/available_locales.rb +2 -4
  192. data/lib/trusty_cms/config/definition.rb +11 -8
  193. data/lib/trusty_cms/engine.rb +13 -14
  194. data/lib/trusty_cms/extension.rb +14 -16
  195. data/lib/trusty_cms/extension_loader.rb +6 -6
  196. data/lib/trusty_cms/extension_migrator.rb +42 -41
  197. data/lib/trusty_cms/extension_path.rb +20 -19
  198. data/lib/trusty_cms/initializer.rb +5 -8
  199. data/lib/trusty_cms/pagination/controller.rb +7 -10
  200. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  201. data/lib/trusty_cms/resource_responses.rb +3 -3
  202. data/lib/trusty_cms/setup.rb +130 -132
  203. data/lib/trusty_cms/taggable.rb +19 -22
  204. data/lib/trusty_cms/task_support.rb +9 -6
  205. data/package.json +10 -2
  206. data/public/dispatch.fcgi +1 -1
  207. data/public/dispatch.rb +2 -2
  208. data/script/extension +1 -1
  209. data/script/rails +2 -2
  210. data/spec/dummy/package.json +1 -1
  211. data/spec/dummy/yarn.lock +3 -3
  212. data/trusty_cms.gemspec +25 -25
  213. data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
  214. data/yarn.lock +1992 -4
  215. metadata +54 -43
  216. data/app/assets/javascripts/rad_social/captcha.js +0 -42
  217. data/app/assets/stylesheets/admin/partials/_deprecated.scss +0 -65
  218. data/app/assets/stylesheets/admin/partials/_jquery-ui-structure.scss +0 -258
  219. data/app/assets/stylesheets/admin/partials/_jquery-ui-theme.scss +0 -410
  220. data/app/assets/stylesheets/admin/partials/_jquery-ui.scss +0 -650
  221. 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(*args) #:nodoc
20
+ def before_clear(*_args) #:nodoc
21
21
  ExtensionLoader.deactivate_extensions
22
22
  end
23
23
 
24
- def after_clear(*args) #:nodoc
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
- $stderr.puts "Could not load extension: #{name}.\n#{e.inspect}"
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
- def extension_name
33
- self.class.extension.extension_name
34
- end
29
+ def quote(s)
30
+ ActiveRecord::Base.connection.quote(s)
31
+ end
35
32
 
36
- def version_string(version)
37
- "#{extension_name}-#{version}"
38
- end
33
+ def extension_name
34
+ self.class.extension.extension_name
35
+ end
39
36
 
40
- def initialize_extension_schema_migrations
41
- current_version = ActiveRecord::Base.connection.select_value("SELECT schema_version FROM extension_meta WHERE name = #{sanitize(quote(extension_name))}")
42
- if current_version
43
- assume_migrated_upto_version(current_version.to_i)
44
- ActiveRecord::Base.connection.delete("DELETE FROM extension_meta WHERE name = #{sanitize(quote(extension_name))}")
45
- end
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
- def initialize_received_migrations
49
- if donors = self.class.extension.migrates_from
50
- donors.each do |extension_name, until_migration|
51
- 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}
52
- replaced.delete_if{|v| v > until_migration.to_i} if until_migration
53
- assume_migrated_upto_version(replaced.max) if replaced.any?
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
- def assume_migrated_upto_version(version)
59
- version = version.to_i
60
- sm_table = self.class.schema_migrations_table_name
59
+ def assume_migrated_upto_version(version)
60
+ version = version.to_i
61
+ sm_table = self.class.schema_migrations_table_name
61
62
 
62
- migrated = self.class.get_all_versions
63
- versions = Dir["#{@migrations_path}/[0-9]*_*.rb"].map do |filename|
64
- filename.split('/').last.split('_').first.to_i
65
- end
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
- unless migrated.include?(version)
68
- ActiveRecord::Base.connection.execute "INSERT INTO #{sm_table} (version) VALUES (#{sanitize(quote(version_string(version)))})"
69
- end
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
- inserted = Set.new
72
- (versions - migrated).each do |v|
73
- if inserted.include?(v)
74
- raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict."
75
- elsif v < version
76
- ActiveRecord::Base.connection.execute "INSERT INTO #{sm_table} (version) VALUES (#{sanitize(quote(version_string(v)))})"
77
- inserted << v
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, @path = options[:name].underscore, options[:path]
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(:name => name, :path => path)
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("vendor/plugins")
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("config/locales")
89
- Dir[File.join("#{path}","config/locales","*.{rb,yml}")]
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("app/helpers")
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("app/models")
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("app/controllers")
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("app/views")
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("app/metal")
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("lib/tasks")
133
- Dir[File.join("#{path}","lib/tasks/**","*.rake")]
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
- [:load_paths, :plugin_paths, :helper_paths, :model_paths, :controller_paths, :eager_load_paths].each do |m|
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
- [:locale_paths, :view_paths, :metal_paths, :rake_task_paths].each do |m|
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
- private
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), found|
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, :if => Rails::Rack::Metal.metals.any?)
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 # also calls initialize_views
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["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
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
- [:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container].each do |opt|
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
- :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
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
- %Q{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
26
+ %{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
27
27
  end
28
28
 
29
- def page_span(page, text, attributes = {})
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/ and proc.lambda? and proc.arity != 1
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, "Block required to publish" unless @publish_block
93
+ raise ArgumentError, 'Block required to publish' unless @publish_block
94
94
  end
95
95
  end
96
96
 
@@ -1,9 +1,8 @@
1
- require "highline"
2
- require "forwardable"
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 "Finished."
21
+ announce 'Finished.'
23
22
  end
24
23
 
25
24
  def create_admin_user(name, username, password)
26
- unless name and username and password
27
- announce "Create the admin user (press enter for defaults)."
28
- name = prompt_for_admin_name unless name
29
- username = prompt_for_admin_username unless username
30
- password = prompt_for_admin_password unless 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
- :name => name,
34
- :login => username,
35
- :password => password,
36
- :password_confirmation => password
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 = User.new unless 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' ] = 'TrustyCms CMS' }
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' ] = 'body, extended' }
51
- step { TrustyCms::Config['defaults.page.status' ] = 'Draft' }
52
- step { TrustyCms::Config['defaults.page.filter' ] = nil }
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
- unless name
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
- def prompt_for_admin_name
92
- username = ask('Name (Administrator): ', String) do |q|
93
- q.validate = /^.{0,100}$/
94
- q.responses[:not_valid] = "Invalid name. Must be under 100 characters long."
95
- q.whitespace = :strip
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
- def prompt_for_admin_username
102
- username = ask('Username (admin): ', String) do |q|
103
- q.validate = /^(|.{3,40})$/
104
- q.responses[:not_valid] = "Invalid username. Must be at least 3 characters long."
105
- q.whitespace = :strip
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
- def prompt_for_admin_password
112
- default_password = 'trusty'
113
- password = ask("Password (#{default_password}): ", String) do |q|
114
- q.echo = false unless defined?(::JRuby) # JRuby doesn't support stty interaction
115
- q.validate = /^(|.{5,40})$/
116
- q.responses[:not_valid] = "Invalid password. Must be at least 5 characters long."
117
- q.whitespace = :strip
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
- def find_template_in_path(filename)
124
- (
125
- [
126
- filename,
127
- "#{TRUSTY_CMS_ROOT}/#{filename}",
128
- "#{TRUSTY_CMS_ROOT}/db/templates/#{filename}",
129
- "#{Rails.root}/#{filename}",
130
- "#{Rails.root}/db/templates/#{filename}",
131
- "#{Dir.pwd}/#{filename}",
132
- "#{Dir.pwd}/db/templates/#{filename}"
133
- ] +
134
- Dir.glob("#{TRUSTY_CMS_ROOT}/vendor/extensions/**/db/templates/#{filename}") +
135
- Dir.glob("#{Rails.root}/vendor/extensions/**/db/templates/#{filename}") +
136
- TrustyCms::Extension.descendants.inject([]) do |r, d|
137
- r << "#{d.root}/db/templates/#{filename}"
138
- end
139
- ).find { |name| File.file?(name) }
140
- end
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
- def find_and_load_templates(glob)
143
- templates = Dir[glob]
144
- templates.map! { |template| load_template_file(template) }
145
- templates.sort_by { |template| template['name'] }
146
- end
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
- def load_template_file(filename)
149
- YAML.load_file(filename)
150
- end
147
+ def load_template_file(filename)
148
+ YAML.load_file(filename)
149
+ end
151
150
 
152
- def create_records(template)
153
- records = template['records']
154
- if records
155
- puts
156
- records.keys.each do |key|
157
- feedback "Creating #{key.to_s.underscore.humanize}" do
158
- model = model(key)
159
- model.reset_column_information
160
- record_pairs = order_by_id(records[key])
161
- step do
162
- record_pairs.each do |id, record|
163
- model.new(record).save
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
- def model(model_name)
172
- model_name.to_s.singularize.constantize
173
- end
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
- extend Forwardable
180
- def_delegators :terminal, :agree, :ask, :choose, :say
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
- def terminal
183
- @terminal ||= HighLine.new
184
- end
178
+ extend Forwardable
179
+ def_delegators :terminal, :agree, :ask, :choose, :say
185
180
 
186
- def output
187
- terminal.instance_variable_get("@output")
188
- end
181
+ def terminal
182
+ @terminal ||= HighLine.new
183
+ end
189
184
 
190
- def wrap(string)
191
- string = terminal.send(:wrap, string) unless terminal.wrap_at.nil?
192
- string
193
- end
185
+ def output
186
+ terminal.instance_variable_get('@output')
187
+ end
194
188
 
195
- def print(string)
196
- output.print(wrap(string))
197
- output.flush
198
- end
189
+ def wrap(string)
190
+ string = terminal.send(:wrap, string) unless terminal.wrap_at.nil?
191
+ string
192
+ end
199
193
 
200
- def puts(string = "\n")
201
- say string
202
- end
194
+ def print(string)
195
+ output.print(wrap(string))
196
+ output.flush
197
+ end
203
198
 
204
- def announce(string)
205
- puts "\n#{string}"
206
- end
199
+ def puts(string = "\n")
200
+ say string
201
+ end
207
202
 
208
- def feedback(process, &block)
209
- print "#{process}..."
210
- if yield
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
- def step
223
- yield if block_given?
224
- print '.'
225
- end
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