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,9 @@
1
+ * Title for document_2
2
+ Body of document_2
3
+
4
+ * item 1
5
+ * item 2
6
+ * item 3
7
+
8
+ * Section
9
+ Body of section
File without changes
@@ -0,0 +1,6 @@
1
+ ---
2
+ document:
3
+ render:
4
+ output: document_2
5
+ ext: .htm
6
+
@@ -0,0 +1,13 @@
1
+ ---
2
+ key: value
3
+ config: document_1
4
+ ---
5
+ * Title for document_3
6
+ Body of document_3
7
+
8
+ * item 1
9
+ * item 2
10
+ * item 3
11
+
12
+ * Section
13
+ Body of section
File without changes
@@ -0,0 +1,4 @@
1
+ # Heading
2
+
3
+ Body of the paragraph.
4
+
@@ -0,0 +1,5 @@
1
+ render_in:
2
+ - html:
3
+ filters:
4
+ - maruku-html
5
+ - notexists
@@ -0,0 +1 @@
1
+ Test the extension: <%= extension %>
@@ -0,0 +1,6 @@
1
+ ---
2
+ key: value
3
+ ---
4
+ A document that uses nested layouts.
5
+
6
+
@@ -0,0 +1,5 @@
1
+ ---
2
+ layout:
3
+ - document_1
4
+ - nested
5
+
@@ -0,0 +1,3 @@
1
+ * document without layout
2
+
3
+ This is to test the rendering of a document without layout
@@ -0,0 +1,2 @@
1
+ ---
2
+ layout: notexists
@@ -0,0 +1,3 @@
1
+ * Title for document_with_partials
2
+ Body of document_with_partials
3
+
@@ -0,0 +1,2 @@
1
+ ---
2
+ layout: document_with_partials
@@ -0,0 +1,5 @@
1
+ ---
2
+ layout: partials/partial
3
+
4
+
5
+
@@ -0,0 +1,2 @@
1
+ This partial should be rendered in document_with_partials
2
+
@@ -0,0 +1,3 @@
1
+ ---
2
+ layout: document_with_partials
3
+
@@ -0,0 +1,2 @@
1
+ This partial should be rendered in document_with_partials
2
+
@@ -0,0 +1,2 @@
1
+ ---
2
+ test_common_key_in_subdir: common key for all the documents in the current directory
@@ -0,0 +1,11 @@
1
+ * Title for document_4
2
+ Body of document_4
3
+
4
+ * item 1
5
+ * item 2
6
+ * item 3
7
+
8
+ * Section
9
+ Body of section
10
+
11
+
@@ -0,0 +1,2 @@
1
+ ---
2
+ test_common_key_in_subdir_subdir: common value for all the documents in the current directory
@@ -0,0 +1,3 @@
1
+ * Title for document_6
2
+
3
+ Content of document_6
@@ -0,0 +1,3 @@
1
+ require 'tasks/setup'
2
+
3
+ Dir.glob('tasks/*.rake').each {|fn| import fn}
@@ -0,0 +1,3 @@
1
+ require 'dokkit/cleantask'
2
+
3
+ Dokkit::CleanTask.new(MODEL, 'clean')
@@ -0,0 +1,8 @@
1
+ require 'dokkit/rendertask'
2
+
3
+ Dokkit::RenderTask.new(MODEL, 'render') do |task|
4
+ task.config.data_dir = 'doc/data'
5
+ task.documents.include('**/*')
6
+ task.documents.exclude('**/*.yaml', '**/*_extended', '**/*partial*', '*.dep')
7
+ task.data.include('**/*')
8
+ end
@@ -0,0 +1,9 @@
1
+ require 'dokkit/model'
2
+
3
+ MODEL = Dokkit::Model.init({'name' => 'test', 'from' => '.'}) do |model|
4
+ model.config.document_dir = 'doc/pages'
5
+ model.config.config_dir = 'doc/configs'
6
+ model.config.layout_dir = 'doc/layouts'
7
+ model.config.output_dir = 'output'
8
+ model.config.cache_dir = '.cache'
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'dokkit/templatetask'
2
+
3
+ Dokkit::TemplateTask.new(MODEL, 'template')
File without changes
File without changes
@@ -0,0 +1,321 @@
1
+ #
2
+ # File 'document_spec.rb' created on 13 gen 2008 at 17:46:37.
3
+ # See 'dokkit.rb' or +LICENSE+ for licence information.
4
+ #
5
+ # (c)2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors).
6
+ #
7
+ # To execute this spec run:
8
+ #
9
+ # spec spec/document_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/document'
18
+ require 'dokkit/pathhelper'
19
+ require 'dokkit/filters/all'
20
+ require File.dirname(__FILE__) + '/spec_helper.rb'
21
+
22
+ describe 'a configured Document instance', :shared => true do
23
+ include SpecPathHelper, CaptureStdout
24
+ before(:all) do
25
+ @initial_dir = Dir.pwd
26
+ Dir.chdir(File.join(File.dirname(__FILE__), SpecPathHelper::DATA_TEST_DIR))
27
+ end
28
+ before do
29
+ @cache = Dokkit::CacheManager.instance
30
+ @cache.init('deps.yaml', '.cache')
31
+ @config = mock('config')
32
+ @config.should_receive(:document_dir).at_least(1).and_return(document_path)
33
+ @config.should_receive(:config_dir).at_least(1).and_return(config_path)
34
+ @config.should_receive(:layout_dir).at_least(1).and_return(layout_path)
35
+ @config.should_receive(:output_dir).at_least(1).and_return(output_path)
36
+ end
37
+ after(:all) do
38
+ Dir.chdir(@initial_dir)
39
+ end
40
+ end
41
+
42
+ describe Dokkit::Document, ' when initialized with document_1' do
43
+
44
+ it_should_behave_like 'a configured Document instance'
45
+
46
+ before do
47
+ @document = Dokkit::Document.new(document_path('document_1'), @config)
48
+ end
49
+ it 'should be initialized with the name of the source file' do
50
+ @document.document.should == document_path('document_1')
51
+ end
52
+ it 'should get the basename of the source file' do
53
+ @document.document_basename.should == 'document_1'
54
+ end
55
+ it 'should resolve its configuration files' do
56
+ @document.configs.should == [
57
+ config_path('document_1.yaml'),
58
+ document_path('COMMON.yaml'),
59
+ document_path('document_1.yaml'),
60
+ config_path('required.yaml')
61
+ ]
62
+ end
63
+ it 'should read the configuration files and fill a configuration hash' do
64
+ @document.configuration.should_not be_empty
65
+ end
66
+ it 'should read document source file' do
67
+ @document.source_text.should =~ /\* Title for document_1/
68
+ end
69
+ it 'should define output targets' do
70
+ @document.targets['html'].should == output_path('document_1.html')
71
+ @document.targets['tex'].should == output_path('latex/document_1.latex')
72
+ end
73
+ it 'should define layouts grouped by output target' do
74
+ @document.layouts['html'].should == [layout_path('document_1.html')]
75
+ @document.layouts['tex'].should == [layout_path('document_1.latex')]
76
+ end
77
+ it 'should know the filters to use for rendering in the given output format' do
78
+ @document.filter_chain['html'].should == ['deplate-html']
79
+ @document.filter_chain['tex'].should == ['deplate-latex']
80
+ end
81
+ it 'should return the list of prerequisites grouped by output format' do
82
+ @document.prerequisites['html'].should include(
83
+ document_path('document_1'),
84
+ config_path('document_1.yaml'),
85
+ config_path('required.yaml'),
86
+ document_path('document_1.yaml'),
87
+ document_path('COMMON.yaml'),
88
+ layout_path('document_1.html')
89
+ )
90
+ end
91
+ describe ' and rendered in html' do
92
+ before do
93
+ @result = @document.render('html')
94
+ end
95
+ it 'should execute embedded erb code and render the document' do
96
+ @result.should =~ /test embedded erb/
97
+ end
98
+ it 'should render the content of the configuration hash' do
99
+ @result.should =~ /test configuration rendering/
100
+ @result.should =~ /test the correct merge/
101
+ end
102
+ it 'should return a default value if a configuration key is not found' do
103
+ @document.configuration['notexist'].should match(/'notexist' not defined/)
104
+ end
105
+ it 'should know which is the current format' do
106
+ @result.should =~ /Current rendering format is: html/
107
+ end
108
+ it 'should apply filters to render in html format' do
109
+ @result.should =~ /\<h1.*\>.*\<\/h1\>/
110
+ end
111
+ it 'should render partial inside it' do
112
+ @result.should =~ /partial should be rendered/
113
+ end
114
+ end
115
+ describe ' and rendered in tex' do
116
+ before do
117
+ @result = @document.render('tex')
118
+ end
119
+ it 'should apply filters to render in html format' do
120
+ @result.should =~ /\\section\{.*\}/
121
+ end
122
+ end
123
+ end
124
+
125
+ describe Dokkit::Document, ' when initialized with document_nolayout.ext' do
126
+
127
+ it_should_behave_like 'a configured Document instance'
128
+
129
+ before do
130
+ @document = Dokkit::Document.new(document_path('document_nolayout.ext'), @config)
131
+ end
132
+ it 'should define output targets' do
133
+ @document.targets['html'].should == output_path('document_nolayout.html')
134
+ end
135
+ it 'should set a nil layout' do
136
+ @document.layouts['html'].should be_empty
137
+ end
138
+ it 'should know the filters to use for rendering in the given output format' do
139
+ @document.filter_chain['html'].should == ['deplate-html']
140
+ end
141
+ it 'should return the list of prerequisites grouped by output format' do
142
+ @document.prerequisites['html'].should include(
143
+ document_path('document_nolayout.ext'),
144
+ document_path('document_nolayout.yaml'),
145
+ document_path('COMMON.yaml')
146
+ )
147
+ end
148
+ it 'should resolve its configuration files' do
149
+ @document = Dokkit::Document.new(document_path('document_nolayout.ext'), @config)
150
+ @document.configs.should == [
151
+ document_path('COMMON.yaml'),
152
+ document_path('document_nolayout.yaml'),
153
+ ]
154
+ end
155
+ it 'should raise a -layout not found- warning' do
156
+ capture_stderr do
157
+ @document = Dokkit::Document.new(document_path('document_nolayout.ext'), @config)
158
+ end.should match(/Layout not found/)
159
+ end
160
+ describe ' and rendered in html' do
161
+ before do
162
+ @document = Dokkit::Document.new(document_path('document_nolayout.ext'), @config)
163
+ @result = @document.render('html')
164
+ end
165
+ it 'should apply filters to render in html format' do
166
+ @result.should =~ /\<h1.*\>.*\<\/h1\>/
167
+ end
168
+ end
169
+ end
170
+
171
+ describe Dokkit::Document, ' when initialized with subdir/document_4' do
172
+
173
+ it_should_behave_like 'a configured Document instance'
174
+
175
+ before do
176
+ @document = Dokkit::Document.new(document_path('subdir/document_4'), @config)
177
+ end
178
+ it 'should get the basename of the source file' do
179
+ @document.document_basename == 'document_4'
180
+ end
181
+ it 'should resolve its configuration files' do
182
+ @document.configs.should == [
183
+ config_path('subdir/document_4.yaml'),
184
+ File.expand_path(document_path('COMMON.yaml')),
185
+ document_path('subdir/COMMON.yaml'),
186
+ ]
187
+ end
188
+ it 'should define output targets' do
189
+ @document.targets['html'].should == output_path('subdir/document_4.html')
190
+ end
191
+ it 'should define layouts grouped by output format' do
192
+ @document.layouts['html'].should == [layout_path('document_1.html')]
193
+ end
194
+ it 'should know the filters to use for rendering in the given output format' do
195
+ @document.filter_chain['html'].should == ['deplate-html']
196
+ end
197
+ it 'should resolve relative path' do
198
+ @document.relative('/images/image.img').should == '../images/image.img'
199
+ end
200
+ describe ' and rendered in html' do
201
+ before do
202
+ @result = @document.render('html')
203
+ end
204
+ it 'should apply filters to render in html format' do
205
+ @result.should =~ /\<h1.*\>.*\<\/h1\>/
206
+ end
207
+ end
208
+ end
209
+
210
+ describe Dokkit::Document, ' when initialized with subdir/subdir/document_6' do
211
+
212
+ it_should_behave_like 'a configured Document instance'
213
+
214
+ before do
215
+ @document = Dokkit::Document.new(document_path('subdir/subdir/document_6'), @config)
216
+ end
217
+ it 'should resolve its configuration files' do
218
+ @document.configs.should == [
219
+ File.expand_path(document_path('COMMON.yaml')),
220
+ File.expand_path(document_path('subdir/COMMON.yaml')),
221
+ document_path('subdir/subdir/COMMON.yaml'),
222
+ ]
223
+ end
224
+ it 'should define output targets' do
225
+ @document.targets['html'].should == output_path('subdir/subdir/document_6.html')
226
+ end
227
+ it 'should define layouts grouped by output target' do
228
+ @document.layouts['html'].should == [layout_path('document_1.html')]
229
+ end
230
+ end
231
+
232
+ describe Dokkit::Document, ' when initialized with document_7' do
233
+
234
+ it_should_behave_like 'a configured Document instance'
235
+
236
+ before do
237
+ @document = Dokkit::Document.new(document_path('document_7'), @config)
238
+ end
239
+ it 'should resolve its configuration files' do
240
+ @document.configs.should == [
241
+ document_path('COMMON.yaml'),
242
+ document_path('document_7.yaml'),
243
+ ]
244
+ end
245
+ it 'should define output targets' do
246
+ @document.targets['html'].should == output_path('document_7.html')
247
+ end
248
+ it 'should define layouts grouped by output target' do
249
+ @document.layouts['html'].should == [layout_path('document_1.html')]
250
+ end
251
+ describe ' and rendered in html using maruku filter' do
252
+ before do
253
+ @result = @document.render('html')
254
+ end
255
+ it 'should apply filters to render in html format' do
256
+ @result.should =~ /\<h1.*\>.*\<\/h1\>/
257
+ end
258
+ end
259
+ describe ' and rendered using a not defined target format' do
260
+ it 'should raise an error' do
261
+ lambda {
262
+ @document.render('notexistent')
263
+ }.should raise_error(RuntimeError, /Don't know how to render in '.*' format!/)
264
+ end
265
+ it 'should warn that a filter was not found' do
266
+ capture_stderr do
267
+ @document.render('html')
268
+ end.should match(/Filter '.*' not found/)
269
+ end
270
+ end
271
+ end
272
+
273
+ describe Dokkit::Document, ' when initialized with document_with_partials' do
274
+
275
+ it_should_behave_like 'a configured Document instance'
276
+
277
+ before do
278
+ @document = Dokkit::Document.new(document_path('document_with_partials'), @config)
279
+ end
280
+ describe ' and rendered in html' do
281
+ it 'should fail if a circular dependency is detected' do
282
+ lambda { @document.render('html') }.should raise_error(RuntimeError, /Circular dependency detected in/)
283
+ end
284
+ end
285
+ end
286
+
287
+ describe Dokkit::Document, ' when initialized with document_nested' do
288
+
289
+ it_should_behave_like 'a configured Document instance'
290
+
291
+ before do
292
+ @result = Dokkit::Document.new(document_path('document_nested'), @config).render('html')
293
+ end
294
+ describe ' and rendered in html' do
295
+ it 'should render nested layout' do
296
+ @result.should match(/<div class=\"nested\"/)
297
+ end
298
+ end
299
+ end
300
+
301
+ describe Dokkit::Document, ' when initialized with document_3' do
302
+
303
+ it_should_behave_like 'a configured Document instance'
304
+
305
+ before do
306
+ @document = Dokkit::Document.new(document_path('document_3'), @config)
307
+ end
308
+ it 'should read the meta configuration inside it' do
309
+ @document.configuration['key'].should == 'value'
310
+ end
311
+ it 'should collect config file in meta configuration' do
312
+ @document.configs.should == [
313
+ document_path('COMMON.yaml'),
314
+ config_path('document_1.yaml'),
315
+ ]
316
+ end
317
+ it 'should read configuration from config file' do
318
+ @document.configuration['test_config_merge'].should match(/test the correct merge/)
319
+ end
320
+ end
321
+
@@ -0,0 +1,63 @@
1
+ #
2
+ # File 'dokkitlib_spec.rb' created on 18 feb 2008 at 17:49:23.
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/dokkitlib_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/dokkitlib'
19
+ require File.dirname(__FILE__) + '/spec_helper.rb'
20
+
21
+ describe Dokkit::DokkitLib, ' when initialized' do
22
+ include SpecPathHelper
23
+
24
+ before do
25
+ class Dokkit::DokkitLib
26
+ private
27
+ def define_dokkit_task
28
+ dokkit_task 'test' => 'dep'
29
+ end
30
+ def pre_block_configuration
31
+ @config.another_test_option = 'default value'
32
+ end
33
+ def post_block_configuration
34
+ @config.yet_another_test_option = @config.test_option
35
+ end
36
+ end
37
+ model = mock('model')
38
+ model.should_receive(:config).and_return(OpenStruct.new)
39
+ @dokkittask = Dokkit::DokkitLib.new(model, 'dokkit') do |task|
40
+ task.config.test_dir = 'test_dir/'
41
+ task.config.test_option = 'test_option'
42
+ end
43
+ end
44
+ it 'should define a namespace for its tasks' do
45
+ @dokkittask.ns.should_not be_empty
46
+ end
47
+ it 'should be initialized with a configuration hash' do
48
+ @dokkittask.config.test_dir.should == 'test_dir/'
49
+ @dokkittask.config.test_option.should == 'test_option'
50
+ end
51
+ it 'should do pre configuration' do
52
+ @dokkittask.config.another_test_option.should == 'default value'
53
+ end
54
+ it 'should do post configuration' do
55
+ @dokkittask.config.yet_another_test_option.should == @dokkittask.config.test_option
56
+ end
57
+ it 'should encapsulate the tasks defined in its namespace' do
58
+ task('dokkit:test').prerequisites.should == ['dep']
59
+ end
60
+ it 'should define the same task only once' do
61
+ @dokkittask.dokkit_task('test' => 'dep').should be_nil
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # File 'filehelper_spec.rb' created on 28 feb 2008 at 16:44:07.
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/filehelper_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/extension/filehelper'
19
+ require File.dirname(__FILE__) + '/spec_helper.rb'
20
+
21
+ describe Dokkit::Extension::FileHelper do
22
+ before do
23
+ @document = mock('document')
24
+ @document.extend Dokkit::Extension::FileHelper
25
+ end
26
+ it 'should resolve the absolute path name' do
27
+ @taskconfig = mock('taskconfig')
28
+ @taskconfig.should_receive(:document_dir).and_return('doc/pages')
29
+ @document.should_receive(:taskconfig).and_return(@taskconfig)
30
+ @document.should_receive(:document).and_return('doc/pages/subdir/document.ext')
31
+ @document.relative('/images/image.img').should == '../images/image.img'
32
+ end
33
+ end
34
+