Skip to content

Commit

Permalink
Align parameter and if/end blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 1, 2016
1 parent acf1bcc commit e074bbf
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 154 deletions.
43 changes: 0 additions & 43 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
# SupportedStyles: keyword, variable, start_of_line
Lint/EndAlignment:
Exclude:
- 'app/controllers/concerns/blacklight/token_based_user.rb'
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
- 'app/helpers/blacklight/facets_helper_behavior.rb'
- 'app/helpers/blacklight/render_partials_helper_behavior.rb'
- 'app/helpers/blacklight/url_helper_behavior.rb'
- 'app/models/concerns/blacklight/configurable.rb'
- 'app/presenters/blacklight/index_presenter.rb'
- 'lib/blacklight/configuration/fields.rb'
- 'lib/blacklight/search_builder.rb'
- 'lib/blacklight/solr/response/facets.rb'
- 'lib/blacklight/solr/search_builder_behavior.rb'

# Offense count: 7
Lint/UselessAssignment:
Exclude:
Expand Down Expand Up @@ -93,18 +75,6 @@ Style/Alias:
- 'lib/blacklight/solr/response.rb'
- 'lib/blacklight/solr/response/group_response.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Style/AlignParameters:
Exclude:
- 'app/helpers/blacklight/render_constraints_helper_behavior.rb'
- 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb'
- 'lib/blacklight/configuration.rb'
- 'lib/generators/blacklight/solr4_generator.rb'


# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down Expand Up @@ -157,19 +127,6 @@ Style/DoubleNegation:
Exclude:
- 'lib/blacklight/search_builder.rb'

# Offense count: 16
# Cop supports --auto-correct.
Style/ElseAlignment:
Exclude:
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
- 'app/helpers/blacklight/facets_helper_behavior.rb'
- 'app/helpers/blacklight/url_helper_behavior.rb'
- 'app/models/concerns/blacklight/configurable.rb'
- 'lib/blacklight/search_builder.rb'
- 'lib/blacklight/solr/response/facets.rb'
- 'lib/blacklight/solr/search_builder_behavior.rb'

# Offense count: 20
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/concerns/blacklight/token_based_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def token_or_current_or_guest_user

def token_user
@token_user ||= if params[:encrypted_user_id]
user_id = decrypt_user_id params[:encrypted_user_id]
User.find(user_id)
end
user_id = decrypt_user_id params[:encrypted_user_id]
User.find(user_id)
end
end

# Used for #export action, with encrypted user_id.
Expand Down
51 changes: 26 additions & 25 deletions app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ def page_entries_info(collection, options = {})
return unless show_pagination? collection

entry_name = if options[:entry_name]
options[:entry_name]
elsif collection.respond_to? :model # DataMapper
collection.model.model_name.human.downcase
elsif collection.respond_to?(:model_name) && !collection.model_name.nil? # AR, Blacklight::PaginationMethods
collection.model_name.human.downcase
else
t('blacklight.entry_name.default')
end
options[:entry_name]
elsif collection.respond_to? :model # DataMapper
collection.model.model_name.human.downcase
elsif collection.respond_to?(:model_name) && !collection.model_name.nil? # AR, Blacklight::PaginationMethods
collection.model_name.human.downcase
else
t('blacklight.entry_name.default')
end

entry_name = entry_name.pluralize unless collection.total_count == 1

# grouped response objects need special handling
end_num = if collection.respond_to?(:groups) && render_grouped_response?(collection)
collection.groups.length
else
collection.limit_value
end
collection.groups.length
else
collection.limit_value
end

end_num = if collection.offset_value + end_num <= collection.total_count
collection.offset_value + end_num
else
collection.total_count
end
collection.offset_value + end_num
else
collection.total_count
end

case collection.total_count
when 0
Expand Down Expand Up @@ -211,12 +211,13 @@ def has_thumbnail? document
# @return [String]
def render_thumbnail_tag document, image_options = {}, url_options = {}
value = if blacklight_config.view_config(document_index_view_type).thumbnail_method
send(blacklight_config.view_config(document_index_view_type).thumbnail_method, document, image_options)
elsif blacklight_config.view_config(document_index_view_type).thumbnail_field
url = thumbnail_url(document)
method_name = blacklight_config.view_config(document_index_view_type).thumbnail_method
send(method_name, document, image_options)
elsif blacklight_config.view_config(document_index_view_type).thumbnail_field
url = thumbnail_url(document)

image_tag url, image_options if url.present?
end
image_tag url, image_options if url.present?
end

if value
if url_options == false || url_options[:suppress_link]
Expand Down Expand Up @@ -280,10 +281,10 @@ def render_search_to_page_title_filter(facet, values)
facet_config = facet_configuration_for_field(facet)
filter_label = facet_field_label(facet_config.key)
filter_value = if values.size < 3
values.map {|value| facet_display_value(facet, value)}.to_sentence
else
t('blacklight.search.page_title.many_constraint_values', values: values.size)
end
values.map {|value| facet_display_value(facet, value)}.to_sentence
else
t('blacklight.search.page_title.many_constraint_values', values: values.size)
end
t('blacklight.search.page_title.constraint', label: filter_label, value: filter_value)
end

Expand Down
8 changes: 4 additions & 4 deletions app/helpers/blacklight/facets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ def facet_display_value field, item
facet_config = facet_configuration_for_field(field)

value = if item.respond_to? :label
item.label
else
facet_value_for_facet_item(item)
end
item.label
else
facet_value_for_facet_item(item)
end

