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.
Files changed (180) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +90 -105
  3. data/README.txt +27 -7
  4. data/Rakefile +2 -3
  5. data/bin/dokkit +3 -2
  6. data/lib/dokkit/application.rb +159 -0
  7. data/lib/dokkit/cache/cache.rb +53 -0
  8. data/lib/dokkit/{models/simpledocument/model/Rakefile → cache.rb} +3 -15
  9. data/lib/dokkit/environment/basic.rb +156 -0
  10. data/lib/dokkit/environment/helpers/extmap.rb +29 -0
  11. data/lib/dokkit/environment/helpers/fileselection.rb +53 -0
  12. data/lib/dokkit/environment/helpers.rb +20 -0
  13. data/{spec/data/test_build/Rakefile → lib/dokkit/environment.rb} +4 -15
  14. data/lib/dokkit/factory/factory.rb +56 -0
  15. data/lib/dokkit/factory.rb +9 -0
  16. data/lib/dokkit/filters/deplate.rb +25 -20
  17. data/lib/dokkit/filters/maruku.rb +6 -5
  18. data/lib/dokkit/filters/nil.rb +7 -6
  19. data/lib/dokkit/filters.rb +5 -27
  20. data/lib/dokkit/hash.rb +82 -0
  21. data/lib/dokkit/{logger.rb → logging/logger.rb} +30 -24
  22. data/lib/dokkit/logging/observers/console.rb +52 -0
  23. data/lib/dokkit/{extension/extension.rb → logging/observers.rb} +7 -5
  24. data/lib/dokkit/logging.rb +11 -0
  25. data/lib/dokkit/models/simple/Rakefile +6 -0
  26. data/lib/dokkit/models/simple/doc/data/html/css/style.css +3 -0
  27. data/lib/dokkit/models/simple/doc/data/latex/deplate.sty +46 -0
  28. data/lib/dokkit/models/simple/doc/layouts/simple.html +9 -0
  29. data/lib/dokkit/models/simple/doc/layouts/simple.latex +11 -0
  30. data/lib/dokkit/models/simple/doc/pages/simple.deplate +80 -0
  31. data/lib/dokkit/models/simple/setup/setup.rb +10 -0
  32. data/lib/dokkit/resource/data.rb +36 -0
  33. data/lib/dokkit/resource/document.rb +385 -0
  34. data/lib/dokkit/resource/extensions/builtin.rb +19 -0
  35. data/lib/dokkit/resource/extensions/html.rb +22 -0
  36. data/lib/dokkit/resource/extensions/url.rb +25 -0
  37. data/lib/dokkit/{filters/base.rb → resource/extensions.rb} +7 -8
  38. data/lib/dokkit/resource/filenamehelper.rb +28 -0
  39. data/lib/dokkit/resource.rb +11 -0
  40. data/lib/dokkit/tasklib/clean.rb +73 -0
  41. data/lib/dokkit/tasklib/render.rb +137 -0
  42. data/lib/dokkit/tasklib.rb +11 -0
  43. data/lib/dokkit.rb +26 -29
  44. data/spec/dokkit/application_spec.rb +141 -0
  45. data/spec/dokkit/cache/cache_spec.rb +87 -0
  46. data/spec/dokkit/dokkit_spec.rb +20 -0
  47. data/spec/dokkit/environment/basic_spec.rb +135 -0
  48. data/spec/dokkit/environment/helpers/extmap_spec.rb +52 -0
  49. data/spec/dokkit/environment/helpers/fileselection_spec.rb +80 -0
  50. data/spec/dokkit/environment/test_data/doc/pages/document_1.yaml +3 -0
  51. data/spec/dokkit/factory/factory_spec.rb +69 -0
  52. data/spec/{filter_deplate_spec.rb → dokkit/filters/deplate_spec.rb} +7 -8
  53. data/spec/{filter_maruku_spec.rb → dokkit/filters/maruku_spec.rb} +3 -4
  54. data/spec/{filter_nil_spec.rb → dokkit/filters/nil_spec.rb} +3 -4
  55. data/spec/{recursivemerge_spec.rb → dokkit/hash_spec.rb} +25 -27
  56. data/spec/{logger_spec.rb → dokkit/logging/logger_spec.rb} +35 -47
  57. data/spec/{consolelog_spec.rb → dokkit/logging/observers/console_spec.rb} +14 -15
  58. data/spec/dokkit/resource/data_spec.rb +32 -0
  59. data/spec/dokkit/resource/document_spec.rb +485 -0
  60. data/spec/dokkit/resource/extensions/html_spec.rb +35 -0
  61. data/spec/dokkit/resource/extensions/url_spec.rb +29 -0
  62. data/spec/{filehelper_spec.rb → dokkit/resource/filenamehelper_spec.rb} +12 -13
  63. data/spec/dokkit/resource/test_data/doc/configs/config_1.yaml +3 -0
  64. data/spec/dokkit/resource/test_data/doc/configs/config_2.yaml +3 -0
  65. data/spec/dokkit/resource/test_data/doc/configs/required.yaml +3 -0
  66. data/spec/dokkit/resource/test_data/doc/configs/subdir/document.yaml +3 -0
  67. data/spec/dokkit/resource/test_data/doc/layouts/container.html +6 -0
  68. data/spec/dokkit/resource/test_data/doc/layouts/layout.html +6 -0
  69. data/spec/{data/test_build/doc/layouts → dokkit/resource/test_data/doc/layouts/nested}/nested.html +2 -1
  70. data/spec/dokkit/resource/test_data/doc/layouts/subdir/document.html +6 -0
  71. data/spec/dokkit/resource/test_data/doc/pages/COMMON.yaml +4 -0
  72. data/spec/dokkit/resource/test_data/doc/pages/document_with_many_config.ext +7 -0
  73. data/spec/dokkit/resource/test_data/doc/pages/document_with_many_errors.ext +12 -0
  74. data/spec/dokkit/resource/test_data/doc/pages/document_with_many_targets.ext +19 -0
  75. data/spec/dokkit/resource/test_data/doc/pages/document_with_nested_layout.ext +13 -0
  76. data/spec/dokkit/resource/test_data/doc/pages/document_with_nil_target.ext +5 -0
  77. data/spec/dokkit/resource/test_data/doc/pages/document_with_not_defined_target.ext +6 -0
  78. data/spec/dokkit/resource/test_data/doc/pages/document_with_one_target.ext +8 -0
  79. data/spec/dokkit/resource/test_data/doc/pages/subdir/COMMON.yaml +3 -0
  80. data/spec/dokkit/resource/test_data/doc/pages/subdir/document.ext +8 -0
  81. data/spec/dokkit/resource/test_data/doc/pages/subdir/document.yaml +5 -0
  82. data/spec/dokkit/tasklib/clean_spec.rb +75 -0
  83. data/spec/dokkit/tasklib/render_spec.rb +125 -0
  84. data/spec/dokkit/tasklib/test_data/doc/pages/document_2 +0 -0
  85. data/spec/dokkit/test_data/dokkit/models/model1/doc/pages/model1 +0 -0
  86. data/spec/dokkit/test_data/dokkit/models/model2/doc/pages/model2 +0 -0
  87. data/spec/spec.opts +4 -0
  88. data/spec/spec_helper.rb +120 -47
  89. metadata +94 -117
  90. data/lib/dokkit/app.rb +0 -131
  91. data/lib/dokkit/builtintask.rb +0 -85
  92. data/lib/dokkit/cachemanager.rb +0 -61
  93. data/lib/dokkit/cleantask.rb +0 -51
  94. data/lib/dokkit/consolelog.rb +0 -42
  95. data/lib/dokkit/defaults.rb +0 -19
  96. data/lib/dokkit/deplate/fmt/html-notemplate.rb +0 -21
  97. data/lib/dokkit/deplate/fmt/latex-notemplate.rb +0 -24
  98. data/lib/dokkit/document.rb +0 -221
  99. data/lib/dokkit/dokkitlib.rb +0 -68
  100. data/lib/dokkit/extension/filehelper.rb +0 -25
  101. data/lib/dokkit/fileselection.rb +0 -44
  102. data/lib/dokkit/filters/all.rb +0 -18
  103. data/lib/dokkit/model.rb +0 -34
  104. data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.html +0 -9
  105. data/lib/dokkit/models/simpledocument/model/doc/pages/simpledocument.deplate +0 -102
  106. data/lib/dokkit/models/simpledocument/model/tasks/all.rb +0 -3
  107. data/lib/dokkit/models/simpledocument/model/tasks/clean.rake +0 -3
  108. data/lib/dokkit/models/simpledocument/model/tasks/render.rake +0 -8
  109. data/lib/dokkit/models/simpledocument/model/tasks/setup.rb +0 -9
  110. data/lib/dokkit/modeltask.rb +0 -83
  111. data/lib/dokkit/pathhelper.rb +0 -46
  112. data/lib/dokkit/recursivemerge.rb +0 -59
  113. data/lib/dokkit/rendertask.rb +0 -101
  114. data/lib/dokkit/resourcemanager.rb +0 -177
  115. data/lib/dokkit/taskconfig.rb +0 -39
  116. data/lib/dokkit/templatetask.rb +0 -37
  117. data/spec/app_spec.rb +0 -55
  118. data/spec/builtintask_spec.rb +0 -114
  119. data/spec/cachemanager_spec.rb +0 -107
  120. data/spec/cleantask_spec.rb +0 -72
  121. data/spec/data/test_build/doc/configs/document_1.yaml +0 -3
  122. data/spec/data/test_build/doc/configs/required.yaml +0 -3
  123. data/spec/data/test_build/doc/configs/subdir/document_4.yaml +0 -3
  124. data/spec/data/test_build/doc/layouts/document_1.html +0 -9
  125. data/spec/data/test_build/doc/layouts/document_with_partials.html +0 -9
  126. data/spec/data/test_build/doc/layouts/layout.html +0 -8
  127. data/spec/data/test_build/doc/layouts/layout.html.backup +0 -8
  128. data/spec/data/test_build/doc/layouts/partials/partial.html +0 -4
  129. data/spec/data/test_build/doc/pages/COMMON.yaml +0 -6
  130. data/spec/data/test_build/doc/pages/document_1 +0 -20
  131. data/spec/data/test_build/doc/pages/document_1.dep +0 -4
  132. data/spec/data/test_build/doc/pages/document_1.yaml +0 -11
  133. data/spec/data/test_build/doc/pages/document_2 +0 -9
  134. data/spec/data/test_build/doc/pages/document_2.yaml +0 -6
  135. data/spec/data/test_build/doc/pages/document_3 +0 -13
  136. data/spec/data/test_build/doc/pages/document_7 +0 -4
  137. data/spec/data/test_build/doc/pages/document_7.yaml +0 -5
  138. data/spec/data/test_build/doc/pages/document_extended +0 -1
  139. data/spec/data/test_build/doc/pages/document_nested +0 -6
  140. data/spec/data/test_build/doc/pages/document_nested.yaml +0 -5
  141. data/spec/data/test_build/doc/pages/document_nolayout.ext +0 -3
  142. data/spec/data/test_build/doc/pages/document_nolayout.yaml +0 -2
  143. data/spec/data/test_build/doc/pages/document_with_partials +0 -3
  144. data/spec/data/test_build/doc/pages/document_with_partials.yaml +0 -2
  145. data/spec/data/test_build/doc/pages/partials/COMMON.yaml +0 -5
  146. data/spec/data/test_build/doc/pages/partials/circular_partial +0 -2
  147. data/spec/data/test_build/doc/pages/partials/circular_partial.yaml +0 -3
  148. data/spec/data/test_build/doc/pages/partials/partial +0 -2
  149. data/spec/data/test_build/doc/pages/subdir/COMMON.yaml +0 -2
  150. data/spec/data/test_build/doc/pages/subdir/document_4 +0 -11
  151. data/spec/data/test_build/doc/pages/subdir/subdir/COMMON.yaml +0 -2
  152. data/spec/data/test_build/doc/pages/subdir/subdir/document_6 +0 -3
  153. data/spec/data/test_build/tasks/all.rb +0 -3
  154. data/spec/data/test_build/tasks/clean.rake +0 -3
  155. data/spec/data/test_build/tasks/render.rake +0 -8
  156. data/spec/data/test_build/tasks/setup.rb +0 -9
  157. data/spec/data/test_build/tasks/template.rake +0 -3
  158. data/spec/document_spec.rb +0 -321
  159. data/spec/dokkitlib_spec.rb +0 -63
  160. data/spec/fileselection_spec.rb +0 -101
  161. data/spec/filter_base_spec.rb +0 -29
  162. data/spec/filters_spec.rb +0 -37
  163. data/spec/model_spec.rb +0 -45
  164. data/spec/pathhelper_spec.rb +0 -62
  165. data/spec/rendertask_spec.rb +0 -374
  166. data/spec/taskconfig_spec.rb +0 -45
  167. data/spec/templatetask_spec.rb +0 -72
  168. /data/lib/dokkit/models/{simpledocument/model/doc/configs/simpledocument.yaml → simple/doc/configs/simple.yaml} +0 -0
  169. /data/lib/dokkit/models/{simpledocument/model/doc/layouts/simpledocument.text → simple/doc/layouts/simple.text} +0 -0
  170. /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
  171. /data/spec/{data/test_build/doc/data/resource → dokkit/environment/helpers/test_data/doc/pages/document_2} +0 -0
  172. /data/spec/{data/test_build/doc/data/resource.exclude → dokkit/environment/helpers/test_data/doc/pages/document_3.ext_3} +0 -0
  173. /data/spec/{data/test_build/doc/data/subdir/resource.insubdir → dokkit/environment/test_data/doc/data/data} +0 -0
  174. /data/spec/{data/test_build/doc/layouts/layout → dokkit/environment/test_data/doc/pages/document_1} +0 -0
  175. /data/spec/{data/test_build/doc/pages/document_2.dep → dokkit/environment/test_data/doc/pages/document_2} +0 -0
  176. /data/spec/{data/test_build/doc/pages/document_5.exclude → dokkit/environment/test_data/doc/pages/subdir/document_1} +0 -0
  177. /data/{lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.latex → spec/dokkit/resource/test_data/doc/layouts/layout.latex} +0 -0
  178. /data/spec/{data/test_build/doc/layouts/document_1.latex → dokkit/resource/test_data/doc/layouts/subdir/document.latex} +0 -0
  179. /data/spec/{data/test_build/templates/layouts/layout → dokkit/tasklib/test_data/doc/data/data_1} +0 -0
  180. /data/spec/{data/test_build/templates/pages/template → dokkit/tasklib/test_data/doc/pages/document_1} +0 -0
