trusty-cms 4.1.2 → 4.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +104 -104
  4. data/README.md +1 -1
  5. data/Rakefile +7 -7
  6. data/app/assets/javascripts/admin/assets.js +1 -1
  7. data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
  8. data/app/assets/javascripts/rad_social/rad_email.js +0 -1
  9. data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
  10. data/app/assets/stylesheets/admin/partials/_content.scss +1 -2
  11. data/app/assets/stylesheets/rad_social/rad_screen.scss +0 -4
  12. data/app/controllers/admin/assets_controller.rb +22 -21
  13. data/app/controllers/admin/configuration_controller.rb +9 -11
  14. data/app/controllers/admin/extensions_controller.rb +3 -3
  15. data/app/controllers/admin/layouts_controller.rb +3 -4
  16. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  17. data/app/controllers/admin/page_fields_controller.rb +3 -4
  18. data/app/controllers/admin/page_parts_controller.rb +4 -5
  19. data/app/controllers/admin/pages_controller.rb +55 -56
  20. data/app/controllers/admin/references_controller.rb +1 -1
  21. data/app/controllers/admin/resource_controller.rb +132 -130
  22. data/app/controllers/admin/sites_controller.rb +4 -4
  23. data/app/controllers/admin/snippets_controller.rb +3 -4
  24. data/app/controllers/admin/users_controller.rb +16 -16
  25. data/app/controllers/application_controller.rb +47 -48
  26. data/app/controllers/site_controller.rb +51 -48
  27. data/app/controllers/social_mailer_controller.rb +12 -22
  28. data/app/helpers/admin/configuration_helper.rb +19 -20
  29. data/app/helpers/admin/layouts_helper.rb +0 -1
  30. data/app/helpers/admin/node_helper.rb +27 -24
  31. data/app/helpers/admin/pages_helper.rb +2 -2
  32. data/app/helpers/admin/preferences_helper.rb +0 -1
  33. data/app/helpers/admin/references_helper.rb +9 -10
  34. data/app/helpers/admin/regions_helper.rb +3 -3
  35. data/app/helpers/application_helper.rb +32 -33
  36. data/app/helpers/rad_social_helper.rb +8 -11
  37. data/app/helpers/scoped_helper.rb +1 -3
  38. data/app/helpers/sites_helper.rb +4 -4
  39. data/app/mailers/devise_mailer.rb +3 -4
  40. data/app/mailers/rad_social_mailer.rb +8 -8
  41. data/app/models/asset.rb +62 -63
  42. data/app/models/asset_type.rb +38 -39
  43. data/app/models/deprecated_tags.rb +3 -4
  44. data/app/models/file_not_found_page.rb +1 -3
  45. data/app/models/haml_filter.rb +1 -1
  46. data/app/models/layout.rb +4 -5
  47. data/app/models/legacy_user.rb +2 -2
  48. data/app/models/menu_renderer.rb +16 -18
  49. data/app/models/page.rb +96 -93
  50. data/app/models/page_attachment.rb +1 -2
  51. data/app/models/page_context.rb +11 -12
  52. data/app/models/page_part.rb +3 -4
  53. data/app/models/rails_page.rb +10 -12
  54. data/app/models/site.rb +22 -21
  55. data/app/models/snippet.rb +6 -8
  56. data/app/models/snippet_finder.rb +3 -3
  57. data/app/models/snippet_tags.rb +4 -4
  58. data/app/models/standard_tags.rb +258 -252
  59. data/app/models/status.rb +8 -8
  60. data/app/models/trusty_cms/config.rb +25 -25
  61. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  62. data/app/models/user.rb +15 -14
  63. data/app/models/user_action_observer.rb +3 -3
  64. data/app/views/admin/assets/edit.html.haml +3 -0
  65. data/app/views/rad_social_mailer/social_mail_form.html.haml +1 -3
  66. data/app/views/widget/_email_form.html.haml +0 -5
  67. data/bin/rails +4 -4
  68. data/bin/trusty_cms +3 -5
  69. data/config.ru +1 -1
  70. data/config/application.rb +14 -15
  71. data/config/boot.rb +1 -2
  72. data/config/environment.rb +1 -1
  73. data/config/environments/production.rb +0 -1
  74. data/config/environments/test.rb +1 -2
  75. data/config/initializers/devise.rb +1 -1
  76. data/config/initializers/kraken.rb +2 -2
  77. data/config/initializers/tmp.rb +1 -1
  78. data/config/initializers/trusty_cms_config.rb +48 -48
  79. data/config/locales/en.yml +1 -0
  80. data/config/routes.rb +6 -6
  81. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  82. data/lib/annotatable.rb +3 -5
  83. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  84. data/lib/inheritable_class_attributes.rb +13 -9
  85. data/lib/login_system.rb +73 -73
  86. data/lib/method_observer.rb +13 -12
  87. data/lib/ostruct.rb +7 -10
  88. data/lib/simpleton.rb +0 -4
  89. data/lib/string_extensions/string_extensions.rb +3 -3
  90. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  91. data/lib/tasks/database.rake +28 -28
  92. data/lib/tasks/extensions.rake +18 -18
  93. data/lib/tasks/framework.rake +68 -68
  94. data/lib/tasks/radiant_config.rake +4 -4
  95. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  96. data/lib/tasks/translate.rake +14 -14
  97. data/lib/tasks/upgrade_to_devise.rake +1 -1
  98. data/lib/translation_support.rb +22 -22
  99. data/lib/trusty_cms.rb +2 -2
  100. data/lib/trusty_cms/admin_ui.rb +19 -16
  101. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  102. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  103. data/lib/trusty_cms/available_locales.rb +2 -4
  104. data/lib/trusty_cms/config/definition.rb +11 -8
  105. data/lib/trusty_cms/engine.rb +13 -14
  106. data/lib/trusty_cms/extension.rb +14 -16
  107. data/lib/trusty_cms/extension_loader.rb +6 -6
  108. data/lib/trusty_cms/extension_migrator.rb +42 -41
  109. data/lib/trusty_cms/extension_path.rb +20 -19
  110. data/lib/trusty_cms/initializer.rb +5 -8
  111. data/lib/trusty_cms/pagination/controller.rb +7 -10
  112. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  113. data/lib/trusty_cms/resource_responses.rb +3 -3
  114. data/lib/trusty_cms/setup.rb +130 -132
  115. data/lib/trusty_cms/taggable.rb +19 -22
  116. data/lib/trusty_cms/task_support.rb +9 -6
  117. data/public/dispatch.fcgi +1 -1
  118. data/public/dispatch.rb +2 -2
  119. data/script/extension +1 -1
  120. data/script/rails +2 -2
  121. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/core.js +126 -0
  122. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/index.js +4 -0
  123. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/map.js +56 -0
  124. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/seq.js +43 -0
  125. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/string.js +28 -0
  126. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/index.js +36 -0
  127. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/json.js +76 -0
  128. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/options.js +23 -0
  129. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/binary.js +87 -0
  130. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/index.js +157 -0
  131. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/omap.js +142 -0
  132. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/pairs.js +81 -0
  133. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/set.js +114 -0
  134. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/timestamp.js +97 -0
  135. data/spec/spec/dummy/node_modules/yaml/dist/tags/core.js +114 -0
  136. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/index.js +17 -0
  137. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/map.js +37 -0
  138. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/seq.js +34 -0
  139. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/string.js +40 -0
  140. data/spec/spec/dummy/node_modules/yaml/dist/tags/index.js +62 -0
  141. data/spec/spec/dummy/node_modules/yaml/dist/tags/json.js +60 -0
  142. data/spec/spec/dummy/node_modules/yaml/dist/tags/options.js +35 -0
  143. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/binary.js +97 -0
  144. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/index.js +131 -0
  145. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/omap.js +105 -0
  146. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/pairs.js +80 -0
  147. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/set.js +91 -0
  148. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/timestamp.js +93 -0
  149. data/trusty_cms.gemspec +24 -24
  150. data/yarn.lock +3 -3
  151. metadata +7602 -103
  152. data/app/assets/javascripts/rad_social/captcha.js +0 -42