if facet_config.helper_method
send facet_config.helper_method, value
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/blacklight/render_constraints_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def render_constraints_query(localized_params = params)
return "".html_safe if localized_params[:q].blank?

render_constraint_element(constraint_query_label(localized_params),
localized_params[:q],
classes: ["query"],
remove: remove_constraint_url(localized_params))
localized_params[:q],
classes: ["query"],
remove: remove_constraint_url(localized_params))
end

##
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/render_partials_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def document_partial_name(document, base_name = nil)
view_config = blacklight_config.view_config(:show)

display_type = if base_name && view_config.key?(:"#{base_name}_display_type_field")
document[view_config[:"#{base_name}_display_type_field"]]
end
document[view_config[:"#{base_name}_display_type_field"]]
end

display_type ||= document[view_config.display_type_field]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ def render_search_to_s_filters(params)

safe_join(params[:f].collect do |facet_field, value_list|
render_search_to_s_element(facet_field_label(facet_field),
safe_join(value_list.collect do |value|
render_filter_value(value, facet_field)
end,
content_tag(:span,
" #{t('blacklight.and')} ",
class: 'filter-separator')))
safe_join(value_list.collect do |value|
render_filter_value(value, facet_field)
end,
content_tag(:span, " #{t('blacklight.and')} ", class: 'filter-separator')))
end, " \n ")
end

Expand Down
8 changes: 4 additions & 4 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def link_back_to_catalog(opts={:label=>nil})
end

link_url = if query_params.empty?
search_action_path(only_path: true)
else
scope.url_for(query_params)
end
search_action_path(only_path: true)
else
scope.url_for(query_params)
end
label = opts.delete(:label)

if link_url =~ /bookmarks/
Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/blacklight/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def copy_blacklight_config_from(other_class)
# we lazy load to 'inherit' how we want.
def blacklight_config
@blacklight_config ||= if superclass.respond_to?(:blacklight_config)
superclass.blacklight_config.deep_copy
else
default_configuration
end
superclass.blacklight_config.deep_copy
else
default_configuration
end
end
attr_writer :blacklight_config

Expand Down
16 changes: 8 additions & 8 deletions app/presenters/blacklight/index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def initialize(document, view_context, configuration = view_context.blacklight_c
def label(field_or_string_or_proc, opts = {})
config = Configuration::NullField.new
value = case field_or_string_or_proc
when Symbol
config = field_config(field_or_string_or_proc)
document[field_or_string_or_proc]
when Proc
field_or_string_or_proc.call(document, opts)
when String
field_or_string_or_proc
end
when Symbol
config = field_config(field_or_string_or_proc)
document[field_or_string_or_proc]
when Proc
field_or_string_or_proc.call(document, opts)
when String
field_or_string_or_proc
end

value ||= document.id
field_values(config, value: value)
Expand Down
18 changes: 9 additions & 9 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def default_values
),
# Configurations for specific types of index views
view: NestedOpenStructWithHashAccess.new(ViewConfig,
list: {},
atom: {
if: false, # by default, atom should not show up as an alternative view
partials: [:document]
},
rss: {
if: false, # by default, rss should not show up as an alternative view
partials: [:document]
}),
list: {},
atom: {
if: false, # by default, atom should not show up as an alternative view
partials: [:document]
},
rss: {
if: false, # by default, rss should not show up as an alternative view
partials: [:document]
}),
#
# These fields are created and managed below by `defined_field_access`
# facet_fields
Expand Down
22 changes: 11 additions & 11 deletions lib/blacklight/configuration/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ def add_#{key}(*args, &block)
#
def add_blacklight_field config_key, *args, &block
field_config = case args.first
when String
field_config_from_key_and_hash(config_key, *args)
when Symbol
args[0] = args[0].to_s
field_config_from_key_and_hash(config_key, *args)
when Array
field_config_from_array(config_key, *args, &block)
return # we've iterated over the array above.
else
field_config_from_field_or_hash(config_key, *args)
end
when String
field_config_from_key_and_hash(config_key, *args)
when Symbol
args[0] = args[0].to_s
field_config_from_key_and_hash(config_key, *args)
when Array
field_config_from_array(config_key, *args, &block)
return # we've iterated over the array above.
else
field_config_from_field_or_hash(config_key, *args)
end

if (field_config.field || field_config.key).to_s =~ /\*/
field_config.match = Regexp.new("^" + (field_config.field || field_config.key).to_s.gsub('*', '.+') + "$")
Expand Down
22 changes: 11 additions & 11 deletions lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,19 @@ def facet(value = nil)

def sort
sort_field = if blacklight_params[:sort].blank?
# no sort param provided, use default
blacklight_config.default_sort_field
else
# check for sort field key
blacklight_config.sort_fields[blacklight_params[:sort]]
end
# no sort param provided, use default
blacklight_config.default_sort_field
else
# check for sort field key
blacklight_config.sort_fields[blacklight_params[:sort]]
end

field = if sort_field.present?
sort_field.sort
else
# just pass the key through
blacklight_params[:sort]
end
sort_field.sort
else
# just pass the key through
blacklight_params[:sort]
end

field unless field.blank?
end
Expand Down
12 changes: 6 additions & 6 deletions lib/blacklight/solr/response/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def list_as_hash solr_list
else
solr_list.each_with_object({}) do |(key, values), hash|
hash[key] = if values.first.is_a? Array
# arrarr
Hash[values]
else
# flat
Hash[values.each_slice(2).to_a]
end
# arrarr
Hash[values]
else
# flat
Hash[values.each_slice(2).to_a]
end
end
end
end
Expand Down
Loading

0 comments on commit e074bbf

Please sign in to comment.