Class: Codex::Rake::CodexTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/codex/rake/codextask.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :codex) {|_self| ... } ⇒ CodexTask

Returns a new instance of CodexTask.

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
23
24
25
26
# File 'lib/codex/rake/codextask.rb', line 19

def initialize(name = :codex)
  @name = name
  @content_dir = 'content'
  @output_dir = 'html'
  @metadata = "config/metadata.yml"
  yield self if block_given?
  define
end

Instance Attribute Details

#content_dirObject

Directory of the source content. Defaults to ‘content’



11
12
13
# File 'lib/codex/rake/codextask.rb', line 11

def content_dir
  @content_dir
end

#metadataObject

Metadata filename. Defaults to config/metadata.yml



17
18
19
# File 'lib/codex/rake/codextask.rb', line 17

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/codex/rake/codextask.rb', line 8

def name
  @name
end

#output_dirObject

Directory to output the built files into. Defaults to ‘html’



14
15
16
# File 'lib/codex/rake/codextask.rb', line 14

def output_dir
  @output_dir
end

Instance Method Details

#content_pathObject



28
29
30
# File 'lib/codex/rake/codextask.rb', line 28

def content_path
  File.join(*[Codex.root, content_dir].compact)
end

#contentsObject



36
37
38
39
40
41
42
# File 'lib/codex/rake/codextask.rb', line 36

def contents
  Dir.chdir(content_path) do
    filelist = FileList["*"]
    filelist.resolve
    filelist
  end
end

#defineObject



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
87
88
89
# File 'lib/codex/rake/codextask.rb', line 44

def define
  @output = []
  pressie = Codex::Pressie.new()
  
  contents.each do |file|
    input_file = File.join(content_dir, file)
    output_file = File.join(output_dir, file.ext('.html'))
    @output << output_file
    desc "Build #{output_file} from #{input_file}"
    file output_file => [output_dir, input_file] do
      pressie.process(input_file, output_file)
    end
  end

  task :default => name
  
  desc "Build all the content"
  task name => @output
  
  # FIXME: clean up all this
  all_html   = File.join(output_dir, "all.html")

  task :remove_tmp do
    FileUtils.rm_rf("tmp")
  end
  
  desc "Build all based on the contents of content/table_of_contents.textile"
  task :all => [ 'tmp', output_dir, all_html, :remove_tmp ]

  desc "Remove all generated output and temporary files"
  task :clean => "remove_tmp" do
    FileUtils.rm_rf output_path
  end
  
  task all_html => 'tmp/all.textile' do
    pressie.process('tmp/all.textile', all_html)
  end

  task 'tmp/all.textile' => @output do
    sh "ruby bin/build_all.rb #{} #{content_dir}/table_of_contents.textile tmp/all.textile"
  end

  directory "tmp"

  directory output_dir
end

#output_pathObject



32
33
34
# File 'lib/codex/rake/codextask.rb', line 32

def output_path
  File.join(*[Codex.root, output_dir].compact)
end