Class: ConcordionCSSDecorator

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

Instance Method Summary collapse

Instance Method Details



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/concordion_css_decorator.rb', line 5

def add_concordion_css_link(root, html, type)
  if html.at("head").nil?
    root.search("html").prepend('<head></head>')
  end
  #TODO add an environment variable for this?
  if type == :link
    link_to_css(html)
  else
    inline_css(html)
  end
end

#add_css_file_to_output_dir(writer, type) ⇒ Object



37
38
39
40
41
# File 'lib/concordion_css_decorator.rb', line 37

def add_css_file_to_output_dir(writer, type)
  if !writer.output_file_exists?(css_filename) && type == :link
    writer.calculate_filename_and_overwrite(css, css_filename)
  end
end

#append_to_head(html, s) ⇒ Object



17
18
19
# File 'lib/concordion_css_decorator.rb', line 17

def append_to_head(html, s)
  html.search("head").append(s)
end

#cssObject



29
30
31
# File 'lib/concordion_css_decorator.rb', line 29

def css
  ConcordionCSS.css_string
end

#css_filenameObject



33
34
35
# File 'lib/concordion_css_decorator.rb', line 33

def css_filename
  ConcordionCSS.css_filename
end

#decorate_tag(rv, tag, cpr) ⇒ Object



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
# File 'lib/concordion_css_decorator.rb', line 43

def decorate_tag(rv, tag, cpr) 
  context = tag.to_html
  expected = tag.inner_html
  xpath = tag.xpath
  
  if rv[:result]
    tag[:class] = 'concordion_success'
    return nil
  end

  tag[:class] = 'concordion_failure'
  if cpr.is_verify_command?
    if rv[:actual] > rv[:expected]
      diff = rv[:actual] - rv[:expected]
      tag.inner_html += "<tr><td>[#{diff} Surplus Row(s) Returned By Fixture]</td></tr>"
    end
  else
    if cpr.is_assert_true_command?
      tag.inner_html += ": expected true but received #{rv[:actual]}"
    else
      tag.inner_html += " expected but received #{rv[:actual]}"
    end
  end
  #TODO refactor: move some of this logic into the conc parse result?
  ConcordionErrorCondition.new(expected, rv[:actual], xpath, context, cpr.is_assert_true_command?)
end

#inline_css(html) ⇒ Object



25
26
27
# File 'lib/concordion_css_decorator.rb', line 25

def inline_css(html)
  append_to_head(html, "<style type='text/css'>#{css}</style>")
end


20
21
22
# File 'lib/concordion_css_decorator.rb', line 20

def link_to_css(html)
  append_to_head(html, "<link rel='stylesheet' type='text/css' href='#{css_filename}' />")
end