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
data/lib/dokkit/app.rb CHANGED
@@ -3,96 +3,41 @@
3
3
  #
4
4
  # See 'dokkit.rb' or +LICENSE+ for licence information.
5
5
  #
6
- # (C) 2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
+ # (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
7
  #
8
8
 
9
9
  require 'optparse'
10
10
  require 'rake'
11
+ require 'dokkit/model'
12
+ require 'dokkit/logger'
13
+ require 'dokkit/consolelog'
14
+ require 'dokkit/builtintask'
11
15
 
12
16
  module Dokkit
13
- # The path from where to copy the model structure.
14
- MODEL_PATH = 'lib/model'
15
- # The path from which to load the built-in layout of the model.
16
- MODEL_LAYOUT_PATH = 'lib/doc/layouts'
17
- # The path from which to load the built-in config of the model.
18
- MODEL_CONFIG_PATH = 'lib/doc/config'
19
- # Dokkit module singleton methods.
17
+ # Master Dokkit version. Manage this from the Rake release support.
18
+ DOKKITVERSION = '0.3.0'
20
19
  class << self
21
- # Current Dokkit Application
22
20
  def application
23
- @application ||= Dokkit::Application.new(dokkit_lib)
21
+ @application ||= Application.new
24
22
  end
25
- # Set the current Rake application object.
26
- def application=(app)
27
- @application = app
23
+ def release
24
+ @application = Rake.application = nil
28
25
  end
