dokkit 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +135 -3
- data/Manifest.txt +9 -2
- data/README.txt +35 -17
- data/Rakefile +12 -8
- data/lib/dokkit.rb +1 -1
- data/lib/dokkit/cache/cache.rb +6 -1
- data/lib/dokkit/environment.rb +1 -0
- data/lib/dokkit/environment/basic.rb +148 -122
- data/lib/dokkit/environment/container.rb +35 -0
- data/lib/dokkit/environment/helpers.rb +43 -0
- data/lib/dokkit/environment/helpers/fileselection.rb +17 -6
- data/lib/dokkit/factory/factory.rb +4 -4
- data/lib/dokkit/filters.rb +1 -0
- data/lib/dokkit/filters/maruku.rb +9 -1
- data/lib/dokkit/filters/yaml.rb +26 -0
- data/lib/dokkit/logging.rb +1 -1
- data/lib/dokkit/resource/document.rb +141 -142
- data/lib/dokkit/resource/extensions/builtin.rb +2 -0
- data/lib/dokkit/resource/extensions/url.rb +1 -1
- data/lib/dokkit/resource/filenamehelper.rb +5 -1
- data/lib/dokkit/tasklib.rb +5 -0
- data/lib/dokkit/tasklib/base.rb +36 -0
- data/lib/dokkit/tasklib/clean.rb +12 -19
- data/lib/dokkit/tasklib/render.rb +20 -24
- data/lib/models/simple/setup/setup.rb +5 -3
- data/tasks/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +67 -30
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +30 -22
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/{doc.rake → rdoc.rake} +11 -9
- data/tasks/rubyforge.rake +12 -12
- data/tasks/setup.rb +189 -72
- data/tasks/spec.rake +24 -9
- data/tasks/svn.rake +15 -11
- data/tasks/test.rake +7 -9
- metadata +14 -7
- data/tasks/annotations.rake +0 -30
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# File 'container.rb' created on 15 ago 2008 at 15:16:11.
|
3
|
+
#
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for license information.
|
5
|
+
#
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
7
|
+
#
|
8
|
+
|
9
|
+
module Dokkit
|
10
|
+
module Environment
|
11
|
+
|
12
|
+
class Container
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@registry = { }
|
16
|
+
@instances = { }
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(meth)
|
20
|
+
self[meth]
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](service_name)
|
24
|
+
@instances[service_name] || (@instances[service_name] = @registry[service_name].call)
|
25
|
+
end
|
26
|
+
|
27
|
+
def register(service_name, &blk)
|
28
|
+
@instances[service_name] = nil
|
29
|
+
@registry[service_name] = blk
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
7
7
|
#
|
8
8
|
|
9
|
+
require 'ostruct'
|
9
10
|
require 'dokkit/environment/helpers/fileselection'
|
10
11
|
require 'dokkit/environment/helpers/extmap'
|
11
12
|
|
@@ -14,7 +15,49 @@ module Dokkit
|
|
14
15
|
# Collect helper class that simplify the setup of
|
15
16
|
# documentation environment.
|
16
17
|
module Helper
|
18
|
+
|
19
|
+
def configure(&blk)
|
20
|
+
|
21
|
+
yield ostruct = OpenStruct.new
|
22
|
+
|
23
|
+
register :configuration do
|
24
|
+
OpenStruct.new(default_configuration.merge(ostruct.marshal_dump))
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
17
28
|
|
29
|
+
def select_document(&blk)
|
30
|
+
|
31
|
+
yield new_fs = document_fs
|
32
|
+
|
33
|
+
register :document_fs do
|
34
|
+
FileSelection.new(configuration.document_dir) do |fs|
|
35
|
+
fs.include(*new_fs.includes)
|
36
|
+
fs.exclude(*new_fs.excludes)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def select_data(&blk)
|
43
|
+
|
44
|
+
yield new_fs = data_fs
|
45
|
+
|
46
|
+
register :data_fs do
|
47
|
+
FileSelection.new(configuration.data_dir) do |fs|
|
48
|
+
fs.include(*new_fs.includes)
|
49
|
+
fs.exclude(*new_fs.excludes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def extend_document(glob, extension)
|
56
|
+
FileSelection.new(configuration.document_dir).include(glob).files.each do |document_fn|
|
57
|
+
@extmap[document_fn] = extension
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
18
61
|
end
|
19
62
|
end
|
20
63
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# File 'fileselection.rb' created on 01 mag 2008 at 16:31:18.
|
3
3
|
#
|
4
|
-
# See 'dokkit.rb' or +LICENSE+ for
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for license information.
|
5
5
|
#
|
6
6
|
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
7
7
|
#
|
@@ -11,6 +11,7 @@ require 'rake'
|
|
11
11
|
module Dokkit
|
12
12
|
module Environment
|
13
13
|
module Helper
|
14
|
+
|
14
15
|
# FileSelection encapsulates the behaviour of Rake::FileList
|
15
16
|
# class. Objects of class FileSelection are capable to return
|
16
17
|
# the list of file in a directory. Objects are initialized with
|
@@ -18,8 +19,10 @@ module Dokkit
|
|
18
19
|
# FileSelection#include and FileSelection#exclude instance
|
19
20
|
# methods.
|
20
21
|
class FileSelection
|
21
|
-
|
22
|
+
|
23
|
+
attr_reader :base_dir, :includes, :excludes
|
22
24
|
alias :dir :base_dir
|
25
|
+
|
23
26
|
# Initialize a FileSelection object.
|
24
27
|
# base_dir :: the base dir for all inclusion/exclusion operations.
|
25
28
|
def initialize(base_dir = '.')
|
@@ -28,25 +31,33 @@ module Dokkit
|
|
28
31
|
@excludes = []
|
29
32
|
yield self if block_given?
|
30
33
|
end
|
34
|
+
|
31
35
|
# Include files to the list.
|
32
36
|
# patterns :: array of glob patterns
|
33
37
|
def include(*patterns)
|
38
|
+
@includes.clear
|
34
39
|
patterns.each { |pattern| @includes << pattern }
|
35
40
|
self
|
36
41
|
end
|
42
|
+
|
37
43
|
# Exclude files from the list.
|
38
44
|
# patterns :: array of glob patterns
|
39
45
|
def exclude(*patterns)
|
46
|
+
@excludes.clear
|
40
47
|
patterns.each { |pattern| @excludes << pattern }
|
41
48
|
self
|
42
49
|
end
|
50
|
+
|
43
51
|
# Return an array containing the file list.
|
44
52
|
def files
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
if File.exists?(@base_dir)
|
54
|
+
FileList.new(@base_dir) do |fl|
|
55
|
+
fl.exclude *@excludes.collect { |exclude| File.join(@base_dir, exclude) } unless @excludes.empty?
|
56
|
+
fl.include *@includes.collect { |include| File.join(@base_dir, include) } unless @includes.empty?
|
57
|
+
end.uniq.select { |fn| not File.directory?(fn) }
|
58
|
+
end
|
49
59
|
end
|
60
|
+
|
50
61
|
end
|
51
62
|
end
|
52
63
|
end
|
@@ -27,11 +27,11 @@ module Dokkit
|
|
27
27
|
#
|
28
28
|
# Example:
|
29
29
|
#
|
30
|
-
# factory.add(:bar
|
31
|
-
#
|
30
|
+
# factory.add(:bar) { Bar.new } # add a method that
|
31
|
+
# # instantiates Bar object
|
32
32
|
#
|
33
|
-
def add(factory_method)
|
34
|
-
@methods
|
33
|
+
def add(key, &factory_method)
|
34
|
+
@methods[key] = factory_method
|
35
35
|
end
|
36
36
|
|
37
37
|
# Construct an instance for the given class. Note that, if an
|
data/lib/dokkit/filters.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# File 'yaml.rb' created on 18 ago 2008 at 14:56:12.
|
3
|
+
#
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for license information.
|
5
|
+
#
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
module Dokkit
|
12
|
+
module Filter
|
13
|
+
class YAML
|
14
|
+
|
15
|
+
def initialize(document)
|
16
|
+
@document = document
|
17
|
+
end
|
18
|
+
|
19
|
+
def filter(text)
|
20
|
+
@document.configuration.recursive_merge! ::YAML::load(text)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/dokkit/logging.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
# (C) 2006, 2007, 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
7
7
|
#
|
8
8
|
|
9
|
+
require 'rubygems'
|
10
|
+
|
9
11
|
require 'yaml'
|
10
12
|
require 'erb'
|
11
13
|
require 'dokkit/hash'
|
@@ -18,140 +20,58 @@ module Dokkit
|
|
18
20
|
# instances are usually created on demand by
|
19
21
|
# Dokkit::Resource::Factory.
|
20
22
|
class Document
|
21
|
-
include FilenameHelper
|
22
|
-
|
23
|
-
|
24
|
-
include Extension::Builtin
|
23
|
+
include FilenameHelper, Extension::Builtin
|
24
|
+
|
25
|
+
attr_accessor :logger, :cache, :resource_factory, :filter_factory
|
25
26
|
|
26
|
-
attr_reader :source_fn
|
27
|
-
attr_reader :
|
28
|
-
attr_reader :
|
29
|
-
attr_reader :targets, :layouts, :deps
|
30
|
-
attr_reader :default_config_ext, :default_format, :default_formatter
|
31
|
-
attr_accessor :configuration, :default_configuration_value
|
27
|
+
attr_reader :source_fn, :env_configuration, :configuration
|
28
|
+
attr_reader :configs, :targets, :layouts, :deps
|
29
|
+
attr_reader :formatter, :format
|
32
30
|
|
33
31
|
# Initialize a Document instance.
|
34
32
|
# +source_fn+:: is the file name of the document source file.
|
35
33
|
# +configuration+:: is the configuration hash to be associated with the document.
|
36
34
|
# +logger+:: is the logger instance.
|
37
35
|
# +cache+:: is the cache manager instance.
|
38
|
-
def initialize(source_fn,
|
39
|
-
@source_fn
|
40
|
-
@
|
41
|
-
@targets = { }
|
42
|
-
@layouts = { }
|
43
|
-
@deps = { }
|
44
|
-
|
45
|
-
# Get basename stripping out path and extension from +source_fn+
|
46
|
-
@basename = File.basename(source_fn, File.extname(source_fn))
|
47
|
-
|
48
|
-
# Get the directory part of source_fn
|
49
|
-
@dirname = File.dirname(source_fn)
|
36
|
+
def initialize(source_fn, env_configuration, &blk)
|
37
|
+
@source_fn = source_fn
|
38
|
+
@env_configuration = env_configuration
|
50
39
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
40
|
+
reconfigure(&blk)
|
41
|
+
end
|
42
|
+
|
43
|
+
def config(config_fn)
|
44
|
+
reconfigure('config' => config_fn)
|
45
|
+
end
|
46
|
+
|
47
|
+
def layout(layout_fn)
|
48
|
+
reconfigure('layout' => layout_fn)
|
49
|
+
end
|
50
|
+
|
51
|
+
def reconfigure(configuration = { }, &blk)
|
52
|
+
init_default(configuration)
|
63
53
|
|
64
|
-
@default_configuration_value = 'not defined'
|
65
|
-
|
66
|
-
# yield self to an optional configuration block
|
67
54
|
yield self if block_given?
|
68
55
|
|
69
|
-
# Setup hashes
|
70
|
-
setup_header_configuration
|
71
|
-
@configuration = configuration.recursive_merge('layout' => @relativename)
|
72
|
-
setup_targets(@default_format)
|
73
|
-
|
74
|
-
# Configure the document
|
75
56
|
configure
|
76
|
-
|
77
|
-
@formatter = @configuration['formatter'] || @default_formatter
|
78
|
-
|
79
|
-
collect_all
|
80
57
|
end
|
81
58
|
|
82
|
-
def method_missing(meth)
|
83
|
-
if @configuration.has_key?(meth.to_s)
|
84
|
-
@configuration[meth.to_s]
|
85
|
-
else
|
86
|
-
@logger.warn("Configuration key '#{meth.to_s}' is not defined for #{source_fn}.")
|
87
|
-
@default_configuration_value
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
59
|
def get_binding
|
92
60
|
binding
|
93
61
|
end
|
94
62
|
|
95
|
-
# Read the configuration file +fn+ and return:
|
96
|
-
# * the resulting configuration hash
|
97
|
-
# * an array containing the names of the read config files
|
98
|
-
# If +fn+ contains configuration data in the
|
99
|
-
# header then this method extract it. Note that the method read
|
100
|
-
# *recursively* the configuration file specified in config key
|
101
|
-
# loading it from config_dir folder.
|
102
|
-
# For example:
|
103
|
-
#
|
104
|
-
# ---
|
105
|
-
# key: value
|
106
|
-
# config: required
|
107
|
-
#
|
108
|
-
#
|
109
|
-
# The resulting configuration hash will be the key/value pair
|
110
|
-
# *plus* the configuration in +config_dir/required.yaml+.
|
111
|
-
def add_config(fn)
|
112
|
-
File.exists?(fn) ? merge_configuration_file(fn) : @logger.error("Configuration file '#{fn}' not found for '#{@source_fn}'!")
|
113
|
-
end
|
114
|
-
|
115
|
-
def add_layout(name, format = @default_format)
|
116
|
-
if File.exists?(get_layout_filename(name, format))
|
117
|
-
@layouts[format] << get_layout_filename(name, format)
|
118
|
-
else
|
119
|
-
@logger.warn("Layout file '#{get_layout_filename(name, format)}' does not exists for '#{source_fn}'!")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def default_filter_chain_for(formatter, format)
|
124
|
-
if @configuration[:default_filter_chain][formatter].has_key?(format)
|
125
|
-
@configuration[:default_filter_chain][formatter][format]
|
126
|
-
else
|
127
|
-
@logger.error("Output format '#{format}' is not available for '#{formatter}' formatter.")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def default_postfilter_chain_for(format)
|
132
|
-
@configuration[:default_postfilter_chain][format]
|
133
|
-
end
|
134
|
-
|
135
63
|
def has_format?(format)
|
136
64
|
@targets.has_key?(format)
|
137
65
|
end
|
138
66
|
|
139
67
|
# Return the filters chain associated with the given formatter and output format.
|
140
|
-
def filters_for(
|
141
|
-
|
142
|
-
process_filter_key('filter', format, default_filter_chain_for(formatter, format))
|
143
|
-
else
|
144
|
-
default_filter_chain_for(formatter, format)
|
145
|
-
end
|
68
|
+
def filters_for(format, formatter = @formatter)
|
69
|
+
process_filter_key('filter', format) || default_filter_chain_for(formatter, format)
|
146
70
|
end
|
147
71
|
|
148
72
|
# Return the post filters chain associated with the given format.
|
149
73
|
def post_filters_for(format)
|
150
|
-
|
151
|
-
process_filter_key('postfilter', format, default_postfilter_chain_for(format))
|
152
|
-
else
|
153
|
-
default_postfilter_chain_for(format)
|
154
|
-
end
|
74
|
+
process_filter_key('postfilter', format) || default_postfilter_chain_for(format)
|
155
75
|
end
|
156
76
|
|
157
77
|
def target_for(format)
|
@@ -162,32 +82,104 @@ module Dokkit
|
|
162
82
|
@deps[format]
|
163
83
|
end
|
164
84
|
|
165
|
-
def
|
85
|
+
def format
|
166
86
|
@current_format || @default_format
|
167
87
|
end
|
168
|
-
|
88
|
+
|
89
|
+
def render?
|
90
|
+
if @configuration.has_key?('render')
|
91
|
+
return false unless @configuration['render']
|
92
|
+
end
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
169
96
|
# Render the document in the specified format.
|
170
97
|
def render(args = { })
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
document.render(:format => args[:format])
|
98
|
+
if args[:format].nil?
|
99
|
+
unless @current_format
|
100
|
+
args = { :format => @default_format }.merge args
|
101
|
+
@current_format = args[:format]
|
102
|
+
end
|
177
103
|
else
|
178
|
-
|
104
|
+
@current_format = args[:format]
|
179
105
|
end
|
106
|
+
args.has_key?(:partial) ? render_partial(args[:partial], @current_format) : do_render!(@formatter, @current_format)
|
180
107
|
end
|
181
108
|
|
182
109
|
# Return the content of the source document file.
|
183
110
|
def source
|
184
111
|
@source ||= read_source
|
185
112
|
end
|
186
|
-
|
113
|
+
|
187
114
|
private
|
188
115
|
|
189
|
-
def
|
190
|
-
@
|
116
|
+
def method_missing(meth)
|
117
|
+
if @configuration.has_key?(meth.to_s)
|
118
|
+
@configuration[meth.to_s]
|
119
|
+
else
|
120
|
+
@logger.warn("Configuration key '#{meth.to_s}' is not defined for #{source_fn}.")
|
121
|
+
@default_configuration_value
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def init_default(configuration)
|
126
|
+
@configs = []
|
127
|
+
@targets = { }
|
128
|
+
@layouts = { }
|
129
|
+
@deps = { }
|
130
|
+
|
131
|
+
@default_config_ext = '.yaml'
|
132
|
+
@default_format = 'html'
|
133
|
+
@default_formatter = 'deplate'
|
134
|
+
@default_configuration_value = 'not defined'
|
135
|
+
@configuration = { 'layout' => relative_name }.merge configuration
|
136
|
+
@configuration['render'] = false if basename =~ /^_/
|
137
|
+
end
|
138
|
+
|
139
|
+
# Get basename stripping out path and extension from +source_fn+
|
140
|
+
def basename
|
141
|
+
File.basename(source_fn, File.extname(source_fn))
|
142
|
+
end
|
143
|
+
|
144
|
+
# Get the directory part of source_fn
|
145
|
+
def dirname
|
146
|
+
File.dirname(source_fn)
|
147
|
+
end
|
148
|
+
|
149
|
+
def name_noext
|
150
|
+
File.join(dirname, basename)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Get name relative to configuration.document_dir
|
154
|
+
def relative_name
|
155
|
+
filename_helper(name_noext, @env_configuration[:document_dir], '')
|
156
|
+
end
|
157
|
+
|
158
|
+
def add_config(fn)
|
159
|
+
File.exists?(fn) ? merge_configuration_file(fn) : @logger.error("Configuration file '#{fn}' not found for '#{@source_fn}'!")
|
160
|
+
end
|
161
|
+
|
162
|
+
def add_layout(name, format = @default_format)
|
163
|
+
if File.exists?(get_layout_filename(name, format))
|
164
|
+
@layouts[format] << get_layout_filename(name, format)
|
165
|
+
else
|
166
|
+
@logger.debug("Layout file '#{get_layout_filename(name, format)}' does not exist for '#{source_fn}'.")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def default_filter_chain_for(formatter, format)
|
171
|
+
@env_configuration[:default_filter_chain][formatter][format]
|
172
|
+
end
|
173
|
+
|
174
|
+
def default_postfilter_chain_for(format)
|
175
|
+
@env_configuration[:default_postfilter_chain][format]
|
176
|
+
end
|
177
|
+
|
178
|
+
# @logger.error("Output format '#{format}' is not available for '#{formatter}' formatter.")
|
179
|
+
# @logger.error("Formatter '#{formatter}' is not available.")
|
180
|
+
|
181
|
+
def process_filter_key(key, format)
|
182
|
+
@targets.has_key?(format) ? @targets[format][key] : nil
|
191
183
|
end
|
192
184
|
|
193
185
|
# Read the content of the source document file from disk.
|
@@ -200,7 +192,7 @@ module Dokkit
|
|
200
192
|
end
|
201
193
|
|
202
194
|
def load_config_file(fn)
|
203
|
-
config_fn = File.join(@
|
195
|
+
config_fn = File.join(@env_configuration[:config_dir], fn)
|
204
196
|
config_fn += @default_config_ext if File.extname(config_fn).empty?
|
205
197
|
@configuration.delete('config')
|
206
198
|
add_config(config_fn)
|
@@ -208,7 +200,7 @@ module Dokkit
|
|
208
200
|
|
209
201
|
def merge_configuration_file(fn)
|
210
202
|
fn == @source_fn ? @configuration.recursive_merge!(@header_configuration) : @configuration.recursive_merge!(YAML::load_file(fn))
|
211
|
-
@
|
203
|
+
@configs << fn
|
212
204
|
process_config_configuration_key if @configuration.has_key?('config')
|
213
205
|
end
|
214
206
|
|
@@ -223,24 +215,27 @@ module Dokkit
|
|
223
215
|
|
224
216
|
# Render document in the given format.
|
225
217
|
def do_render!(formatter, format)
|
226
|
-
|
227
|
-
|
228
|
-
render_all_layouts!(format)
|
229
|
-
else
|
230
|
-
@logger.error("Don't know how to render '#{source_fn}': format '#{format}' is unknown.")
|
231
|
-
end
|
218
|
+
render_source!(formatter, format)
|
219
|
+
render_all_layouts!(format)
|
232
220
|
@content_for_layout
|
233
221
|
end
|
234
222
|
|
235
223
|
# Produce output from source.
|
236
224
|
def render_source!(formatter, format)
|
237
|
-
@content_for_layout = apply_filters(@source, filters_for(
|
225
|
+
@content_for_layout = apply_filters(@source, filters_for(format, formatter), format) unless @source.nil?
|
238
226
|
end
|
239
227
|
|
240
228
|
def render_layout!(layout_fn, format)
|
241
229
|
@content_for_layout = apply_filters(File.read(layout_fn), post_filters_for(format), format) unless File.read(layout_fn).nil?
|
242
230
|
end
|
243
231
|
|
232
|
+
def render_partial(source_fn, format)
|
233
|
+
basename, dirname = '_' + File.basename(source_fn), File.dirname(source_fn)
|
234
|
+
partial_fn = File.join(@env_configuration[:document_dir], File.join(dirname, basename))
|
235
|
+
@cache.add_dependency(@source_fn, format, partial_fn)
|
236
|
+
@resource_factory.get(:document, partial_fn).render(:format => format)
|
237
|
+
end
|
238
|
+
|
244
239
|
# Injects rendered content from +source_fn+ in the layout chain.
|
245
240
|
def render_all_layouts!(format)
|
246
241
|
@layouts[format].each { |layout_fn| render_layout!(layout_fn, format) } unless !@layouts[format] || @layouts[format].empty?
|
@@ -260,10 +255,18 @@ module Dokkit
|
|
260
255
|
# 3. configuration in COMMON.yaml file (or files) exist.
|
261
256
|
# 4. configuration in doc/configs/+basename+.yaml if file exists.
|
262
257
|
def configure # :doc:
|
258
|
+
setup_header_configuration
|
259
|
+
setup_targets(@default_format)
|
260
|
+
|
263
261
|
add_config(config_fn_relative_to(:config_dir)) if File.exists?(config_fn_relative_to(:config_dir))
|
264
262
|
add_common_config
|
265
263
|
add_config(config_fn_relative_to(:document_dir)) if File.exists?(config_fn_relative_to(:document_dir))
|
266
264
|
add_config(@source_fn) if @header_configuration
|
265
|
+
|
266
|
+
@formatter = @configuration['formatter'] || @default_formatter
|
267
|
+
|
268
|
+
collect_all
|
269
|
+
@configuration
|
267
270
|
end
|
268
271
|
|
269
272
|
# Collect the layout files traversing +targets+ hash.
|
@@ -284,7 +287,7 @@ module Dokkit
|
|
284
287
|
end
|
285
288
|
|
286
289
|
def get_layout_filename(name, format)
|
287
|
-
File.join(@
|
290
|
+
File.join(@env_configuration[:layout_dir], name + ".#{format.to_s}")
|
288
291
|
end
|
289
292
|
|
290
293
|
# Process +format+ key in configuration hash.
|
@@ -300,14 +303,10 @@ module Dokkit
|
|
300
303
|
def process_format_configuration_key(format)
|
301
304
|
format_key = format.keys.first
|
302
305
|
opts = format.values.first
|
303
|
-
if opts
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
{ :target_fn => target_fn(ext.to_sym), 'filter' => filters, 'postfilter' => post_filters }
|
308
|
-
else
|
309
|
-
@logger.error("You must define format '#{format}'!")
|
310
|
-
end
|
306
|
+
ext = (opts['ext'] if opts.has_key?('ext')) || format_key
|
307
|
+
filters = (opts['filter'] if opts.has_key?('filter')) || default_filter_chain_for(@formatter, 'html')
|
308
|
+
post_filters = (opts['postfilter'] if opts.has_key?('postfilter')) || default_postfilter_chain_for('html')
|
309
|
+
{ :target_fn => target_fn(ext.to_sym), 'filter' => filters, 'postfilter' => post_filters }
|
311
310
|
end
|
312
311
|
|
313
312
|
# Iterates through configuration +:targets+ key (if
|
@@ -321,7 +320,7 @@ module Dokkit
|
|
321
320
|
@targets.each do |format, target|
|
322
321
|
@deps[format] = []
|
323
322
|
@deps[format] << @source_fn # the essential dependency from source file
|
324
|
-
@deps[format].concat @
|
323
|
+
@deps[format].concat @configs # dependency from configuration files
|
325
324
|
@deps[format].concat @layouts[format] if @layouts.has_key?(format) # dependency from layout files
|
326
325
|
@deps[format].concat @cache.deps[source_fn][format] if @cache.deps[source_fn] and @cache.deps[source_fn][format]
|
327
326
|
@deps[format].uniq! # remove duplicates
|
@@ -340,7 +339,7 @@ module Dokkit
|
|
340
339
|
|
341
340
|
# Configure from commons configuration files.
|
342
341
|
def add_common_config
|
343
|
-
resolve_common_configs(
|
342
|
+
resolve_common_configs(dirname).reverse.each do |file|
|
344
343
|
add_config(file)
|
345
344
|
end
|
346
345
|
end
|
@@ -362,7 +361,7 @@ module Dokkit
|
|
362
361
|
# config_fn #=> 'doc/configs/subdir/document.yaml'
|
363
362
|
#
|
364
363
|
def config_fn_relative_to(dir_config_key)
|
365
|
-
filename_helper(
|
364
|
+
filename_helper(name_noext, @env_configuration[:document_dir], @env_configuration[dir_config_key], @default_config_ext)
|
366
365
|
end
|
367
366
|
|
368
367
|
# Return target filename for a given format.
|
@@ -370,11 +369,11 @@ module Dokkit
|
|
370
369
|
# Example:
|
371
370
|
#
|
372
371
|
# source_fn = 'doc/pages/document.ext'
|
373
|
-
# format =
|
372
|
+
# format = 'html'
|
374
373
|
# target_fn(format) #=> 'output/document.html'
|
375
374
|
#
|
376
375
|
def target_fn(format)
|
377
|
-
filename_helper(
|
376
|
+
filename_helper(name_noext, @env_configuration[:document_dir], @env_configuration[:output_dir], ".#{format.to_s}")
|
378
377
|
end
|
379
378
|
|
380
379
|
# Apply filters on text to produce the given format.
|