-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type icon to reading activities and exercises #3178
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The design looks good, but I would extract the code to a helper function (and replace existing occurences of similar code. The helper function will probably also take an optional size argument (e.g., 18 by default).
I'm new to Ruby and tried these two helpers without succes: In def show_type_icon(activity, size)
if activity.exercise?
"<i class='<%= 'mdi mdi-#{activity.programming_language&.icon} mdi-#{size}' %>' title='<%= '#{t 'activities.index.type.exercise_language', language: activity.programming_language&.name&.titleize}' %>'></i>%>"
elsif activity.content_page?
"<i class='mdi mdi-book-open-variant mdi-#{size}' title='<%= t 'activities.index.type.content' %>'></i>"
end
end or def show_type_icon(activity, size)
if activity.exercise?
content_tag(:i, '', class:"mdi mdi-#{activity.programming_language&.icon} mdi-#{size}", title: "#{t 'activities.index.type.exercise_language', language: activity.programming_language&.name&.titleize}")
elsif activity.content_page?
content_tag(:i, '', class:"mdi mdi-book-open-variant mdi-#{size}", title: "#{t 'activities.index.type.content'}")
end
end and this in What am I missing? |
I think you missed an = in the show file, so |
app/helpers/activity_helper.rb
Outdated
@@ -99,6 +99,14 @@ def compare_solutions(a, b) | |||
end | |||
end | |||
|
|||
def show_type_icon(activity, size = 18) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this function isn't very Rails-y. The show
is not something that we usually add. I'm also not sure about the type
name. It doesn't really cover the programming language being returned in case of an exercise. I can't immediately think of a better name though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
activity_icon
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
activity_icon
is good for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Because this is an external repo, the tests aren't run (not sure why) and I can't seem to do a local checkout to run them locally.
@chvp can you run the tests before merging?
Because otherwise everyone can make a fork of this repo, change one of the GitHub Actions workflows to send your naos deploy key to their own server and store it. |
Secrets are never given for pull requests from other repositories. The actions are on push and can definitely be run on pull request too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubocop detects two style issues:
Inspecting 308 files
....................................C...............................................................................................................................................................................................................................................................................
Offenses:
app/helpers/activity_helper.rb:104:103: C: [Correctable] Style/RedundantInterpolation: Prefer to_s over string interpolation.
content_tag(:i, '', class: "mdi mdi-#{activity.programming_language&.icon} mdi-#{size}", title: "#{t 'activities.index.type.exercise_language', language: activity.programming_language&.name&.titleize}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/helpers/activity_helper.rb:106:82: C: [Correctable] Style/RedundantInterpolation: Prefer to_s over string interpolation.
content_tag(:i, '', class: "mdi mdi-book-open-variant mdi-#{size}", title: "#{t 'activities.index.type.content'}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
308 files inspected, 2 offenses detected, 2 offenses auto-correctable
Normally you can run bundle exec rubocop -a
to fix the issues automatically.
Note that rubocop's suggestion isn't even necessary. We know that |
Tests succeed. |
This pull request adds the type icon to reading activities and exercises.
Doesn't account for multiple programming languages for one exercise (one-to-many relationship) because this isn't supported yet.
Related to #1124.