Class: Rack::DevMark::Theme::GithubForkRibbon

Inherits:
Base
  • Object
show all
Defined in:
lib/rack/dev-mark/theme/github_fork_ribbon.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Rack::DevMark::Theme::Base

Instance Method Details

#insert_into(html, env, params = {}) ⇒ Object



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
# File 'lib/rack/dev-mark/theme/github_fork_ribbon.rb', line 8

def insert_into(html, env, params = {})
  revision = params[:revision]
  timestamp = params[:timestamp]

  position = @options[:position] || 'left'
  color = @options[:color] || 'red'
  fixed = @options[:fixed] ? ' fixed' : ''
  title = []
  title << revision if revision.to_s != ''
  title << timestamp if timestamp.to_s != ''
  title = title.join("&#10;")

  style_tag_str = <<-EOS
#{stylesheet_link_tag "github-fork-ribbon-css/gh-fork-ribbon.css"}
<!--[if lt IE 9]>
#{stylesheet_link_tag "github-fork-ribbon-css/gh-fork-ribbon.ie.css"}
<![endif]-->
  EOS

  div_tag_str = <<-EOS
<div class="github-fork-ribbon-wrapper #{position}#{fixed}" onClick="this.style.display='none'" title="#{title}"><div class="github-fork-ribbon #{color}"><span class="github-fork-ribbon-text">#{env}</span></div></div>
  EOS

  html
    .sub(%r{(</head>)}i, "#{style_tag_str.strip}\\1")
    .sub(%r{(<body[^>]*>)}i, "\\1#{div_tag_str.strip}")
end