trusty-cms 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +25 -25
  4. data/Rakefile +7 -7
  5. data/app/assets/stylesheets/admin/partials/_content.scss +1 -2
  6. data/app/controllers/admin/assets_controller.rb +22 -21
  7. data/app/controllers/admin/configuration_controller.rb +9 -11
  8. data/app/controllers/admin/extensions_controller.rb +3 -3
  9. data/app/controllers/admin/layouts_controller.rb +3 -4
  10. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  11. data/app/controllers/admin/page_fields_controller.rb +3 -4
  12. data/app/controllers/admin/page_parts_controller.rb +4 -5
  13. data/app/controllers/admin/pages_controller.rb +55 -56
  14. data/app/controllers/admin/references_controller.rb +1 -1
  15. data/app/controllers/admin/resource_controller.rb +132 -130
  16. data/app/controllers/admin/sites_controller.rb +4 -4
  17. data/app/controllers/admin/snippets_controller.rb +3 -4
  18. data/app/controllers/admin/users_controller.rb +16 -16
  19. data/app/controllers/application_controller.rb +47 -48
  20. data/app/controllers/site_controller.rb +51 -48
  21. data/app/controllers/social_mailer_controller.rb +13 -16
  22. data/app/helpers/admin/configuration_helper.rb +19 -20
  23. data/app/helpers/admin/layouts_helper.rb +0 -1
  24. data/app/helpers/admin/node_helper.rb +27 -24
  25. data/app/helpers/admin/pages_helper.rb +2 -2
  26. data/app/helpers/admin/preferences_helper.rb +0 -1
  27. data/app/helpers/admin/references_helper.rb +9 -10
  28. data/app/helpers/admin/regions_helper.rb +3 -3
  29. data/app/helpers/application_helper.rb +32 -33
  30. data/app/helpers/rad_social_helper.rb +8 -11
  31. data/app/helpers/scoped_helper.rb +1 -3
  32. data/app/helpers/sites_helper.rb +4 -4
  33. data/app/mailers/devise_mailer.rb +3 -4
  34. data/app/mailers/rad_social_mailer.rb +8 -8
  35. data/app/models/asset.rb +62 -63
  36. data/app/models/asset_type.rb +38 -39
  37. data/app/models/deprecated_tags.rb +3 -4
  38. data/app/models/file_not_found_page.rb +1 -3
  39. data/app/models/haml_filter.rb +1 -1
  40. data/app/models/layout.rb +4 -5
  41. data/app/models/legacy_user.rb +2 -2
  42. data/app/models/menu_renderer.rb +16 -18
  43. data/app/models/page.rb +96 -93
  44. data/app/models/page_attachment.rb +1 -2
  45. data/app/models/page_context.rb +11 -12
  46. data/app/models/page_part.rb +3 -4
  47. data/app/models/rails_page.rb +10 -12
  48. data/app/models/site.rb +22 -21
  49. data/app/models/snippet.rb +6 -8
  50. data/app/models/snippet_finder.rb +3 -3
  51. data/app/models/snippet_tags.rb +4 -4
  52. data/app/models/standard_tags.rb +258 -252
  53. data/app/models/status.rb +8 -8
  54. data/app/models/trusty_cms/config.rb +25 -25
  55. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  56. data/app/models/user.rb +15 -14
  57. data/app/models/user_action_observer.rb +3 -3
  58. data/bin/rails +4 -4
  59. data/bin/trusty_cms +3 -5
  60. data/config.ru +1 -1
  61. data/config/application.rb +14 -15
  62. data/config/boot.rb +1 -2
  63. data/config/environment.rb +1 -1
  64. data/config/environments/production.rb +0 -1
  65. data/config/environments/test.rb +1 -2
  66. data/config/initializers/devise.rb +1 -1
  67. data/config/initializers/kraken.rb +2 -2
  68. data/config/initializers/tmp.rb +1 -1
  69. data/config/initializers/trusty_cms_config.rb +48 -48
  70. data/config/routes.rb +6 -6
  71. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  72. data/lib/annotatable.rb +3 -5
  73. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  74. data/lib/inheritable_class_attributes.rb +13 -9
  75. data/lib/login_system.rb +73 -73
  76. data/lib/method_observer.rb +13 -12
  77. data/lib/ostruct.rb +7 -10
  78. data/lib/simpleton.rb +0 -4
  79. data/lib/string_extensions/string_extensions.rb +3 -3
  80. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  81. data/lib/tasks/database.rake +28 -28
  82. data/lib/tasks/extensions.rake +18 -18
  83. data/lib/tasks/framework.rake +68 -68
  84. data/lib/tasks/radiant_config.rake +4 -4
  85. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  86. data/lib/tasks/translate.rake +14 -14
  87. data/lib/tasks/upgrade_to_devise.rake +1 -1
  88. data/lib/translation_support.rb +22 -22
  89. data/lib/trusty_cms.rb +2 -2
  90. data/lib/trusty_cms/admin_ui.rb +19 -16
  91. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  92. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  93. data/lib/trusty_cms/available_locales.rb +2 -4
  94. data/lib/trusty_cms/config/definition.rb +11 -8
  95. data/lib/trusty_cms/engine.rb +14 -14
  96. data/lib/trusty_cms/extension.rb +14 -16
  97. data/lib/trusty_cms/extension_loader.rb +6 -6
  98. data/lib/trusty_cms/extension_migrator.rb +42 -41
  99. data/lib/trusty_cms/extension_path.rb +20 -19
  100. data/lib/trusty_cms/initializer.rb +5 -8
  101. data/lib/trusty_cms/pagination/controller.rb +7 -10
  102. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  103. data/lib/trusty_cms/resource_responses.rb +3 -3
  104. data/lib/trusty_cms/setup.rb +130 -132
  105. data/lib/trusty_cms/taggable.rb +19 -22
  106. data/lib/trusty_cms/task_support.rb +9 -6
  107. data/public/dispatch.fcgi +1 -1
  108. data/public/dispatch.rb +2 -2
  109. data/script/extension +1 -1
  110. data/script/rails +2 -2
  111. data/trusty_cms.gemspec +23 -23
  112. metadata +32 -32
