about summary refs log tree commit diff
path: root/app/controllers/user_webapp_css_controller.rb
blob: 3acb21bb1f7f35b5ff5b565362f782ee07922de9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

class UserWebappCssController < ApplicationController
  skip_before_action :store_current_location
  skip_before_action :require_functional!

  before_action :set_account

  def show
    render plain: css, content_type: 'text/css'
  end

  private

  def css_dashed_nest
    return unless @account.user&.setting_style_dashed_nest

    %(
      div[data-nest-level]
      { border-style: dashed; }
    )
  end

  def css_underline_a
    return unless @account.user&.setting_style_underline_a

    %(
      .status__content__text a,
      .reply-indicator__content a,
      .composer--reply > .content a,
      .account__header__content a
      { text-decoration: underline; }

      .status__content__text a:hover,
      .reply-indicator__content a:hover,
      .composer--reply > .content a:hover,
      .account__header__content a:hover
      { text-decoration: none; }
    )
  end

  def css_wide_media
    return unless @account.user&.setting_style_wide_media

    %(
      .media-gallery
      { height: auto !important; }

      .media-gallery__item
      { width: 100% !important; }

      .spoiler-button + .media-gallery__item
      { height: 5em !important; }

      .spoiler-button--minified + .media-gallery__item
      { height: 280px !important; }
    )
  end

  def css_lowercase
    return unless @account.user&.setting_style_lowercase

    %(
      div, button, span
      { text-transform: lowercase; }

      code, pre
      { text-transform: initial !important; }
    )
  end

  def css_webapp
    @account.user&.setting_style_css_webapp_errors.blank? ? (@account.user&.setting_style_css_webapp || '') : ''
  end

  def css
    "#{css_dashed_nest}\n#{css_underline_a}\n#{css_wide_media}\n#{css_lowercase}\n#{css_webapp}".squish
  end

  def set_account
    @account = Account.find(params[:id])
  end
end