Class: Dokkit::Environment::Basic
Instance Method Summary
collapse
Methods included from Helper
#configure, #extend_document, #select_data, #select_document
Methods inherited from Container
#[], #method_missing, #register
Constructor Details
#initialize {|_self| ... } ⇒ Basic
Returns a new instance of Basic.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/dokkit/environment/basic.rb', line 29
def initialize(&blk)
super
add_lib_to_load_path
init_extmap
init_services
yield self if block_given?
define_tasks
end
|
Instance Method Details
#add_lib_to_load_path ⇒ Object
Add lib folder to the load path.
139
140
141
|
# File 'lib/dokkit/environment/basic.rb', line 139
def add_lib_to_load_path
$: << 'lib'
end
|
#data_factory_block ⇒ Object
196
197
198
199
200
|
# File 'lib/dokkit/environment/basic.rb', line 196
def data_factory_block
lambda do |source_fn|
Resource::Data.new(source_fn, configuration.marshal_dump)
end
end
|
#default_configuration ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/dokkit/environment/basic.rb', line 159
def default_configuration
{
:document_dir => 'doc/pages',
:config_dir => 'doc/configs',
:layout_dir => 'doc/layouts',
:data_dir => 'doc/data',
:output_dir => 'output',
:cache_dir => '.cache',
:default_filter_chain => default_filter_chain,
:default_postfilter_chain => default_postfilter_chain
}
end
|
#default_filter_chain ⇒ Object
147
148
149
150
151
152
153
|
# File 'lib/dokkit/environment/basic.rb', line 147
def default_filter_chain
{
'deplate' => { 'html' => ['erb', 'deplate-html'], 'latex' => ['erb', 'deplate-latex'], 'text' => ['erb', 'deplate-text']},
'maruku' => { 'html' => ['erb', 'maruku-html'], 'latex' => ['erb', 'maruku-latex'] },
'haml' => { 'html' => ['haml'] },
}
end
|
#default_postfilter_chain ⇒ Object
155
156
157
|
# File 'lib/dokkit/environment/basic.rb', line 155
def default_postfilter_chain
{ 'html' => ['erb'], 'latex' => ['erb'], 'text' => ['erb'] }
end
|
#define_tasks ⇒ Object
41
42
43
44
|
# File 'lib/dokkit/environment/basic.rb', line 41
def define_tasks
render
clean
end
|
#document ⇒ Object
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/dokkit/environment/basic.rb', line 172
def document
register :document do
Resource::Document.new(source_fn, configuration.marshal_dump) do |document|
document.logger = logger
document.cache = cache
document.resource_factory = resource_factory
document.filter_factory = filter_factory
end
end
end
|
#document_factory_block ⇒ Object
Return a block that is able to construct a Document instance.
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/dokkit/environment/basic.rb', line 184
def document_factory_block
lambda do |source_fn|
Resource::Document.new(source_fn, configuration.marshal_dump) do |document|
document.logger = logger
document.cache = cache
document.resource_factory = resource_factory
document.filter_factory = filter_factory
document.extend @extmap[source_fn] if @extmap[source_fn]
end
end
end
|
#init_extmap ⇒ Object
143
144
145
|
# File 'lib/dokkit/environment/basic.rb', line 143
def init_extmap
@extmap = { }
end
|
#init_services ⇒ Object
46
47
48
|
# File 'lib/dokkit/environment/basic.rb', line 46
def init_services
methods.select { |meth| meth =~ /register_/ }.each { |meth| send(meth) }
end
|
#register_cache ⇒ Object
99
100
101
102
103
|
# File 'lib/dokkit/environment/basic.rb', line 99
def register_cache
register :cache do
Cache.new
end
end
|
#register_clean ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'lib/dokkit/environment/basic.rb', line 116
def register_clean
register :clean do
TaskLib::Clean.new do |task|
task.logger = logger
task.output_dir = configuration.output_dir
task.cache_dir = configuration.cache_dir
end
end
end
|
#register_configuration ⇒ Object
132
133
134
135
136
|
# File 'lib/dokkit/environment/basic.rb', line 132
def register_configuration
register :configuration do
OpenStruct.new(default_configuration)
end
end
|
#register_data_fs ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/dokkit/environment/basic.rb', line 59
def register_data_fs
register :data_fs do
Environment::Helper::FileSelection.new(configuration.data_dir) do |fs|
fs.include('**/*')
end
end
end
|
#register_document_fs ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/dokkit/environment/basic.rb', line 50
def register_document_fs
register :document_fs do
Environment::Helper::FileSelection.new(configuration.document_dir) do |fs|
fs.include('**/*')
fs.exclude('**/*.yaml')
end
end
end
|
#register_extmap ⇒ Object
67
68
69
70
71
|
# File 'lib/dokkit/environment/basic.rb', line 67
def register_extmap
register :extmap do
Helper::ExtMap.new(configuration.document_dir)
end
end
|
#register_filter_factory ⇒ Object
#register_logger ⇒ Object
126
127
128
129
130
|
# File 'lib/dokkit/environment/basic.rb', line 126
def register_logger
register :logger do
Logging::Observer::Console.logger
end
end
|
#register_render ⇒ Object
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/dokkit/environment/basic.rb', line 105
def register_render
register :render do
TaskLib::Render.new do |task|
task.logger = logger
task.resource_factory = resource_factory
task.document_fns = document_fs.files
task.data_fns = data_fs.files
end
end
end
|
#register_resource_factory ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/dokkit/environment/basic.rb', line 90
def register_resource_factory
register :resource_factory do
Factory.new do |factory|
factory.add(:document, &document_factory_block)
factory.add(:data, &data_factory_block)
end
end
end
|