dokkit 0.3.0 → 0.4.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 +5 -0
- data/Manifest.txt +90 -105
- data/README.txt +27 -7
- data/Rakefile +2 -3
- data/bin/dokkit +3 -2
- data/lib/dokkit/application.rb +159 -0
- data/lib/dokkit/cache/cache.rb +53 -0
- data/lib/dokkit/{models/simpledocument/model/Rakefile → cache.rb} +3 -15
- data/lib/dokkit/environment/basic.rb +156 -0
- data/lib/dokkit/environment/helpers/extmap.rb +29 -0
- data/lib/dokkit/environment/helpers/fileselection.rb +53 -0
- data/lib/dokkit/environment/helpers.rb +20 -0
- data/{spec/data/test_build/Rakefile → lib/dokkit/environment.rb} +4 -15
- data/lib/dokkit/factory/factory.rb +56 -0
- data/lib/dokkit/factory.rb +9 -0
- data/lib/dokkit/filters/deplate.rb +25 -20
- data/lib/dokkit/filters/maruku.rb +6 -5
- data/lib/dokkit/filters/nil.rb +7 -6
- data/lib/dokkit/filters.rb +5 -27
- data/lib/dokkit/hash.rb +82 -0
- data/lib/dokkit/{logger.rb → logging/logger.rb} +30 -24
- data/lib/dokkit/logging/observers/console.rb +52 -0
- data/lib/dokkit/{extension/extension.rb → logging/observers.rb} +7 -5
- data/lib/dokkit/logging.rb +11 -0
- data/lib/dokkit/models/simple/Rakefile +6 -0
- data/lib/dokkit/models/simple/doc/data/html/css/style.css +3 -0
- data/lib/dokkit/models/simple/doc/data/latex/deplate.sty +46 -0
- data/lib/dokkit/models/simple/doc/layouts/simple.html +9 -0
- data/lib/dokkit/models/simple/doc/layouts/simple.latex +11 -0
- data/lib/dokkit/models/simple/doc/pages/simple.deplate +80 -0
- data/lib/dokkit/models/simple/setup/setup.rb +10 -0
- data/lib/dokkit/resource/data.rb +36 -0
- data/lib/dokkit/resource/document.rb +385 -0
- data/lib/dokkit/resource/extensions/builtin.rb +19 -0
- data/lib/dokkit/resource/extensions/html.rb +22 -0
- data/lib/dokkit/resource/extensions/url.rb +25 -0
- data/lib/dokkit/{filters/base.rb → resource/extensions.rb} +7 -8
- data/lib/dokkit/resource/filenamehelper.rb +28 -0
- data/lib/dokkit/resource.rb +11 -0
- data/lib/dokkit/tasklib/clean.rb +73 -0
- data/lib/dokkit/tasklib/render.rb +137 -0
- data/lib/dokkit/tasklib.rb +11 -0
- data/lib/dokkit.rb +26 -29
- data/spec/dokkit/application_spec.rb +141 -0
- data/spec/dokkit/cache/cache_spec.rb +87 -0
- data/spec/dokkit/dokkit_spec.rb +20 -0
- data/spec/dokkit/environment/basic_spec.rb +135 -0
- data/spec/dokkit/environment/helpers/extmap_spec.rb +52 -0
- data/spec/dokkit/environment/helpers/fileselection_spec.rb +80 -0
- data/spec/dokkit/environment/test_data/doc/pages/document_1.yaml +3 -0
- data/spec/dokkit/factory/factory_spec.rb +69 -0
- data/spec/{filter_deplate_spec.rb → dokkit/filters/deplate_spec.rb} +7 -8
- data/spec/{filter_maruku_spec.rb → dokkit/filters/maruku_spec.rb} +3 -4
- data/spec/{filter_nil_spec.rb → dokkit/filters/nil_spec.rb} +3 -4
- data/spec/{recursivemerge_spec.rb → dokkit/hash_spec.rb} +25 -27
- data/spec/{logger_spec.rb → dokkit/logging/logger_spec.rb} +35 -47
- data/spec/{consolelog_spec.rb → dokkit/logging/observers/console_spec.rb} +14 -15
- data/spec/dokkit/resource/data_spec.rb +32 -0
- data/spec/dokkit/resource/document_spec.rb +485 -0
- data/spec/dokkit/resource/extensions/html_spec.rb +35 -0
- data/spec/dokkit/resource/extensions/url_spec.rb +29 -0
- data/spec/{filehelper_spec.rb → dokkit/resource/filenamehelper_spec.rb} +12 -13
- data/spec/dokkit/resource/test_data/doc/configs/config_1.yaml +3 -0
- data/spec/dokkit/resource/test_data/doc/configs/config_2.yaml +3 -0
- data/spec/dokkit/resource/test_data/doc/configs/required.yaml +3 -0
- data/spec/dokkit/resource/test_data/doc/configs/subdir/document.yaml +3 -0
- data/spec/dokkit/resource/test_data/doc/layouts/container.html +6 -0
- data/spec/dokkit/resource/test_data/doc/layouts/layout.html +6 -0
- data/spec/{data/test_build/doc/layouts → dokkit/resource/test_data/doc/layouts/nested}/nested.html +2 -1
- data/spec/dokkit/resource/test_data/doc/layouts/subdir/document.html +6 -0
- data/spec/dokkit/resource/test_data/doc/pages/COMMON.yaml +4 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_many_config.ext +7 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_many_errors.ext +12 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_many_targets.ext +19 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_nested_layout.ext +13 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_nil_target.ext +5 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_not_defined_target.ext +6 -0
- data/spec/dokkit/resource/test_data/doc/pages/document_with_one_target.ext +8 -0
- data/spec/dokkit/resource/test_data/doc/pages/subdir/COMMON.yaml +3 -0
- data/spec/dokkit/resource/test_data/doc/pages/subdir/document.ext +8 -0
- data/spec/dokkit/resource/test_data/doc/pages/subdir/document.yaml +5 -0
- data/spec/dokkit/tasklib/clean_spec.rb +75 -0
- data/spec/dokkit/tasklib/render_spec.rb +125 -0
- data/spec/dokkit/tasklib/test_data/doc/pages/document_2 +0 -0
- data/spec/dokkit/test_data/dokkit/models/model1/doc/pages/model1 +0 -0
- data/spec/dokkit/test_data/dokkit/models/model2/doc/pages/model2 +0 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +120 -47
- metadata +94 -117
- data/lib/dokkit/app.rb +0 -131
- data/lib/dokkit/builtintask.rb +0 -85
- data/lib/dokkit/cachemanager.rb +0 -61
- data/lib/dokkit/cleantask.rb +0 -51
- data/lib/dokkit/consolelog.rb +0 -42
- data/lib/dokkit/defaults.rb +0 -19
- data/lib/dokkit/deplate/fmt/html-notemplate.rb +0 -21
- data/lib/dokkit/deplate/fmt/latex-notemplate.rb +0 -24
- data/lib/dokkit/document.rb +0 -221
- data/lib/dokkit/dokkitlib.rb +0 -68
- data/lib/dokkit/extension/filehelper.rb +0 -25
- data/lib/dokkit/fileselection.rb +0 -44
- data/lib/dokkit/filters/all.rb +0 -18
- data/lib/dokkit/model.rb +0 -34
- data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.html +0 -9
- data/lib/dokkit/models/simpledocument/model/doc/pages/simpledocument.deplate +0 -102
- data/lib/dokkit/models/simpledocument/model/tasks/all.rb +0 -3
- data/lib/dokkit/models/simpledocument/model/tasks/clean.rake +0 -3
- data/lib/dokkit/models/simpledocument/model/tasks/render.rake +0 -8
- data/lib/dokkit/models/simpledocument/model/tasks/setup.rb +0 -9
- data/lib/dokkit/modeltask.rb +0 -83
- data/lib/dokkit/pathhelper.rb +0 -46
- data/lib/dokkit/recursivemerge.rb +0 -59
- data/lib/dokkit/rendertask.rb +0 -101
- data/lib/dokkit/resourcemanager.rb +0 -177
- data/lib/dokkit/taskconfig.rb +0 -39
- data/lib/dokkit/templatetask.rb +0 -37
- data/spec/app_spec.rb +0 -55
- data/spec/builtintask_spec.rb +0 -114
- data/spec/cachemanager_spec.rb +0 -107
- data/spec/cleantask_spec.rb +0 -72
- data/spec/data/test_build/doc/configs/document_1.yaml +0 -3
- data/spec/data/test_build/doc/configs/required.yaml +0 -3
- data/spec/data/test_build/doc/configs/subdir/document_4.yaml +0 -3
- data/spec/data/test_build/doc/layouts/document_1.html +0 -9
- data/spec/data/test_build/doc/layouts/document_with_partials.html +0 -9
- data/spec/data/test_build/doc/layouts/layout.html +0 -8
- data/spec/data/test_build/doc/layouts/layout.html.backup +0 -8
- data/spec/data/test_build/doc/layouts/partials/partial.html +0 -4
- data/spec/data/test_build/doc/pages/COMMON.yaml +0 -6
- data/spec/data/test_build/doc/pages/document_1 +0 -20
- data/spec/data/test_build/doc/pages/document_1.dep +0 -4
- data/spec/data/test_build/doc/pages/document_1.yaml +0 -11
- data/spec/data/test_build/doc/pages/document_2 +0 -9
- data/spec/data/test_build/doc/pages/document_2.yaml +0 -6
- data/spec/data/test_build/doc/pages/document_3 +0 -13
- data/spec/data/test_build/doc/pages/document_7 +0 -4
- data/spec/data/test_build/doc/pages/document_7.yaml +0 -5
- data/spec/data/test_build/doc/pages/document_extended +0 -1
- data/spec/data/test_build/doc/pages/document_nested +0 -6
- data/spec/data/test_build/doc/pages/document_nested.yaml +0 -5
- data/spec/data/test_build/doc/pages/document_nolayout.ext +0 -3
- data/spec/data/test_build/doc/pages/document_nolayout.yaml +0 -2
- data/spec/data/test_build/doc/pages/document_with_partials +0 -3
- data/spec/data/test_build/doc/pages/document_with_partials.yaml +0 -2
- data/spec/data/test_build/doc/pages/partials/COMMON.yaml +0 -5
- data/spec/data/test_build/doc/pages/partials/circular_partial +0 -2
- data/spec/data/test_build/doc/pages/partials/circular_partial.yaml +0 -3
- data/spec/data/test_build/doc/pages/partials/partial +0 -2
- data/spec/data/test_build/doc/pages/subdir/COMMON.yaml +0 -2
- data/spec/data/test_build/doc/pages/subdir/document_4 +0 -11
- data/spec/data/test_build/doc/pages/subdir/subdir/COMMON.yaml +0 -2
- data/spec/data/test_build/doc/pages/subdir/subdir/document_6 +0 -3
- data/spec/data/test_build/tasks/all.rb +0 -3
- data/spec/data/test_build/tasks/clean.rake +0 -3
- data/spec/data/test_build/tasks/render.rake +0 -8
- data/spec/data/test_build/tasks/setup.rb +0 -9
- data/spec/data/test_build/tasks/template.rake +0 -3
- data/spec/document_spec.rb +0 -321
- data/spec/dokkitlib_spec.rb +0 -63
- data/spec/fileselection_spec.rb +0 -101
- data/spec/filter_base_spec.rb +0 -29
- data/spec/filters_spec.rb +0 -37
- data/spec/model_spec.rb +0 -45
- data/spec/pathhelper_spec.rb +0 -62
- data/spec/rendertask_spec.rb +0 -374
- data/spec/taskconfig_spec.rb +0 -45
- data/spec/templatetask_spec.rb +0 -72
- /data/lib/dokkit/models/{simpledocument/model/doc/configs/simpledocument.yaml → simple/doc/configs/simple.yaml} +0 -0
- /data/lib/dokkit/models/{simpledocument/model/doc/layouts/simpledocument.text → simple/doc/layouts/simple.text} +0 -0
- /data/{lib/dokkit/models/simpledocument/model/doc/data/css/style.css → spec/dokkit/environment/helpers/test_data/doc/pages/document_1.ext_1} +0 -0
- /data/spec/{data/test_build/doc/data/resource → dokkit/environment/helpers/test_data/doc/pages/document_2} +0 -0
- /data/spec/{data/test_build/doc/data/resource.exclude → dokkit/environment/helpers/test_data/doc/pages/document_3.ext_3} +0 -0
- /data/spec/{data/test_build/doc/data/subdir/resource.insubdir → dokkit/environment/test_data/doc/data/data} +0 -0
- /data/spec/{data/test_build/doc/layouts/layout → dokkit/environment/test_data/doc/pages/document_1} +0 -0
- /data/spec/{data/test_build/doc/pages/document_2.dep → dokkit/environment/test_data/doc/pages/document_2} +0 -0
- /data/spec/{data/test_build/doc/pages/document_5.exclude → dokkit/environment/test_data/doc/pages/subdir/document_1} +0 -0
- /data/{lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.latex → spec/dokkit/resource/test_data/doc/layouts/layout.latex} +0 -0
- /data/spec/{data/test_build/doc/layouts/document_1.latex → dokkit/resource/test_data/doc/layouts/subdir/document.latex} +0 -0
- /data/spec/{data/test_build/templates/layouts/layout → dokkit/tasklib/test_data/doc/data/data_1} +0 -0
- /data/spec/{data/test_build/templates/pages/template → dokkit/tasklib/test_data/doc/pages/document_1} +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'builtin.rb' created on 21 giu 2008 at 20:41:42.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'dokkit/resource/extensions/html'
|
|
10
|
+
|
|
11
|
+
module Dokkit
|
|
12
|
+
module Resource
|
|
13
|
+
module Extension
|
|
14
|
+
module Builtin
|
|
15
|
+
include HTML
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'html.rb' created on 21 giu 2008 at 19:55:48.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'dokkit/resource/extensions/url'
|
|
10
|
+
|
|
11
|
+
module Dokkit
|
|
12
|
+
module Resource
|
|
13
|
+
module Extension
|
|
14
|
+
module HTML
|
|
15
|
+
include Url
|
|
16
|
+
def link_to(name, args = { })
|
|
17
|
+
"<a href=\"#{relative(args[:href])}\" class=\"#{args[:class]}\">#{name}</a>"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'url.rb' created on 09 mag 2008 at 19:13:53.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
module Dokkit
|
|
10
|
+
module Resource
|
|
11
|
+
module Extension
|
|
12
|
+
module Url
|
|
13
|
+
def relative(href)
|
|
14
|
+
thr = href
|
|
15
|
+
if thr.is_a?(String) && href[0,1] == '/'
|
|
16
|
+
dtfn = File.dirname(source_fn[/^#{configuration[:document_dir]}\/(.*)/,1]) + '/'
|
|
17
|
+
count = dtfn == './' ? 0 : dtfn.split('/').length
|
|
18
|
+
thr = ('../' * count) + href[1..href.length]
|
|
19
|
+
end
|
|
20
|
+
thr
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
#
|
|
2
|
-
# File '
|
|
2
|
+
# File 'extension.rb' created on 09 mag 2008 at 19:12:50.
|
|
3
3
|
#
|
|
4
4
|
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
5
|
#
|
|
6
|
-
# (C)
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
7
|
#
|
|
8
8
|
|
|
9
|
+
require 'dokkit/resource/extensions/url'
|
|
10
|
+
|
|
9
11
|
module Dokkit
|
|
10
|
-
module
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
nil
|
|
14
|
-
end
|
|
12
|
+
module Resource
|
|
13
|
+
module Extension
|
|
14
|
+
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
-
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'filenamehelper.rb' created on 21 apr 2008 at 14:25:47.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C) 2006, 2007, 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
module Dokkit
|
|
10
|
+
module Resource
|
|
11
|
+
# This is a helper module that aims to simplify operation with
|
|
12
|
+
# filenames.
|
|
13
|
+
module FilenameHelper
|
|
14
|
+
# Return a filename transformed in its directory part and
|
|
15
|
+
# (optionally) in its extension.
|
|
16
|
+
# +fn+:: is the source filename.
|
|
17
|
+
# +dir+:: is the directory part to be changed.
|
|
18
|
+
# +new_dir+:: is the new directory part that substitutes +dir+.
|
|
19
|
+
# +new_ext+:: is the (optionally) new extension for the +fn+.
|
|
20
|
+
def filename_helper(fn, dir, new_dir, new_ext = '')
|
|
21
|
+
ext = File.extname(fn).sub(/^\./,'') # strip leading dot
|
|
22
|
+
new_fn = fn.sub(/#{dir}/, new_dir)
|
|
23
|
+
new_fn = new_fn << new_ext unless new_ext.empty?
|
|
24
|
+
new_fn
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'resource.rb' created on 04 mag 2008 at 17:41:25.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'dokkit/resource/document'
|
|
10
|
+
require 'dokkit/resource/data'
|
|
11
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'clean.rb' created on 14 apr 2008 at 16:04:19.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
module Dokkit
|
|
10
|
+
module TaskLib
|
|
11
|
+
# The Clean task library is a collection of rake tasks devoted to
|
|
12
|
+
# the cleaning of the documentation environment. The library
|
|
13
|
+
# defines a clean:output that remove the generated output folder
|
|
14
|
+
# (if exists). It defines also a clean:cache task that remove the
|
|
15
|
+
# cache folder (if exists).
|
|
16
|
+
class Clean
|
|
17
|
+
attr_reader :output_dir, :cache_dir
|
|
18
|
+
|
|
19
|
+
# Initialize the library with the logger instance, an optional
|
|
20
|
+
# namespace and configuration hash.
|
|
21
|
+
def initialize(logger, configuration, namespace = 'clean')
|
|
22
|
+
@namespace = namespace
|
|
23
|
+
@logger = logger
|
|
24
|
+
@configuration = configuration
|
|
25
|
+
@output_dir = configuration[:output_dir]
|
|
26
|
+
@cache_dir = configuration[:cache_dir]
|
|
27
|
+
define_tasks
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# Define library tasks under the given namespace.
|
|
33
|
+
def define_tasks
|
|
34
|
+
namespace @namespace do
|
|
35
|
+
define_output_task
|
|
36
|
+
define_cache_task
|
|
37
|
+
define_clean_all_task
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Define a task to remove output directory.
|
|
42
|
+
def define_output_task
|
|
43
|
+
desc "Remove the generated output."
|
|
44
|
+
task :output do
|
|
45
|
+
remove_dir(output_dir)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Define a task to remove cache directory.
|
|
50
|
+
def define_cache_task
|
|
51
|
+
desc "Remove cache directory."
|
|
52
|
+
task :cache do
|
|
53
|
+
remove_dir(cache_dir)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def remove_dir(dir)
|
|
58
|
+
if File.exists?(dir)
|
|
59
|
+
@logger.info("Removing directory '#{dir}'.")
|
|
60
|
+
rm_rf dir unless dir == '.'
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Define a task that clean the documentation environment
|
|
65
|
+
# removing both output and cache directory.
|
|
66
|
+
def define_clean_all_task
|
|
67
|
+
desc "Clean the documentation environment."
|
|
68
|
+
task :all => ["#{@namespace}:output", "#{@namespace}:cache"]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'render.rb' created on 18 feb 2008 at 17:47:44.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'rake/tasklib'
|
|
10
|
+
|
|
11
|
+
module Dokkit
|
|
12
|
+
module TaskLib
|
|
13
|
+
# Render task library defines a set of rake tasks devoted to the
|
|
14
|
+
# transformation (rendering) of the documents and data files.
|
|
15
|
+
class Render < Rake::TaskLib
|
|
16
|
+
|
|
17
|
+
# Initialize a set of tasks that transform resources.
|
|
18
|
+
# +namespace+:: is the namespace for the tasks defined in the library.
|
|
19
|
+
# +logger+:: is the logger instance.
|
|
20
|
+
# +factory+:: is a factory class that creates document instances.
|
|
21
|
+
# +document_fns+:: is an array of source filenames.
|
|
22
|
+
# +data_fns+:: is an array of data files.
|
|
23
|
+
def initialize(logger, resource_factory, document_fns, data_fns, namespace = 'render')
|
|
24
|
+
@namespace = namespace
|
|
25
|
+
@document_fns = document_fns
|
|
26
|
+
@data_fns = data_fns
|
|
27
|
+
@resource_factory = resource_factory
|
|
28
|
+
@logger = logger
|
|
29
|
+
define_tasks
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Use factory to get an instance of Dokkit::Resource::Document
|
|
33
|
+
# starting from document filename.
|
|
34
|
+
def get_document(document_fn)
|
|
35
|
+
@resource_factory.get(:document, document_fn)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# use factory to get an instance of Dokkit::Resource::Data
|
|
39
|
+
# starting from data filename. Note that Data instances are
|
|
40
|
+
# *immutable* resources, that is no rendering process occurs:
|
|
41
|
+
# the file is copied as is.
|
|
42
|
+
def get_data(data_fn)
|
|
43
|
+
@resource_factory.get(:data, data_fn)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
# Create output directory +dn+ unless it already exists.
|
|
49
|
+
def mkdir(dn)
|
|
50
|
+
mkdir_p(dn, :verbose => false) unless File.exists?(dn)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Write the result of the rendering to the target file. The
|
|
54
|
+
# output directory is created at this time.
|
|
55
|
+
def write_document(render_text, target_fn)
|
|
56
|
+
mkdir(File.dirname(target_fn))
|
|
57
|
+
File.open(target_fn, 'w') { |file| file << render_text }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Copy the given source data file to the given target destination.
|
|
61
|
+
def write_data(data)
|
|
62
|
+
mkdir(File.dirname(data.target_fn))
|
|
63
|
+
cp(data.source_fn, data.target_fn, :preserve => true, :verbose => false)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Define all tasks in library.
|
|
67
|
+
def define_tasks
|
|
68
|
+
namespace @namespace do
|
|
69
|
+
define_render_all_documents_task
|
|
70
|
+
define_data_task
|
|
71
|
+
define_render_all_task
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Define render all documents task.
|
|
76
|
+
def define_render_all_documents_task
|
|
77
|
+
desc "Render documents."
|
|
78
|
+
task :doc do
|
|
79
|
+
render_all_documents
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def render_all_documents
|
|
84
|
+
@document_fns.each { |fn| render_all_targets(get_document(fn)) }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def render_all_targets(document)
|
|
88
|
+
document.targets.each_key do |format|
|
|
89
|
+
render_target(document, format) if need_update?(document.target_for(format), document.deps_for(format))
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def render_target(document, format)
|
|
94
|
+
@logger.info("Render '#{document.source_fn}' => '#{document.target_for(format)}'.")
|
|
95
|
+
write_document(document.render(:format => format), document.target_for(format))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Define data task.
|
|
99
|
+
def define_data_task
|
|
100
|
+
desc "Copy data files."
|
|
101
|
+
task :data do
|
|
102
|
+
copy_all_data
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def copy_all_data
|
|
107
|
+
@data_fns.each { |fn| copy_data(get_data(fn)) }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def copy_data(data)
|
|
111
|
+
if need_update?(data.target_fn, data.source_fn)
|
|
112
|
+
@logger.info("Copy '#{data.source_fn}' => '#{data.target_fn}'.")
|
|
113
|
+
write_data(data)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Define a task that render all documents and copy all data.
|
|
118
|
+
def define_render_all_task
|
|
119
|
+
desc "Render the documents and copy the data."
|
|
120
|
+
task :all => ["#{@namespace}:doc", "#{@namespace}:data"]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
# Compares target mtime against dependencies mtime. Returns true
|
|
126
|
+
# if target mtime is greater than dependencies mtime returns
|
|
127
|
+
# true. Otherwise return false (target needs update).
|
|
128
|
+
def need_update?(target, deps)
|
|
129
|
+
return true unless File.exists?(target)
|
|
130
|
+
deps.each { |dep| return true if File.mtime(target) < File.mtime(dep) }
|
|
131
|
+
false
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'tasklib.rb' created on 04 mag 2008 at 17:40:50.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'dokkit/tasklib/render'
|
|
10
|
+
require 'dokkit/tasklib/clean'
|
|
11
|
+
|
data/lib/dokkit.rb
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
# dokkit.rb - main Dokkit module
|
|
2
2
|
|
|
3
3
|
#####
|
|
4
|
-
## *Dokkit* is a
|
|
5
|
-
##
|
|
6
|
-
##
|
|
7
|
-
## It enables embedded
|
|
8
|
-
## to be used to automatically generate output in any
|
|
9
|
-
##
|
|
4
|
+
## *Dokkit* is a rake (http://rake.rubyforge.org) based documentation
|
|
5
|
+
## building tool. It uses filters to produce very polished tex file,
|
|
6
|
+
## page-based documentation, websites, and general textual templates.
|
|
7
|
+
## It enables embedded ruby code, layouts, YAML config files and rake
|
|
8
|
+
## tasks to be used to automatically generate output in any (textual)
|
|
9
|
+
## format from a directory tree containing template files.
|
|
10
10
|
##
|
|
11
|
-
## Dokkit was created to manage the documentation produced by Alca
|
|
12
|
-
## and it is a fairly
|
|
11
|
+
## Dokkit was created to manage the documentation produced by Alca
|
|
12
|
+
## Coop (http://alca.le.it/) for its customers and it is a fairly
|
|
13
|
+
## flexible tool.
|
|
13
14
|
##
|
|
14
|
-
## Dokkit can be used from the command-line, or in your own
|
|
15
|
-
## supports both manual and automatic rendering of
|
|
16
|
-
##
|
|
15
|
+
## Dokkit can be used from the command-line, or in your own
|
|
16
|
+
## +Rakefile+. It supports both manual and automatic rendering of
|
|
17
|
+
## modified resources.
|
|
17
18
|
##
|
|
18
|
-
## See +README+ and http://dokkit.rubyforge.org for general usage
|
|
19
|
+
## See +README+ and http://dokkit.rubyforge.org for general usage
|
|
20
|
+
## information.
|
|
19
21
|
##
|
|
20
|
-
## Copyright (C) 2006, 2007 Andrea Fazzi (and contributors).
|
|
22
|
+
## Copyright (C) 2006, 2007, 2008 Andrea Fazzi (and contributors).
|
|
21
23
|
##
|
|
22
|
-
## This program is free software: you can redistribute it and/or
|
|
23
|
-
## it under the terms of the GNU General Public License as
|
|
24
|
-
## the Free Software Foundation, either version 3 of the
|
|
25
|
-
## (at your option) any later version.
|
|
24
|
+
## This program is free software: you can redistribute it and/or
|
|
25
|
+
## modify it under the terms of the GNU General Public License as
|
|
26
|
+
## published by the Free Software Foundation, either version 3 of the
|
|
27
|
+
## License, or (at your option) any later version.
|
|
26
28
|
##
|
|
27
|
-
## This program is distributed in the hope that it will be useful,
|
|
28
|
-
##
|
|
29
|
-
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
30
|
-
##
|
|
29
|
+
## This program is distributed in the hope that it will be useful, but
|
|
30
|
+
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
31
|
+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
32
|
+
## General Public License for more details.
|
|
31
33
|
##
|
|
32
34
|
## You should have received a copy of the GNU General Public License
|
|
33
|
-
## along with this program. If not, see
|
|
35
|
+
## along with this program. If not, see
|
|
36
|
+
## <http://www.gnu.org/licenses/>.
|
|
34
37
|
##
|
|
35
38
|
## See +LICENSE+ for details.
|
|
36
39
|
|
|
@@ -47,12 +50,6 @@ rescue LoadError
|
|
|
47
50
|
nil # just try without then...
|
|
48
51
|
end
|
|
49
52
|
|
|
50
|
-
require 'rake'
|
|
51
|
-
require 'dokkit/app'
|
|
52
|
-
require 'dokkit/defaults'
|
|
53
|
-
|
|
54
53
|
module Dokkit
|
|
55
|
-
|
|
56
|
-
# this space intentionally left blank
|
|
57
|
-
|
|
54
|
+
VERSION = '0.4.0'
|
|
58
55
|
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'application_spec.rb' created on 08 mag 2008 at 17:26:24.
|
|
3
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
4
|
+
#
|
|
5
|
+
# (c)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../../lib')))
|
|
9
|
+
|
|
10
|
+
require 'rubygems'
|
|
11
|
+
require 'spec'
|
|
12
|
+
require 'dokkit/application'
|
|
13
|
+
require 'spec/spec_helper'
|
|
14
|
+
|
|
15
|
+
describe Dokkit::Application, ' options behaviour' do
|
|
16
|
+
include SpecHelper::CaptureOutput, SpecHelper::Logger
|
|
17
|
+
before(:all) do
|
|
18
|
+
@initial_dir = Dir.pwd
|
|
19
|
+
Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
|
|
20
|
+
end
|
|
21
|
+
after(:all) do
|
|
22
|
+
Dir.chdir(@initial_dir)
|
|
23
|
+
end
|
|
24
|
+
before do
|
|
25
|
+
@logger = logger
|
|
26
|
+
@dokkit = Dokkit::Application.new(@logger, { :dokkit_dir => 'dokkit', :model_dir => 'models', :default_model => 'model1' })
|
|
27
|
+
end
|
|
28
|
+
after do
|
|
29
|
+
ARGV.clear
|
|
30
|
+
end
|
|
31
|
+
it 'should set default model' do
|
|
32
|
+
@dokkit.default_model.should == 'model1'
|
|
33
|
+
end
|
|
34
|
+
it 'should display version number' do
|
|
35
|
+
ARGV << '--version'
|
|
36
|
+
capture_stdout do
|
|
37
|
+
lambda do
|
|
38
|
+
@dokkit.run
|
|
39
|
+
end.should raise_error(SystemExit)
|
|
40
|
+
end.should match(/dokkit, version \d.\d.\d/)
|
|
41
|
+
end
|
|
42
|
+
#FIXME: Code duplication here ...
|
|
43
|
+
it 'should alias --help option with --usage' do
|
|
44
|
+
ARGV << '--help'
|
|
45
|
+
@output = capture_stdout do
|
|
46
|
+
lambda do
|
|
47
|
+
@dokkit.run
|
|
48
|
+
end.should raise_error(SystemExit)
|
|
49
|
+
end
|
|
50
|
+
@output.should match(/Usage: dokkit/)
|
|
51
|
+
@output.should match(/Recognized options/)
|
|
52
|
+
end
|
|
53
|
+
it 'should display usage information' do
|
|
54
|
+
ARGV << '--usage'
|
|
55
|
+
@output = capture_stdout do
|
|
56
|
+
lambda do
|
|
57
|
+
@dokkit.run
|
|
58
|
+
end.should raise_error(SystemExit)
|
|
59
|
+
end
|
|
60
|
+
@output.should match(/Usage: dokkit/)
|
|
61
|
+
@output.should match(/Recognized options/)
|
|
62
|
+
end
|
|
63
|
+
it 'should display the list of available models' do
|
|
64
|
+
ARGV << '--list'
|
|
65
|
+
@logger.should_receive(:info).with(/model[1-2]/).twice
|
|
66
|
+
lambda do
|
|
67
|
+
@dokkit.run
|
|
68
|
+
end.should raise_error(SystemExit)
|
|
69
|
+
end
|
|
70
|
+
it 'should fail if the number of commandline argument is less than one' do
|
|
71
|
+
@output = capture_stdout do
|
|
72
|
+
lambda do
|
|
73
|
+
@dokkit.run
|
|
74
|
+
end.should raise_error(SystemExit)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe Dokkit::Application, ' creating new documentation environment based on builtin model' do
|
|
80
|
+
include SpecHelper::CaptureOutput, SpecHelper::Logger
|
|
81
|
+
before(:all) do
|
|
82
|
+
@initial_dir = Dir.pwd
|
|
83
|
+
Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
|
|
84
|
+
end
|
|
85
|
+
after(:all) do
|
|
86
|
+
Dir.chdir(@initial_dir)
|
|
87
|
+
end
|
|
88
|
+
before do
|
|
89
|
+
@logger = logger
|
|
90
|
+
@dokkit = Dokkit::Application.new(@logger)
|
|
91
|
+
end
|
|
92
|
+
after do
|
|
93
|
+
ARGV.clear
|
|
94
|
+
FileUtils.rm_rf 'project'
|
|
95
|
+
end
|
|
96
|
+
it 'should copy builtin model directory structure on destination dir' do
|
|
97
|
+
ARGV << 'project'
|
|
98
|
+
@dokkit.run
|
|
99
|
+
File.exists?('project/doc/pages/simple.deplate').should be_true
|
|
100
|
+
end
|
|
101
|
+
it 'should fail if the destination directory exists' do
|
|
102
|
+
ARGV << 'project'
|
|
103
|
+
FileUtils.mkdir 'project'
|
|
104
|
+
@logger.should_receive(:error).with(/already exists/)
|
|
105
|
+
@dokkit.run
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe Dokkit::Application, ' creating new documentation environment based on user models' do
|
|
110
|
+
include SpecHelper::CaptureOutput, SpecHelper::Logger
|
|
111
|
+
before(:all) do
|
|
112
|
+
@initial_dir = Dir.pwd
|
|
113
|
+
Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
|
|
114
|
+
end
|
|
115
|
+
after(:all) do
|
|
116
|
+
Dir.chdir(@initial_dir)
|
|
117
|
+
end
|
|
118
|
+
before do
|
|
119
|
+
@logger = logger
|
|
120
|
+
@dokkit = Dokkit::Application.new(@logger, { :dokkit_dir => 'dokkit', :model_dir => 'models', :default_model => 'model1' })
|
|
121
|
+
end
|
|
122
|
+
after do
|
|
123
|
+
ARGV.clear
|
|
124
|
+
FileUtils.rm_rf 'project'
|
|
125
|
+
end
|
|
126
|
+
it 'should copy model1 directory structure on destination dir' do
|
|
127
|
+
ARGV << 'project'
|
|
128
|
+
@dokkit.run
|
|
129
|
+
File.exists?('project/doc/pages/model1').should be_true
|
|
130
|
+
end
|
|
131
|
+
it 'should copy model2 directory structure on destination dir' do
|
|
132
|
+
ARGV.concat(['--model', 'model2', 'project'])
|
|
133
|
+
@dokkit.run
|
|
134
|
+
File.exists?('project/doc/pages/model2').should be_true
|
|
135
|
+
end
|
|
136
|
+
it 'should fail if not existent model is specified' do
|
|
137
|
+
ARGV.concat(['--model', 'notexists', 'project'])
|
|
138
|
+
@logger.should_receive(:error).with(/not found/)
|
|
139
|
+
@dokkit.run
|
|
140
|
+
end
|
|
141
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'cachemanager_spec.rb' created on 28 gen 2008 at 18:31:31.
|
|
3
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
4
|
+
#
|
|
5
|
+
# (c)2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
6
|
+
#
|
|
7
|
+
# To execute this spec run:
|
|
8
|
+
#
|
|
9
|
+
# spec spec/cachemanager_spec.rb
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__),'../../../lib'))
|
|
14
|
+
|
|
15
|
+
require 'rubygems'
|
|
16
|
+
require 'spec'
|
|
17
|
+
require 'dokkit'
|
|
18
|
+
require 'dokkit/cache'
|
|
19
|
+
require 'spec/spec_helper'
|
|
20
|
+
|
|
21
|
+
describe Dokkit::Cache do
|
|
22
|
+
include SpecHelper::Path
|
|
23
|
+
|
|
24
|
+
before(:all) do
|
|
25
|
+
@initial_dir = Dir.pwd
|
|
26
|
+
Dir.chdir(File.join(File.dirname(__FILE__), SpecHelper::Path::TEST_DATA))
|
|
27
|
+
end
|
|
28
|
+
after(:all) do
|
|
29
|
+
Dir.chdir(@initial_dir)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe ' when initialized' do
|
|
33
|
+
before do
|
|
34
|
+
mkdir '.cache_test' unless File.exists?('.cache_test')
|
|
35
|
+
File.open(base_path('.cache_test/deps.rake'), 'w') do |file|
|
|
36
|
+
file.write YAML::dump({ document_path('document_1') => { 'html' => [document_path('document_1.dep')] } } )
|
|
37
|
+
end
|
|
38
|
+
@cache = Dokkit::Cache.new('deps.rake', '.cache_test')
|
|
39
|
+
end
|
|
40
|
+
it 'should import the cache file (if exists)' do
|
|
41
|
+
@cache.deps.should == { document_path('document_1') => { 'html' => [document_path('document_1.dep')] } }
|
|
42
|
+
end
|
|
43
|
+
after do
|
|
44
|
+
@cache.clean
|
|
45
|
+
rm_rf base_path('.cache_test')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#add_dependency' do
|
|
50
|
+
before do
|
|
51
|
+
@cache = Dokkit::Cache.new('deps.rake', '.cache_test')
|
|
52
|
+
end
|
|
53
|
+
it 'should add dependecies to the given document' do
|
|
54
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_1.dep')
|
|
55
|
+
@cache.deps.should == { document_path('document_1') => { 'html' => [document_path('document_1.dep')] } }
|
|
56
|
+
end
|
|
57
|
+
it 'should not add an existing dependency to the given document' do
|
|
58
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_1.dep')
|
|
59
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_1.dep')
|
|
60
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_2.dep')
|
|
61
|
+
@cache.deps.should == { document_path('document_1') => { 'html' => ['doc/pages/document_1.dep', 'doc/pages/document_2.dep'] } }
|
|
62
|
+
end
|
|
63
|
+
after do
|
|
64
|
+
@cache.clean
|
|
65
|
+
rm_rf '.cache_test'
|
|
66
|
+
@cache = nil
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#save' do
|
|
71
|
+
before do
|
|
72
|
+
@cache = Dokkit::Cache.new('deps.rake', '.cache_test')
|
|
73
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_1.dep')
|
|
74
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_2.dep')
|
|
75
|
+
@cache.add_dependency(document_path('document_1'), 'html', 'doc/pages/document_3.dep')
|
|
76
|
+
end
|
|
77
|
+
it 'should save the dependencies to file' do
|
|
78
|
+
@cache.save
|
|
79
|
+
File.exists?(base_path('.cache_test/deps.rake')).should be_true
|
|
80
|
+
end
|
|
81
|
+
after do
|
|
82
|
+
@cache.clean
|
|
83
|
+
rm_rf '.cache_test'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|