Class: Doc::Configurator::Ruby

Inherits:
Doc::Configurator show all
Includes:
Source, Stdlib
Defined in:
lib/doc/configurator/ruby.rb,
lib/doc/configurator/ruby/source.rb,
lib/doc/configurator/ruby/stdlib.rb,
lib/doc/configurator/ruby/path_info.rb,
lib/doc/configurator/ruby/version_specifier.rb

Defined Under Namespace

Modules: Source, Stdlib Classes: PathInfo, VersionSpecifier

Constant Summary

Constants included from Stdlib

Stdlib::STDLIB_CONFIG_NAME, Stdlib::STDLIB_CONFIG_URL, Stdlib::STDLIB_CONFIG_VENDOR_PATH

Instance Attribute Summary

Attributes inherited from Doc::Configurator

#config, #documentor

Instance Method Summary collapse

Methods included from Source

#by_binary, #by_version, #from_archive, #from_dir

Methods included from Stdlib

#download_stdlib_config, #read_stdlib_config, #stdlib_config, #stdlib_config_path

Methods inherited from Doc::Configurator

default_config_key, inherited, #initialize

Constructor Details

This class inherits a constructor from Doc::Configurator

Instance Method Details

#avaliable_formatsObject



42
43
44
# File 'lib/doc/configurator/ruby.rb', line 42

def avaliable_formats
  @avaliable_formats ||= methods.map{ |m| m[/^tasks_(.*)$/, 1] }.compact.map(&:to_sym)
end

#configure(update) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/doc/configurator/ruby.rb', line 9

def configure(update)
  config.check_options!([], [[:source, :archive, :version, :binary], :format, :except, :index])

  @source_dirs = case
  when config[:source]
    Array(config[:source]).map{ |source| from_dir(source) }
  when config[:archive]
    Array(config[:archive]).map{ |archive| from_archive(archive) }
  when config[:version]
    Array(config[:version]).map{ |version| by_version(version, update) }
  else
    Array(config[:binary] || [nil]).map{ |binary| by_binary(binary, update) }
  end

  @format = (config[:format] || :all).to_sym
  unless avaliable_formats.include?(@format)
    raise "format can be one of: #{avaliable_formats.join(', ')}"
  end
  if [:separate, :integrate].include?(@format)
    @stdlib_config = stdlib_config(update) or raise 'can\'t get stdlib config'
    stdlib_config_path.touch
  end

  @except_regexp = /^(?:lib|ext)\/(?:#{Array(config[:except]).map(&Regexp.method(:escape)).join('|')})(?:.rb$|\/)/

  if config[:index]
    @index = FSPath(config[:index])
    unless @index.directory? && (@index / 'index.html').file?
      raise 'index should be a path to directory with index.html inside'
    end
  end
end

#tasksObject



46
47
48
49
50
51
52
53
# File 'lib/doc/configurator/ruby.rb', line 46

def tasks
  @source_dirs.map do |source_dir|
    source_dir.touch
    Dir.chdir(source_dir) do
      send("tasks_#@format", source_dir)
    end
  end
end

#tasks_all(source_dir) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/doc/configurator/ruby.rb', line 55

def tasks_all(source_dir)
  file_list = FileList.new
  file_list.include(*%w[NEWS LEGAL COPYING GPL LGPL])
  file_list.include("*.#{PARSABLE_EXTENSIONS_GLOB}")
  file_list.include("{lib,ext}/**/*.#{PARSABLE_EXTENSIONS_GLOB}")
  file_list.exclude @except_regexp

  builder({
    :title => source_dir.basename.to_s,
    :source_dir => source_dir,
    :dir_name => source_dir.basename.to_s,
    :paths => file_list,
    :index => @index,
  })
end

#tasks_integrate(source_dir) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/doc/configurator/ruby.rb', line 116

def tasks_integrate(source_dir)
  file_list = FileList.new
  file_list.add(core_paths)
  @stdlib_config['targets'].each do |target|
    file_list.add(stdlib_paths_for_target(target['target']))
  end
  file_list.exclude @except_regexp
  builder({
    :title => "#{source_dir.basename} +stdlib",
    :source_dir => source_dir,
    :dir_name => "#{source_dir.basename}_with_stdlib",
    :paths => file_list,
    :index => @index,
  })
end

#tasks_separate(source_dir) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/doc/configurator/ruby.rb', line 71

def tasks_separate(source_dir)
  tasks = []

  core_paths_a = core_paths.to_a

  file_list = FileList.new
  file_list.add(*core_paths_a)
  file_list.exclude @except_regexp

  tasks << builder({
    :title => "#{source_dir.basename} core",
    :source_dir => source_dir,
    :dir_name => "#{source_dir.basename}_core",
    :paths => file_list,
    :index => @index,
  })

  stdlib_tasks = []
  @stdlib_config['targets'].each do |target|
    name = target['target']
    file_list = FileList.new
    file_list.add(*stdlib_paths_for_target(name) - core_paths_a)
    file_list.exclude @except_regexp

    unless file_list.empty?
      stdlib_tasks << builder({
        :title => name,
        :source_dir => source_dir,
        :dir_name => "#{source_dir.basename}_#{name.gsub(/[^a-z0-9\-_]/i, '-')}",
        :paths => file_list,
        :main => target['mainpage'],
        :no_auto_add_paths => true,
      })
    end
  end

  tasks << merger({
    :title => "#{source_dir.basename} stdlib",
    :dir_name => "#{source_dir.basename}_stdlib",
    :tasks => stdlib_tasks
  })

  tasks
end