dokkit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +125 -0
  3. data/README.txt +53 -0
  4. data/Rakefile +25 -167
  5. data/bin/dokkit +4 -60
  6. data/lib/dokkit/app.rb +63 -192
  7. data/lib/dokkit/builtintask.rb +85 -0
  8. data/lib/dokkit/cachemanager.rb +61 -0
  9. data/lib/dokkit/cleantask.rb +51 -0
  10. data/lib/dokkit/consolelog.rb +42 -0
  11. data/lib/dokkit/defaults.rb +19 -0
  12. data/lib/dokkit/document.rb +221 -0
  13. data/lib/dokkit/dokkitlib.rb +68 -0
  14. data/lib/dokkit/extension/extension.rb +15 -0
  15. data/lib/dokkit/extension/filehelper.rb +25 -0
  16. data/lib/dokkit/fileselection.rb +44 -0
  17. data/lib/dokkit/filters/all.rb +18 -0
  18. data/lib/dokkit/filters/base.rb +18 -0
  19. data/lib/dokkit/filters/deplate.rb +21 -25
  20. data/lib/dokkit/filters/maruku.rb +23 -0
  21. data/lib/dokkit/filters/nil.rb +23 -0
  22. data/lib/dokkit/filters.rb +29 -21
  23. data/lib/dokkit/logger.rb +73 -0
  24. data/lib/dokkit/model.rb +34 -0
  25. data/lib/dokkit/models/{Rakefile.tpl → simpledocument/model/Rakefile} +15 -2
  26. data/lib/dokkit/models/simpledocument/model/doc/configs/simpledocument.yaml +3 -0
  27. data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.html +9 -0
  28. data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.latex +8 -0
  29. data/lib/dokkit/models/simpledocument/model/doc/layouts/simpledocument.text +1 -0
  30. data/lib/dokkit/models/simpledocument/model/doc/pages/simpledocument.deplate +102 -0
  31. data/lib/dokkit/models/simpledocument/model/tasks/all.rb +3 -0
  32. data/lib/dokkit/models/simpledocument/model/tasks/clean.rake +3 -0
  33. data/lib/dokkit/models/simpledocument/model/tasks/render.rake +8 -0
  34. data/lib/dokkit/models/simpledocument/model/tasks/setup.rb +9 -0
  35. data/lib/dokkit/modeltask.rb +83 -0
  36. data/lib/dokkit/pathhelper.rb +46 -0
  37. data/lib/dokkit/recursivemerge.rb +59 -0
  38. data/lib/dokkit/rendertask.rb +101 -0
  39. data/lib/dokkit/resourcemanager.rb +177 -0
  40. data/lib/dokkit/taskconfig.rb +39 -0
  41. data/lib/dokkit/templatetask.rb +37 -0
  42. data/lib/dokkit.rb +2 -8
  43. data/spec/app_spec.rb +55 -0
  44. data/spec/builtintask_spec.rb +114 -0
  45. data/spec/cachemanager_spec.rb +107 -0
  46. data/spec/cleantask_spec.rb +72 -0
  47. data/spec/consolelog_spec.rb +69 -0
  48. data/{tests/data/projects/simple-document → spec/data/test_build}/Rakefile +8 -8
  49. data/spec/data/test_build/doc/configs/document_1.yaml +3 -0
  50. data/spec/data/test_build/doc/configs/required.yaml +3 -0
  51. data/spec/data/test_build/doc/configs/subdir/document_4.yaml +3 -0
  52. data/spec/data/test_build/doc/layouts/document_1.html +9 -0
  53. data/spec/data/test_build/doc/layouts/document_1.latex +8 -0
  54. data/spec/data/test_build/doc/layouts/document_with_partials.html +9 -0
  55. data/spec/data/test_build/doc/layouts/layout +0 -0
  56. data/spec/data/test_build/doc/layouts/layout.html +8 -0
  57. data/spec/data/test_build/doc/layouts/layout.html.backup +8 -0
  58. data/spec/data/test_build/doc/layouts/nested.html +3 -0
  59. data/spec/data/test_build/doc/layouts/partials/partial.html +4 -0
  60. data/spec/data/test_build/doc/pages/COMMON.yaml +6 -0
  61. data/spec/data/test_build/doc/pages/document_1 +20 -0
  62. data/spec/data/test_build/doc/pages/document_1.dep +4 -0
  63. data/spec/data/test_build/doc/pages/document_1.yaml +11 -0
  64. data/spec/data/test_build/doc/pages/document_2 +9 -0
  65. data/spec/data/test_build/doc/pages/document_2.dep +0 -0
  66. data/spec/data/test_build/doc/pages/document_2.yaml +6 -0
  67. data/spec/data/test_build/doc/pages/document_3 +13 -0
  68. data/spec/data/test_build/doc/pages/document_5.exclude +0 -0
  69. data/spec/data/test_build/doc/pages/document_7 +4 -0
  70. data/spec/data/test_build/doc/pages/document_7.yaml +5 -0
  71. data/spec/data/test_build/doc/pages/document_extended +1 -0
  72. data/spec/data/test_build/doc/pages/document_nested +6 -0
  73. data/spec/data/test_build/doc/pages/document_nested.yaml +5 -0
  74. data/spec/data/test_build/doc/pages/document_nolayout.ext +3 -0
  75. data/spec/data/test_build/doc/pages/document_nolayout.yaml +2 -0
  76. data/spec/data/test_build/doc/pages/document_with_partials +3 -0
  77. data/spec/data/test_build/doc/pages/document_with_partials.yaml +2 -0
  78. data/spec/data/test_build/doc/pages/partials/COMMON.yaml +5 -0
  79. data/spec/data/test_build/doc/pages/partials/circular_partial +2 -0
  80. data/spec/data/test_build/doc/pages/partials/circular_partial.yaml +3 -0
  81. data/spec/data/test_build/doc/pages/partials/partial +2 -0
  82. data/spec/data/test_build/doc/pages/subdir/COMMON.yaml +2 -0
  83. data/spec/data/test_build/doc/pages/subdir/document_4 +11 -0
  84. data/spec/data/test_build/doc/pages/subdir/subdir/COMMON.yaml +2 -0
  85. data/spec/data/test_build/doc/pages/subdir/subdir/document_6 +3 -0
  86. data/spec/data/test_build/tasks/all.rb +3 -0
  87. data/spec/data/test_build/tasks/clean.rake +3 -0
  88. data/spec/data/test_build/tasks/render.rake +8 -0
  89. data/spec/data/test_build/tasks/setup.rb +9 -0
  90. data/spec/data/test_build/tasks/template.rake +3 -0
  91. data/spec/data/test_build/templates/layouts/layout +0 -0
  92. data/spec/data/test_build/templates/pages/template +0 -0
  93. data/spec/document_spec.rb +321 -0
  94. data/spec/dokkitlib_spec.rb +63 -0
  95. data/spec/filehelper_spec.rb +34 -0
  96. data/spec/fileselection_spec.rb +101 -0
  97. data/spec/filter_base_spec.rb +29 -0
  98. data/spec/filter_deplate_spec.rb +48 -0
  99. data/spec/filter_maruku_spec.rb +29 -0
  100. data/spec/filter_nil_spec.rb +30 -0
  101. data/spec/filters_spec.rb +37 -0
  102. data/spec/logger_spec.rb +150 -0
  103. data/spec/model_spec.rb +45 -0
  104. data/spec/pathhelper_spec.rb +62 -0
  105. data/spec/recursivemerge_spec.rb +91 -0
  106. data/spec/rendertask_spec.rb +374 -0
  107. data/spec/spec_helper.rb +61 -0
  108. data/spec/taskconfig_spec.rb +45 -0
  109. data/spec/templatetask_spec.rb +72 -0
  110. data/tasks/annotations.rake +30 -0
  111. data/tasks/doc.rake +49 -0
  112. data/tasks/gem.rake +89 -0
  113. data/tasks/manifest.rake +41 -0
  114. data/tasks/rubyforge.rake +57 -0
  115. data/tasks/setup.rb +151 -0
  116. data/tasks/spec.rake +40 -0
  117. data/tasks/svn.rake +44 -0
  118. data/tasks/test.rake +40 -0
  119. metadata +188 -161
  120. data/CHANGES +0 -26
  121. data/LICENSE +0 -674
  122. data/README +0 -32
  123. data/lib/dokkit/#render_task_factory.rb# +0 -94
  124. data/lib/dokkit/dokkittasks.rb +0 -99
  125. data/lib/dokkit/hash.rb +0 -41
  126. data/lib/dokkit/models/share/builtin.rf +0 -28
  127. data/lib/dokkit/page.rb +0 -195
  128. data/lib/dokkit/render_task_factory.rb +0 -91
  129. data/tests/data/output/simple_document/README +0 -57
  130. data/tests/data/output/simple_document/Rakefile +0 -7
  131. data/tests/data/output/simple_document/doc/config/simple_document.yaml +0 -5
  132. data/tests/data/output/simple_document/doc/pages/simple_document.dpl +0 -12
  133. data/tests/data/output/website_project/README +0 -49
  134. data/tests/data/output/website_project/Rakefile +0 -82
  135. data/tests/data/output/website_project/doc/layouts/normal.thtml +0 -38
  136. data/tests/data/output/website_project/doc/pages/COMMON.rb +0 -9
  137. data/tests/data/output/website_project/doc/pages/deplate.dplhtml +0 -9
  138. data/tests/data/output/website_project/doc/pages/index.rb +0 -10
  139. data/tests/data/output/website_project/doc/pages/index.thtml +0 -12
  140. data/tests/data/output/website_project/doc/res/images/rote-tiny.png +0 -0
  141. data/tests/data/projects/simple-document/README +0 -57
  142. data/tests/data/projects/simple-document/doc/config/author.yaml +0 -4
  143. data/tests/data/projects/simple-document/doc/config/model.yaml +0 -18
  144. data/tests/data/projects/simple-document/doc/config/simple_document.yaml +0 -6
  145. data/tests/data/projects/simple-document/doc/layouts/another_simple_document.html +0 -8
  146. data/tests/data/projects/simple-document/doc/layouts/another_simple_document.tex +0 -10
  147. data/tests/data/projects/simple-document/doc/layouts/layout_with_custom_name.html +0 -8
  148. data/tests/data/projects/simple-document/doc/layouts/semantic.cache +0 -23
  149. data/tests/data/projects/simple-document/doc/pages/COMMON.yaml +0 -23
  150. data/tests/data/projects/simple-document/doc/pages/another_simple_document.dpl +0 -12
  151. data/tests/data/projects/simple-document/doc/pages/simple_document.dpl +0 -12
  152. data/tests/data/projects/simple-document/doc/pages/simple_document_without_layout.dpl +0 -12
  153. data/tests/data/projects/simple-document/doc/pages/subdir/COMMON.yaml +0 -4
  154. data/tests/data/projects/simple-document/doc/pages/subdir/simple_document_in_subdir.dpl +0 -12
  155. data/tests/data/projects/simple-document/doc/pages/subdir/simple_document_in_subdir.yaml +0 -3
  156. data/tests/data/projects/simple-document/doc/pages/subdir/subdir/COMMON.yaml +0 -2
  157. data/tests/data/projects/simple-document/doc/pages/subdir/subdir/another_simple_document_in_subdir.dpl +0 -12
  158. data/tests/data/projects/simple-document/doc/pages/yet_another_simple_document.dpl +0 -12
  159. data/tests/data/projects/simple-document/doc/pages/yet_another_simple_document.yaml +0 -8
  160. data/tests/gem_tests.rb +0 -4
  161. data/tests/spec_page.rb +0 -25
  162. data/tests/test.rb +0 -2
  163. data/tests/test_application.rb +0 -40
  164. data/tests/test_builtin_tasks.rb +0 -37
  165. data/tests/test_config.rb +0 -108
  166. data/tests/test_core.rb +0 -12
  167. data/tests/test_dokkit_commandline.rb +0 -18
  168. data/tests/test_exception.rb +0 -7
  169. data/tests/test_filters.rb +0 -46
  170. data/tests/test_layout.rb +0 -64
  171. data/tests/test_options.rb +0 -33
  172. data/tests/test_project_tasks.rb +0 -48
  173. data/tests/test_recursive_merge.rb +0 -42
  174. data/tests/test_task_factory.rb +0 -38
  175. /data/{CONTRIBUTORS → lib/dokkit/models/simpledocument/model/doc/data/css/style.css} +0 -0
  176. /data/{DONE → spec/data/test_build/doc/data/resource} +0 -0
  177. /data/{TODO → spec/data/test_build/doc/data/resource.exclude} +0 -0
  178. /data/{tests/pages/test.dpltex → spec/data/test_build/doc/data/subdir/resource.insubdir} +0 -0
@@ -0,0 +1,221 @@
1
+ #
2
+ # File 'document.rb' created on 13 gen 2008 at 18:49:57.
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 'ostruct'
10
+ require 'yaml'
11
+ require 'erb'
12
+ require 'dokkit/logger'
13
+ require 'dokkit/consolelog'
14
+ require 'dokkit/pathhelper'
15
+ require 'dokkit/cachemanager'
16
+ require 'dokkit/recursivemerge'
17
+ require 'dokkit/pathhelper'
18
+ require 'dokkit/filters/all'
19
+ require 'dokkit/extension/filehelper'
20
+
21
+ module Dokkit
22
+ class Document
23
+ DEFAULT_FILTER_CHAIN = {
24
+ 'html' => ['deplate-html'],
25
+ 'latex' => ['deplate-latex'],
26
+ 'text' => ['deplate-text'],
27
+ 'nil' => ['nil']
28
+ }
29
+ include Extension::FileHelper, PathHelper
30
+ attr_reader :document, :taskconfig
31
+ attr_reader :document_basename
32
+ attr_reader :configs, :targets, :layouts
33
+ attr_reader :filter_chain
34
+ attr_reader :configuration
35
+ attr_reader :source_text
36
+ attr_reader :prerequisites
37
+ attr_reader :logger
38
+ def initialize(document, taskconfig, rendered = [], &blk)
39
+ @logger = Log::ConsoleLog.consolelog
40
+ @document, @taskconfig, @rendered = document, taskconfig, rendered
41
+ @document_basename = File.basename(document)
42
+ @stripped_document = strip_ext(@document)
43
+ @layouts, @targets, @prerequisites, @filter_chain = { }, { }, { }, { }
44
+ @configs = []
45
+ @configuration = Hash.new do |h, k|
46
+ @logger.warn("Configuration key '#{k}' not defined in '#{targets[@format]}'!")
47
+ h[k] = "'#{k}' not defined!"
48
+ end
49
+ @configuration.extend ConfigHash
50
+ @source_text = read_source
51
+ @cache = CacheManager.instance
52
+
53
+ yield self if block_given?
54
+
55
+ collect_resources
56
+ end
57
+ def render(format)
58
+ @format = format
59
+ unless @source_text.nil?
60
+ erb = ERB.new(@source_text)
61
+ erb.filename = @document
62
+ @content_for_layout = apply_filters(erb.result(binding), format)
63
+ end
64
+ unless @layouts[format].empty?
65
+ @layouts[format].each do |layout_fn|
66
+ erb = ERB.new(File.read(layout_fn))
67
+ erb.filename = layout_fn
68
+ @content_for_layout = erb.result(binding)
69
+ end
70
+ end
71
+ @content_for_layout
72
+ end
73
+
74
+ private
75
+
76
+ def extract_meta!(text)
77
+ meta_regexp = /\A-{3}$(.*?)-{3}$/m
78
+ meta = text.scan(meta_regexp).to_s
79
+ text.sub!(meta_regexp, '')
80
+ return meta
81
+ end
82
+ def render_partial(document_fn, format = @format, &blk)
83
+ unless @rendered.include?(document)
84
+ result = Document.new(File.join(@taskconfig.document_dir, document_fn), @taskconfig, @rendered << document, &blk).render(format)
85
+ @cache.add_dependency(targets[format], File.join(@taskconfig.document_dir, document_fn))
86
+ @rendered.clear
87
+ else
88
+ @logger.error("Circular dependency detected in '#{document}', aborting.")
89
+ end
90
+ result
91
+ end
92
+ def collect_resources
93
+ collect_configs
94
+ collect_targets
95
+ collect_layouts
96
+ collect_prerequisites
97
+ end
98
+ def collect_prerequisites
99
+ @targets.each_key do |format|
100
+ @prerequisites[format] = []
101
+ @prerequisites[format] << document
102
+ @prerequisites[format].concat @configs
103
+ @prerequisites[format].concat(@layouts[format]) if @layouts[format]
104
+ @prerequisites
105
+ end
106
+ end
107
+ def collect_configs
108
+ @configs << (config_fn_helper(@stripped_document, @taskconfig)) if File.exists?(config_fn_helper(@stripped_document, @taskconfig))
109
+ @configs.concat(resolve_common_configs(File.dirname(@document)))
110
+ @configs << (@stripped_document + '.yaml') if File.exists?(@stripped_document + '.yaml')
111
+
112
+ meta_configuration = YAML::load(extract_meta!(@source_text))
113
+ if meta_configuration
114
+ if meta_configuration.has_key?('config')
115
+ (@configs << get_config_fns(meta_configuration['config'])).flatten!
116
+ meta_configuration.delete('config')
117
+ end
118
+ end
119
+
120
+ @configs.each do |config_fn|
121
+ @configuration.recursive_merge!(YAML::load(File.open(config_fn)))
122
+ if @configuration.has_key?('config')
123
+ (@configs << get_config_fns(@configuration['config'])).flatten!
124
+ @configuration.delete('config')
125
+ end
126
+ end
127
+
128
+ @configuration.recursive_merge!(meta_configuration) if meta_configuration
129
+ end
130
+ def resolve_common_configs(dir, arr = [])
131
+ parent = File.expand_path(File.join(dir, '..'))
132
+ resolve_common_configs(parent, arr) unless parent == dir # at root
133
+ fn = File.join(dir,'COMMON.yaml')
134
+ arr << fn if (File.exists?(fn) && File.readable?(fn))
135
+ arr
136
+ end
137
+ def build_config_fn(fn)
138
+ result_fn = fn
139
+ if File.extname(fn).empty?
140
+ result_fn += '.yaml'
141
+ end
142
+ result_fn = File.join(@taskconfig.config_dir, result_fn)
143
+ end
144
+ def get_config_fns(configuration)
145
+ if configuration.is_a?(String)
146
+ result = build_config_fn(configuration)
147
+ elsif configuration.is_a?(Array)
148
+ result = configuration.collect do |fn|
149
+ fn = build_config_fn(fn)
150
+ end
151
+ else
152
+ @logger.fail('Invalid config file value.')
153
+ end
154
+ result
155
+ end
156
+ def collect_targets
157
+ if @configuration.has_key?('render_in')
158
+ @configuration['render_in'].each do |fmt|
159
+ if fmt.class != Hash
160
+ @targets[fmt] = output_fn_helper(@stripped_document, ".#{fmt}", @taskconfig)
161
+ @filter_chain[fmt] = DEFAULT_FILTER_CHAIN[fmt]
162
+ else
163
+ fmt.each do |format, configuration|
164
+ if(configuration.empty?)
165
+ @targets[format] = output_fn_helper(@stripped_document, ".#{format}")
166
+ @filter_chain[fmt] = DEFAULT_FILTER_CHAIN[fmt]
167
+ else
168
+ output, ext = @taskconfig.output_dir, ".#{format}"
169
+ ext = configuration['ext'] if configuration.has_key?('ext')
170
+ output = File.join(@taskconfig.output_dir, configuration['output']) if configuration.has_key?('output')
171
+ @targets[format] = File.join(output, strip_ext(@document_basename) + ext)
172
+ if configuration.has_key?('filters')
173
+ @filter_chain[format] = configuration['filters']
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+ else
180
+ @targets['html'] = output_fn_helper(@stripped_document, '.html', @taskconfig)
181
+ @filter_chain['html'] = DEFAULT_FILTER_CHAIN['html']
182
+ end
183
+ end
184
+ def collect_layouts
185
+ @targets.each do |format, target|
186
+ layout_fn = []
187
+ layout_ext = File.extname(target)
188
+ layout_fn << (layout_fn_helper(@stripped_document, layout_ext, @taskconfig)) if File.exists?(layout_fn_helper(@stripped_document, layout_ext, @taskconfig))
189
+ layout_fn << (@stripped_document + layout_ext) if File.exists?(@stripped_document + layout_ext)
190
+ if @configuration.has_key?('layout')
191
+ @configuration['layout'].each do |layout|
192
+ config_layout_fn = strip_ext(layout)
193
+ layout_fn << File.join(@taskconfig.layout_dir, config_layout_fn + layout_ext) if File.exists?(File.join(@taskconfig.layout_dir, config_layout_fn + layout_ext))
194
+ layout_fn << (config_layout_fn + layout_ext) if File.exists?(config_layout_fn + layout_ext)
195
+ end
196
+ end
197
+ @logger.warn("Layout not found for '#{target}'!") if layout_fn.empty?
198
+ @layouts[format] = layout_fn.uniq.reverse
199
+ end
200
+ end
201
+ def read_source
202
+ File.read(document)
203
+ end
204
+ def apply_filters(text, target)
205
+ filters = []
206
+ chain = @filter_chain[target]
207
+ if chain
208
+ @filter_chain[target].each do |name|
209
+ begin
210
+ filters << Filters[name]
211
+ rescue
212
+ @logger.warn("Filter '#{name}' not found, ignored.")
213
+ end
214
+ end
215
+ filters.inject(text) { |s, f| f.filter(s) }
216
+ else
217
+ @logger.error("Don't know how to render in '#{target}' format!")
218
+ end
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,68 @@
1
+ #
2
+ # File 'dokkitlib.rb' created on 18 feb 2008 at 17:54:20.
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
+ require 'rake'
11
+ require 'rake/tasklib'
12
+ require 'dokkit/defaults'
13
+ require 'dokkit/taskconfig'
14
+ require 'dokkit/pathhelper'
15
+ require 'dokkit/consolelog'
16
+
17
+ module Dokkit
18
+ class DokkitLib < Rake::TaskLib
19
+ include PathHelper, Rake::TaskManager
20
+ attr_reader :ns
21
+ attr_reader :logger
22
+ attr_reader :model
23
+ attr_accessor :config
24
+ def initialize(model, namespace = 'dokkit', opts = { })
25
+ @ns = namespace
26
+ @model = model
27
+ @config = model.config
28
+ @logger = Log::ConsoleLog.consolelog
29
+
30
+ pre_block_configuration
31
+
32
+ yield self if block_given?
33
+
34
+ post_block_configuration
35
+
36
+ check_directories if opts[:check_dir]
37
+ define_dokkit_tasks
38
+ end
39
+ def dokkit_task(*args, &block)
40
+ task_name, arg_names, needs = resolve_args(args.dup)
41
+ task(*args, &block) unless Rake::Task.task_defined?("#{@ns}:#{task_name}")
42
+ end
43
+
44
+ private
45
+
46
+ def check_directories
47
+ unless @config.directories.empty?
48
+ @config.directories.each_value do |dir|
49
+ @logger.error("Directory '#{dir}' does not exist") unless (dir =~ /output|cache/ || File.exists?(dir))
50
+ end
51
+ end
52
+ end
53
+ def pre_block_configuration
54
+ nil
55
+ end
56
+ def post_block_configuration
57
+ nil
58
+ end
59
+ def define_dokkit_tasks
60
+ namespace @ns do
61
+ private_methods.select { |meth| meth =~ /define_dokkit_/ and not meth =~ /define_dokkit_tasks/ }.each do |method|
62
+ self.send(method)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,15 @@
1
+ #
2
+ # File 'extension.rb' created on 28 feb 2008 at 16:39:38.
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'
10
+
11
+ module Dokkit
12
+ module Extension
13
+ # space left blank
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # File 'filehelper.rb' created on 28 feb 2008 at 16:40:57.
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/extension/extension'
10
+
11
+ module Dokkit
12
+ module Extension
13
+ module FileHelper
14
+ def relative(href)
15
+ thr = href
16
+ if thr.is_a?(String) && href[0,1] == '/'
17
+ dtfn = File.dirname(document[/^#{taskconfig.document_dir}\/(.*)/,1]) + '/'
18
+ count = dtfn == './' ? 0 : dtfn.split('/').length
19
+ thr = ('../' * count) + href[1..href.length]
20
+ end
21
+ thr
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # File 'fileselection.rb' created on 07 feb 2008 at 15:52:42.
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 'rake'
10
+
11
+ module Dokkit
12
+ module ExtMapping
13
+ attr_reader :extmapping
14
+ def extend(regexp=/.*/, &blk)
15
+ @extmapping ||= { }
16
+ (files.select { |file| file =~ regexp }).each do |file|
17
+ @extmapping[file] = blk
18
+ end
19
+ end
20
+ end
21
+ class FileSelection
22
+ attr_accessor :base_dir
23
+ alias :dir :base_dir
24
+ alias :dir= :base_dir=
25
+ def initialize(base_dir = '.')
26
+ @base_dir = base_dir
27
+ @includes = []
28
+ @excludes = []
29
+ yield self if block_given?
30
+ end
31
+ def include(*patterns)
32
+ patterns.each { |pattern| @includes << pattern }
33
+ end
34
+ def exclude(*patterns)
35
+ patterns.each { |pattern| @excludes << pattern }
36
+ end
37
+ def files
38
+ FileList.new(@base_dir) do |fl|
39
+ fl.exclude *@excludes.collect { |exclude| File.join(@base_dir, exclude) } unless @excludes.empty?
40
+ fl.include *@includes.collect { |include| File.join(@base_dir, include) } unless @includes.empty?
41
+ end.uniq.select { |fn| not File.directory?(fn) }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # File 'all_filters.rb' created on 18 feb 2008 at 17:13:12.
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/filters/base'
10
+
11
+ Dir[File.join(File.dirname(__FILE__), '*.rb')].each do |fn|
12
+ begin
13
+ require fn unless fn =~ /[\\\/]base.rb$/ or fn == 'all.rb'
14
+ rescue LoadError
15
+ nil
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ #
2
+ # File 'base.rb' created on 15 feb 2008 at 22:56:37.
3
+ #
4
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
5
+ #
6
+ # (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
+ #
8
+
9
+ module Dokkit
10
+ module Filters
11
+ class Base
12
+ def filter(text)
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -6,38 +6,34 @@
6
6
 
7
7
  require 'deplate/converter'
8
8
  require 'deplate/core'
9
- require 'rote/filters/base'
9
+ require 'dokkit/filters'
10
+ require 'dokkit/filters/base'
10
11
  require 'dokkit/deplate/fmt/latex-notemplate'
11
12
  require 'dokkit/deplate/fmt/html-notemplate'
12
13
 
13
14
  module Dokkit
14
15
  module Filters
15
-
16
- def Filters.declare_formatters
17
- ::Deplate::Core.declare_formatter(::Deplate::Formatter::LatexNoTemplate,'latex-notemplate')
18
- ::Deplate::Core.declare_formatter(::Deplate::Formatter::HTMLNoTemplate,'html-notemplate')
19
- end
20
-
21
- #####
22
- ## Page filter that converts emacs-wiki formatting in various formats (tex, html,
23
- ## docbook, plain text, etc.) using deplate.
24
- ##
25
- class Deplate < Rote::Filters::TextFilter
26
-
27
- Filters.declare_formatters
28
-
29
- # Create a new filter instance. If a block is defined returns a Deplate::Converter instance.
30
- # You can supply options directly to the instance. See deplate docs for a full list
31
- # of options.
32
- def initialize(formatter)
33
- super()
34
- @deplate = ::Deplate::Converter.new(formatter) { |instance| yield(instance) if block_given? }
35
- end
36
-
37
- def handler(text,page)
38
- @deplate.convert_string(text)
16
+ class DeplateHTML < Base
17
+ def filter(text)
18
+ ::Deplate::Core.declare_formatter(::Deplate::Formatter::HTMLNoTemplate,'html-notemplate')
19
+ ::Deplate::Converter.new('html-notemplate').convert_string(text)
39
20
  end
40
21
  end
22
+ class DeplateLatex < Base
23
+ def filter(text)
24
+ ::Deplate::Core.declare_formatter(::Deplate::Formatter::LatexNoTemplate,'latex-notemplate')
25
+ ::Deplate::Converter.new('latex-notemplate').convert_string(text)
26
+ end
27
+ end
28
+ class DeplateText < Base
29
+ def filter(text)
30
+ ::Deplate::Converter.new('plain').convert_string(text)
31
+ end
32
+ end
41
33
  end
42
34
  end
43
35
 
36
+ Dokkit::Filters.register('deplate-html') { Dokkit::Filters::DeplateHTML.new }
37
+ Dokkit::Filters.register('deplate-latex') { Dokkit::Filters::DeplateLatex.new }
38
+ Dokkit::Filters.register('deplate-text') { Dokkit::Filters::DeplateText.new }
39
+
@@ -0,0 +1,23 @@
1
+ #
2
+ # File 'maruku.rb' created on 15 feb 2008 at 22:58:04.
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/filters/base'
10
+ require 'dokkit/filters'
11
+ require 'maruku'
12
+
13
+ module Dokkit
14
+ module Filters
15
+ class MarukuHTML < Base
16
+ def filter(text)
17
+ Maruku.new(text).to_html
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ Dokkit::Filters.register('maruku-html') { Dokkit::Filters::MarukuHTML.new }
@@ -0,0 +1,23 @@
1
+ #
2
+ # File 'nil.rb' created on 18 mar 2008 at 12:41:27.
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/filters/base'
10
+ require 'dokkit/filters'
11
+
12
+ module Dokkit
13
+ module Filters
14
+ class Nil < Base
15
+ def filter(text)
16
+ text
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Dokkit::Filters.register('nil') { Dokkit::Filters::Nil.new }
23
+
@@ -1,26 +1,34 @@
1
- #--
2
- # Require all filters
3
- # (c)2005, 2006 Ross Bamford (and contributors)
1
+ #
2
+ # File 'filters.rb' created on 18 feb 2008 at 14:25:19.
4
3
  #
5
- # See 'rote.rb' or LICENSE for licence information.
6
- # $Id: filters.rb 156 2006-01-05 01:13:43 +0000 (Thu, 05 Jan 2006) roscopeco $
7
- #++
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
8
 
9
- # Everyone requires this, we need to get it loaded first.
10
- require 'rote/filters/base'
11
-
12
- # This now requires conservatively, ignoring any filters that
13
- # throw a LoadError. This allows a simple 'require rote/filters' to
14
- # be used to load all filters _for which dependencies are
15
- # available_.
16
- Dir[File.join(File.dirname(__FILE__), 'filters/*.rb')].each do |fn|
17
- begin
18
- require fn unless fn =~ /[\\\/]base.rb$/
19
- rescue LoadError
20
-
21
- # ignore, different filters require different library
22
- # support.
9
+ require 'dokkit'
10
+ require 'dokkit/consolelog'
23
11
 
12
+ module Dokkit
13
+ module Filters
14
+ @filters = { }
15
+ @logger = Log::ConsoleLog.consolelog
16
+ def Filters.register(name, &blk)
17
+ @filters[name] = blk
18
+ end
19
+ def Filters.[](name)
20
+ filter = @filters[name]
21
+ if filter
22
+ @filters[name].call
23
+ else
24
+ @logger.error("Filter '#{name}' is not defined!")
25
+ end
26
+ end
27
+ def Filters.filters
28
+ return @filters
29
+ end
30
+ def Filters.clean
31
+ @filters = { }
32
+ end
24
33
  end
25
34
  end
26
-
@@ -0,0 +1,73 @@
1
+ #
2
+ # File 'logger.rb' created on 23 feb 2008 at 15:46:54.
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'
10
+
11
+ module Dokkit
12
+ module Log
13
+ ERROR = 0
14
+ WARNING = 1
15
+ INFO = 2
16
+ DEBUG = 3
17
+ class LogMessage
18
+ attr_reader :text
19
+ attr_reader :level
20
+ def initialize(text, level)
21
+ @text, @level = text, level
22
+ end
23
+ end
24
+ class Logger
25
+ class << self
26
+ def logger
27
+ @logger ||= Logger.new
28
+ end
29
+ def clear
30
+ @logger = nil
31
+ end
32
+ end
33
+ attr_reader :observers
34
+ attr_reader :last_message
35
+ attr_reader :level
36
+ def initialize
37
+ @observers = []
38
+ @level = INFO
39
+ end
40
+ def level=(new_level)
41
+ new_level = Log::DEBUG if new_level > Log::DEBUG
42
+ new_level = Log::ERROR if new_level < Log::ERROR
43
+ @level = new_level
44
+ end
45
+ def attach(observer)
46
+ (@observers << observer).last
47
+ end
48
+ def detach(observer)
49
+ @observers.delete(observer)
50
+ end
51
+ def notify
52
+ @observers.each { |observer| observer.update }
53
+ end
54
+ def message(message)
55
+ @last_message = message
56
+ notify
57
+ @last_message
58
+ end
59
+ def info(text)
60
+ message({ :text => text, :level => Log::INFO }) if level >= INFO
61
+ end
62
+ def error(text)
63
+ message({ :text => text, :level => ERROR }) if level >= ERROR
64
+ end
65
+ def warn(text)
66
+ message({ :text => text, :level => WARNING }) if level >= WARNING
67
+ end
68
+ def debug(text)
69
+ message({ :text => text, :level => Log::DEBUG }) if level >= DEBUG
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # File 'model.rb' created on 10 mar 2008 at 13:39:48.
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/taskconfig'
11
+ require 'dokkit/cachemanager'
12
+
13
+ module Dokkit
14
+ class Model
15
+ class << self
16
+ def init(name = 'model', &blk)
17
+ @model ||= Model.new(name, &blk)
18
+ end
19
+ end
20
+ attr_accessor :config
21
+ attr_reader :name, :cache
22
+ def initialize(name, &blk)
23
+ @name = name
24
+ @config = TaskConfig.new
25
+
26
+ yield self if block_given?
27
+
28
+ @cache = CacheManager.instance
29
+ @cache.init('deps.yaml', @config.cache_dir)
30
+
31
+ self
32
+ end
33
+ end
34
+ end