@@ -0,0 +1,52 @@
1
+ #
2
+ # File 'consolelog.rb' created on 23 feb 2008 at 16:39:59.
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/logging/logger'
10
+
11
+ module Dokkit
12
+ module Logging
13
+ module Observer
14
+
15
+ class Console
16
+
17
+ class << self
18
+ def logger
19
+ Console.new(Logger.new).logger
20
+ end
21
+ end
22
+
23
+ attr_reader :logger
24
+
25
+ def initialize(logger)
26
+ @logger = logger
27
+ @logger.attach(self)
28
+ end
29
+
30
+ def update
31
+ case last_message[:level]
32
+ when Logging::ERROR
33
+ fail "[#{Time.now.asctime}][ERROR] #{last_message[:text]}"
34
+ when Logging::WARNING
35
+ warn "[#{Time.now.asctime}][WARNING] #{last_message[:text]}"
36
+ when Logging::INFO
37
+ puts "[#{Time.now.asctime}][INFO] #{last_message[:text]}"
38
+ when Logging::DEBUG
39
+ puts "[#{Time.now.asctime}][DEBUG] #{last_message[:text]}"
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def last_message
46
+ @logger.last_message
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,15 +1,17 @@
1
1
  #
2
- # File 'extension.rb' created on 28 feb 2008 at 16:39:38.
2
+ # File 'observers.rb' created on 04 mag 2008 at 17:45:50.
3
3
  #