29
- # Return the original directory where the Dokkit application was started.
30
- def original_dir
31
- application.original_dir
32
- end
33
- def dokkit_lib
34
- lib = nil
35
- unless lib = ENV['DOKKIT_LIB']
36
- $:.each do |it|
37
- if File.exists?(File.join(it,'dokkit/dokkittasks.rb'))
38
- lib = it
39
- break
40
- end
41
- end
42
- end
43
- lib
44
- end
45
- # Return the directory containing models related files.
46
- def projects_dir
47
- File.join(dokkit_lib, 'dokkit', 'models')
48
- end
49
-
50
- def fetch_models
51
- models = { }
52
- Dir["#{Gem.dir}/gems/dokkit-model-*"].each do |path|
53
- path.scan(/dokkit-model-(.+)-(\d\.\d\.\d)/) { models[$1] = path }
54
- end
55
- Dir["#{File.expand_path("~/.dokkit/models/*")}"].each do |path|
56
- path.scan(/.dokkit\/models\/(.+)/) { models[$1] = path }
57
- end
58
- models
59
- end
60
- # Return the full path from where to copy the model.
61
- def model_dir(model)
62
- File.join(fetch_models[model], MODEL_PATH)
63
- end
64
- # Return the full path from where to copy the model.
65
- def model_layout_dir(model)
66
- File.join(fetch_models[model], MODEL_LAYOUT_PATH)
67
- end
68
- # Return the full path from where to copy the model.
69
- def model_config_dir(model)
70
- File.join(fetch_models[model], MODEL_CONFIG_PATH)
71
- end
72
- # Return the directory containing the tests
73
- def tests_dir
74
- File.expand_path(File.join(dokkit_lib, '..', 'tests'))
75
- end
76
- end
77
-
78
- # Command-line launcher for Dokkit.
26
+ end
79
27
  class Application
80
-
81
- attr_accessor :dokkit_lib
82
-
83
- DEFAULT_PROJECT_MODEL = "simpledocument"
28
+ DEFAULT_MODEL = 'simpledocument'
84
29
  USAGE_PREAMBLE = <<-EOU
85
30
  Usage: dokkit [options] [task1] .. [taskN]
86
31
 
87
- Where [taskN] is a valid task or target name for the current project.
88
- Dokkit generates targets for each page source, and also defines a number
89
- of top-level tasks for various things. Use the '--tasks' option to get
90
- a list of valid tasks.
32
+ Where [taskN] is a valid task or target name for the current model.
33
+ dokkit generates defines a number of top-level tasks for various
34
+ things. Use the '--tasks' option to get a list of valid tasks.
91
35
 
92
- In addition to the standard render_XXX tasks and those provided by any
93
- local configuration, the following 'special' tasks are recognised:
36
+ In addition to the standard tasks and those provided by any
37
+ local configuration, the following builtin tasks are recognised:
94
38
 
95
- create <project> Create a blank project from the built-in template using the #{DEFAULT_PROJECT_MODEL} project model.
39
+ create[model] modeldir Create a blank project based on model template.
40
+ list List the models available.
96
41
 
97
42
  In non-standard environments, it may be necessary to set the DOKKIT_LIB
98
43
  variable to point to the location of Dokkit libraries.
@@ -103,144 +48,53 @@ EOU
103
48
  "Display usage information." ],
104
49
  [ "--help", "-h", GetoptLong::NO_ARGUMENT,
105
50
  "Synonim for usage."],
106
- [ "--project", "-P", GetoptLong::REQUIRED_ARGUMENT,
107
- "Set the PROJECT model to create. Use --list for the full list of project models available."],
108
- [ "--directory","-D", GetoptLong::REQUIRED_ARGUMENT,
109
- "Change to directory DIR before reading the rakefiles or doing anything else."],
110
- [ "--list", "-l", GetoptLong::NO_ARGUMENT,
111
- "Display the list of the project models available." ],
112
51
  [ "--version", "-V", GetoptLong::NO_ARGUMENT,
113
52
  "Display the version number and quit." ],
114
53
  [ "--trace", "-t", GetoptLong::NO_ARGUMENT,
115
54
  "Enable trace-level output (debugging)"],
116
55
  [ "--tasks", "-T", GetoptLong::NO_ARGUMENT,
117
56
  "Display the list of the tasks available."],
118
- [ "--nosearch", "-N", GetoptLong::NO_ARGUMENT,
119
- "Do not search parent directories for the Rakefiles. Only builtin tasks can be invoked."]
120
- ]
121
-
122
- @@project_dirs = nil
123
-
124
- # Create a new Application instance, processing command-line arguments,
125
- # optionally passing +self+ to the supplied block for further
126
- # configuration.
127
- def initialize(dokkit_lib) # :yield: self if block_given?
128
- # init vars
129
- @dokkit_lib = dokkit_lib
130
- ENV['PROJECT'] = @project = DEFAULT_PROJECT_MODEL
131
- yield self if block_given?
132
- end
133
- # Application options from the command line
134
- def options
135
- @options ||= OpenStruct.new
136
- end
137
- # set an option
138
- def do_option(opt,value)
139
- case opt
140
- when '--version'
141
- options.version = true
142
- print "dokkit, version #{DOKKITVERSION}\n"
143
- exit
144
- when '--directory'
145
- options.directory = value
146
- Dir.chdir(options.directory)
147
- when '--tasks'
148
- options.tasks = true
149
- Rake.application.do_option('--tasks', nil)
150
- when '--project'
151
- ENV['PROJECT'] = @project = options.project = value
152
- when '--list'
153
- options.list_projects = true
154
- Dokkit.fetch_models.each_key { |key| puts key }
155
- exit
57
+ ]
58
+ attr_reader :builtintask, :logger
59
+ def initialize
60
+ @rake = Rake.application
61
+ @logger = Log::ConsoleLog.consolelog
62
+ @builtintask = Dokkit::BuiltinTask.new(self)
63
+ end
64
+ def do_option(option, value)
65
+ case option
156
66
  when '--usage'
157
- options.usage = options.help = true
158
67
  help
159
68
  exit
160
69
  when '--help'
161
- options.usage = options.help = true
162
70
  help
163
- exit
164
- when '--nosearch'
165
- options.nosearch = true
166
- Rake.application.do_option('--nosearch', nil)
167
- when '--trace'
168
- options.trace = true
169
- Rake.application.do_option('--trace', nil)
170
- end
171
- end
172
-
173
- def init
174
- Rake.application.init('dokkit')
175
- end
176
-
177
- def clear
178
- Rake.application.clear
179
- end
180
-
181
- def load_rakefile
182
- Rake.application.init('dokkit')
183
- Rake.application.load_rakefile
184
- end
185
- def load_builtin
186
- raise "#{@project} model not found!" unless model_dir = Dokkit.fetch_models[@project]
187
- Dir["#{File.join(model_dir, 'lib/tasks/builtin')}/*.{rake,rf}"].each { |name| Rake.application.add_import name }
188
- Rake.application.load_imports
189
- end
190
- def [](task_name)
191
- Rake.application[task_name]
192
- end
193
-
194
- def task_defined?(task)
195
- Rake.application.task_defined?(task)
196
- end
197
- # check if a Rakefile exists in the current directory or in any parent directory.
198
- def have_rakefile
199
- Rake.application.have_rakefile
200
- end
201
- # search for a Rakefile in the current directory and in all parent directory.
202
- def search_for_rakefile
203
- initial_dir = here = Dir.pwd
204
- while ! have_rakefile
205
- Dir.chdir("..")
206
- if Dir.pwd == here || options.nosearch
207
- Dir.chdir(initial_dir)
208
- return false
209
- end
210
- here = Dir.pwd
71
+ exit
72
+ when '--version'
73
+ print "dokkit, version #{DOKKITVERSION}\n"
74
+ exit
75
+ when '--tasks'
76
+ @rake.do_option('--tasks', value)
211
77
  end
212
- Dir.chdir(initial_dir)
213
- true
214
78
  end
215
- # Run the application with the current options.
216
- def run(args = nil)
217
- begin
218
- warn "Warning: No models found on this system! The task 'create' will not work!" if Dokkit.fetch_models.empty?
219
- if args
220
- ARGV.clear
221
- ARGV.concat(args)
222
- end
223
- process_args
224
- init
225
- load_builtin
226
- Rake.application.load_rakefile if search_for_rakefile
227
- Rake.application.top_level
228
- Rake.application = nil
229
- end
79
+ def run
80
+ process_args
81
+ @rake.init('dokkit')
82
+ @rake.load_rakefile if search_for_rakefile
83
+ @rake.top_level
230
84
  end
231
85
 
232
86
  private
233
-
87
+
234
88
  def command_line_options
235
89
  OPTIONS.collect { |lst| lst[0..-2] }
236
90
  end
237
-
238
- # Process commandline
239
91
  def process_args
240
92
  opts = GetoptLong.new(*command_line_options)
241
93
  opts.each { |opt, value| do_option(opt, value) }
242
94
  end
243
-
95
+ def version
96
+ DOKKITVERSION
97
+ end
244
98
  def help
245
99
  puts USAGE_PREAMBLE
246
100
  puts "Recognized options are:"
@@ -255,6 +109,23 @@ EOU
255
109
  printf " %s\n", desc
256
110
  end
257
111
  end
258
-
259
- end # Application
260
- end # Dokkit
112
+ # check if a Rakefile exists in the current directory or in any parent directory.
113
+ def have_rakefile
114
+ @rake.have_rakefile
115
+ end
116
+ # search for a Rakefile in the current directory and in all parent directory.
117
+ def search_for_rakefile
118
+ initial_dir = here = Dir.pwd
119
+ while ! have_rakefile
120
+ Dir.chdir("..")
121
+ if Dir.pwd == here
122
+ Dir.chdir(initial_dir)
123
+ return false
124
+ end
125
+ here = Dir.pwd
126
+ end
127
+ Dir.chdir(initial_dir)
128
+ true
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # File 'modeltask.rb' created on 23 feb 2008 at 20:45:10.
3
+ #
4
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
5
+ #
6
+ # (C) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
+ #
8
+
9
+ require 'yaml'
10
+ require 'dokkit'
11
+
12
+ module Dokkit
13
+ class BuiltinTask
14
+ attr_reader :models, :local_dir, :search_in
15
+ def initialize(application)
16
+ @application = application
17
+ @local_dir = DEFAULT_LOCAL_DIR
18
+ @search_in = [:dokkit_dir, :local_dir]
19
+ @logger = @application.logger
20
+ @models = fetch_models
21
+ define_builtin_tasks
22
+ end
23
+ def dokkit_dir
24
+ lib = nil
25
+ unless lib = ENV['DOKKIT_LIB']
26
+ $:.each do |it|
27
+ if File.exists?(File.join(it, 'dokkit/app.rb'))
28
+ lib = it
29
+ break
30
+ end
31
+ end
32
+ end
33
+ lib
34
+ end
35
+ def builtin_model_dir
36
+ File.join(dokkit_dir, 'dokkit/models')
37
+ end
38
+
39
+ private
40
+
41
+ def define_builtin_tasks
42
+ define_list_model_task
43
+ define_create_task
44
+ end
45
+ def from_location(location)
46
+ return builtin_model_dir if location == :dokkit_dir
47
+ return File.join(((ENV['HOMEPATH'] if RUBY_PLATFORM =~ /win32/) || ENV['HOME']), @local_dir) if location == :local_dir
48
+ end
49
+ def fetch_models
50
+ models = { }
51
+ @search_in.each do |location|
52
+ Dir.glob(File.join(from_location(location), '**/model/Rakefile')).each do |model|
53
+ models[model.scan(/models\/(.*)\/model\/Rakefile/).flatten.to_s] = File.expand_path(File.join(File.dirname(model), '..'))
54
+ end
55
+ end
56
+ models
57
+ end
58
+ def define_list_model_task
59
+ desc 'List the installed models'
60
+ task 'list' do
61
+ @models.each do |modelname, path|
62
+ @logger.info("Found model '#{modelname}' in #{path}")
63
+ end
64
+ end
65
+ end
66
+ def define_create_task
67
+ desc 'Bootstrap a new documentation project'
68
+ task 'create', :model do |t, args|
69
+ model = args.model || DEFAULT_MODEL
70
+ if ARGV.size == 2
71
+ dest_dir = t.application.top_level_tasks.pop
72
+ else
73
+ @logger.error('A target directory must be provided.')
74
+ end
75
+ @logger.error("Directory '#{dest_dir}' exists.") if File.exists?(dest_dir)
76
+ @logger.error("Model '#{model}' not found.") unless @models[model]
77
+ @logger.info("Create '#{dest_dir}' based on '#{model}' model.")
78
+ cp_r(File.join(@models[model], 'model'), dest_dir, :verbose => false)
79
+ File.open(File.join(dest_dir, 'doc/configs/model.yaml'), 'w') do |file|
80
+ file << { 'name' => model, 'from' => @models[model] }.to_yaml
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,61 @@
1
+ #
2
+ # File 'cachemanager.rb' created on 28 gen 2008 at 18:31:05.
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 'singleton'
10
+ require 'rake'
11
+ require 'yaml'
12
+
13
+ module Dokkit
14
+ class CacheManager
15
+ include Singleton
16
+ def init(cache_filename = 'deps.yaml', cache_dir = '.cache')
17
+ @cache_filename = cache_filename
18
+ @cache_dir = cache_dir
19
+ @complete_cache_filename = File.join(cache_dir, cache_filename)
20
+ @deps = {}
21
+ load if File.exists?(@complete_cache_filename)
22
+ at_exit { save }
23
+ end
24
+ def add_dependency(task_name, dep)
25
+ @deps[task_name] ||= []
26
+ @deps[task_name] << dep unless (dep.nil? or @deps[task_name].include?(dep))
27
+ end
28
+ def load
29
+ File.open(@complete_cache_filename) do |file|
30
+ @deps = YAML::load(file)
31
+ @deps.each do |task, dep|
32
+ file task => dep
33
+ end
34
+ end
35
+ end
36
+ def save
37
+ unless @deps.empty?
38
+ mkdir_p(cache_dir, :verbose => false) unless File.exists?(cache_dir)
39
+ File.open(@complete_cache_filename, 'w') do |file|
40
+ file.write YAML::dump(@deps)
41
+ end
42
+ end
43
+ end
44
+ def clean_deps
45
+ @deps.clear
46
+ end
47
+ def clean
48
+ clean_deps
49
+ rm_rf(cache_dir, :verbose => false) unless cache_dir == '.'
50
+ end
51
+ def deps
52
+ @deps
53
+ end
54
+ def cache_dir
55
+ @cache_dir
56
+ end
57
+ def cache_filename
58
+ @cache_filename
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # File 'cleantask.rb' created on 19 feb 2008 at 19:33: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 'rake/clean'
10
+ require 'dokkit/dokkitlib'
11
+
12
+ module Dokkit
13
+ class CleanTask < DokkitLib
14
+ def initialize(model, namespace = 'clean')
15
+ super(model, namespace)
16
+ end
17
+
18
+ private
19
+
20
+ def pre_block_configuration
21
+ @config.output_dir ||= Dokkit::DEFAULT_OUTPUT_DIR
22
+ @config.cache_dir ||= Dokkit::DEFAULT_CACHE_DIR
23
+ end
24
+ def define_dokkit_clean_output
25
+ desc 'Remove output directory'
26
+ dokkit_task :output do
27
+ if File.exists?(@config.output_dir)
28
+ @logger.info('Removing output directory')
29
+ rm_rf(@config.output_dir, :verbose => false)
30
+ end
31
+ end
32
+ end
33
+ def define_dokkit_clean_cache
34
+ desc 'Remove cache directory'
35
+ dokkit_task :cache do
36
+ if File.exists?(@model.cache.cache_dir)
37
+ @logger.info('Removing cache directory')
38
+ @model.cache.clean
39
+ end
40
+ end
41
+ end
42
+ def define_dokkit_clean_backup
43
+ desc 'Remove backup files (invoke rake:clean)'
44
+ dokkit_task :backup => ['rake:clean']
45
+ end
46
+ def define_dokkit_clean_all
47
+ desc 'Clobber all generated output and cache'
48
+ dokkit_task :all => [:output, :cache, :backup]
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,42 @@
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) 2008 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
7
+ #
8
+
9
+ require 'dokkit/logger'
10
+
11
+ module Dokkit
12
+ module Log
13
+ class ConsoleLog
14
+ class << self
15
+ def consolelog
16
+ @consolelog ||= ConsoleLog.new(Logger.logger)
17
+ @consolelog.logger
18
+ end
19
+ end
20
+ attr_reader :logger
21
+ def initialize(logger)
22
+ @logger = logger
23
+ logger.attach(self)
24
+ end
25
+ def update
26
+ message = @logger.last_message
27
+ case message[:level]
28
+ when Log::ERROR
29
+ fail "[#{Time.now.asctime}][ERROR] #{message[:text]}"
30
+ when Log::WARNING
31
+ warn "[#{Time.now.asctime}][WARNING] #{message[:text]}"
32
+ when Log::INFO
33
+ puts "[#{Time.now.asctime}][INFO] #{message[:text]}"
34
+ when Log::DEBUG
35
+ puts "[#{Time.now.asctime}][DEBUG] #{message[:text]}"
36
+ end
37
+ message
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,19 @@
1
+ #
2
+ # File 'defaults.rb' created on 20 feb 2008 at 19:31: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
+ module Dokkit
10
+ DEFAULT_DOCUMENT_DIR = 'doc/pages'
11
+ DEFAULT_DATA_DIR = 'doc/data'
12
+ DEFAULT_OUTPUT_DIR = 'output'
13
+ DEFAULT_LAYOUT_DIR = 'doc/layouts'
14
+ DEFAULT_CONFIG_DIR = 'doc/configs'
15
+ DEFAULT_TEMPLATE_DIR = 'templates'
16
+ DEFAULT_CACHE_DIR = '.cache'
17
+ DEFAULT_LOCAL_DIR = '.dokkit/models'
18
+ DEFAULT_MODEL = 'simpledocument'
19
+ end