Skip to content

Instantly share code, notes, and snippets.

@roblevintennis
Last active July 17, 2018 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblevintennis/e776c245adc052e6060250e76b3d800f to your computer and use it in GitHub Desktop.
Save roblevintennis/e776c245adc052e6060250e76b3d800f to your computer and use it in GitHub Desktop.
String Interpolation Refactoring Examples
<% svgIconName = ''
case story.story_type
when 'deliverable'
svgIconName = 'icon-deliverable'
when 'milestone'
svgIconName = 'icon-milestone'
when 'task'
svgIconName = 'icon-task'
when 'issue'
svgIconName = 'icon-issue'
end
%>
<div>
Normal markup stuff...
<span class='story-icon'>
<%= svg_icon(svgIconName, 'icon-fill-'+story.story_type+' legacy-filled-icons-sqkd-18b901') %>
</span>
</div>
styles = require './story.scss'
templateHelpers: ->
iconClass: @_iconClassForStoryType
_iconClassForStoryType: (type) ->
fillKlass = styles['legacy-filled-icons']
switch type
when 'task'
iconClassName = "#{fillKlass} icon-fill-highlight"
when 'deliverable'
iconClassName = "#{fillKlass} icon-fill-action"
when 'milestone'
iconClassName = "#{fillKlass} icon-fill-primary"
when 'issue'
iconClassName = "#{fillKlass} icon-fill-caution"
else
return ''
iconClassName
<%= @svgIcon("icon-#{@story_type}", @iconClass(@story_type)) %>
.legacy-filled-icons {
composes: legacy-filled-icons-sqkd-18b901 from 'internal/base/utilities.scss';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment