BuildMaster 0.9.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. data/bin/svnfix.rb +3 -0
  2. data/lib/buildmaster/ci/server.rb +55 -0
  3. data/lib/buildmaster/common.rb +3 -0
  4. data/lib/buildmaster/common/properties.rb +28 -0
  5. data/lib/buildmaster/{tree_to_object.rb → common/tree_to_object.rb} +0 -0
  6. data/lib/buildmaster/cotta.rb +1 -1
  7. data/lib/buildmaster/cotta/command_error.rb +6 -1
  8. data/lib/buildmaster/cotta/command_interface.rb +44 -0
  9. data/lib/buildmaster/cotta/command_runner.rb +39 -0
  10. data/lib/buildmaster/cotta/cotta.rb +40 -3
  11. data/lib/buildmaster/cotta/cotta_dir.rb +28 -7
  12. data/lib/buildmaster/cotta/cotta_file.rb +14 -2
  13. data/lib/buildmaster/cotta/cotta_pathname.rb +9 -0
  14. data/lib/buildmaster/cotta/in_memory_system.rb +20 -9
  15. data/lib/buildmaster/cotta/physical_system.rb +4 -8
  16. data/lib/buildmaster/project.rb +10 -0
  17. data/lib/buildmaster/{ant_driver.rb → project/ant_driver.rb} +0 -0
  18. data/lib/buildmaster/project/build.rb +3 -0
  19. data/lib/buildmaster/{build_number_file.rb → project/build_number_file.rb} +4 -0
  20. data/lib/buildmaster/project/ci.rb +3 -0
  21. data/lib/buildmaster/{cvs_driver.rb → project/cvs_driver.rb} +0 -0
  22. data/lib/buildmaster/project/ftp_driver.rb +64 -0
  23. data/lib/buildmaster/{java_manifest.rb → project/java_manifest.rb} +0 -0
  24. data/lib/buildmaster/project/pscp_driver.rb +17 -0
  25. data/lib/buildmaster/project/release.rb +67 -0
  26. data/lib/buildmaster/project/ruby_forge_project.rb +26 -0
  27. data/lib/buildmaster/{run_ant.rb → project/run_ant.rb} +0 -0
  28. data/lib/buildmaster/project/server_manager.rb +64 -0
  29. data/lib/buildmaster/project/svn_admin_driver.rb +20 -0
  30. data/lib/buildmaster/project/svn_driver.rb +94 -0
  31. data/lib/buildmaster/project/svn_helper.rb +113 -0
  32. data/lib/buildmaster/project/svn_status_info.rb +54 -0
  33. data/lib/buildmaster/{try.rb → project/try.rb} +0 -0
  34. data/lib/buildmaster/project/version_number_file.rb +45 -0
  35. data/lib/buildmaster/{windows → project/windows}/iis_driver.rb +4 -4
  36. data/lib/buildmaster/{windows → project/windows}/sql_server_driver.rb +0 -0
  37. data/lib/buildmaster/site.rb +5 -0
  38. data/lib/buildmaster/site/about_handler.rb +43 -0
  39. data/lib/buildmaster/site/content_engine_repository.rb +83 -0
  40. data/lib/buildmaster/site/element_processor_by_name.rb +18 -0
  41. data/lib/buildmaster/site/file_processor.rb +59 -0
  42. data/lib/buildmaster/site/site.rb +29 -6
  43. data/lib/buildmaster/site/site_server.rb +56 -0
  44. data/lib/buildmaster/{site_spec.rb → site/site_spec.rb} +63 -38
  45. data/lib/buildmaster/{site_tester.rb → site/site_tester.rb} +0 -0
  46. data/lib/buildmaster/site/source_content.rb +12 -0
  47. data/lib/buildmaster/{source_file_handler.rb → site/source_file_handler.rb} +13 -27
  48. data/lib/buildmaster/site/template_builder.rb +4 -0
  49. data/lib/buildmaster/site/template_error.rb +18 -0
  50. data/lib/buildmaster/{template_runner.rb → site/template_runner.rb} +6 -16
  51. data/lib/buildmaster/{templatelets.rb → site/templatelets.rb} +3 -1
  52. data/lib/buildmaster/site/templatelets/attribute.rb +21 -0
  53. data/lib/buildmaster/site/templatelets/code.rb +82 -0
  54. data/lib/buildmaster/{templatelets → site/templatelets}/each.rb +7 -5
  55. data/lib/buildmaster/{templatelets → site/templatelets}/href.rb +1 -1
  56. data/lib/buildmaster/{templatelets → site/templatelets}/include.rb +0 -0
  57. data/lib/buildmaster/{templatelets → site/templatelets}/link.rb +2 -3
  58. data/lib/buildmaster/{templatelets → site/templatelets}/text.rb +1 -1
  59. data/lib/buildmaster/{templatelets → site/templatelets}/when.rb +4 -7
  60. data/lib/buildmaster/site/templates/buildmaster/content/border_bottom.gif +0 -0
  61. data/lib/buildmaster/site/templates/buildmaster/content/buildmaster.css +370 -0
  62. data/lib/buildmaster/site/templates/buildmaster/content/logo.gif +0 -0
  63. data/lib/buildmaster/site/templates/buildmaster/content/news-rss2.xml +4 -0
  64. data/lib/buildmaster/site/templates/buildmaster/content/print.css +65 -0
  65. data/lib/buildmaster/site/templates/buildmaster/content/ruby.css +14 -0
  66. data/lib/buildmaster/site/templates/buildmaster/template.html +121 -0
  67. data/lib/buildmaster/site/templates/cotta/content/border_bottom.gif +0 -0
  68. data/lib/buildmaster/site/templates/cotta/content/cotta.css +363 -0
  69. data/lib/buildmaster/site/templates/cotta/content/cotta.gif +0 -0
  70. data/lib/buildmaster/site/templates/cotta/content/news-rss2.xml +2 -0
  71. data/lib/buildmaster/site/templates/cotta/template.html +106 -0
  72. data/lib/buildmaster/site/xtemplate.rb +26 -0
  73. data/lib/buildmaster/version +1 -0
  74. data/test/buildmaster/common/tc_properties.rb +24 -0
  75. data/test/buildmaster/{tc_tree_to_object.rb → common/tc_tree_to_object.rb} +18 -18
  76. data/test/buildmaster/cotta/cotta_specifications.rb +88 -64
  77. data/test/buildmaster/cotta/physical_system_stub.rb +3 -3
  78. data/test/buildmaster/cotta/system_file_specifications.rb +38 -47
  79. data/test/buildmaster/cotta/tc_command_interface.rb +46 -0
  80. data/test/buildmaster/cotta/tc_command_runner.rb +28 -0
  81. data/test/buildmaster/cotta/tc_cotta.rb +35 -9
  82. data/test/buildmaster/cotta/tc_cotta_dir_in_memory.rb +10 -5
  83. data/test/buildmaster/cotta/tc_cotta_file_in_memory.rb +3 -3
  84. data/test/buildmaster/cotta/tc_in_memory_system.rb +7 -2
  85. data/test/buildmaster/cotta/tc_pathname.rb +22 -0
  86. data/test/buildmaster/cotta/tc_physical_system.rb +12 -2
  87. data/test/buildmaster/{build.xml → project/build.xml} +0 -0
  88. data/test/buildmaster/{manifest.mf → project/manifest.mf} +0 -0
  89. data/test/buildmaster/{tc_ant_driver.rb → project/tc_ant_driver.rb} +3 -3
  90. data/test/buildmaster/{tc_build_number_file.rb → project/tc_build_number_file.rb} +7 -7
  91. data/test/buildmaster/{tc_cvs_driver.rb → project/tc_cvs_driver.rb} +14 -14
  92. data/test/buildmaster/{tc_java_manifest.rb → project/tc_java_manifest.rb} +7 -7
  93. data/test/buildmaster/project/tc_release.rb +61 -0
  94. data/test/buildmaster/project/tc_server_manager.rb +70 -0
  95. data/test/buildmaster/project/tc_svn_driver.rb +104 -0
  96. data/test/buildmaster/project/tc_svn_status_info.rb +37 -0
  97. data/test/buildmaster/project/tc_version_number_file.rb +46 -0
  98. data/test/buildmaster/{windows → project/windows}/tc_iis_driver.rb +5 -4
  99. data/test/buildmaster/{windows → project/windows}/tc_sql_server_driver.rb +4 -4
  100. data/test/buildmaster/site/content/tc_content_engine_repository.rb +63 -0
  101. data/test/buildmaster/site/tc_element_processor_by_name.rb +29 -0
  102. data/test/buildmaster/site/tc_file_processor.rb +141 -0
  103. data/test/buildmaster/site/tc_site.rb +42 -11
  104. data/test/buildmaster/site/tc_site_server.rb +43 -0
  105. data/test/buildmaster/{tc_site_spec.rb → site/tc_site_spec.rb} +9 -9
  106. data/test/buildmaster/{tc_source_file_handler.rb → site/tc_source_file_handler.rb} +10 -9
  107. data/test/buildmaster/site/tc_template_builder.rb +23 -23
  108. data/test/buildmaster/site/tc_template_error.rb +15 -0
  109. data/test/buildmaster/{tc_template_runner.rb → site/tc_template_runner.rb} +22 -17
  110. data/test/buildmaster/site/tc_templatelets.rb +37 -0
  111. data/test/buildmaster/{tc_xtemplate.rb → site/tc_xtemplate.rb} +14 -15
  112. data/test/buildmaster/{template.xhtml → site/template.xhtml} +0 -0
  113. data/test/buildmaster/{templatelets → site/templatelets}/common_templatelet_test.rb +11 -7
  114. data/test/buildmaster/{templatelets → site/templatelets}/tc_attribute.rb +14 -10
  115. data/test/buildmaster/site/templatelets/tc_code.rb +132 -0
  116. data/test/buildmaster/{templatelets → site/templatelets}/tc_each.rb +25 -12
  117. data/test/buildmaster/{templatelets → site/templatelets}/tc_href.rb +6 -8
  118. data/test/buildmaster/{templatelets → site/templatelets}/tc_include.rb +3 -12
  119. data/test/buildmaster/{templatelets → site/templatelets}/tc_link.rb +11 -18
  120. data/test/buildmaster/{templatelets → site/templatelets}/tc_text.rb +2 -9
  121. data/test/buildmaster/{templatelets → site/templatelets}/tc_when.rb +8 -15
  122. data/test/manual/bms.rb +10 -0
  123. data/test/tmp/svn_test/repository/README.txt +5 -0
  124. data/test/tmp/svn_test/repository/conf/authz +21 -0
  125. data/test/tmp/svn_test/repository/conf/passwd +8 -0
  126. data/test/tmp/svn_test/repository/conf/svnserve.conf +30 -0
  127. data/test/tmp/svn_test/repository/db/current +1 -0
  128. data/test/tmp/svn_test/repository/db/format +1 -0
  129. data/test/tmp/svn_test/repository/db/fs-type +1 -0
  130. data/test/tmp/svn_test/repository/db/revprops/0 +5 -0
  131. data/test/tmp/svn_test/repository/db/revprops/1 +13 -0
  132. data/test/tmp/svn_test/repository/db/revprops/2 +13 -0
  133. data/test/tmp/svn_test/repository/db/revprops/3 +13 -0
  134. data/test/tmp/svn_test/repository/db/revprops/4 +13 -0
  135. data/test/tmp/svn_test/repository/db/revs/0 +11 -0
  136. data/test/tmp/svn_test/repository/db/revs/1 +25 -0
  137. data/test/tmp/svn_test/repository/db/revs/2 +29 -0
  138. data/test/tmp/svn_test/repository/db/revs/3 +33 -0
  139. data/test/tmp/svn_test/repository/db/revs/4 +0 -0
  140. data/test/tmp/svn_test/repository/db/uuid +1 -0
  141. data/test/tmp/svn_test/repository/db/write-lock +0 -0
  142. data/test/tmp/svn_test/repository/format +1 -0
  143. data/test/tmp/svn_test/repository/hooks/post-commit.tmpl +51 -0
  144. data/test/tmp/svn_test/repository/hooks/post-lock.tmpl +44 -0
  145. data/test/tmp/svn_test/repository/hooks/post-revprop-change.tmpl +56 -0
  146. data/test/tmp/svn_test/repository/hooks/post-unlock.tmpl +42 -0
  147. data/test/tmp/svn_test/repository/hooks/pre-commit.tmpl +70 -0
  148. data/test/tmp/svn_test/repository/hooks/pre-lock.tmpl +64 -0
  149. data/test/tmp/svn_test/repository/hooks/pre-revprop-change.tmpl +66 -0
  150. data/test/tmp/svn_test/repository/hooks/pre-unlock.tmpl +60 -0
  151. data/test/tmp/svn_test/repository/hooks/start-commit.tmpl +54 -0
  152. data/test/tmp/svn_test/repository/locks/db-logs.lock +3 -0
  153. data/test/tmp/svn_test/repository/locks/db.lock +3 -0
  154. data/test/tmp/svn_test/second/test.txt +1 -0
  155. data/test/tmp/svn_test/workdir/test.txt +1 -0
  156. data/test/ts_buildmaster.rb +0 -1
  157. metadata +168 -69
  158. data/lib/buildmaster.rb +0 -10
  159. data/lib/buildmaster/build_file.rb +0 -11
  160. data/lib/buildmaster/buildnumber +0 -1
  161. data/lib/buildmaster/file_processor.rb +0 -138
  162. data/lib/buildmaster/site_server.rb +0 -33
  163. data/lib/buildmaster/source_content.rb +0 -11
  164. data/lib/buildmaster/svn_driver.rb +0 -78
  165. data/lib/buildmaster/template_error.rb +0 -8
  166. data/lib/buildmaster/templatelets/attribute.rb +0 -16
  167. data/lib/buildmaster/xtemplate.rb +0 -27
  168. data/lib/mock.rb +0 -3
  169. data/lib/mock/mock_base.rb +0 -24
  170. data/test/buildmaster/tc_file_processor.rb +0 -125
  171. data/test/buildmaster/tc_svn_driver.rb +0 -81
  172. data/test/tmp/output/index.html +0 -8
  173. data/test/tmp/output/markdown.html +0 -8
  174. data/test/tmp/output/textile.html +0 -8
@@ -1,9 +1,9 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", '..', "lib", 'buildmaster')
2
2
 
3
3
  require 'spec'
4
- require 'buildmaster'
5
4
  require 'webrick'
6
- require 'source_file_handler'
5
+ require 'site/source_file_handler'
6
+ require 'cotta'
7
7
 
8
8
  module BuildMaster
9
9
 
@@ -11,8 +11,9 @@ context 'SourceFileHandler' do
11
11
  attr_reader :path_info
12
12
 
13
13
  specify 'should_be_able_to_find_source' do
14
- server = WEBrick::HTTPServer.new(:Port => 2000)
15
- dir = File.dirname(__FILE__)
14
+ server = WEBrick::HTTPServer.new(:Port => 2001)
15
+ current_file = Cotta.file(__FILE__)
16
+ dir = current_file.parent
16
17
  spec = SiteSpec.new
17
18
  spec.template =<<TEMPLATE
18
19
  <html xmlns="http://www.w3.org/1999/xhtml"
@@ -24,13 +25,13 @@ context 'SourceFileHandler' do
24
25
  </body>
25
26
  </html>
26
27
  TEMPLATE
27
- spec.content_dir = File.join(dir, 'site', 'content')
28
- spec.output_dir = File.join(dir, 'output')
28
+ spec.content_dir = dir.dir('content').path
29
+ spec.output_dir = dir.dir('output').path
29
30
  file_handler = SourceFileHandler.new(server, spec)
30
- @path_info = '/markdown.html'
31
+ @path_info = '/markdown.markdown'
31
32
  file_handler.service(self, self)
32
33
  document = REXML::Document.new(self['body'])
33
- REXML::XPath.first(document, '/html/head/title').text.should_equal 'Title'
34
+ REXML::XPath.first(document, '/html/head/title').text.should == 'Title'
34
35
  end
35
36
 
36
37
  def []=(name, value)
@@ -1,9 +1,9 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'buildmaster')
2
2
 
3
3
  require 'spec'
4
4
  require 'rexml/xpath'
5
- require 'buildmaster/site/template_builder'
6
- require 'buildmaster/tree_to_object'
5
+ require 'site/template_builder'
6
+ require 'common/tree_to_object'
7
7
  require 'yaml'
8
8
 
9
9
  module BuildMaster
@@ -12,7 +12,7 @@ context 'Template Builder' do
12
12
  specify 'should generate template document' do
13
13
  builder = TemplateBuilder.new
14
14
  document = builder.generate
15
- REXML::XPath.first(document, '/html/head/title/*').name.should_equal 'include'
15
+ REXML::XPath.first(document, '/html/head/title/*').name.should == 'include'
16
16
  assert_css_path(document, 'buildmaster.css')
17
17
  end
18
18
 
@@ -22,15 +22,15 @@ context 'Template Builder' do
22
22
  builder.css_path = 'mycss.css'
23
23
  document = builder.generate
24
24
  first_child = REXML::XPath.first(document, '/html/head/title').children[0]
25
- first_child.class.should_equal REXML::Text
26
- first_child.value.should_equal 'Title Header - '
25
+ first_child.class.should == REXML::Text
26
+ first_child.value.should == 'Title Header - '
27
27
  assert_css_path(document, 'mycss.css')
28
28
  end
29
29
 
30
30
  specify 'test_should_have_logo_defaults' do
31
31
  builder = TemplateBuilder.new
32
- builder.logo.path.should_equal nil
33
- builder.logo.link.should_equal 'index.html'
32
+ builder.logo.path.should == nil
33
+ builder.logo.link.should == 'index.html'
34
34
  end
35
35
 
36
36
  specify 'test_should_generate_logo_and_link' do
@@ -40,9 +40,9 @@ context 'Template Builder' do
40
40
  document = builder.generate
41
41
  header = assert_first(document, '/html/body/div[@class="header"]')
42
42
  anchor_href = assert_first(header, 'a/template:href')
43
- anchor_href.attributes['url'].should_equal 'main.html'
43
+ anchor_href.attributes['url'].should == 'main.html'
44
44
  img_href = assert_first(header, 'a/img/template:href')
45
- img_href.attributes['url'].should_equal 'gif/logo.gif'
45
+ img_href.attributes['url'].should == 'gif/logo.gif'
46
46
  end
47
47
 
48
48
  specify 'test_should_build_left_menu' do
@@ -56,18 +56,18 @@ context 'Template Builder' do
56
56
  group.menu_item('Getting Started', 'doc/getting-started')
57
57
  document = builder.generate
58
58
  groups = REXML::XPath.match(document, '/html/body/div[@class="left"]/div[@class="MenuGroup"]')
59
- groups.size.should_equal 2
59
+ groups.size.should == 2
60
60
  first_group = groups[0]
61
61
  header = assert_first(first_group, 'h1')
62
- header.text.should_equal 'Software'
62
+ header.text.should == 'Software'
63
63
  items = REXML::XPath.match(first_group, 'ul/li')
64
- items.size.should_equal 3
64
+ items.size.should == 3
65
65
  first_item = items[0]
66
66
  anchor = assert_first(first_item, 'template:link')
67
- anchor.attributes['href'].should_equal 'download.html'
68
- anchor.text.should_equal 'Download'
67
+ anchor.attributes['href'].should == 'download.html'
68
+ anchor.text.should == 'Download'
69
69
  more = items[2]
70
- more.attributes['class'].should_equal 'More'
70
+ more.attributes['class'].should == 'More'
71
71
  end
72
72
 
73
73
  specify 'should_have_releases_info' do
@@ -79,14 +79,14 @@ context 'Template Builder' do
79
79
  releases.download_link = 'download.html'
80
80
  releases.versioning_link = 'versioning.html'
81
81
  document = builder.generate
82
- REXML::XPath.first(document, '/html/body/template:when/div[@class="right"]/div/h1').text.should_equal 'Latest Versions'
82
+ REXML::XPath.first(document, '/html/body/template:when/div[@class="right"]/div/h1').text.should == 'Latest Versions'
83
83
  end
84
84
 
85
85
  specify 'should_have_no_release_info_if_not_assigned' do
86
86
  builder = TemplateBuilder.new
87
87
  builder.releases.download_link = nil
88
88
  document = builder.generate
89
- REXML::XPath.match(document, '/html/body/template:when/div/*').size.should_equal 0
89
+ REXML::XPath.match(document, '/html/body/template:when/div/*').size.should == 0
90
90
  end
91
91
 
92
92
  specify 'should_read_from_yaml' do
@@ -116,16 +116,16 @@ menu_groups:
116
116
  more: doc/index.html
117
117
  CONTENT
118
118
  builder = TreeToObject.from_yaml(content, TemplateBuilder.new)
119
- builder.title_header.should_equal 'BuilderMaster -'
120
- builder.logo.path.should_equal 'logo.gif'
121
- builder.logo.link.should_equal 'index.html'
119
+ builder.title_header.should == 'BuilderMaster -'
120
+ builder.logo.path.should == 'logo.gif'
121
+ builder.logo.link.should == 'index.html'
122
122
  end
123
123
 
124
124
  private
125
125
  def assert_css_path(document, expected)
126
126
  href = REXML::XPath.first(document, '/html/head/link/*')
127
- href.name.should_equal 'href'
128
- href.attributes['url'].should_equal expected
127
+ href.name.should == 'href'
128
+ href.attributes['url'].should == expected
129
129
  end
130
130
 
131
131
  def assert_first(xml_model, xpath)
@@ -0,0 +1,15 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'buildmaster')
2
+
3
+ require 'site/template_error'
4
+ require 'spec'
5
+
6
+ context 'template error' do
7
+ specify 'format of exception' do
8
+ begin
9
+ raise BuildMaster::TemplateError.new('test'), 'message'
10
+ fail('error should have been raised')
11
+ rescue StandardError => error
12
+ $!.to_s.should == 'BuildMaster::TemplateError: message - test'
13
+ end
14
+ end
15
+ end
@@ -1,12 +1,13 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib", 'buildmaster')
2
2
 
3
3
  require 'rexml/xpath'
4
4
  require 'rexml/document'
5
5
  require 'spec'
6
6
  require 'pathname'
7
- require 'buildmaster/template_runner'
8
- require 'buildmaster/source_content'
9
- require 'buildmaster/templatelets'
7
+ require 'site/template_runner'
8
+ require 'site/source_content'
9
+ require 'site/templatelets'
10
+ require 'site/element_processor_by_name'
10
11
 
11
12
  module BuildMaster
12
13
  class NameTemplatelet
@@ -20,6 +21,10 @@ class NameTemplatelet
20
21
  end
21
22
 
22
23
  context 'TemplateRunnerTest' do
24
+ setup do
25
+ @templatelets = Hash.new
26
+ end
27
+
23
28
  specify 'process_element_in_document' do
24
29
  target_content = <<END
25
30
  <html>
@@ -45,11 +50,11 @@ END
45
50
  template_element = REXML::XPath.first(REXML::Document.new(template_content), "/html/p")
46
51
  source_xml = REXML::Document.new(source_content)
47
52
  source_element = REXML::XPath.first(source_xml, '/persons/person[@id="1"]')
48
- runner = TemplateRunner.new(target_element, template_element,
49
- SourceContent.new(Pathname.new('content'), source_element))
50
- runner.templatelets['include'] = Include.new(self)
51
- runner.process
52
- REXML::XPath.first(REXML::Document.new(target_xml.to_s), '/html/h1/text()').value.strip.should_equal 'Name One'
53
+ @templatelets['include'] = Include.new(self)
54
+ runner = TemplateRunner.new(target_element, ElementProcessorByName.new(@templatelets),
55
+ SourceContent.new(Pathname.new('content'), source_element, nil))
56
+ runner.process template_element
57
+ REXML::XPath.first(REXML::Document.new(target_xml.to_s), '/html/h1/text()').value.strip.should == 'Name One'
53
58
  end
54
59
 
55
60
  specify 'should_use_templatelet_based_on_name' do
@@ -63,14 +68,14 @@ END
63
68
  </html>
64
69
  END
65
70
  template_document = REXML::Document.new(template_content)
66
- runner = TemplateRunner.new(output, template_document,
67
- SourceContent.new(Pathname.new('content/index.textile'), REXML::Document.new))
68
- runner.templatelets['name'] = NameTemplatelet.new(self)
69
- runner.process
70
- @element_target.name.should_equal 'p'
71
- @element_processed.name.should_equal 'name'
72
- @element_processed.attributes['attribute'].should_equal 'value'
73
- @element_processed.attributes['attribute2'].should_equal 'value2'
71
+ @templatelets['name'] = NameTemplatelet.new(self)
72
+ runner = TemplateRunner.new(output, ElementProcessorByName.new(@templatelets),
73
+ SourceContent.new(Pathname.new('content/index.textile'), REXML::Document.new, nil))
74
+ runner.process template_document
75
+ @element_target.name.should == 'p'
76
+ @element_processed.name.should == 'name'
77
+ @element_processed.attributes['attribute'].should == 'value'
78
+ @element_processed.attributes['attribute2'].should == 'value2'
74
79
  end
75
80
 
76
81
  def processed(target, element)
@@ -0,0 +1,37 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'templatelets/common_templatelet_test'
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'buildmaster')
5
+
6
+ require 'templatelets'
7
+ require 'rexml/element'
8
+ require 'spec'
9
+
10
+ module BuildMaster
11
+
12
+ context 'element class alternation' do
13
+ include HelperMethods
14
+
15
+ specify 'get attribute value' do
16
+ content = <<CONTENT
17
+ <root>
18
+ <element name="value"/>
19
+ </root>
20
+ CONTENT
21
+ element = create_template_element(content, 'root/element')
22
+ element.attribute_value('name').should == 'value'
23
+ end
24
+
25
+ specify 'raise template error if value is not there' do
26
+ content = <<CONTENT
27
+ <root>
28
+ <element/>
29
+ </root>
30
+ CONTENT
31
+ element = create_template_element(content, 'root/element')
32
+ Proc.new{element.attribute_value!('name')}.should_raise TemplateError
33
+ end
34
+ end
35
+
36
+
37
+ end
@@ -1,11 +1,10 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib", 'buildmaster')
2
2
 
3
3
  require 'rexml/xpath'
4
4
  require 'spec'
5
- require 'buildmaster'
6
- require 'buildmaster/source_content'
7
- require 'buildmaster/cotta'
8
- require 'buildmaster/cotta/in_memory_system'
5
+ require 'site/source_content'
6
+ require 'cotta'
7
+ require 'cotta/in_memory_system'
9
8
 
10
9
  module BuildMaster
11
10
 
@@ -28,7 +27,7 @@ context 'XTemplate' do
28
27
  </body>
29
28
  </html>
30
29
  CONTENT
31
- template = template_file.read {|file| BuildMaster::XTemplate.new(file, Hash.new)}
30
+ template = BuildMaster::XTemplate.new(REXML::Document.new(template_file.load), Hash.new)
32
31
  end
33
32
 
34
33
  specify 'should_initialize_with_content' do
@@ -41,9 +40,9 @@ CONTENT
41
40
  <body>Body</body>
42
41
  </html>
43
42
  CONTENT
44
- template = XTemplate.new(template_content, Hash.new)
45
- xml_output = template.process(SourceContent.new(Pathname.new('content'), ''))
46
- REXML::XPath.first(xml_output, '/html/body').text.should_equal 'Body'
43
+ template = XTemplate.new(REXML::Document.new(template_content), Hash.new)
44
+ xml_output = template.process(SourceContent.new(Pathname.new('content'), nil, nil))
45
+ REXML::XPath.first(xml_output, '/html/body').text.should == 'Body'
47
46
  end
48
47
 
49
48
  specify 'should_hook_up_templatelets' do
@@ -71,11 +70,11 @@ INCLUDE_CONTENT
71
70
  <body></body>
72
71
  </html>
73
72
  INCLUDE_SOURCE
74
- template = XTemplate.new(template_content, load_templatelets)
75
- xml_document = template.process(SourceContent.new(nil, source_content))
73
+ template = XTemplate.new(REXML::Document.new(template_content), load_element_processor)
74
+ xml_document = template.process(SourceContent.new(nil, source_content, nil))
76
75
  xml_output = REXML::Document.new(xml_document.to_s())
77
- REXML::XPath.first(xml_output, '/html/head/title').text.should_equal 'BuildMaster - Index'
78
- REXML::XPath.first(xml_output, '/html/body/ul/li').text.should_equal 'one'
76
+ REXML::XPath.first(xml_output, '/html/head/title').text.should == 'BuildMaster - Index'
77
+ REXML::XPath.first(xml_output, '/html/body/ul/li').text.should == 'one'
79
78
  end
80
79
 
81
80
  def what?(path)
@@ -86,8 +85,8 @@ INCLUDE_SOURCE
86
85
  return true
87
86
  end
88
87
 
89
- def load_templatelets
90
- return {'when' => When.new(self, self)}
88
+ def load_element_processor
89
+ ElementProcessorByName.new({'when' => When.new(self, self)})
91
90
  end
92
91
  end
93
92
  end
@@ -1,14 +1,14 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "..", "..", "..", "lib")
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "..", '..', "lib", 'buildmaster')
2
2
 
3
3
  require 'rexml/xpath'
4
4
  require 'rexml/document'
5
5
  require 'spec'
6
- require 'buildmaster/site_spec'
7
- require 'buildmaster/source_content'
8
- require 'buildmaster/template_error'
9
- require 'buildmaster/templatelets'
10
- require 'buildmaster/cotta'
11
- require 'buildmaster/cotta/in_memory_system'
6
+ require 'site/site_spec'
7
+ require 'site/source_content'
8
+ require 'site/template_error'
9
+ require 'site/templatelets'
10
+ require 'cotta'
11
+ require 'cotta/in_memory_system'
12
12
 
13
13
  module BuildMaster
14
14
  module HelperMethods
@@ -24,5 +24,9 @@ module HelperMethods
24
24
  element.name=name
25
25
  return element
26
26
  end
27
+
28
+ def create_template_element(content, xpath)
29
+ REXML::XPath.first(REXML::Document.new(content), xpath)
30
+ end
27
31
  end
28
32
  end
@@ -2,11 +2,6 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'common_templatelet_test'
4
4
 
5
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
-
7
- require 'buildmaster/template_error'
8
- require 'buildmaster/templatelets/attribute'
9
-
10
5
  module BuildMaster
11
6
 
12
7
  class AttributeForTest
@@ -32,18 +27,27 @@ context 'AttributeTest' do
32
27
  target = create_element('a')
33
28
  template_element = create_attribute_element('attr-name', 'expression')
34
29
  expected_pathname = Pathname.new('/path')
35
- @source_path = SourceContent.new(expected_pathname, nil)
30
+ @source_path = SourceContent.new(expected_pathname, nil, nil)
36
31
  templatelet.process(target, template_element, @source_path)
37
- target.attributes['attr-name'].should_equal 'value'
38
- @path_logged.should_equal expected_pathname
32
+ target.attributes['attr-name'].should == 'value'
33
+ @path_logged.path.should == expected_pathname
39
34
  end
40
35
 
41
36
  specify 'should_check_for_expression_responder' do
42
37
  target = create_element('a')
43
38
  template_element = create_attribute_element('name', 'eval')
44
- source_path = SourceContent.new(Pathname.new('./'), create_element('name'))
39
+ source_path = SourceContent.new(Pathname.new('./'), create_element('name'), nil)
45
40
  attribute = Attribute.new(self)
46
- lambda {attribute.process(target, template_element, source_path)}.should_raise TemplateError
41
+ Proc.new {attribute.process(target, template_element, source_path)}.should_raise TemplateError
42
+ end
43
+
44
+ specify 'shoul check properties as a backup' do
45
+ target = create_element('a')
46
+ template_element = create_attribute_element('name', 'property')
47
+ source_path = SourceContent.new(Pathname.new('./'), create_element('name'), nil)
48
+ attribute = Attribute.new(self, {'property' => 'value'})
49
+ attribute.process(target, template_element, @source_path)
50
+ target.attributes['name'].should == 'value'
47
51
  end
48
52
 
49
53
  def create_attribute_element(name, eval)
