Class: Nova::Task::Compile

Inherits:
Nova::Task show all
Defined in:
lib/cocoanova/tasks/compile.rb

Constant Summary

Constants inherited from Nova::Task

Tasks

Instance Method Summary collapse

Methods inherited from Nova::Task

[], []=, invoke, require_all, task

Instance Method Details

#invoke(params = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoanova/tasks/compile.rb', line 22

def invoke(params = {})
    raise "Nova.local_root not set" unless Nova.local_root
    raise "Nova.src_root not set"   unless Nova.src_root

    Nova::Helper.require_all
    Nova::Loader.require_all
    Nova::Engine.require_all

    self.load_data

    # Find all *.erb and render from yml file
    Dir["#{Nova.src_root}/**/*"].each do |file|
        extname = file.split('.').last.to_sym
        if Nova::Engine.supported_extensions.include? extname
            template= File.open(file).read
            target  = File.join File.dirname(file), File.basename(file, ".*")
            puts "File Rendering: #{target}"
            result  = Nova::Engine[extname].new.render(template, Nova.data, target)
            File.open(target, 'w') { |tf| tf.write(result) }
        end
    end

    puts "Done !"
end

#load_dataObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cocoanova/tasks/compile.rb', line 4

def load_data
    # Load regular data
    Dir["#{Nova.local_root}/data/*"].each do |file|
        key     = File.basename(file).split('.').first.downcase.to_sym
        extname = file.split('.').last.to_sym
        if Nova::Loader.supported_extensions.include?(extname)
            content = File.open(file).read
            Nova.data[key] = Nova::Loader[extname].new.load(content)
        else
            raise "Data file extension '#{extname}' not supported"
        end
    end
    # Load phony data
    Nova::Loader::Phony.each_pair do |key, clazz|
        Nova.data[key] = clazz.new.load(key)
    end
end