Class: JSWebBuilder::BuildTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/js_web_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :js_build) {|_self| ... } ⇒ BuildTask

Create a testing task.

Yields:

  • (_self)

Yield Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/js_web_builder.rb', line 28

def initialize(name=:js_build)
    @name = name
    @description = "Building/Concatenating the JS files"
    @pattern = '*.js'
    @deps = []
    @outdir = "."
    @inputdirs = []

    # don't look here!
    @file_list = []

    yield self if block_given?
    define
end

Instance Attribute Details

#depsObject

Task prerequisites.



19
20
21
# File 'lib/js_web_builder.rb', line 19

def deps
  @deps
end

#descriptionObject

Description of the build task. (default is ‘Building/Concatenating the JS files’)



13
14
15
# File 'lib/js_web_builder.rb', line 13

def description
  @description
end

#inputdirsObject

The input directories, can be a single string or an array



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

def inputdirs
  @inputdirs
end

#nameObject

Name of build task. (default is :js_build)



10
11
12
# File 'lib/js_web_builder.rb', line 10

def name
  @name
end

#outdirObject

The output directory (default is ‘.’)



22
23
24
# File 'lib/js_web_builder.rb', line 22

def outdir
  @outdir
end

#patternObject

Glob pattern to match input files. (default is ‘*.js’)



16
17
18
# File 'lib/js_web_builder.rb', line 16

def pattern
  @pattern
end

Instance Method Details

#defineObject

Create the tasks defined by this task lib.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/js_web_builder.rb', line 44

def define 
    desc @description
    task @name => Array(deps) do
        unless Dir.exist?(@outdir)
            Dir.mkdir(@outdir)
        end
        make_file_list
        @file_list.each do |target|
            js = target.execute
            target_file = File.join(@outdir,File.basename(target.file))
            File.open(target_file, 'w') { |f| f.write(js) }
        end
    end

    self
end

#make_file_listObject

define



61
62
63
64
65
66
67
# File 'lib/js_web_builder.rb', line 61

def make_file_list # :nodoc:
    @inputdirs.each do |dir|
        Rake::FileList[File.join(dir,@pattern)].each do |file|
            @file_list << TargetFile.new(:file => file)
        end
    end
end