Class: ASDocPackage

Inherits:
Tool
  • Object
show all
Defined in:
lib/shed/asdoc_package.rb

Overview

Reads ‘.asdoc’ files from a specified source tree and concatencates them into a xml configuration file that can be used to generate ActionScript documentation for the Actionscript packages.

Constant Summary

Constants inherited from Tool

Tool::INVALID_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

#add_sigint_handler, #generated_at, #log, #puts, #to_disk, #valid_opts

Constructor Details

#initialize(opt, out = STDOUT) ⇒ ASDocPackage

Returns a new instance of ASDocPackage.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shed/asdoc_package.rb', line 11

def initialize(opt,out=STDOUT)
  super(opt,out)

  @asdoc = /\.asdoc$/

  @header = "<?xml version='1.0' encoding='utf-8'?>\n<flex-config>\n\t<packages>\n"
  @package = "\t\t<package>\n\t\t\t<string>%s</string>\n\t\t\t<string><![CDATA[%s]]></string>\n\t\t</package>\n"
  @footer = "\t</packages>\n</flex-config>"

  build
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



9
10
11
# File 'lib/shed/asdoc_package.rb', line 9

def xml
  @xml
end

Instance Method Details

#buildObject

Build the flex compiler config file that can be passed to the asdoc tool.



43
44
45
46
47
48
49
50
51
52
# File 'lib/shed/asdoc_package.rb', line 43

def build
  asdocs = scan(@src)

  if asdocs.empty?
    puts "No .asdoc files found."
  else
    create_xml(asdocs)
    to_disk(xml)
  end
end

#create_xml(asdocs) ⇒ Object

Constructs the flex complier config file when given a list of paths to asdoc files.



58
59
60
61
62
63
# File 'lib/shed/asdoc_package.rb', line 58

def create_xml(asdocs)
  @xml = @header
  asdocs.each { |asdoc| @xml << sprintf(@package, asdoc[:package], IO.read(asdoc[:path])) }
  @xml << @footer
  @xml
end

#scan(dir) ⇒ Object

Scan the given path and it’s child directories for all .asdoc files.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shed/asdoc_package.rb', line 26

def scan(dir)
  puts "Scanning '#{dir}' for asdoc files..."

  found = []

  Search.find_all(@asdoc,dir,@excludes) do |path|
    found << {:path => path, :package => ProjectTools.package(path)}
  end

  found.each { |file| log("Adding #{file[:path]}") }

  found
end