Skip to content

Commit

Permalink
Run rubocop autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
phrdang committed Jun 25, 2024
1 parent e7e70c1 commit 6db5707
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions _plugins/code_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,28 @@ def initialize(tag_name, params, tokens)

def get_extension_and_comment_chars(file_name)
SUPPORTED_LANGUAGES.each do |extension, comment_chars|
if file_name.end_with?(extension.to_s)
@file_extension = extension
@comment_chars = comment_chars
return
end
next unless file_name.end_with?(extension.to_s)

@file_extension = extension
@comment_chars = comment_chars
return
end

raise ArgumentError, "File extension not supported: #{file_name}. Supported extensions: #{SUPPORTED_LANGUAGES.join(', ')}"
raise ArgumentError,
"File extension not supported: #{file_name}. Supported extensions: #{SUPPORTED_LANGUAGES.join(', ')}"
end

def parse_params(params)
file_name, show_solution = params.strip.split

raise ArgumentError, "Missing first argument to code tag, which must be a file path relative to _includes directory" if file_name.nil?
raise ArgumentError, "Missing second argument to code tag, which must be a boolean representing whether solutions are displayed" if show_solution.nil?
if file_name.nil?
raise ArgumentError,
'Missing first argument to code tag, which must be a file path relative to _includes directory'
end
if show_solution.nil?
raise ArgumentError,
'Missing second argument to code tag, which must be a boolean representing whether solutions are displayed'
end

get_extension_and_comment_chars(file_name)

Expand All @@ -74,7 +81,10 @@ def boolean?(value)
end

def to_boolean(value)
raise ArgumentError, "value must be 'true' or 'false' not '#{value}' (type #{value.class})" unless string_boolean?(value)
unless string_boolean?(value)
raise ArgumentError,
"value must be 'true' or 'false' not '#{value}' (type #{value.class})"
end

value == 'true'
end
Expand Down Expand Up @@ -123,7 +133,10 @@ def render(context)
elsif !boolean?(@show_solution)
jekyll_variable_value = context[@show_solution]

raise ArgumentError, "Second argument to code tag must be a boolean, not '#{jekyll_variable_value}' (type #{jekyll_variable_value.class})" unless boolean?(jekyll_variable_value)
unless boolean?(jekyll_variable_value)
raise ArgumentError,
"Second argument to code tag must be a boolean, not '#{jekyll_variable_value}' (type #{jekyll_variable_value.class})"
end

@show_solution = jekyll_variable_value
end
Expand Down

0 comments on commit 6db5707

Please sign in to comment.