dokkit 0.2.0 → 0.3.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 +4 -0
- data/Manifest.txt +125 -0
- data/README.txt +53 -0
- data/Rakefile +25 -167
- data/bin/dokkit +4 -60
- data/lib/dokkit/app.rb +63 -192
- data/lib/dokkit/builtintask.rb +85 -0
- data/lib/dokkit/cachemanager.rb +61 -0
- data/lib/dokkit/cleantask.rb +51 -0
- data/lib/dokkit/consolelog.rb +42 -0
- data/lib/dokkit/defaults.rb +19 -0
- data/lib/dokkit/document.rb +221 -0
- data/lib/dokkit/dokkitlib.rb +68 -0
- data/lib/dokkit/extension/extension.rb +15 -0
- data/lib/dokkit/extension/filehelper.rb +25 -0
- data/lib/dokkit/fileselection.rb +44 -0
- data/lib/dokkit/filters/all.rb +18 -0
- data/lib/dokkit/filters/base.rb +18 -0
- data/lib/dokkit/filters/deplate.rb +21 -25
- data/lib/dokkit/filters/maruku.rb +23 -0
- data/lib/dokkit/filters/nil.rb +23 -0
- data/lib/dokkit/filters.rb +29 -21
- data/lib/dokkit/logger.rb +73 -0
- data/lib/dokkit/model.rb +34 -0
- data/lib/dokkit/models/{Rakefile.tpl → simpledocument/model/Rakefile} +15 -2
- data/lib/dokkit/models/simpledocument/model/doc/configs/simpledocument.yaml +3 -0
- data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.html +9 -0
- data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.latex +8 -0
- data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.text +1 -0
- data/lib/dokkit/models/simpledocument/model/doc/pages/simpledocument.deplate +102 -0
- data/lib/dokkit/models/simpledocument/model/tasks/all.rb +3 -0
- data/lib/dokkit/models/simpledocument/model/tasks/clean.rake +3 -0
- data/lib/dokkit/models/simpledocument/model/tasks/render.rake +8 -0
- data/lib/dokkit/models/simpledocument/model/tasks/setup.rb +9 -0
- data/lib/dokkit/modeltask.rb +83 -0
- data/lib/dokkit/pathhelper.rb +46 -0
- data/lib/dokkit/recursivemerge.rb +59 -0
- data/lib/dokkit/rendertask.rb +101 -0
- data/lib/dokkit/resourcemanager.rb +177 -0
- data/lib/dokkit/taskconfig.rb +39 -0
- data/lib/dokkit/templatetask.rb +37 -0
- data/lib/dokkit.rb +2 -8
- data/spec/app_spec.rb +55 -0
- data/spec/builtintask_spec.rb +114 -0
- data/spec/cachemanager_spec.rb +107 -0
- data/spec/cleantask_spec.rb +72 -0
- data/spec/consolelog_spec.rb +69 -0
- data/{tests/data/projects/simple-document → spec/data/test_build}/Rakefile +8 -8
- data/spec/data/test_build/doc/configs/document_1.yaml +3 -0
- data/spec/data/test_build/doc/configs/required.yaml +3 -0
- data/spec/data/test_build/doc/configs/subdir/document_4.yaml +3 -0
- data/spec/data/test_build/doc/layouts/document_1.html +9 -0
- data/spec/data/test_build/doc/layouts/document_1.latex +8 -0
- data/spec/data/test_build/doc/layouts/document_with_partials.html +9 -0
- data/spec/data/test_build/doc/layouts/layout +0 -0
- data/spec/data/test_build/doc/layouts/layout.html +8 -0
- data/spec/data/test_build/doc/layouts/layout.html.backup +8 -0
- data/spec/data/test_build/doc/layouts/nested.html +3 -0
- data/spec/data/test_build/doc/layouts/partials/partial.html +4 -0
- data/spec/data/test_build/doc/pages/COMMON.yaml +6 -0
- data/spec/data/test_build/doc/pages/document_1 +20 -0
- data/spec/data/test_build/doc/pages/document_1.dep +4 -0
- data/spec/data/test_build/doc/pages/document_1.yaml +11 -0
- data/spec/data/test_build/doc/pages/document_2 +9 -0
- data/spec/data/test_build/doc/pages/document_2.dep +0 -0
- data/spec/data/test_build/doc/pages/document_2.yaml +6 -0
- data/spec/data/test_build/doc/pages/document_3 +13 -0
- data/spec/data/test_build/doc/pages/document_5.exclude +0 -0
- data/spec/data/test_build/doc/pages/document_7 +4 -0
- data/spec/data/test_build/doc/pages/document_7.yaml +5 -0
- data/spec/data/test_build/doc/pages/document_extended +1 -0
- data/spec/data/test_build/doc/pages/document_nested +6 -0
- data/spec/data/test_build/doc/pages/document_nested.yaml +5 -0
- data/spec/data/test_build/doc/pages/document_nolayout.ext +3 -0
- data/spec/data/test_build/doc/pages/document_nolayout.yaml +2 -0
- data/spec/data/test_build/doc/pages/document_with_partials +3 -0
- data/spec/data/test_build/doc/pages/document_with_partials.yaml +2 -0
- data/spec/data/test_build/doc/pages/partials/COMMON.yaml +5 -0
- data/spec/data/test_build/doc/pages/partials/circular_partial +2 -0
- data/spec/data/test_build/doc/pages/partials/circular_partial.yaml +3 -0
- data/spec/data/test_build/doc/pages/partials/partial +2 -0
- data/spec/data/test_build/doc/pages/subdir/COMMON.yaml +2 -0
- data/spec/data/test_build/doc/pages/subdir/document_4 +11 -0
- data/spec/data/test_build/doc/pages/subdir/subdir/COMMON.yaml +2 -0
- data/spec/data/test_build/doc/pages/subdir/subdir/document_6 +3 -0
- data/spec/data/test_build/tasks/all.rb +3 -0
- data/spec/data/test_build/tasks/clean.rake +3 -0
- data/spec/data/test_build/tasks/render.rake +8 -0
- data/spec/data/test_build/tasks/setup.rb +9 -0
- data/spec/data/test_build/tasks/template.rake +3 -0
- data/spec/data/test_build/templates/layouts/layout +0 -0
- data/spec/data/test_build/templates/pages/template +0 -0
- data/spec/document_spec.rb +321 -0
- data/spec/dokkitlib_spec.rb +63 -0
- data/spec/filehelper_spec.rb +34 -0
- data/spec/fileselection_spec.rb +101 -0
- data/spec/filter_base_spec.rb +29 -0
- data/spec/filter_deplate_spec.rb +48 -0
- data/spec/filter_maruku_spec.rb +29 -0
- data/spec/filter_nil_spec.rb +30 -0
- data/spec/filters_spec.rb +37 -0
- data/spec/logger_spec.rb +150 -0
- data/spec/model_spec.rb +45 -0
- data/spec/pathhelper_spec.rb +62 -0
- data/spec/recursivemerge_spec.rb +91 -0
- data/spec/rendertask_spec.rb +374 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/taskconfig_spec.rb +45 -0
- data/spec/templatetask_spec.rb +72 -0
- data/tasks/annotations.rake +30 -0
- data/tasks/doc.rake +49 -0
- data/tasks/gem.rake +89 -0
- data/tasks/manifest.rake +41 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +151 -0
- data/tasks/spec.rake +40 -0
- data/tasks/svn.rake +44 -0
- data/tasks/test.rake +40 -0
- metadata +188 -161
- data/CHANGES +0 -26
- data/LICENSE +0 -674
- data/README +0 -32
- data/lib/dokkit/#render_task_factory.rb# +0 -94
- data/lib/dokkit/dokkittasks.rb +0 -99
- data/lib/dokkit/hash.rb +0 -41
- data/lib/dokkit/models/share/builtin.rf +0 -28
- data/lib/dokkit/page.rb +0 -195
- data/lib/dokkit/render_task_factory.rb +0 -91
- data/tests/data/output/simple_document/README +0 -57
- data/tests/data/output/simple_document/Rakefile +0 -7
- data/tests/data/output/simple_document/doc/config/simple_document.yaml +0 -5
- data/tests/data/output/simple_document/doc/pages/simple_document.dpl +0 -12
- data/tests/data/output/website_project/README +0 -49
- data/tests/data/output/website_project/Rakefile +0 -82
- data/tests/data/output/website_project/doc/layouts/normal.thtml +0 -38
- data/tests/data/output/website_project/doc/pages/COMMON.rb +0 -9
- data/tests/data/output/website_project/doc/pages/deplate.dplhtml +0 -9
- data/tests/data/output/website_project/doc/pages/index.rb +0 -10
- data/tests/data/output/website_project/doc/pages/index.thtml +0 -12
- data/tests/data/output/website_project/doc/res/images/rote-tiny.png +0 -0
- data/tests/data/projects/simple-document/README +0 -57
- data/tests/data/projects/simple-document/doc/config/author.yaml +0 -4
- data/tests/data/projects/simple-document/doc/config/model.yaml +0 -18
- data/tests/data/projects/simple-document/doc/config/simple_document.yaml +0 -6
- data/tests/data/projects/simple-document/doc/layouts/another_simple_document.html +0 -8
- data/tests/data/projects/simple-document/doc/layouts/another_simple_document.tex +0 -10
- data/tests/data/projects/simple-document/doc/layouts/layout_with_custom_name.html +0 -8
- data/tests/data/projects/simple-document/doc/layouts/semantic.cache +0 -23
- data/tests/data/projects/simple-document/doc/pages/COMMON.yaml +0 -23
- data/tests/data/projects/simple-document/doc/pages/another_simple_document.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/simple_document.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/simple_document_without_layout.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/subdir/COMMON.yaml +0 -4
- data/tests/data/projects/simple-document/doc/pages/subdir/simple_document_in_subdir.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/subdir/simple_document_in_subdir.yaml +0 -3
- data/tests/data/projects/simple-document/doc/pages/subdir/subdir/COMMON.yaml +0 -2
- data/tests/data/projects/simple-document/doc/pages/subdir/subdir/another_simple_document_in_subdir.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/yet_another_simple_document.dpl +0 -12
- data/tests/data/projects/simple-document/doc/pages/yet_another_simple_document.yaml +0 -8
- data/tests/gem_tests.rb +0 -4
- data/tests/spec_page.rb +0 -25
- data/tests/test.rb +0 -2
- data/tests/test_application.rb +0 -40
- data/tests/test_builtin_tasks.rb +0 -37
- data/tests/test_config.rb +0 -108
- data/tests/test_core.rb +0 -12
- data/tests/test_dokkit_commandline.rb +0 -18
- data/tests/test_exception.rb +0 -7
- data/tests/test_filters.rb +0 -46
- data/tests/test_layout.rb +0 -64
- data/tests/test_options.rb +0 -33
- data/tests/test_project_tasks.rb +0 -48
- data/tests/test_recursive_merge.rb +0 -42
- data/tests/test_task_factory.rb +0 -38
- /data/{CONTRIBUTORS → lib/dokkit/models/simpledocument/model/doc/data/css/style.css} +0 -0
- /data/{DONE → spec/data/test_build/doc/data/resource} +0 -0
- /data/{TODO → spec/data/test_build/doc/data/resource.exclude} +0 -0
- /data/{tests/pages/test.dpltex → spec/data/test_build/doc/data/subdir/resource.insubdir} +0 -0
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
#
|
|
2
|
-
# File '
|
|
2
|
+
# File 'Rakefile' created on 09 ott 2007 at 16:06:57.
|
|
3
3
|
#
|
|
4
4
|
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
5
|
#
|
|
6
6
|
# (C) 2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
7
|
#
|
|
8
|
+
# Rakefile for website project model
|
|
9
|
+
|
|
10
|
+
require 'tasks/all'
|
|
11
|
+
|
|
12
|
+
task :clobber => 'clean:all'
|
|
13
|
+
task :default => 'render:all'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
8
22
|
|
|
9
|
-
(>>>POINT<<<)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= @content_for_layout %>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The simpledocument model
|
|
3
|
+
render_in:
|
|
4
|
+
- html
|
|
5
|
+
- latex
|
|
6
|
+
- text
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
%% Dynamic generation of the Table of Contents.
|
|
10
|
+
%% Generate TOC only if formatter is different from html.
|
|
11
|
+
|
|
12
|
+
#IF: fmt==html-notemplate
|
|
13
|
+
#VAR: headings=plain
|
|
14
|
+
#ELSE
|
|
15
|
+
#LIST: toc
|
|
16
|
+
----8<----
|
|
17
|
+
#ENDIF
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
* Description of the model
|
|
21
|
+
|
|
22
|
+
This is a simple document model for ''dokkit''. You can use this model
|
|
23
|
+
as a base to create simple documents like tutorials, howtos, technical
|
|
24
|
+
reports, etc.
|
|
25
|
+
|
|
26
|
+
* Edit and render your document
|
|
27
|
+
|
|
28
|
+
To edit the content of the document simply edit
|
|
29
|
+
''simpledocument.deplate'' in ''doc/pages'' folder or create a new
|
|
30
|
+
file in ''doc/pages'' directory.
|
|
31
|
+
|
|
32
|
+
To get further information about the deplate wiki syntax please check
|
|
33
|
+
[[http://deplate.sf.net/deplate.html][deplate]] homepage.
|
|
34
|
+
|
|
35
|
+
To render this document in ''html'', ''tex'' and ''plain text'', open a terminal and type:
|
|
36
|
+
|
|
37
|
+
#Verbatim <<EOB
|
|
38
|
+
$ dokkit ## or rake
|
|
39
|
+
EOB
|
|
40
|
+
|
|
41
|
+
from the top-level directory or from any subdirectory contained in it.
|
|
42
|
+
|
|
43
|
+
You should get the output files in the 'output' folder.
|
|
44
|
+
|
|
45
|
+
* Rendering the modified parts of the document and cleaning up
|
|
46
|
+
|
|
47
|
+
Once you have rendered the document, running the ''dokkit'' command again will
|
|
48
|
+
appear to do nothing, because only changed resources are re-rendered.
|
|
49
|
+
To clean the output and start over run:
|
|
50
|
+
|
|
51
|
+
#Verbatim <<EOB
|
|
52
|
+
$ dokkit clobber
|
|
53
|
+
EOB
|
|
54
|
+
|
|
55
|
+
Note that if you modify any part of the document then you must re-run
|
|
56
|
+
''dokkit'' command in order to apply changes and to re-generate the
|
|
57
|
+
desidered output.
|
|
58
|
+
|
|
59
|
+
So, once you have modified your document, run:
|
|
60
|
+
|
|
61
|
+
#Verbatim <<EOB
|
|
62
|
+
$ dokkit ## or rake
|
|
63
|
+
EOB
|
|
64
|
+
|
|
65
|
+
Only the modified resources will be transformed.
|
|
66
|
+
|
|
67
|
+
* Configure the documentation environment
|
|
68
|
+
|
|
69
|
+
To configure your documentation environment edit the *.rake files in
|
|
70
|
+
''tasks'' folder.
|
|
71
|
+
|
|
72
|
+
* How to get other ''dokkit'' models
|
|
73
|
+
|
|
74
|
+
To search for other document models open a terminal and type:
|
|
75
|
+
|
|
76
|
+
#Verbatim <<EOB
|
|
77
|
+
$ gem list dokkit-model
|
|
78
|
+
EOB
|
|
79
|
+
|
|
80
|
+
To get a particular model named <model_name> run:
|
|
81
|
+
|
|
82
|
+
#Verbatim <<EOB
|
|
83
|
+
$ gem install dokkit-model-<model_name>
|
|
84
|
+
EOB
|
|
85
|
+
|
|
86
|
+
or check http://rubyforge.org/projects/dokkit/.
|
|
87
|
+
|
|
88
|
+
* What's next?
|
|
89
|
+
|
|
90
|
+
* See what else you can do by typing:
|
|
91
|
+
|
|
92
|
+
''$ dokkit --tasks''
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
- Modify the configuration of the document by editing
|
|
96
|
+
''doc/config/simpledocument.yaml''.
|
|
97
|
+
|
|
98
|
+
- Override the default layout creating in custom layouts in ''doc/layouts''.
|
|
99
|
+
|
|
100
|
+
For further information about ''dokkit'' see http://dokkit.rubyforge.org/.
|
|
101
|
+
|
|
102
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'dokkit/model'
|
|
2
|
+
|
|
3
|
+
MODEL = Dokkit::Model.init('simpledocument') do |model|
|
|
4
|
+
model.config.document_dir = 'doc/pages'
|
|
5
|
+
model.config.config_dir = 'doc/configs'
|
|
6
|
+
model.config.layout_dir = 'doc/layouts'
|
|
7
|
+
model.config.output_dir = 'output'
|
|
8
|
+
model.config.cache_dir = '.cache'
|
|
9
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'modeltask.rb' created on 23 feb 2008 at 20:45:10.
|
|
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 'yaml'
|
|
10
|
+
require 'dokkit'
|
|
11
|
+
require 'dokkit/dokkitlib'
|
|
12
|
+
|
|
13
|
+
module Dokkit
|
|
14
|
+
class ModelTask < DokkitLib
|
|
15
|
+
attr_reader :models
|
|
16
|
+
def initialize(model, namespace = 'model')
|
|
17
|
+
super(model, namespace)
|
|
18
|
+
end
|
|
19
|
+
def pre_block_configuration
|
|
20
|
+
@config.local_dir ||= DEFAULT_LOCAL_DIR
|
|
21
|
+
@config.search_in ||= [:dokkit_dir, :local_dir]
|
|
22
|
+
end
|
|
23
|
+
def post_block_configuration
|
|
24
|
+
fetch_models
|
|
25
|
+
end
|
|
26
|
+
def dokkit_dir
|
|
27
|
+
lib = nil
|
|
28
|
+
unless lib = ENV['DOKKIT_LIB']
|
|
29
|
+
$:.each do |it|
|
|
30
|
+
if File.exists?(File.join(it, 'dokkit/app.rb'))
|
|
31
|
+
lib = it
|
|
32
|
+
break
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
lib
|
|
37
|
+
end
|
|
38
|
+
def builtin_model_dir
|
|
39
|
+
File.join(dokkit_dir, 'dokkit/models')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def from_location(location)
|
|
45
|
+
return builtin_model_dir if location == :dokkit_dir
|
|
46
|
+
return File.expand_path(File.join('~', @config.local_dir)) if location == :local_dir
|
|
47
|
+
end
|
|
48
|
+
def fetch_models
|
|
49
|
+
@models = { }
|
|
50
|
+
config.search_in.each do |location|
|
|
51
|
+
Dir.glob(File.join(from_location(location), '**/Rakefile')).each do |model|
|
|
52
|
+
@models[model.scan(/models\/(.*)\/Rakefile/).flatten.to_s] = File.dirname(model)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
def define_dokkit_list_model_task
|
|
57
|
+
desc 'List the installed models'
|
|
58
|
+
dokkit_task 'list' do
|
|
59
|
+
@models.each do |modelname, path|
|
|
60
|
+
@logger.info("Found model '#{modelname}' in #{path}")
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
def define_dokkit_create_task
|
|
65
|
+
desc 'Bootstrap a new documentation project'
|
|
66
|
+
dokkit_task 'create', :model do |t, args|
|
|
67
|
+
model = args.model || DEFAULT_MODEL
|
|
68
|
+
if ARGV.size == 2
|
|
69
|
+
dest_dir = t.application.top_level_tasks.pop
|
|
70
|
+
else
|
|
71
|
+
@logger.error('A target directory must be provided.')
|
|
72
|
+
end
|
|
73
|
+
@logger.error("Directory '#{dest_dir}' exists.") if File.exists?(dest_dir)
|
|
74
|
+
@logger.error("Model '#{model}' not found.") unless @models[model]
|
|
75
|
+
@logger.info("Create '#{dest_dir}' based on '#{model}' model.")
|
|
76
|
+
cp_r(@models[model], dest_dir)
|
|
77
|
+
File.open(File.join(dest_dir, 'tasks/model.yaml'), 'w') do |file|
|
|
78
|
+
file << { 'name' => model, 'from' => @models[model] }.to_yaml
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'pathhelper.rb' created on 15 feb 2008 at 16:33:15.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C) 2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
module Dokkit
|
|
10
|
+
module PathHelper
|
|
11
|
+
def strip_ext(fn)
|
|
12
|
+
ext = File.extname(fn)
|
|
13
|
+
fn.sub(/#{ext}/, '')
|
|
14
|
+
end
|
|
15
|
+
# Get a new filename from a given filename substituting the
|
|
16
|
+
# sub_dir portion of the given file with new_dir and the file
|
|
17
|
+
# extension with new_ext.
|
|
18
|
+
#
|
|
19
|
+
# Example:
|
|
20
|
+
#
|
|
21
|
+
# filename_helper('output/subdir/document.output', 'output', 'doc/pages', '.in')
|
|
22
|
+
#
|
|
23
|
+
# should return:
|
|
24
|
+
#
|
|
25
|
+
# => 'doc/pages/subdir/document.in'
|
|
26
|
+
#
|
|
27
|
+
def filename_helper(fn, sub_dir, new_dir, new_ext = '')
|
|
28
|
+
ext = File.extname(fn).sub(/^\./,'') # strip leading dot
|
|
29
|
+
new_fn = fn.sub(/#{sub_dir}/, new_dir)
|
|
30
|
+
new_fn = new_fn << new_ext unless new_ext.empty?
|
|
31
|
+
new_fn
|
|
32
|
+
end
|
|
33
|
+
def output_fn_helper(fn, output_ext, config)
|
|
34
|
+
filename_helper(fn, config.document_dir, config.output_dir, output_ext)
|
|
35
|
+
end
|
|
36
|
+
def layout_fn_helper(fn, layout_ext, config)
|
|
37
|
+
filename_helper(fn, config.document_dir, config.layout_dir, layout_ext)
|
|
38
|
+
end
|
|
39
|
+
def config_fn_helper(fn, config)
|
|
40
|
+
filename_helper(fn, config.document_dir, config.config_dir, '.yaml')
|
|
41
|
+
end
|
|
42
|
+
def data_fn_helper(fn, config)
|
|
43
|
+
filename_helper(fn, config.data_dir, config.output_dir)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'recursivemerge.rb' created on 17 mar 2008 at 09:37:25.
|
|
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
|
+
class Hash
|
|
10
|
+
def recursive_store(key, value, other_value = nil)
|
|
11
|
+
if(value.class == Hash && other_value.class == Hash)
|
|
12
|
+
value.recursive_merge other_value
|
|
13
|
+
else
|
|
14
|
+
store(key, other_value)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
# Hash#recursive_merge merges two arbitrarily deep hashes into a single hash.
|
|
18
|
+
# The hash is followed recursively, so that deeply nested hashes that are at
|
|
19
|
+
# the same level will be merged when the parent hashes are merged.
|
|
20
|
+
def recursive_merge!(other_hash, &blk)
|
|
21
|
+
if block_given?
|
|
22
|
+
merge!(other_hash, &blk)
|
|
23
|
+
else
|
|
24
|
+
merge!(other_hash) do |key, value, other_value|
|
|
25
|
+
recursive_store(key, value, other_value)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
# Non-destructive version of Hash#recursive_merge method.
|
|
30
|
+
def recursive_merge(other_hash, &blk)
|
|
31
|
+
clone.recursive_merge!(other_hash, &blk)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module ConfigHash
|
|
36
|
+
def recursive_store(key, value, other_value)
|
|
37
|
+
unless (key.to_sym == :layout || key.to_sym == :config)
|
|
38
|
+
if(value.class == Hash && other_value.class == Hash)
|
|
39
|
+
value.extend ConfigHash
|
|
40
|
+
other_value.extend ConfigHash
|
|
41
|
+
value.recursive_merge other_value
|
|
42
|
+
elsif(value.class == Array && other_value.class == Array)
|
|
43
|
+
value.concat(other_value)
|
|
44
|
+
elsif(value.class == String && other_value.class == Array)
|
|
45
|
+
value.to_a.concat(other_value)
|
|
46
|
+
elsif(value.class == Array && other_value.class == String)
|
|
47
|
+
value << other_value
|
|
48
|
+
else
|
|
49
|
+
store(key, other_value)
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
if(value.class == Hash && other_value.class == Hash)
|
|
53
|
+
value.recursive_merge other_value
|
|
54
|
+
else
|
|
55
|
+
store(key, other_value)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'rendertask.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
|
+
require 'dokkit/document'
|
|
11
|
+
require 'dokkit/pathhelper'
|
|
12
|
+
require 'dokkit/dokkitlib'
|
|
13
|
+
require 'dokkit/fileselection'
|
|
14
|
+
|
|
15
|
+
module Dokkit
|
|
16
|
+
class RenderTask < DokkitLib
|
|
17
|
+
attr_accessor :documents, :data
|
|
18
|
+
def initialize(model, namespace = 'render')
|
|
19
|
+
super(model, namespace, { :check_dir => true })
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def pre_block_configuration
|
|
25
|
+
@config.document_dir ||= Dokkit::DEFAULT_DOCUMENT_DIR
|
|
26
|
+
@config.data_dir ||= Dokkit::DEFAULT_DATA_DIR
|
|
27
|
+
@config.output_dir ||= Dokkit::DEFAULT_OUTPUT_DIR
|
|
28
|
+
@config.layout_dir ||= Dokkit::DEFAULT_LAYOUT_DIR
|
|
29
|
+
@config.config_dir ||= Dokkit::DEFAULT_CONFIG_DIR
|
|
30
|
+
@config.cache_dir ||= Dokkit::DEFAULT_CACHE_DIR
|
|
31
|
+
@documents = FileSelection.new(@config.document_dir) do |fs|
|
|
32
|
+
fs.include('*')
|
|
33
|
+
fs.exclude('*.yaml')
|
|
34
|
+
end
|
|
35
|
+
@documents.extend ExtMapping
|
|
36
|
+
@data = FileSelection.new(@config.data_dir) { |fs| fs.include('*') }
|
|
37
|
+
end
|
|
38
|
+
def post_block_configuration
|
|
39
|
+
data.dir = @config.data_dir
|
|
40
|
+
documents.dir = @config.document_dir
|
|
41
|
+
end
|
|
42
|
+
def define_document_task(document)
|
|
43
|
+
targets = document.targets
|
|
44
|
+
source_fn = document.document
|
|
45
|
+
targets.each do |format, target_fn|
|
|
46
|
+
file target_fn => document.prerequisites[format] do
|
|
47
|
+
dn = File.dirname(target_fn)
|
|
48
|
+
mkdir_p(dn, :verbose => false) unless File.exists?(dn)
|
|
49
|
+
@logger.info("Render #{target_fn}")
|
|
50
|
+
File.open(target_fn, 'w+') do |f|
|
|
51
|
+
f << document.render(format)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
targets.values
|
|
56
|
+
end
|
|
57
|
+
def define_document_tasks
|
|
58
|
+
unless documents.files.empty?
|
|
59
|
+
documents.files.collect do |source_fn|
|
|
60
|
+
blk = documents.extmapping[source_fn] if documents.extmapping
|
|
61
|
+
define_document_task Document.new(source_fn, config, &blk)
|
|
62
|
+
end
|
|
63
|
+
else @logger.error("No documents found in '#{@config.document_dir}'")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
def define_dokkit_render_doc_task
|
|
67
|
+
dokkit_task :doc => define_document_tasks.flatten!
|
|
68
|
+
task(:doc).comment = 'Render documents'
|
|
69
|
+
end
|
|
70
|
+
def define_dokkit_render_all_task
|
|
71
|
+
dokkit_task :all => ["#{@ns}:doc", "#{@ns}:data"]
|
|
72
|
+
task(:all).comment = 'Render documents and copy data'
|
|
73
|
+
end
|
|
74
|
+
def define_data_task(source_fn)
|
|
75
|
+
target_fn = data_fn_helper(source_fn, config)
|
|
76
|
+
file target_fn => source_fn do
|
|
77
|
+
dn = File.dirname(target_fn)
|
|
78
|
+
mkdir_p(dn, :verbose => false) unless File.exists?(dn)
|
|
79
|
+
@logger.info("Copy #{target_fn}")
|
|
80
|
+
cp(source_fn, target_fn, :preserve => true, :verbose => false)
|
|
81
|
+
end
|
|
82
|
+
target_fn
|
|
83
|
+
end
|
|
84
|
+
def define_data_tasks
|
|
85
|
+
unless data.files.empty?
|
|
86
|
+
data.files.collect do |source_fn|
|
|
87
|
+
define_data_task(source_fn)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
def define_dokkit_copy_all_data_task
|
|
92
|
+
if data_tasks = define_data_tasks
|
|
93
|
+
dokkit_task :data => data_tasks
|
|
94
|
+
else
|
|
95
|
+
dokkit_task :data
|
|
96
|
+
end
|
|
97
|
+
task(:data).comment = 'Copy data files only'
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#
|
|
2
|
+
# File 'resourcemanager.rb' created on 06 feb 2008 at 21:44:10.
|
|
3
|
+
#
|
|
4
|
+
# See 'dokkit.rb' or +LICENSE+ for licence information.
|
|
5
|
+
#
|
|
6
|
+
# (C) 2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'dokkit'
|
|
10
|
+
require 'dokkit/hash'
|
|
11
|
+
require 'dokkit/cachemanager'
|
|
12
|
+
require 'dokkit/fileselection'
|
|
13
|
+
|
|
14
|
+
DOCUMENT_DIR = 'doc/pages/'
|
|
15
|
+
OUTPUT_DIR = 'output/'
|
|
16
|
+
LAYOUT_DIR = 'doc/layouts/'
|
|
17
|
+
CONFIG_DIR = 'doc/configs/'
|
|
18
|
+
DATA_DIR = 'doc/data/'
|
|
19
|
+
|
|
20
|
+
module Dokkit
|
|
21
|
+
module DocumentManager
|
|
22
|
+
attr_accessor :document_dir
|
|
23
|
+
attr_accessor :documents
|
|
24
|
+
def documentmanager_defaults
|
|
25
|
+
@document_dir = DOCUMENT_DIR
|
|
26
|
+
@documents = FileSelection.new(@document_dir) { |fs| fs.include('*') }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
module OutputManager
|
|
30
|
+
attr_accessor :output_dir
|
|
31
|
+
attr_accessor :output_ext
|
|
32
|
+
attr_reader :outputs
|
|
33
|
+
def outputmanager_defaults
|
|
34
|
+
@output_dir = OUTPUT_DIR
|
|
35
|
+
@output_ext = '.html'
|
|
36
|
+
@outputs = { }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def collect_outputs
|
|
42
|
+
@documents.files.each do |document|
|
|
43
|
+
if(@config[document]['document'].has_key?('render'))
|
|
44
|
+
output_ext = @config[document]['document']['render']['ext'] if @config[document]['document']['render']['ext']
|
|
45
|
+
output_dir = @config[document]['document']['render']['output'] if @config[document]['document']['render']['output']
|
|
46
|
+
@outputs[document] = File.join(@output_dir, output_dir, File.basename(document)) + output_ext
|
|
47
|
+
else
|
|
48
|
+
@outputs[document] = output_fn_helper(document)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
def output_fn_helper(fn, output_ext = @output_ext)
|
|
53
|
+
filename_helper(fn, document_dir, output_dir, output_ext)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
module DataManager
|
|
57
|
+
attr_accessor :data_dir
|
|
58
|
+
attr_reader :data
|
|
59
|
+
|
|
60
|
+
def datamanager_defaults
|
|
61
|
+
@data_dir = DATA_DIR
|
|
62
|
+
@data = Dokkit::FileSelection.new(@data_dir) { |fs| fs.include('*') }
|
|
63
|
+
end
|
|
64
|
+
def data_fn_helper(fn)
|
|
65
|
+
filename_helper(fn, data_dir, output_dir)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
module ConfigManager
|
|
69
|
+
attr_accessor :config_dir
|
|
70
|
+
attr_reader :configs
|
|
71
|
+
attr_reader :config
|
|
72
|
+
def configmanager_defaults
|
|
73
|
+
@config_dir = 'doc/configs/'
|
|
74
|
+
@configs = { }
|
|
75
|
+
@config = { }
|
|
76
|
+
end
|
|
77
|
+
def resolve_common_configs(document)
|
|
78
|
+
FileList.new(File.join(document_dir, '**/COMMON.yaml')).exclude(/#{File.dirname(document)}\/.*\/.*/).reverse!
|
|
79
|
+
end
|
|
80
|
+
def collect_configs
|
|
81
|
+
@documents.files.each do |document|
|
|
82
|
+
@configs[document] = []
|
|
83
|
+
@configs[document] << (config_fn_helper(document)) if File.exists?(config_fn_helper(document))
|
|
84
|
+
@configs[document].concat(resolve_common_configs(document))
|
|
85
|
+
@configs[document] << (document + '.yaml') if File.exists?(document + '.yaml')
|
|
86
|
+
end
|
|
87
|
+
@configs
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def load_configs
|
|
93
|
+
collect_configs.each do |document, configs|
|
|
94
|
+
@config[document] = { }
|
|
95
|
+
configs.each do |fn|
|
|
96
|
+
@config[document].recursive_merge!(YAML::load(File.open(fn)))
|
|
97
|
+
if @config[document].has_key?('document')
|
|
98
|
+
if @config[document]['document'].has_key?('config')
|
|
99
|
+
@configs[document] << @config[document]['document']['config'] + '.yaml'
|
|
100
|
+
@config[document]['document'].delete('config')
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
@config
|
|
106
|
+
end
|
|
107
|
+
def config_fn_helper(fn)
|
|
108
|
+
filename_helper(fn, document_dir, config_dir, '.yaml')
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
module LayoutManager
|
|
112
|
+
attr_accessor :layout_dir
|
|
113
|
+
attr_reader :layouts
|
|
114
|
+
def layoutmanager_defaults
|
|
115
|
+
@layout_dir = 'doc/layouts/'
|
|
116
|
+
@layouts = { }
|
|
117
|
+
end
|
|
118
|
+
def collect_layouts
|
|
119
|
+
@documents.files.each do |document|
|
|
120
|
+
@layouts[document] = []
|
|
121
|
+
@layouts[document] << (layout_fn_helper(document)) if File.exists?(layout_fn_helper(document))
|
|
122
|
+
@layouts[document] << (document + '.html') if File.exists?(document + '.html')
|
|
123
|
+
if @config[document]['document']['layout']
|
|
124
|
+
@layouts[document] = (@config[document]['document']['layout'] + '.html') if File.exists?(@config[document]['document']['layout'] + '.html')
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
@layouts
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
def layout_fn_helper(fn)
|
|
133
|
+
filename_helper(fn, document_dir, layout_dir, '.html')
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
class ResourceManager
|
|
137
|
+
include DocumentManager, OutputManager, ConfigManager, LayoutManager, DataManager
|
|
138
|
+
def initialize
|
|
139
|
+
set_defaults
|
|
140
|
+
|
|
141
|
+
yield self if block_given?
|
|
142
|
+
|
|
143
|
+
load_configs
|
|
144
|
+
collect_outputs
|
|
145
|
+
collect_layouts
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def set_defaults
|
|
149
|
+
documentmanager_defaults
|
|
150
|
+
outputmanager_defaults
|
|
151
|
+
configmanager_defaults
|
|
152
|
+
layoutmanager_defaults
|
|
153
|
+
datamanager_defaults
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
private
|
|
157
|
+
|
|
158
|
+
# Get a new filename from a given filename substituting the
|
|
159
|
+
# sub_dir portion of the given file with new_dir and the file
|
|
160
|
+
# extension with new_ext.
|
|
161
|
+
#
|
|
162
|
+
# Example:
|
|
163
|
+
#
|
|
164
|
+
# filename_helper('output/subdir/document.output', 'output', 'doc/pages', '.in')
|
|
165
|
+
#
|
|
166
|
+
# should return:
|
|
167
|
+
#
|
|
168
|
+
# => 'doc/pages/subdir/document.in'
|
|
169
|
+
#
|
|
170
|
+
def filename_helper(fn, sub_dir, new_dir, new_ext = '')
|
|
171
|
+
ext = File.extname(fn).sub(/^\./,'') # strip leading dot
|
|
172
|
+
new_fn = fn.sub(/#{sub_dir}/, new_dir)
|
|
173
|
+
new_fn = new_fn << new_ext unless new_ext.empty? #new_fn.sub(/#{ext}$/, new_ext) unless new_ext.empty?
|
|
174
|
+
new_fn
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|