@@ -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
@@ -13,20 +13,21 @@ module TrustyCms::Taggable
13
13
  end
14
14
  class << new_base
15
15
  def default_url_options
16
- {:controller => "site", :action => "show_page", :only_path => true}
16
+ { controller: 'site', action: 'show_page', only_path: true }
17
17
  end
18
18
  end
19
- new_base.tag_descriptions.merge! self.tag_descriptions
19
+ new_base.tag_descriptions.merge! tag_descriptions
20
20
  end
21
21
 
22
22
  protected
23
- def params
24
- @params ||= request.parameters unless request.nil?
25
- end
26
23
 
27
- def request_uri
28
- @request_url ||= request.request_uri unless request.nil?
29
- end
24
+ def params
25
+ @params ||= request.parameters unless request.nil?
26
+ end
27
+
28
+ def request_uri
29
+ @request_url ||= request.request_uri unless request.nil?
30
+ end
30
31
  end
31
32
  end
32
33
 
@@ -44,11 +45,11 @@ module TrustyCms::Taggable
44
45
  Util.tags_in_array(methods)
45
46
  end
46
47
 
47
- def tag_descriptions(hash=nil)
48
+ def tag_descriptions(hash = nil)
48
49
  self.class.tag_descriptions hash
49
50
  end
50
51
 
