Completed
Branch scrut-fixes (283d0e)
by Ahmad
05:43
created

Themer.generate_sass()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
19
module Themer
20
  extend ActiveSupport::Concern
21
22
  # Lightens a color by 40%
23
  def color_lighten(color)
24
    # Uses the built in Sass Engine to lighten the color
25
    generate_sass("lighten", color, "40%")
26
  end
27
28
  # Darkens a color by 10%
29
  def color_darken(color)
30
    # Uses the built in Sass Engine to darken the color
31
    generate_sass("darken", color, "10%")
32
  end
33
34
  private
35
36
  def generate_sass(action, color, percentage)
37
    dummy_scss = "h1 { color: $#{action}; }"
38
    compiled = SassC::Engine.new("$#{action}:#{action}(#{color}, #{percentage});" + dummy_scss, syntax: :scss).render
39
40
    string_locater = 'color: '
41
    color_start = compiled.index(string_locater) + string_locater.length
42
43
    compiled[color_start..color_start + 6]
44
  end
45
end
46