Module: Cuporter::Formatter::HtmlMethods

Included in:
NameReport::Html, TagReport::Html
Defined in:
lib/cuporter/formatter/html_methods.rb

Instance Method Summary collapse

Instance Method Details

#body(html) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/cuporter/formatter/html_methods.rb', line 37

def body(html)
  html.body do |body|
    header(body)
    body.ul(:class => :main_list) do |ul|
      write_report_node(body)
    end
  end
end

#documentObject



9
10
11
12
13
14
15
16
# File 'lib/cuporter/formatter/html_methods.rb', line 9

def document
  builder = Builder::XmlMarkup.new
  builder.declare!(:DOCTYPE, :html,
                   :PUBLIC, "-//W3C//DTD XHTML 1.0 Transitional//EN",
                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  )
  builder
end

#head(html) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cuporter/formatter/html_methods.rb', line 25

def head(html)
  html.head do |head|
    head.title(title)
    head.style(inline_file("cuporter.css"))
    head.style(inline_file(inline_style))
    head.script(:type => "text/javascript") do
      head << inline_jquery  # jquery is corrupted if it isn't handled this way
      head << inline_js_content
    end
  end
end

#htmlObject



18
19
20
21
22
23
# File 'lib/cuporter/formatter/html_methods.rb', line 18

def html
  document.html(:xmlns => "http://www.w3.org/1999/xhtml") do |html|
    head(html)
    body(html)
  end.to_s.sub("<to_s/>",'')
end

#inline_file(file_name) ⇒ Object



52
53
54
# File 'lib/cuporter/formatter/html_methods.rb', line 52

def inline_file(file_name)
  File.read("#{File.dirname(__FILE__)}/#{file_name}")
end

#inline_jqueryObject



64
65
66
# File 'lib/cuporter/formatter/html_methods.rb', line 64

def inline_jquery
  inline_file('/jquery-min.js')
end

#inline_js_contentObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cuporter/formatter/html_methods.rb', line 68

def inline_js_content
  <<-EOF

  FEATURES = "li.feature .feature_name";
  TAGS = "li.tag .tag_name";
  
  $(document).ready(function() {
    $(FEATURES).css('cursor', 'pointer');
    $(FEATURES).click(function() {
$(this).siblings().toggle(250);
    });

    $(TAGS).css('cursor', 'pointer');
    $(TAGS).click(function() {
$(this).siblings().toggle(250);
    });

    $("#collapser").css('cursor', 'pointer');
    $("#collapser").click(function() {
$(TAGS).siblings().hide();
$(FEATURES).siblings().hide();
    });
    
    $("#expand_tags").css('cursor', 'pointer');
    $("#expand_tags").click(function() {
$(TAGS).siblings().show();
$(FEATURES).siblings().hide();
    });

    $("#expand_all").css('cursor', 'pointer');
    $("#expand_all").click(function() {
$(TAGS).siblings().show();
$(FEATURES).siblings().show();
    });

    $("#expand_features").css('cursor', 'pointer');
    $("#expand_features").click(function() {
$(FEATURES).siblings().show();
    });

    $("#collapse_features").css('cursor', 'pointer');
    $("#collapse_features").click(function() {
$(FEATURES).siblings().hide();
    });

    // load page with features collapsed
    $("#collapser, #collapse_features").click();
  })
  
  EOF
end

#label(header) ⇒ Object



46
47
48
49
50
# File 'lib/cuporter/formatter/html_methods.rb', line 46

def label(header)
  header.div(:id => :label) do |div|
    div.h1(title)
  end
end

#writeObject



60
61
62
# File 'lib/cuporter/formatter/html_methods.rb', line 60

def write
  @output.puts html
end

#write_report_node(body) ⇒ Object



56
57
58
# File 'lib/cuporter/formatter/html_methods.rb', line 56

def write_report_node(body)
  report_node_writer.new(@report, body).write_report_node
end