4
4
  # See 'dokkit.rb' or +LICENSE+ for licence information.
5
5
  #
6
- # (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
+ # (C)2006-2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
7
  #
8
8
 
9
- require 'dokkit'
9
+ require 'dokkit/logging/observers/console'
10
10
 
11
11
  module Dokkit
12
- module Extension
13
- # space left blank
12
+ module Logging
13
+ module Observer
14
+
15
+ end
14
16
  end
15
17
  end
@@ -0,0 +1,11 @@
1
+ #
2
+ # File 'logging.rb' created on 04 mag 2008 at 17:39:01.
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/logging/logger'
10
+ require 'dokkit/logging/observers'
11
+
@@ -0,0 +1,6 @@
1
+
2
+ require 'rake/clean'
3
+ require 'setup/setup'
4
+
5
+ task :clobber => [:clean, 'clean:all']
6
+ task :default => 'render:all'
@@ -0,0 +1,46 @@
1
+ \newcommand{\customListPrefs}{\setlength{\parsep}{0cm}\setlength{\itemsep}{0cm}}
2
+ \newenvironment{customList}{\begin{list}{}{\customListPrefs{}}}{\end{list}}
3
+ \newcommand{\customItem}[2]{\item[#1] #2}
4
+
5
+ \newenvironment{tasklist}{\begin{list}{}{\customListPrefs{}}}{\end{list}}
6
+ \newcommand{\task}[2]{\item[\textbf{#1}] #2}
7
+
8
+ \definecolor{taskA}{rgb}{1,.5,.5}
9
+ \definecolor{taskB}{rgb}{.5,1,.5}
10
+ \definecolor{taskC}{rgb}{.5,.5,1}
11
+ \definecolor{taskD}{rgb}{.5,1,1}
12
+ \definecolor{taskE}{rgb}{1,.5,1}
13
+ \definecolor{taskF}{rgb}{1,1,.5}
14
+ \definecolor{taskdone}{rgb}{.5,.5,.5}
15
+
16
+ \newcommand{\taskdone}[1]{{\footnotesize\textcolor{taskdone}{#1}}}
17
+ \newcommand{\taskA}[1]{\colorbox{taskA}{#1}}
18
+ \newcommand{\taskB}[1]{\colorbox{taskB}{#1}}
19
+ \newcommand{\taskC}[1]{\colorbox{taskC}{#1}}
20
+ \newcommand{\taskD}[1]{\colorbox{taskD}{#1}}
21
+ \newcommand{\taskE}[1]{\colorbox{taskE}{#1}}
22
+ \newcommand{\taskF}[1]{\colorbox{taskF}{#1}}
23
+
24
+ \newcommand{\emphStyle}{\em}
25
+ \newcommand{\emphSpan}[1]{\emph{#1}}
26
+ \newcommand{\boldSpan}[1]{\textbf{#1}}
27
+ \newcommand{\remoteSpan}[1]{#1}
28
+
29
+ \newenvironment{overlayBlock}{}{}
30
+ \newenvironment{scriptsizeBlock}{\scriptsize{}}{}
31
+ \newenvironment{boxBlock}{}{}
32
+ \newenvironment{footnotesizeBlock}{\footnotesize{}}{}
33
+ \newenvironment{smallBlock}{\small{}}{}
34
+ \newenvironment{landscapeBlock}{}{}
35
+ \newenvironment{gridBlock}{}{}
36
+ \newenvironment{formalBlock}{}{}
37
+
38
+ \newenvironment{todoBlock}{}{}
39
+
40
+ \newenvironment{bookBlock}{}{}
41
+ \newenvironment{booksList}{\begin{list}{}{\customListPrefs{}}}{\end{list}}
42
+ \newcommand{\booksItem}[2]{\item[\textbf{#1}] #2}
43
+
44
+ \newenvironment{exampleBlock}{\bfseries{}}{}
45
+ \newenvironment{examplesList}{\begin{list}{}{\customListPrefs{}}}{\end{list}}
46
+ \newcommand{\examplesItem}[2]{\item[#1] #2}
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <link href="<%= relative('/html/css/style.css') %>" rel="stylesheet" type="text/css" media="screen" />
3
+ <head>
4
+ <title><%= @configuration['title'] %></title>
5
+ </head>
6
+ <body>
7
+ <%= @content_for_layout %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,11 @@
1
+ \documentclass[a4paper,12pt]{article}
2
+ \usepackage[utf8]{inputenc}
3
+ \usepackage{color}
4
+ \usepackage{hyperref}
5
+ \usepackage{<%= relative('/latex/deplate') %>}
6
+
7
+ \begin{document}
8
+
9
+ <%= @content_for_layout %>
10
+
11
+ \end{document}
@@ -0,0 +1,80 @@
1
+ ---
2
+ title: The simple model
3
+ format:
4
+ - html
5
+ - latex
6
+ - text
7
+ ---
8
+
9
+ #LIST: toc
10
+
11
+ * Description of the model
12
+
13
+ The simple model is built-in in the ''dokkit'' core distribution. You
14
+ can use this model as a base to create simple documents like static
15
+ websites, tutorials, howtos, technical reports, etc.
16
+
17
+ * Edit and render your document
18
+
19
+ To edit the content of the document simply edit ''simple.deplate'' in
20
+ the ''doc/pages'' folder or create a new file in the ''doc/pages''
21
+ directory.
22
+
23
+ To get further information about the deplate wiki syntax used in
24
+ ''simple.deplate'', please check
25
+ [[http://deplate.sf.net/deplate.html][deplate]] homepage.
26
+
27
+ To render this document in ''html'', ''latex'' and ''plain text'',
28
+ open a terminal and type:
29
+
30
+ #Verbatim <<EOB
31
+ rake
32
+ EOB
33
+
34
+ from the top-level directory or from any subdirectory contained in it.
35
+
36
+ You should get output files in the ''output'' folder.
37
+
38
+ * Rendering the modified parts of the document and cleaning up
39
+
40
+ Once you have rendered the document, running the ''rake'' command
41
+ again will appear to do nothing, because only changed resources are
42
+ re-rendered. To clean the output and start over run:
43
+
44
+ #Verbatim <<EOB
45
+ rake clobber
46
+ EOB
47
+
48
+ Note that if you modify any part of the document you must re-run
49
+ ''rake'' command in order to apply changes and to re-generate the
50
+ desidered output.
51
+
52
+ So, once you have modified your document, run:
53
+
54
+ #Verbatim <<EOB
55
+ rake
56
+ EOB
57
+
58
+ Only the modified resources will be transformed.
59
+
60
+ * Configure the documentation environment
61
+
62
+ To configure your documentation environment edit the
63
+ ''setup/setup.rb'' file according to the instructions on ''dokkit''
64
+ website.
65
+
66
+ * What's next?
67
+
68
+ - See what else you can do by typing:
69
+
70
+ #Verbatim <<EOB
71
+ rake --tasks
72
+ EOB
73
+
74
+ - Modify the configuration of the document by editing
75
+ ''doc/configs/simple.yaml'' or by editing the meta configuration
76
+ information on the top of this file.
77
+
78
+ - Override the default layout creating custom layouts in ''doc/layouts''.
79
+
80
+ For further information about ''dokkit'' see http://dokkit.rubyforge.org/.
@@ -0,0 +1,10 @@
1
+
2
+ require 'dokkit/environment'
3
+
4
+ include Dokkit::Environment::Basic
5
+
6
+ Container.new do |c|
7
+
8
+ c.documents.include('*')
9
+
10
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # File 'data.rb' created on 21 apr 2008 at 14:28:57.
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
+ require 'dokkit/resource/filenamehelper'
10
+
11
+ module Dokkit
12
+ module Resource
13
+ # Data are *immutable* resources. Data files are copied from
14
+ # source directory (usually doc/data) to output directory. No
15
+ # rendering process occurs during copying.
16
+ class Data
17
+ include FilenameHelper
18
+ attr_reader :source_fn, :configuration
19
+ # A Data instance is initialized with the source filename and a
20
+ # configuration hash containing data and output directory.
21
+ def initialize(source_fn, configuration = { :data_dir => 'doc/data', :output_dir => 'output' } )
22
+ @source_fn = source_fn
23
+ @configuration = configuration
24
+ end
25
+ # Return the filename of the target data file.
26
+ #
27
+ # Example:
28
+ #
29
+ # target_fn = Data.new('doc/data/data_1').target_fn #=> 'output/data_1'
30
+ #
31
+ def target_fn
32
+ filename_helper(source_fn, @configuration[:data_dir], @configuration[:output_dir], '')
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,385 @@
1
+ #
2
+ # File 'document.rb' created on 17 apr 2008 at 18:04:42.
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
+ require 'yaml'
10
+ require 'erb'
11
+ require 'dokkit/hash'
12
+ require 'dokkit/resource/extensions/builtin'
13
+ require 'dokkit/resource/filenamehelper'
14
+
15
+ module Dokkit
16
+ module Resource
17
+ # Document is the core resource class of dokkit. Document
18
+ # instances are usually created on demand by
19
+ # Dokkit::Resource::Factory.
20
+ class Document
21
+ include FilenameHelper
22
+
23
+ # Includes the builtin extensions to be used by Document objects.
24
+ include Extension::Builtin
25
+
26
+ # Set the default filters chain for commonly used output format.
27
+ DEFAULT_FILTERS_CHAIN = {
28
+ 'html' => ['deplate-html'],
29
+ 'latex' => ['deplate-latex'],
30
+ 'text' => ['deplate-text']
31
+ }
32
+
33
+ attr_reader :configuration
34
+ attr_reader :source_fn
35
+ attr_reader :basename, :name_noext, :dirname, :relativename
36
+ attr_reader :config_fns, :layout_fns, :target_fns
37
+ attr_reader :targets, :layouts, :deps
38
+ attr_reader :default_config_ext, :default_format
39
+ attr_accessor :default_configuration_value
40
+
41
+ # Initialize a Document instance.
42
+ # +source_fn+:: is the file name of the document source file.
43
+ # +configuration+:: is the configuration hash to be associated with the document.
44
+ # +logger+:: is the logger instance.
45
+ # +cache+:: is the cache manager instance.
46
+ def initialize(source_fn, configuration, logger, cache, resource_factory, filter_factory, &blk)
47
+ @source_fn, @logger, @cache, @resource_factory, @filter_factory = source_fn, logger, cache, resource_factory, filter_factory
48
+ @config_fns = []
49
+ @targets = { }
50
+ @layouts = { }
51
+ @deps = { }
52
+
53
+ # Get basename stripping out path and extension from +source_fn+
54
+ @basename = File.basename(source_fn, File.extname(source_fn))
55
+
56
+ # Get the directory part of source_fn
57
+ @dirname = File.dirname(source_fn)
58
+
59
+ # Set the document name with path but without extension
60
+ @name_noext = File.join(@dirname, @basename)
61
+
62
+ # Get name relative to configuration.document_dir
63
+ @relativename = filename_helper(@name_noext, configuration[:document_dir], '')
64
+
65
+ # Set defaults
66
+ @default_config_ext = '.yaml'
67
+ @default_format = 'html'
68
+
69
+ # yield self to an optional configuration block
70
+ yield self if block_given?
71
+
72
+ # Setup hashes
73
+ setup_header_configuration
74
+ setup_configuration_hash(configuration.recursive_merge('layout' => @relativename))
75
+ setup_targets(@default_format)
76
+
77
+ # Configure the document
78
+ configure
79
+ collect_all
80
+ end
81
+
82
+ # Read the configuration file +fn+ and return:
83
+ # * the resulting configuration hash
84
+ # * an array containing the names of the read config files
85
+ # If +fn+ contains configuration data in the
86
+ # header then this method extract it. Note that the method read
87
+ # *recursively* the configuration file specified in config key
88
+ # loading it from config_dir folder.
89
+ # For example:
90
+ #
91
+ # ---
92
+ # key: value
93
+ # config: required
94
+ #
95
+ #
96
+ # The resulting configuration hash will be the key/value pair
97
+ # *plus* the configuration in +config_dir/required.yaml+.
98
+ def add_config(fn)
99
+ File.exists?(fn) ? merge_configuration_file(fn) : @logger.error("Configuration file '#{fn}' not found for '#{@source_fn}'!")
100
+ end
101
+
102
+ def add_layout(name, format = @default_format)
103
+ if File.exists?(get_layout_filename(name, format))
104
+ @layouts[format] << get_layout_filename(name, format)
105
+ else
106
+ @logger.warn("Layout file '#{get_layout_filename(name, format)}' does not exists for '#{source_fn}'!")
107
+ end
108
+ end
109
+
110
+ # Return the filters chain associated with the given format.
111
+ def filters_for(format)
112
+ if @targets.has_key?(format)
113
+ if @targets[format].has_key?('filter')
114
+ @targets[format]['filter']
115
+ elsif DEFAULT_FILTERS_CHAIN.has_key?(format)
116
+ DEFAULT_FILTERS_CHAIN[format]
117
+ end
118
+ elsif DEFAULT_FILTERS_CHAIN.has_key?(format)
119
+ DEFAULT_FILTERS_CHAIN[format]
120
+ else
121
+ @logger.error("No defined filters chain for format '#{format}'!")
122
+ end
123
+ end
124
+
125
+ def target_for(format)
126
+ @targets[format][:target_fn]
127
+ end
128
+
129
+ def deps_for(format)
130
+ @deps[format]
131
+ end
132
+
133
+ def current_format
134
+ @current_format || @default_format
135
+ end
136
+
137
+ def include(fn)
138
+ @cache.add_dependency(source_fn, current_format, fn)
139
+ erb = ERB.new(File.read(fn))
140
+ erb.filename = fn
141
+ erb.result
142
+ end
143
+
144
+ # Render the document in the specified format.
145
+ def render(args = { })
146
+ @current_format = args[:format]
147
+ args = { :format => @default_format }.merge args
148
+ if args.has_key?(:document)
149
+ document = @resource_factory.get(:document, args[:document])
150
+ @cache.add_dependency(source_fn, args[:format], document.source_fn)
151
+ document.render(:format => args[:format])
152
+ else
153
+ do_render!(args[:format])
154
+ end
155
+ end
156
+
157
+ # Return the content of the source document file.
158
+ def source
159
+ @source ||= read_source
160
+ end
161
+
162
+ private
163
+
164
+ # Read the content of the source document file from disk.
165
+ def read_source
166
+ File.read(source_fn)
167
+ end
168
+
169
+ def process_config_configuration_key
170
+ @configuration['config'].to_a.each { |fn| load_config_file(fn) }
171
+ end
172
+
173
+ def load_config_file(fn)
174
+ config_fn = File.join(@configuration[:config_dir], fn)
175
+ config_fn += @default_config_ext if File.extname(config_fn).empty?
176
+ @configuration.delete('config')
177
+ add_config(config_fn)
178
+ end
179
+
180
+ def merge_configuration_file(fn)
181
+ fn == @source_fn ? @configuration.recursive_merge!(@header_configuration) : @configuration.recursive_merge!(YAML::load_file(fn))
182
+ @config_fns << fn
183
+ process_config_configuration_key if @configuration.has_key?('config')
184
+ end
185
+
186
+ # Setup configuration hash with initial value.
187
+ def setup_configuration_hash(configuration)
188
+ @default_configuration_value = "not defined"
189
+ @configuration = Hash.new do |h, k|
190
+ @logger.warn("Configuration key '#{k}' is not defined for #{source_fn}.")
191
+ h[k] = @default_configuration_value
192
+ end
193
+ @configuration.merge! configuration
194
+ end
195
+
196
+ def setup_header_configuration
197
+ @header_configuration = extract_configuration_from_source!
198
+ end
199
+
200
+ # Setup targets hash initializing it with a default format.
201
+ def setup_targets(format)
202
+ @targets[format] = { :target_fn => target_fn(format) }
203
+ end
204
+
205
+ # Render document in the given format.
206
+ def do_render!(format)
207
+ if @targets[format]
208
+ render_source!(format)
209
+ render_all_layouts!(format)
210
+ else
211
+ @logger.error("Don't know how to render '#{source_fn}': format '#{format}' is unknown.")
212
+ end
213
+ @content_for_layout
214
+ end
215
+
216
+ # Produce output from source.
217
+ def render_source!(format)
218
+ unless @source.nil?
219
+ erb = ERB.new(@source)
220
+ erb.filename = @source_fn
221
+ @content_for_layout = apply_filters(erb.result(binding), format)
222
+ end
223
+ end
224
+
225
+ # Injects rendered content from +source_fn+ in the layout chain.
226
+ def render_all_layouts!(format)
227
+ unless !@layouts[format] || @layouts[format].empty?
228
+ @layouts[format].each { |layout_fn| render_layout!(layout_fn) }
229
+ end
230
+ end
231
+
232
+ def render_layout!(layout_fn)
233
+ erb = ERB.new(File.read(layout_fn))
234
+ erb.filename = layout_fn
235
+ @content_for_layout = erb.result(binding)
236
+ end
237
+
238
+ # Collect all dependencies.
239
+ def collect_all
240
+ collect_formats
241
+ collect_layouts
242
+ collect_deps
243
+ end
244
+
245
+ # Configure the document reading all the configuration files.
246
+ # Configuration infos are read in this order:
247
+ # 1. configuration in header if present.
248
+ # 2. configuration in ./+basename+.yaml if file exists.
249
+ # 3. configuration in COMMON.yaml file (or files) exist.
250
+ # 4. configuration in doc/configs/+basename+.yaml if file exists.
251
+ def configure # :doc:
252
+ add_config(config_fn_relative_to(:config_dir)) if File.exists?(config_fn_relative_to(:config_dir))
253
+ add_common_config
254
+ add_config(config_fn_relative_to(:document_dir)) if File.exists?(config_fn_relative_to(:document_dir))
255
+ add_config(@source_fn) if @header_configuration
256
+ end
257
+
258
+ # Collect the layout files traversing +targets+ hash.
259
+ def collect_layouts
260
+ @targets.each_key do |format|
261
+ @layouts[format] = []
262
+
263
+ process_layout_configuration_key(format)
264
+
265
+ @layouts[format].uniq!
266
+ @layouts[format].compact!
267
+ end
268
+ @layouts
269
+ end
270
+
271
+ def process_layout_configuration_key(format)
272
+ @configuration['layout'].to_a.each { |name| add_layout(name, format) }
273
+ end
274
+
275
+ def get_layout_filename(name, format)
276
+ File.join(@configuration[:layout_dir], name + ".#{format.to_s}")
277
+ end
278
+
279
+ # Process +format+ key in configuration hash.
280
+ def process_formats
281
+ @targets = { }
282
+ @configuration['format'].to_a.each do |format|
283
+ @targets[format] = { :target_fn => target_fn(format) } if format.is_a?(String)
284
+ @targets[format.keys.first] = process_format_configuration_key(format) if format.is_a?(Hash)
285
+ end
286
+ end
287
+
288
+ # Process option hash related to a particular target.
289
+ def process_format_configuration_key(format)
290
+ format_key = format.keys.first
291
+ opts = format.values.first
292
+ if opts
293
+ ext = (opts['ext'] if opts.has_key?('ext')) || format_key
294
+ filters = (opts['filter'] if opts.has_key?('filter')) || DEFAULT_FILTERS_CHAIN['html']
295
+ { :target_fn => target_fn(ext.to_sym), 'filter' => filters }
296
+ else
297
+ @logger.error("You must define format '#{format}'!")
298
+ end
299
+ end
300
+
301
+ # Iterates through configuration +:targets+ key (if
302
+ # present) and setup target options.
303
+ def collect_formats
304
+ process_formats if @configuration.has_key?('format')
305
+ end
306
+
307
+ # Collect all the dependency.
308
+ def collect_deps
309
+ @targets.each do |format, target|
310
+ @deps[format] = []
311
+ @deps[format] << @source_fn # the essential dependency from source file
312
+ @deps[format].concat @config_fns # dependency from configuration files
313
+ @deps[format].concat @layouts[format] if @layouts.has_key?(format) # dependency from layout files
314
+ @deps[format].concat @cache.deps[source_fn][format] if @cache.deps[source_fn] and @cache.deps[source_fn][format]
315
+ @deps[format].uniq! # remove duplicates
316
+ end
317
+ @deps
318
+ end
319
+
320
+ # Strip configuration from header (if present) and recursive
321
+ # merge it in +configuration hash.
322
+ def extract_configuration_from_source!
323
+ header_configuration_regexp = /\A-{3}$(.*?)-{3}$/m
324
+ header_configuration = source.scan(header_configuration_regexp).to_s
325
+ source.sub!(header_configuration_regexp, '')
326
+ header_configuration = YAML::load(header_configuration)
327
+ end
328
+
329
+ # Configure from commons configuration files.
330
+ def add_common_config
331
+ resolve_common_configs(@dirname).reverse.each do |file|
332
+ add_config(file)
333
+ end
334
+ end
335
+
336
+ # Collect common configuration files COMMON.yaml.
337
+ def resolve_common_configs(dir, arr = [])
338
+ parent = File.expand_path(File.join(dir, '..'))
339
+ resolve_common_configs(parent, arr) unless parent == dir # at root
340
+ fn = File.join(dir,'COMMON.yaml')
341
+ arr << File.expand_path(fn) if (File.exists?(fn) && File.readable?(fn))
342
+ arr.reverse!
343
+ end
344
+
345
+ # Return configuration filename from +source_fn+.
346
+ #
347
+ # Example:
348
+ #
349
+ # source_fn = 'doc/pages/subdir/document.ext'
350
+ # config_fn #=> 'doc/configs/subdir/document.yaml'
351
+ #
352
+ def config_fn_relative_to(dir_config_key)
353
+ filename_helper(@name_noext, @configuration[:document_dir], @configuration[dir_config_key], @default_config_ext)
354
+ end
355
+
356
+ # Return target filename for a given format.
357
+ #
358
+ # Example:
359
+ #
360
+ # source_fn = 'doc/pages/document.ext'
361
+ # format = :html
362
+ # target_fn(format) #=> 'output/document.html'
363
+ #
364
+ def target_fn(format)
365
+ filename_helper(@name_noext, @configuration[:document_dir], @configuration[:output_dir], ".#{format.to_s}")
366
+ end
367
+
368
+ # Apply filters on text to produce the given format.
369
+ def apply_filters(text, format)
370
+ filters_chain = @targets[format]['filter'] || DEFAULT_FILTERS_CHAIN[format]
371
+ filters = []
372
+ if filters_chain
373
+ filters_chain.each do |filter|
374
+ filters << @filter_factory.get(filter)
375
+ end
376
+ filters.inject(text) { |s, f| f.filter(s) }
377
+ else
378
+ @logger.error("Don't know how to render '#{source_fn}': cannot find filters for format '#{format}'!")
379
+ end
380
+ end
381
+
382
+ end
383
+ end
384
+ end
385
+