Class: GHPreview::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ghpreview/wrapper.rb

Constant Summary collapse

GITHUB_URL =
'https://github.com'
STYLED_TEMPLATE_FILEPATH =
"/tmp/ghpreview-template.erb"
TEMPLATE_CACHE_DURATION =

one week

60 * 60 * 24 * 7
RAW_TEMPLATE_FILEPATH =
"#{File.dirname(__FILE__)}/template.erb"

Class Method Summary collapse

Class Method Details



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ghpreview/wrapper.rb', line 11

def self.generate_template_with_fingerprinted_stylesheet_links
  http = HTTPClient.new

  if stale_template?(STYLED_TEMPLATE_FILEPATH)
    stylesheet_links = http.get(GITHUB_URL).body.split("\n").select do |line|
      line =~ /https:.*github.*\.css/
    end.join

    raw_template = File.read(RAW_TEMPLATE_FILEPATH)
    styled_template = ERB.new(raw_template).result(binding)
    File.open(STYLED_TEMPLATE_FILEPATH, 'w') do |f|
      f.write(styled_template)
    end
  end
end

.wrap_html(content) ⇒ Object



27
28
29
30
# File 'lib/ghpreview/wrapper.rb', line 27

def self.wrap_html(content)
  template = File.read(STYLED_TEMPLATE_FILEPATH)
  ERB.new(template).result(binding)
end