Class: Shugoi::ShieldPage

Inherits:
Object
  • Object
show all
Defined in:
lib/shugoi/shield_page.rb

Defined Under Namespace

Classes: Input

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ ShieldPage

Returns a new instance of ShieldPage.



9
10
11
12
# File 'lib/shugoi/shield_page.rb', line 9

def initialize(input)
  @input = input
  @messages = Locales.messages(input.locale)
end

Class Method Details

.render(**attributes) ⇒ Object



5
6
7
# File 'lib/shugoi/shield_page.rb', line 5

def self.render(**attributes)
  new(Input.new(**attributes)).render
end

Instance Method Details

#renderObject



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
# File 'lib/shugoi/shield_page.rb', line 14

def render
  title = escaped(@input.title, :blocked_title)
  badge = escaped(@input.badge, :blocked_badge)
  host = Utils.escape_html((@input.host.to_s.empty? ? "shugoi.com" : @input.host).slice(0, 120))
  description = Utils.escape_html(description_text)
  language = @input.locale == "fr" ? "fr" : "en"
  <<~HTML
    <!DOCTYPE html>
    <html lang="#{language}">
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <style>#{styles}</style>
      </head>
      <body>
        <div id="c">
          <img src="https://shugoi.com/favicon.png" alt class="l">
          <img src="https://shugoi.com/brand.png" alt class="b">
          <div class="bdg">#{badge}</div>
          <h2>#{title}</h2>
          <p class="desc">#{description}</p>
          <p class="ft">#{host} ยท Shugoi</p>
        </div>
      </body>
    </html>
  HTML
end