51
- def warn_of_tag_deprecation(tag_name, options={})
52
+ def warn_of_tag_deprecation(tag_name, options = {})
52
53
  message = "Deprecated radius tag <r:#{tag_name}>"
53
54
  message << " will be removed or significantly changed in trusty #{options[:deadline]}." if options[:deadline]
54
55
  message << " Please use <r:#{options[:substitute]}> instead." if options[:substitute]
@@ -57,12 +58,12 @@ module TrustyCms::Taggable
57
58
 
58
59
  module ClassMethods
59
60
  def inherited(subclass)
60
- subclass.tag_descriptions.reverse_merge! self.tag_descriptions
61
+ subclass.tag_descriptions.reverse_merge! tag_descriptions
61
62
  super
62
63
  end
63
64
 
64
65
  def tag_descriptions(hash = nil)
65
- TrustyCms::Taggable.tag_descriptions[self.name] ||= (hash ||{})
66
+ TrustyCms::Taggable.tag_descriptions[name] ||= (hash || {})
66
67
  end
67
68
 
68
69
  def desc(text)
@@ -71,13 +72,13 @@ module TrustyCms::Taggable
71
72
  end
72
73
 
73
74
  def tag(name, &block)
74
- self.tag_descriptions[name] = TrustyCms::Taggable.last_description if TrustyCms::Taggable.last_description
75
+ tag_descriptions[name] = TrustyCms::Taggable.last_description if TrustyCms::Taggable.last_description
75
76
  TrustyCms::Taggable.last_description = nil
76
77
  define_method("tag:#{name}", &block)
77
78
  end
78
79
 
79
80
  def tags
80
- Util.tags_in_array(self.instance_methods)
81
+ Util.tags_in_array(instance_methods)
81
82
  end
82
83
 
83
84
  # Define a tag while also deprecating it. Normal usage:
@@ -98,7 +99,7 @@ module TrustyCms::Taggable
98
99
  # raise TagError "..."
99
100
  # end
100
101
  #
101
- def deprecated_tag(name, options={}, &dblock)
102
+ def deprecated_tag(name, options = {}, &dblock)
102
103
  TrustyCms::Taggable.tag_deprecations[name] = options.dup
103
104
  if dblock
104
105
  tag(name) do |tag|
@@ -121,18 +122,14 @@ module TrustyCms::Taggable
121
122
 
122
123
  def self.strip_leading_whitespace(text)
123
124
  text = text.dup
124
- text.gsub!("\t", " ")
125
+ text.gsub!("\t", ' ')
125
126
  lines = text.split("\n")
126
127
  leading = lines.map do |line|
127
128
  unless line =~ /^\s*$/
128
- line.match(/^(\s*)/)[0].length
129
- else
130
- nil
129
+ line.match(/^(\s*)/)[0].length
131
130
  end
132
131
  end.compact.min
133
- lines.inject([]) {|ary, line| ary << line.sub(/^[ ]{#{leading}}/, "")}.join("\n")
132
+ lines.inject([]) { |ary, line| ary << line.sub(/^[ ]{#{leading}}/, '') }.join("\n")
134
133
  end
135
-
136
134
  end
137
-
138
135
  end