@@ -1,15 +1,15 @@
1
1
  require 'trusty_cms/task_support'
2
2
  namespace :trusty_cms do
3
3
  namespace :config do
4
- desc "Export TrustyCms::Config to Rails.root/config/trusty_config.yml. Specify a path with TRUSTY_CONFIG_PATH - defaults to Rails.root/config/trusty_config.yml"
5
- task :export => :environment do
4
+ desc 'Export TrustyCms::Config to Rails.root/config/trusty_config.yml. Specify a path with TRUSTY_CONFIG_PATH - defaults to Rails.root/config/trusty_config.yml'
5
+ task export: :environment do
6
6
  config_path = ENV['TRUSTY_CONFIG_PATH'] || "#{Rails.root}/config/trusty_config.yml"
7
7
  clear = ENV['CLEAR_CONFIG'] || nil
8
8
  TrustyCms::TaskSupport.config_export(config_path)
9
9
  end
10
10
 
11
- desc "Import TrustyCms::Config from Rails.root/config/trusty_config.yml. Specify a path with TRUSTY_CONFIG_PATH - defaults to Rails.root/config/trusty_config.yml Set CLEAR_CONFIG=true to delete all existing settings before import"
12
- task :import => :environment do
11
+ desc 'Import TrustyCms::Config from Rails.root/config/trusty_config.yml. Specify a path with TRUSTY_CONFIG_PATH - defaults to Rails.root/config/trusty_config.yml Set CLEAR_CONFIG=true to delete all existing settings before import'
12
+ task import: :environment do
13
13
  config_path = ENV['TRUSTY_CONFIG_PATH'] || "#{Rails.root}/config/trusty_config.yml"
14
14
  clear = ENV['CLEAR_CONFIG'] || nil
15
15
  TrustyCms::TaskSupport.config_import(config_path, clear)
@@ -1,9 +1,8 @@
1
1
  namespace :trusty do
