extract in template code into helper method

pull/6700/head
Jens Ulferts 6 years ago
parent e9f854fa7c
commit 269bfb32e5
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 27
      app/helpers/colors_helper.rb
  2. 36
      app/views/highlighting/styles.css.erb

@ -61,6 +61,33 @@ module ColorsHelper
content_tag(:span, color.hexcode, class: 'color--text-preview', style: style)
end
def resource_color_css(name, scope)
scope.includes(:color).find_each do |entry|
color = entry.color
if color.nil?
concat ".__hl_dot_#{name}_#{entry.id}::before { display: none }\n"
next
end
styles = color.color_styles
inline_style = styles.map { |k,v| "#{k}:#{v} !important"}.join(';')
row_style = "background-color: #{color.hexcode} !important;"
border_color = color.bright? ? '#555555' : color.hexcode
concat ".__hl_inl_#{name}_#{entry.id} { #{inline_style}; }\n"
concat ".__hl_dot_#{name}_#{entry.id}::before { #{inline_style}; border-color: #{border_color}; }\n"
concat ".__hl_row_#{name}_#{entry.id} { #{row_style}; }\n"
# Mark color as bright through CSS variable
# so it can be used to add a separate -bright class
unless color.bright?
concat ":root { --hl-#{name}-#{entry.id}-dark: #{styles[:color]} }\n"
end
end
end
def icon_for_color(color, options = {})
return unless color

@ -1,37 +1,7 @@
<%
colored_resource = Proc.new do |name, scope|
scope.includes(:color).find_each do |entry|
color = entry.color
if color.nil?
concat ".__hl_dot_#{name}_#{entry.id}::before { display: none }\n"
next
end
styles = color.color_styles
inline_style = styles.map{|k,v| "#{k}:#{v} !important"}.join(';')
row_style = "background-color: #{color.hexcode} !important;"
border_color = color.bright? ? '#555555' : color.hexcode
concat ".__hl_inl_#{name}_#{entry.id} { #{inline_style}; }\n"
concat ".__hl_dot_#{name}_#{entry.id}::before { #{inline_style}; border-color: #{border_color}; }\n"
concat ".__hl_row_#{name}_#{entry.id} { #{row_style}; }\n"
# Mark color as bright through CSS variable
# so it can be used to add a separate -bright class
unless color.bright?
concat ":root { --hl-#{name}-#{entry.id}-dark: #{styles[:color]} }\n"
end
end
end
%>
<%# Highlightable resources %>
<%= colored_resource.call('status', ::Status) %>
<%= colored_resource.call('priority', ::IssuePriority) %>
<%= colored_resource.call('type', ::Type) %>
<%= resource_color_css('status', ::Status) %>
<%= resource_color_css('priority', ::IssuePriority) %>
<%= resource_color_css('type', ::Type) %>
<%# Overdue tasks %>
.__hl_date_due_today { color: #F76707 !important; }

Loading…
Cancel
Save