dokkit 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,46 +0,0 @@
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
@@ -1,59 +0,0 @@
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
@@ -1,101 +0,0 @@
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
-
@@ -1,177 +0,0 @@
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
@@ -1,39 +0,0 @@
1
- #
2
- # File 'taskconfig.rb' created on 29 feb 2008 at 07:50:50.
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 'ostruct'
10
-
11
- module Dokkit
12
- class TaskConfig < OpenStruct
13
- STRIP_SLASHES = /^\/?(.*?)\/*$/
14
- attr_reader :config, :directories
15
- def initialize(hash = nil)
16
- super(hash)
17
- @directories = { }
18
-
19
- yield self if block_given?
20
-
21
- strip_slashes_from_dir
22
- end
23
- def directories
24
- methods.each do |meth|
25
- @directories[meth.to_sym] = send(meth.to_sym) if (meth =~ /\_dir$/)
26
- end
27
- @directories
28
- end
29
-
30
- private
31
-
32
- def strip_slashes_from_dir
33
- directories.each do |meth, dir|
34
- stripped_dir = send(meth)[STRIP_SLASHES, 1]
35
- send((meth.to_s + '=').to_sym, stripped_dir)
36
- end
37
- end
38
- end
39
- end
@@ -1,37 +0,0 @@
1
- #
2
- # File 'templatetask.rb' created on 03 mar 2008 at 13:16:03.
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 'dokkit/dokkitlib'
10
-
11
- module Dokkit
12
- class TemplateTask < DokkitLib
13
- def initialize(model, namespace = 'template')
14
- super(model, namespace, { :check_dir => true })
15
- end
16
-
17
- private
18
-
19
- def pre_block_configuration
20
- @config.template_dir ||= Dokkit::DEFAULT_TEMPLATE_DIR
21
- end
22
- def define_dokkit_create_template
23
- desc "Copy the template to the given directory."
24
- dokkit_task 'create', :template do |t, args|
25
- template_fn = File.join(@config.template_dir, args.template)
26
- @logger.error("Template '#{args.template}' doesn't exist") unless File.exists?(template_fn)
27
- if ARGV.size == 2
28
- dest_fn = t.application.top_level_tasks.pop
29
- else
30
- dest_fn = File.join('doc', args.template)
31
- end
32
- @logger.info("Copy template '#{File.basename(template_fn)}' to '#{dest_fn}'")
33
- cp(template_fn, dest_fn, :preserve => true, :verbose => false)
34
- end
35
- end
36
- end
37
- end
data/spec/app_spec.rb DELETED
@@ -1,55 +0,0 @@
1
- #
2
- # File 'app_spec.rb' created on 20 feb 2008 at 20:15:42.
3
- # See 'dokkit.rb' or +LICENSE+ for licence information.
4
- #
5
- # (c)2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
- #
7
- # To execute this spec run:
8
- #
9
- # spec spec/app_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/app'
19
- require File.dirname(__FILE__) + '/spec_helper.rb'
20
-
21
- describe Dokkit::Application, ' when initialized' do
22
- before do
23
- @app = Dokkit.application
24
- end
25
- after(:all) do
26
- Dokkit.release
27
- end
28
- it 'should instantiate a ModelTask object to manage built-in tasks' do
29
- @app.builtintask.should_not be_nil
30
- end
31
- end
32
-
33
- describe Dokkit::Application, ' running' do
34
- include CaptureStdout, SpecPathHelper
35
- before(:all) do
36
- @initial_dir = Dir.pwd
37
- Dir.chdir(File.join(File.dirname(__FILE__), SpecPathHelper::DATA_DEST_DIR))
38
- end
39
- before do
40
- @app = Dokkit.application
41
- end
42
- after do
43
- Dokkit.release
44
- rm_rf 'spec/data/simpledocument'
45
- end
46
- after(:all) do
47
- Dir.chdir(@initial_dir)
48
- end
49
- it 'should output the list of built-in tasks' do
50
- capture_stdout do
51
- @app.do_option('--tasks', nil)
52
- @app.run
53
- end.should match(/new documentation/)
54
- end
55
- end
@@ -1,114 +0,0 @@
1
- #
2
- # File 'modeltask_spec.rb' created on 23 feb 2008 at 20:33:52.
3
- # See 'dokkit.rb' or +LICENSE+ for licence information.
4
- #
5
- # (c)2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
- #
7
- # To execute this spec run:
8
- #
9
- # spec spec/modeltask_spec.rb
10
- #
11
-
12
- $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../lib')))
13
-
14
- require 'rubygems'
15
- require 'spec'
16
- require 'dokkit'
17
- require 'dokkit/builtintask'
18
- require File.dirname(__FILE__) + '/spec_helper.rb'
19
-
20
- describe Dokkit::BuiltinTask, ' when initialized' do
21
- before do
22
- Rake.application = nil
23
- application = mock('application')
24
- application.stub!(:logger)
25
- @builtintask = Dokkit::BuiltinTask.new(application)
26
- end
27
- it 'should know the full path of dokkit installation directory' do
28
- File.exists?(@builtintask.dokkit_dir).should be_true
29
- end
30
- it 'should know the full path of the built-in models dir' do
31
- File.exists?(@builtintask.builtin_model_dir).should be_true
32
- end
33
- it 'should set a default project model' do
34
- Dokkit::DEFAULT_MODEL.should == 'simpledocument'
35
- end
36
- it 'should store the list of the installed models' do
37
- File.exists?(File.join(@builtintask.models['simpledocument'], 'model')).should be_true
38
- end
39
- end
40
-
41
- describe Dokkit::BuiltinTask, ' when list task is invoked' do
42
- include CaptureStdout
43
- before do
44
- Rake.application = nil
45
- application = mock('application')
46
- application.stub!(:logger).and_return(Dokkit::Log::ConsoleLog.consolelog)
47
- @builtintask = Dokkit::BuiltinTask.new(application)
48
- end
49
- it 'should list the models installed on the system' do
50
- capture_stdout do
51
- task('list').invoke
52
- end.should match(/Found model 'simpledocument'/)
53
- end
54
- end
55
-
56
- describe Dokkit::BuiltinTask, ' when create task is invoked' do
57
- include CaptureStdout
58
- before do
59
- Rake.application = nil
60
- ARGV.clear
61
- application = mock('application')
62
- application.stub!(:logger).and_return(Dokkit::Log::ConsoleLog.consolelog)
63
- @builtintask = Dokkit::BuiltinTask.new(application)
64
- end
65
- after do
66
- rm_rf 'spec/data/simpledocument'
67
- end
68
- it 'should create a new documentation directory using the given model' do
69
- ARGV.push('model:create[simpledocument]')
70
- ARGV.push('spec/data/simpledocument')
71
- Rake.application.collect_tasks
72
- task('create').invoke('simpledocument')
73
- File.exists?('spec/data/simpledocument').should be_true
74
- end
75
- it 'should create a new documentation directory using simpledocument as default model' do
76
- ARGV.push('create')
77
- ARGV.push('spec/data/simpledocument')
78
- Rake.application.collect_tasks
79
- task('create').invoke
80
- File.exists?('spec/data/simpledocument').should be_true
81
- end
82
- it 'should inform that a new documentation directory has been created' do
83
- ARGV.push('create')
84
- ARGV.push('spec/data/simpledocument')
85
- Rake.application.collect_tasks
86
- capture_stdout do
87
- task('create').invoke
88
- end.should match(/Create '.*' based on '.*' model/)
89
- end
90
- it 'should raise an error if model not found' do
91
- ARGV.push('create[notexists]')
92
- ARGV.push('spec/data/simpledocument')
93
- Rake.application.collect_tasks
94
- lambda {
95
- task('create').invoke('spec/data/simpledocument')
96
- }.should raise_error(RuntimeError, /Model '.*' not found/)
97
- end
98
- it 'should raise an error if target directory exists' do
99
- ARGV.push('create')
100
- ARGV.push('spec/data/test_build')
101
- Rake.application.collect_tasks
102
- lambda {
103
- task('create').invoke
104
- }.should raise_error(RuntimeError, /Directory '.*' exists./)
105
- end
106
- it 'should copy model.yaml in the target directory' do
107
- ARGV.push('create')
108
- ARGV.push('spec/data/simpledocument')
109
- Rake.application.collect_tasks
110
- task('create').invoke
111
- File.exists?('spec/data/simpledocument/doc/configs/model.yaml').should be_true
112
- end
113
- end
114
-