2
2
  namespace :extensions do
3
3
  namespace :snippets do
4
-
5
4
  desc 'Runs the migration of the Snippets extension'
6
- task :migrate => :environment do
5
+ task migrate: :environment do
7
6
  require 'trusty_cms/extension_migrator'
8
7
  if ENV['VERSION']
9
8
  SnippetsExtension.migrator.migrate(ENV['VERSION'].to_i)
@@ -15,30 +14,31 @@ namespace :trusty do
15
14
  end
16
15
 
17
16
  desc 'Copies public assets of the Snippets to the instance public/ directory.'
18
- task :update => :environment do
19
- is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
17
+ task update: :environment do
18
+ is_svn_or_dir = proc { |path| path =~ /\.svn/ || File.directory?(path) }
20
19
  puts 'Copying assets from SnippetsExtension'
21
20
  Dir[SnippetsExtension.root + '/public/**/*'].reject(&is_svn_or_dir).each do |file|
22
21
  path = file.sub(SnippetsExtension.root, '')
23
22
  directory = File.dirname(path)
24
- mkdir_p Rails.root + directory, :verbose => false
25
- cp file, Rails.root + path, :verbose => false
23
+ mkdir_p Rails.root + directory, verbose: false
24
+ cp file, Rails.root + path, verbose: false
26
25
  end
27
26
  end
28
-
27
+
29
28
  desc 'Syncs all available translations for this ext to the English ext master'
30
- task :sync => :environment do
29
+ task sync: :environment do
31
30
  # The main translation root, basically where English is kept
32
31
  language_root = SnippetsExtension.root + '/config/locales'
33
32
  words = TranslationSupport.get_translation_keys(language_root)
34
-
33
+
35
34
  Dir['#{language_root}/*.yml'].each do |filename|
36
35
  next if filename.match('_available_tags')
36
+
37
37
  basename = File.basename(filename, '.yml')
38
38
  puts "Syncing #{basename}"
39
39
  (comments, other) = TranslationSupport.read_file(filename, basename)
