Class: Behaviors::ReportTask

Inherits:
TaskLib
  • Object
show all
Defined in:
lib/bloggit/tasks/specs.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :behaviors) {|_self| ... } ⇒ ReportTask

Returns a new instance of ReportTask.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
# File 'lib/bloggit/tasks/specs.rb', line 12

def initialize(name=:behaviors)
  @name = name
  @html_dir = 'doc'
  @src_dir = 'doc'
  yield self if block_given?
  define
end

Instance Attribute Details

#html_dirObject

Returns the value of attribute html_dir.



9
10
11
# File 'lib/bloggit/tasks/specs.rb', line 9

def html_dir
  @html_dir
end

#patternObject

Returns the value of attribute pattern.



8
9
10
# File 'lib/bloggit/tasks/specs.rb', line 8

def pattern
  @pattern
end

#src_dirObject

Returns the value of attribute src_dir.



10
11
12
# File 'lib/bloggit/tasks/specs.rb', line 10

def src_dir
  @src_dir
end

Instance Method Details

#defineObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bloggit/tasks/specs.rb', line 20

def define
    desc "List behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
    task @name do
      specifications.each do |spec|
        puts "#{spec.name} should:\n"
        spec.requirements.each do |req|
          puts " - #{req}"
        end
      end
    end

    desc "Generate html report of behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
    task "#{@name}_html" do
      require 'erb'
      txt =<<-EOS 
<html><head>
<style>
div.title { width: 600px; font: bold 14pt trebuchet ms; }
div.specification { font: bold 12pt trebuchet ms; border: solid 1px black; width: 600px; padding: 5px; margin: 5px; }
ul.requirements { font: normal 11pt verdana; padding-left: 0; margin-left: 0; border-bottom: 1px solid gray; width: 600px; }
ul.requirements li { list-style: none; margin: 0; padding: 0.25em; border-top: 1px solid gray; }
</style>
</head>
<body>
<div class="title">Specifications</div>
<% specifications.each do |spec| %>
<div class="specification">
<%= spec.name %> should: 
<ul class="requirements">
<% spec.requirements.each do |req| %>
<li><%= req %></li>
<% end %>
</ul>
</div>
<% end %>
</body>
</html>
      EOS
      output_dir = File.expand_path(@html_dir)
      mkdir_p output_dir
      output_filename = output_dir + "/behaviors.html"
      File.open(output_filename,"w") do |f|
        f.write ERB.new(txt).result(binding)
      end
      puts "(Wrote #{output_filename})"
    end
  
  task "#{@name}_src" do
    require 'erb'
    txt =<<-EOS 
<% specifications.each do |spec| %>
## <%= spec.name %> should: 

<% spec.requirements.each do |req| %>
* <%= req %><% end %>

<% end %>
    EOS
    output_dir = File.expand_path(@src_dir)
    mkdir_p output_dir
    output_filename = output_dir + "/specifications.markdown"
    File.open(output_filename,"w") do |f|
      f.write ERB.new(txt).result(binding)
    end
    puts "(Wrote #{output_filename})"
  end
end