@@ -0,0 +1,132 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ module BuildMaster
6
+ context 'code template processsing' do
7
+ include HelperMethods
8
+
9
+ setup do
10
+ @cotta = Cotta.new(InMemorySystem.new)
11
+ end
12
+
13
+ specify 'generate <pre> tag with code class by default' do
14
+ template_content = <<CONTENT
15
+ <html>
16
+ <code source="samples/sample.rb" tag="sample"/>
17
+ </html>
18
+ CONTENT
19
+ content_path = 'doc/doc.html'
20
+ @cotta.file(content_path).parent.file('samples/sample.rb').save <<CONTENT
21
+ #START sample
22
+
23
+ # Normally you would put release script at the root of the project
24
+ cotta = BuildMaster::Cotta.new
25
+ root = cotta.file(__FILE__).parent
26
+
27
+ # BuildMaster can look into svn files to figure out the svn information
28
+ #END sample
29
+ CONTENT
30
+ target = create_element('test')
31
+ template = create_template_element(template_content, '/html/code')
32
+ site_spec = SiteSpec.new('/root', @cotta);
33
+ code_processor = Code.new(site_spec)
34
+ code_processor.process(target, template, SourceContent.new('doc/doc.html', nil, @cotta.file(content_path)))
35
+ REXML::XPath.first(target, 'pre').attributes['class'].should == 'code'
36
+ REXML::XPath.first(target, 'pre').text.should == <<CONTENT
37
+
38
+ # Normally you would put release script at the root of the project
39
+ cotta = BuildMaster::Cotta.new
40
+ root = cotta.file(__FILE__).parent
41
+
42
+ # BuildMaster can look into svn files to figure out the svn information
43
+ CONTENT
44
+ end
45
+
46
+ specify 'generate error if none found' do
47
+ template_content = <<CONTENT
48
+ <html>
49
+ <code source="samples/sample.rb" tag="sample"/>
50
+ </html>
51
+ CONTENT
52
+ content_path = 'doc/doc.html'
53
+ @cotta.file(content_path).parent.file('samples/sample.rb').save
54
+ target = create_element('test')
55
+ template = create_template_element(template_content, '/html/code')
56
+ site_spec = SiteSpec.new('/root', @cotta);
57
+ code_processor = Code.new(site_spec)
58
+ source = SourceContent.new('doc/doc.html', nil, @cotta.file(content_path))
59
+ Proc.new {code_processor.process(target, template, source)}.should_raise TemplateError
60
+ end
61
+
62
+ specify 'use PCDATA if no source specified' do
63
+ template_content = <<CONTENT
64
+ <html>
65
+ <code tag="sample">
66
+ <![CDATA[
67
+ module BuildMaster
68
+
69
+ #START sample
70
+ class test
71
+ end
72
+ #END sample
73
+ end
74
+ ]]>
75
+ </code>
76
+ </html>
77
+ CONTENT
78
+ content_path = 'doc/doc.html'
79
+ target = create_element('test')
80
+ template = create_template_element(template_content, '/html/code')
81
+ site_spec = SiteSpec.new('/root', @cotta);
82
+ code_processor = Code.new(site_spec)
83
+ code_processor.process(target, template, SourceContent.new('doc/doc.html', nil, @cotta.file(content_path)))
84
+ REXML::XPath.first(target, 'pre').attributes['class'].should == 'code'
85
+ REXML::XPath.first(target, 'pre').text.should == <<CONTENT
86
+ class test
87
+ end
88
+ CONTENT
89
+ end
90
+
91
+ specify 'raise error if no source and no pcdata' do
92
+ template_content = <<CONTENT
93
+ <html>
94
+ <code tag="sample">
95
+ </code>
96
+ </html>
97
+ CONTENT
98
+ content_path = 'doc/doc.html'
99
+ target = create_element('test')
100
+ template = create_template_element(template_content, '/html/code')
101
+ site_spec = SiteSpec.new('/root', @cotta);
102
+ code_processor = Code.new(site_spec)
103
+ source = SourceContent.new('doc/doc.html', nil, @cotta.file(content_path))
104
+ Proc.new{code_processor.process(target, template, source)}.should_raise TemplateError
105
+ end
106
+
107
+ specify 'generate syntax support' do
108
+ template_content = <<CONTENT
109
+ <html>
110
+ <code source="samples/sample.rb" tag="sample" syntax="ruby"/>
111
+ </html>
112
+ CONTENT
113
+ content_path = 'doc/doc.html'
114
+ @cotta.file(content_path).parent.file('samples/sample.rb').save <<CONTENT
115
+ #START sample
116
+ module BuildMaster
117
+
118
+ class test
119
+ end
120
+ end
121
+ #END sample
122
+ CONTENT
123
+ target = create_element('test')
124
+ template = create_template_element(template_content, '/html/code')
125
+ site_spec = SiteSpec.new('/root', @cotta);
126
+ code_processor = Code.new(site_spec)
127
+ code_processor.process(target, template, SourceContent.new('doc/doc.html', nil, @cotta.file(content_path)))
128
+ REXML::XPath.first(target, 'pre').attributes['class'].should == 'code'
129
+ REXML::XPath.first(target, 'pre/span').attributes['class'].should == 'keyword'
130
+ end
131
+ end
132
+ end