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 ="<html><head>\n<style>\ndiv.title { width: 600px; font: bold 14pt trebuchet ms; }\ndiv.specification { font: bold 12pt trebuchet ms; border: solid 1px black; width: 600px; padding: 5px; margin: 5px; }\nul.requirements { font: normal 11pt verdana; padding-left: 0; margin-left: 0; border-bottom: 1px solid gray; width: 600px; }\nul.requirements li { list-style: none; margin: 0; padding: 0.25em; border-top: 1px solid gray; }\n</style>\n</head>\n<body>\n<div class=\"title\">Specifications</div>\n<% specifications.each do |spec| %>\n<div class=\"specification\">\n<%= spec.name %> should:\n<ul class=\"requirements\">\n<% spec.requirements.each do |req| %>\n<li><%= req %></li>\n<% end %>\n</ul>\n</div>\n<% end %>\n</body>\n</html>\n" 
      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 ="<% specifications.each do |spec| %>\n## <%= spec.name %> should:\n\n<% spec.requirements.each do |req| %>\n* <%= req %><% end %>\n\n<% end %>\n" 
    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