Skip to content

Commit

Permalink
Updated Rubocop to import from global configuration.
Browse files Browse the repository at this point in the history
- Enables easier multi-project management.
  • Loading branch information
bkuhlmann committed Feb 5, 2017
1 parent f8bcd21 commit 5fffc8d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 55 deletions.
5 changes: 3 additions & 2 deletions .codeclimate.yml
@@ -1,8 +1,9 @@
prepare:
fetch:
- https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/.rubocop.yml
engines:
shellcheck:
enabled: true
bundler-audit:
enabled: true
reek:
enabled: true
rubocop:
Expand Down
52 changes: 3 additions & 49 deletions .rubocop.yml
@@ -1,49 +1,3 @@
inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- "spec/dummy/**/*"
Style/AndOr:
EnforcedStyle: conditionals
Style/CaseIndentation:
IndentOneStep: true
Style/Documentation:
Enabled: false
Style/EmptyMethod:
EnforcedStyle: expanded
Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/NumericLiterals:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
"%w": "[]"
"%W": "[]"
"%i": "[]"
"%I": "[]"
"%r": "()"
Style/SafeNavigation:
Enabled: false
Style/SignalException:
EnforcedStyle: semantic
Style/SingleLineBlockParams:
Enabled: false
Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/VariableNumber:
EnforcedStyle: snake_case
Metrics/BlockLength:
Exclude:
- "**/*.gemspec"
- "spec/**/*"
Metrics/LineLength:
Max: 100
Exclude:
- "lib/navigator/menu.rb"
- "spec/lib/menu_spec.rb"
Metrics/ParameterLists:
Max: 3
inherit_from:
- https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/.rubocop.yml
- .rubocop_todo.yml
27 changes: 23 additions & 4 deletions lib/navigator/menu.rb
Expand Up @@ -3,11 +3,17 @@
module Navigator
# Renders a HTML menu.
class Menu
# rubocop:disable Metrics/LineLength
def self.allowed_methods
/^(div|section|header|h[1-6]|nav|ul|li|a|img|b|em|s|small|span|strong|sub|sup|form|label|select|option|input|button)$/
end

def initialize template, tag: "ul", attributes: {}, activator: Navigator::TagActivator.new, &block
def initialize template,
tag: "ul",
attributes: {},
activator: Navigator::TagActivator.new,
&block

@template = template
@tag = Navigator::Tag.new tag, attributes: attributes, activator: activator
@menu_activator = activator
Expand Down Expand Up @@ -36,12 +42,22 @@ def image url, alt = nil, attributes: {}, activator: menu_activator
add "img", attributes: modified_attributes, activator: activator
end

def item content = nil, url, item_attributes: {}, link_attributes: {}, activator: menu_activator, &block
def item content = nil,
url,
item_attributes: {},
link_attributes: {},
activator: menu_activator,
&block

modified_item_attributes = item_attributes.clone
activate_item_attributes! modified_item_attributes, url, activator

add "li", attributes: modified_item_attributes, activator: activator do
link content, url, attributes: link_attributes, activator: Navigator::TagActivator.new, &block
link content,
url,
attributes: link_attributes,
activator: Navigator::TagActivator.new,
&block
end
end

Expand Down Expand Up @@ -72,7 +88,10 @@ def method_allowed? name

def activate_item_attributes! attributes, url, activator
return unless url == activator.search_value
attributes[activator.target_key] = [attributes[activator.target_key], activator.target_value].compact * " "

attributes[activator.target_key] = [attributes[activator.target_key], activator.target_value]
.compact
.join " "
end
end
end
1 change: 1 addition & 0 deletions spec/lib/menu_spec.rb
Expand Up @@ -2,6 +2,7 @@

require "rails_helper"

# rubocop:disable Metrics/LineLength
RSpec.describe Navigator::Menu do
let(:erb_handler) { ActionView::Template::Handlers::ERB.new }
let(:template) { ActionView::Template.new "<html></html>", "Example", erb_handler, {} }
Expand Down

0 comments on commit 5fffc8d

Please sign in to comment.