40
- words.each { |k, v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
41
- other.delete_if { |k, v| !words[k] } # Remove if not defined in en.yml
40
+ words.each { |k, _v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
41
+ other.delete_if { |k, _v| !words[k] } # Remove if not defined in en.yml
42
42
  TranslationSupport.write_file(filename, basename, comments, other)
43
43
  end
44
44
  end
@@ -1,8 +1,7 @@
1
1
  namespace :trusty_cms do
2
2
  namespace :i18n do
3
-
4
- desc "Syncs all available translations to the English master"
5
- task :sync => :environment do
3
+ desc 'Syncs all available translations to the English master'
4
+ task sync: :environment do
6
5
  # All places TrustyCms can store locales
7
6
  locale_paths = TrustyCms::AvailableLocales.locale_paths
8
7
  # The main translation root, basically where English is kept
@@ -12,31 +11,32 @@ namespace :trusty_cms do
12
11
  if path == language_root || path.match('language_pack')
13
12
  Dir["#{path}/*.yml"].each do |filename|
14
13
  next if filename.match('_available_tags')
14
+
15
15
  basename = File.basename(filename, '.yml')
16
16
  puts "Syncing #{basename}"
17
17
  (comments, other) = TranslationSupport.read_file(filename, basename)
18
- words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
19
- other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
18
+ words.each { |k, _v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
19
+ other.delete_if { |k, _v| !words[k] } # Remove if not defined in en.yml
20
20
  TranslationSupport.write_file(filename, basename, comments, other)
21
21
  end
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
- desc "Creates or updates the English available tag descriptions"
27
- task :available_tags => :environment do
26
+ desc 'Creates or updates the English available tag descriptions'
27
+ task available_tags: :environment do
28
28
  descriptions = Hash.new
29
29
  Page.tag_descriptions.sort.each do |tag, desc|
30
- tag = ' ' + tag.gsub(':','-') + ':'
31
- desc = desc.gsub(' ',' ')
32
- descriptions[tag] = ' "' + desc.gsub('%','%').gsub('"','\"').strip + '"'
30
+ tag = ' ' + tag.gsub(':', '-') + ':'
31
+ desc = desc.gsub(' ', ' ')
32
+ descriptions[tag] = ' "' + desc.gsub('%', '%').gsub('"', '\"').strip + '"'
33
33
  end
34
34
  comments = ''
35
- TranslationSupport.write_file("#{TRUSTY_CMS_ROOT}/config/locales/en_available_tags.yml","---\nen:\n desc",comments,descriptions)
35
+ TranslationSupport.write_file("#{TRUSTY_CMS_ROOT}/config/locales/en_available_tags.yml", "---\nen:\n desc", comments, descriptions)
36
36
  end
37
37
 
38
- desc "Syncs all translations available_tags to the English master"
39
- task :sync_available_tags => :environment do
38
+ desc 'Syncs all translations available_tags to the English master'
39
+ task sync_available_tags: :environment do
40
40
  # All places TrustyCms can store locales
41
41
  locale_paths = TrustyCms::AvailableLocales.locale_paths
42
42
  # The main translation root, basically where English is kept
@@ -46,6 +46,7 @@ namespace :trusty_cms do
46
46
  if path == language_root || path.match('language_pack')
47
47
  Dir["#{path}/*.yml"].each do |filename|
48
48
  next unless filename.match('_available_tags')
49
+
49
50
  basename = File.basename(filename, '_available_tags.yml')
50
51
  puts "Syncing #{basename}"
51
52
  (comments, other) = TranslationSupport.open_available_tags(filename)
@@ -54,6 +55,5 @@ namespace :trusty_cms do
54
55
  end
55
56
  end
56
57
  end
57
-
58
58
  end
59
59
  end
@@ -17,7 +17,7 @@ namespace :import do
17
17
  admin: legacy.admin,
18
18
  designer: legacy.designer,
19
19
  content_editor: legacy.content_editor,
20
- notes: legacy.notes
20
+ notes: legacy.notes,
21
21
  )
22
22
  u.save!
23
23
  end
@@ -1,54 +1,54 @@
1
1
  class TranslationSupport
2
2
  class << self
3
-
4
- #Retrieve US word set
5
- def get_translation_keys(language_root, suffix=nil)
3
+ # Retrieve US word set
4
+ def get_translation_keys(language_root, suffix = nil)
6
5
  (dummy_comments, words) = read_file("#{language_root}/en#{suffix}.yml", 'en')
7
6
  words
8
7
  end
9
8
 
10
- #Retrieve comments, translation data in hash form
9
+ # Retrieve comments, translation data in hash form
11
10
  def read_file(filename, basename)
12
- (comments, data) = IO.read(filename).split(/\n#{basename}:\s*\n/) #Add error checking for failed file read?
13
- return comments, create_hash(data, basename)
11
+ (comments, data) = IO.read(filename).split(/\n#{basename}:\s*\n/) # Add error checking for failed file read?
12
+ [comments, create_hash(data, basename)]
14
13
  end
15
14
 
16
- #Creates hash of translation data
17
- def create_hash(data, basename)
15
+ # Creates hash of translation data
16
+ def create_hash(data, _basename)
18
17
  words = Hash.new
19
18
  return words if !data
19
+
20
20
  parent = Array.new
21
21
  previous_key = 'base'
22
22
  data.split("\n").each do |w|
23
23
  next if w.strip.blank?
24
+
24
25
  (key, value) = w.split(':', 2)
25
26
  value ||= ''
26
- shift = (key =~ /\w/)/2 - parent.size #Determine level of current key in comparison to parent array
27
- key = key.sub(/^\s+/,'')
28
- parent << previous_key if shift > 0 #If key is child of previous key, add previous key as parent
29
- (shift * -1).times { parent.pop } if shift < 0 #If key is not related to previous key, remove parent keys
30
- previous_key = key #Track key in case next key is child of this key
27
+ shift = (key =~ /\w/) / 2 - parent.size # Determine level of current key in comparison to parent array
28
+ key = key.sub(/^\s+/, '')
29
+ parent << previous_key if shift > 0 # If key is child of previous key, add previous key as parent
30
+ (shift * -1).times { parent.pop } if shift < 0 # If key is not related to previous key, remove parent keys
31
+ previous_key = key # Track key in case next key is child of this key
31
32
  words[parent.join(':') + ':' + key] = value unless key.blank?
32
33
  end
33
34
  words
34
35
  end
35
36
 
36
37
  def open_available_tags(filename)
37
- data = YAML::load(File.open("#{filename}"))
38
+ data = YAML::load(File.open(filename.to_s))
38
39
  data.to_s
39
40
  end
40
41
 
41
- #Writes to file from translation data hash structure
42
- def write_file(filename,basename,comments,words)
43
- File.open(filename, "w") do |log|
44
- log.puts(comments+"\n"+basename+": \n")
45
- words.sort.each do |k,v|
42
+ # Writes to file from translation data hash structure
43
+ def write_file(filename, basename, comments, words)
44
+ File.open(filename, 'w') do |log|
45
+ log.puts(comments + "\n" + basename + ": \n")
46
+ words.sort.each do |k, v|
46
47
  keys = k.split(':')
47
- (keys.size-1).times { keys[keys.size-1] = ' ' + keys[keys.size-1] } #Add indentation for children keys
48
- log.puts(keys[keys.size-1]+':'+v+"\n")
48
+ (keys.size - 1).times { keys[keys.size - 1] = ' ' + keys[keys.size - 1] } # Add indentation for children keys
49
+ log.puts(keys[keys.size - 1] + ':' + v + "\n")
49
50
  end
50
51
  end
51
52
  end
52
-
53
53
  end
54
54
  end
@@ -1,7 +1,7 @@
1
- TRUSTY_CMS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")) unless defined? TRUSTY_CMS_ROOT
1
+ TRUSTY_CMS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) unless defined? TRUSTY_CMS_ROOT
2
2
 
3
3
  unless defined? TrustyCms::VERSION
4
4
  module TrustyCms
5
- VERSION = '4.1.2'
5
+ VERSION = '4.1.3'.freeze
6
6
  end
7
7
  end
@@ -18,10 +18,10 @@ module TrustyCms
18
18
  end
19
19
 
20
20
  def [](id)
21
- unless id.kind_of? Integer
22
- self.find {|subnav_item| subnav_item.name.to_s.titleize == id.to_s.titleize }
23
- else
21
+ if id.is_a? Integer
24
22
  super
23
+ else
24
+ find { |subnav_item| subnav_item.name.to_s.titleize == id.to_s.titleize }
25
25
  end
26
26
  end
27
27
 
@@ -29,6 +29,7 @@ module TrustyCms
29
29
  options = args.extract_options!
30
30
  item = args.size > 1 ? deprecated_add(*(args << caller)) : args.first
31
31
  raise DuplicateTabNameError.new("duplicate tab name `#{item.name}'") if self[item.name]
32
+
32
33
  item.tab = self if item.respond_to?(:tab=)
33
34
  if options.empty?
34
35
  super(item)
@@ -79,8 +80,9 @@ module TrustyCms
79
80
  attr_reader :name, :url
80
81
  attr_accessor :tab
81
82
 
82
- def initialize(name, url = "#")
83
- @name, @url = name, url
83
+ def initialize(name, url = '#')
84
+ @name = name
85
+ @url = url
84
86
  end
85
87
 
86
88
  def visible?(user)
@@ -92,8 +94,9 @@ module TrustyCms
92
94
  end
93
95
 
94
96
  private
97
+
95
98
  def visible_by_controller?(user)
96
- params = TrustyCms::Application.routes.recognize_path(url, :method => :get)
99
+ params = TrustyCms::Application.routes.recognize_path(url, method: :get)
97
100
  if params && params[:controller]
98
101
  klass = "#{params[:controller].camelize}Controller".constantize
99
102
  klass.user_has_access_to_action?(user, params[:action])
@@ -131,24 +134,24 @@ module TrustyCms
131
134
  end
132
135
 
133
136
  def initialize_nav
134
- @nav = NavTab.new("Tab Container")
137
+ @nav = NavTab.new('Tab Container')
135
138
  load_default_nav
136
139
  end
137
140
 
138
141
  def load_default_nav
139
- content = nav_tab("Content")
140
- content << nav_item("Pages", "/admin/pages")
142
+ content = nav_tab('Content')
143
+ content << nav_item('Pages', '/admin/pages')
141
144
  nav << content
142
145
 
143
- design = nav_tab("Design")
144
- design << nav_item("Layouts", "/admin/layouts")
146
+ design = nav_tab('Design')
147
+ design << nav_item('Layouts', '/admin/layouts')
145
148
  nav << design
146
149
 
147
- settings = nav_tab("Settings")
148
- settings << nav_item("General", "/admin/configuration")
149
- settings << nav_item("Personal", "/admin/preferences")
150
- settings << nav_item("Users", "/admin/users")
151
- settings << nav_item("Extensions", "/admin/extensions")
150
+ settings = nav_tab('Settings')
151
+ settings << nav_item('General', '/admin/configuration')
152
+ settings << nav_item('Personal', '/admin/preferences')
153
+ settings << nav_item('Users', '/admin/users')
154
+ settings << nav_item('Extensions', '/admin/extensions')
152
155
  nav << settings
153
156
  end
154
157
 
@@ -1,6 +1,6 @@
1
1
  class TrustyCms::AdminUI::RegionPartials
2
2
  def initialize(template)
3
- @partials = Hash.new {|h,k| h[k] = "<strong>`#{k}' default partial not found!</strong>" }
3
+ @partials = Hash.new { |h, k| h[k] = "<strong>`#{k}' default partial not found!</strong>" }
4
4
  @template = template
5
5
  end
6
6
 
@@ -8,13 +8,14 @@ class TrustyCms::AdminUI::RegionPartials
8
8
  @partials[key.to_s]
9
9
  end
10
10
 
11
- def method_missing(method, *args, &block)
11
+ def method_missing(method, *_args, &block)
12
12
  if block_given?
13
13
  # Ruby 1.9.2 yields self in instance_eval... see https://gist.github.com/479572
14
14
  # lambdas are as strict as methods in 1.9.x, making sure that the args match, Procs are not.
15
- if RUBY_VERSION =~ /^1\.9/ and block.lambda? and block.arity != 1
15
+ if RUBY_VERSION =~ /^1\.9/ && block.lambda? && (block.arity != 1)
16
16
  raise "You can only pass a proc ('Proc.new') or a lambda that takes exactly one arg (for self) to TrustyCms::AdminUI::RegionPartials' method_missing."
17
17
  end
18
+
18
19
  @partials[method.to_s] = @template.capture(&block)
19
20
  else
20
21
  @partials[method.to_s]
@@ -1,7 +1,6 @@
1
1
  class TrustyCms::AdminUI::RegionSet
2
-
3
2
  def initialize
4
- @regions = Hash.new do |h,k|
3
+ @regions = Hash.new do |h, k|
5
4
  h[k] = []
6
5
  end
7
6
  yield self if block_given?
@@ -11,8 +10,9 @@ class TrustyCms::AdminUI::RegionSet
11
10
  @regions[region.to_sym]
12
11
  end
13
12
 
14
- def add(region=nil, partial=nil, options={})
15
- raise ArgumentError, "You must specify a region and a partial" unless region and partial
13
+ def add(region = nil, partial = nil, options = {})
14
+ raise ArgumentError, 'You must specify a region and a partial' unless region && partial
15
+
16
16
  if options[:before]
17
17
  index = @regions[region].empty? ? 0 : (@regions[region].index(options[:before]) || @regions[region].size)
18
18
  self[region].insert(index, partial)
@@ -31,5 +31,4 @@ class TrustyCms::AdminUI::RegionSet
31
31
  super
32
32
  end
33
33
  end
34
-
35
34
  end
@@ -1,5 +1,4 @@
1
1
  module TrustyCms::AvailableLocales
2
-
3
2
  # Returns the list of available locale files in options_for_select format.
4
3
  #
5
4
  def self.locales
@@ -8,12 +7,11 @@ module TrustyCms::AvailableLocales
8
7
  if File.exists?(path) && path !~ /_available_tags/
9
8
  locale_yaml = YAML.load_file(path)
10
9
  stem = File.basename(path, '.yml')
11
- if locale_yaml[stem] && lang = locale_yaml[stem]["this_file_language"]
10
+ if locale_yaml[stem] && lang = locale_yaml[stem]['this_file_language']
12
11
  available_locales[lang] = stem
13
12
  end
14
13
  end
15
14
  end
16
- available_locales.collect {|k,v| [k, v]}.sort_by { |s| s[0] }
15
+ available_locales.collect { |k, v| [k, v] }.sort_by { |s| s[0] }
17
16
  end
18
-
19
17
  end
@@ -1,7 +1,6 @@
1
1
  module TrustyCms
2
2
  class Config
3
3
  class Definition
4
-
5
4
  attr_reader :empty, :default, :type, :notes, :validate_with, :select_from, :allow_blank, :allow_display, :allow_change, :units, :definer
6
5
 
7
6
  # Configuration 'definitions' are metadata held in memory that add restriction and description to individual config entries.
@@ -22,8 +21,8 @@ module TrustyCms
22
21
  #
23
22
  # See the method documentation in TrustyCms::Config for options and conventions.
24
23
  #
25
- def initialize(options={})
26
- [:empty, :default, :type, :notes, :validate_with, :select_from, :allow_blank, :allow_change, :allow_display, :units, :definer].each do |attribute|
24
+ def initialize(options = {})
25
+ %i[empty default type notes validate_with select_from allow_blank allow_change allow_display units definer].each do |attribute|
27
26
  instance_variable_set "@#{attribute}".to_sym, options[attribute]
28
27
  end
29
28
  end
@@ -61,7 +60,7 @@ module TrustyCms
61
60
  choices = select_from
62
61
  choices = choices.call if choices.respond_to? :call
63
62
  choices = normalize_selection(choices)
64
- choices.unshift ["",""] if allow_blank?
63
+ choices.unshift ['', ''] if allow_blank?
65
64
  choices
66
65
  end
67
66
  end
@@ -71,14 +70,14 @@ module TrustyCms
71
70
  #
72
71
  def normalize_selection(choices)
73
72
  choices = choices.to_a if Hash === choices
74
- choices = choices.collect{|c| (c.is_a? Array) ? c : [c,c]}
73
+ choices = choices.collect { |c| (c.is_a? Array) ? c : [c, c] }
75
74
  end
76
75
 
77
76
  # If the config item is a selector and :select_from specifies [name, value] pairs (as hash or array),
78
77
  # this will return the name corresponding to the currently selected value.
79
78
  #
80
79
  def selected(value)
81
- if value && selector? && pair = selection.find{|s| s.last == value}
80
+ if value && selector? && pair = selection.find { |s| s.last == value }
82
81
  pair.first
83
82
  end
84
83
  end
@@ -103,13 +102,18 @@ module TrustyCms
103
102
  setting.errors.add :value, :not_permitted unless selectable?(setting.value)
104
103
  end
105
104
  if integer?
106
- Integer(setting.value) rescue setting.errors.add :value, :not_a_number
105
+ begin
106
+ Integer(setting.value)
107
+ rescue StandardError
108
+ setting.errors.add :value, :not_a_number
109
+ end
107
110
  end
108
111
  end
109
112
 
110
113
  # Returns true if the value is one of the permitted selections. Not case-sensitive.
111
114
  def selectable?(value)
112
115
  return true unless selector?
116
+
113
117
  selection.map(&:last).map(&:downcase).include?(value.downcase)
114
118
  end
115
119
 
@@ -135,7 +139,6 @@ module TrustyCms
135
139
  def hidden?
136
140
  true if allow_display == false
137
141
  end
138
-
139
142
  end
140
143
  end
141
144
  end