sitebuilder 0.0.4 → 0.0.5

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.0.5
2
+ 2010-01-28: refactored use of procs into explicit actions
3
+ 2009-12-19:simplified initiation of sitebuilder - just call "generate" method on a sitebuilder object
1
4
  == 0.0.4
2
5
  2009-12-13:added spike of how to use erb and semantictext gem
3
6
  2009-12-13:added explicit runtime dependency on semantictext
data/README.rdoc CHANGED
@@ -14,7 +14,6 @@ a subdirectory of a destination directory.
14
14
  * Install with:
15
15
  gem install sitebuilder
16
16
  * Basic operation can be seen in demo.rdoc
17
- * Just a core object model & tests right now... needs to be completed.
18
17
  * *rdoc* http://www.greenbarsoft.co.uk/software/sitebuilder/rdoc/
19
18
  * *source* http://github.com/dafydd/sitebuilder
20
19
  * To build me, set an environment variable called *SANDBOX* to the directory above your sitebuilder directory. The tests need this pathname to access test data.
data/TODO.rdoc CHANGED
@@ -1,8 +1,8 @@
1
1
  == todo
2
2
  * make template action - with erb and semantictext
3
3
  * merge a text formatter into template action
4
- * work out how to map file paths to URLs
5
4
  * make copy action
5
+ * work out how to map file paths to URLs
6
6
  * make index action
7
7
  * work out how to handle cross references
8
8
  * work out how to handle non-fatal errors
@@ -10,4 +10,5 @@
10
10
  * integrate SemanticText action
11
11
 
12
12
  == DONE
13
+ * acquire test coverage on SiteBuilder::SiteGenerator#traverse_dir
13
14
  * fix "warning: already initialized constant"
data/doc/demo.rdoc CHANGED
@@ -17,50 +17,54 @@ If using sitebuilder from a gem, remember to "require 'rubygems'"...
17
17
  demo.script(main):010:1> end
18
18
  => nil
19
19
  demo.script(main):011:0>
20
- demo.script(main):012:0* def mapit(src, tmpl, dst)
21
- demo.script(main):013:1> template = ''
22
- demo.script(main):014:1> File.open(tmpl) do |f|
23
- demo.script(main):015:2* f.readlines.each {|l| template += l }
24
- demo.script(main):016:2> end
25
- demo.script(main):017:1> content = ''
26
- demo.script(main):018:1> File.open(src) do |c|
27
- demo.script(main):019:2* c.readlines.each {|l| content += l }
28
- demo.script(main):020:2> end
29
- demo.script(main):021:1> e = ERB.new template
30
- demo.script(main):022:1> document = Document.new(content)
31
- demo.script(main):023:1> File.open(dst,'w') do |f|
32
- demo.script(main):024:2* f.puts e.result(binding)
33
- demo.script(main):025:2> end
34
- demo.script(main):026:1> end
35
- => nil
36
- demo.script(main):027:0> templatepath = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','template.rhtml')
37
- => "/Users/daf/macbook/workspace/sitebuilder/examples/homepage/template.rhtml"
38
- demo.script(main):028:0> swapout = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','source')
20
+ demo.script(main):012:0* @templatepath =
21
+ demo.script(main):013:0* swapout = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','source')
39
22
  => "/Users/daf/macbook/workspace/sitebuilder/examples/homepage/source"
40
- demo.script(main):029:0> replace = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','dest')
23
+ demo.script(main):014:0> replace = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','dest')
41
24
  => "/Users/daf/macbook/workspace/sitebuilder/examples/homepage/dest"
42
- demo.script(main):030:0>
43
- demo.script(main):031:0* s = SiteBuilder::SiteGenerator.new(swapout,replace)
44
- => #<SiteBuilder::SiteGenerator:0x6bf300 @actions={}, @replace="/Users/daf/macbook/workspace/sitebuilder/examples/homepage/dest", @swapout="/Users/daf/macbook/workspace/sitebuilder/examples/homepage/source">
45
- demo.script(main):032:0> s.add_action('.art') do |s,r|
46
- demo.script(main):033:1* mapit(s.path,templatepath,File.join(r,s.extnless+'.html'))
47
- demo.script(main):034:1> end
48
- => #<Proc:0x006a8aec@/Users/daf/macbook/workspace/sitebuilder/doc/demo.script:32>
49
- demo.script(main):035:0>
50
- demo.script(main):036:0* s.add_action('.idx') {|s,r| `cp #{s.path} #{r}`; puts "index template #{s.path}\n\t\t #{r}"}
51
- => #<Proc:0x006908fc@/Users/daf/macbook/workspace/sitebuilder/doc/demo.script:36>
52
- demo.script(main):037:0> s.add_action('.png') {|s,r| `cp #{s.path} #{r}`; puts "png copy #{s.path}\n\t\t #{r}"}
53
- => #<Proc:0x0067a174@/Users/daf/macbook/workspace/sitebuilder/doc/demo.script:37>
54
- demo.script(main):038:0> s.add_action('.css') {|s,r| `cp #{s.path} #{r}`; puts "css copy #{s.path}\n\t\t #{r}"}
55
- => #<Proc:0x0064aca8@/Users/daf/macbook/workspace/sitebuilder/doc/demo.script:38>
25
+ demo.script(main):015:0>
26
+ demo.script(main):016:0* #This is just a templating action - for real use, you'd need to process markup from "content" as well...
27
+ demo.script(main):017:0* class TemplateAction < SiteBuilder::Action
28
+ demo.script(main):018:1> def mapit(src, tmpl, dst)
29
+ demo.script(main):019:2> template = ''
30
+ demo.script(main):020:2> File.open(tmpl) do |f|
31
+ demo.script(main):021:3* f.readlines.each {|l| template += l }
32
+ demo.script(main):022:3> end
33
+ demo.script(main):023:2> content = ''
34
+ demo.script(main):024:2> File.open(src) do |c|
35
+ demo.script(main):025:3* c.readlines.each {|l| content += l }
36
+ demo.script(main):026:3> end
37
+ demo.script(main):027:2> e = ERB.new template
38
+ demo.script(main):028:2> document = Document.new(content)
39
+ demo.script(main):029:2> File.open(dst,'w') do |f|
40
+ demo.script(main):030:3* f.puts e.result(binding)
41
+ demo.script(main):031:3> end
42
+ demo.script(main):032:2> end
43
+ demo.script(main):033:1>
44
+ demo.script(main):034:1* def convert(s, r)
45
+ demo.script(main):035:2> templatepath = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','template.rhtml')
46
+ demo.script(main):036:2> mapit(s.path, templatepath, File.join(r,s.extnless+'.html'))
47
+ demo.script(main):037:2> end
48
+ demo.script(main):038:1> end
49
+ => nil
56
50
  demo.script(main):039:0>
57
- demo.script(main):040:0* SiteBuilder::DirEntry.new(swapout).traverse(s)
58
- css copy /Users/daf/macbook/workspace/sitebuilder/examples/homepage/source/homepage.css
59
- /Users/daf/macbook/workspace/sitebuilder/examples/homepage/dest
60
- => #<Dir:0x6403d4>
61
- demo.script(main):041:0>
62
- demo.script(main):042:0* demo.script(main):042:0>
51
+ demo.script(main):040:0* s = SiteBuilder::SiteGenerator.new(swapout,replace)
52
+ => #<SiteBuilder::SiteGenerator:0x63c61c @swapout="/Users/daf/macbook/workspace/sitebuilder/examples/homepage/source", @actions={}, @replace="/Users/daf/macbook/workspace/sitebuilder/examples/homepage/dest">
53
+ demo.script(main):041:0> s.add_action('.art', TemplateAction.new)
54
+ => #<TemplateAction:0x6336e8>
55
+ demo.script(main):042:0>
56
+ demo.script(main):043:0* s.add_action('.idx', SiteBuilder::CopyAction.new)
57
+ => #<SiteBuilder::CopyAction:0x627938>
58
+ demo.script(main):044:0> s.add_action('.png', SiteBuilder::CopyAction.new)
59
+ => #<SiteBuilder::CopyAction:0x620994>
60
+ demo.script(main):045:0> s.add_action('.css', SiteBuilder::CopyAction.new)
61
+ => #<SiteBuilder::CopyAction:0x618384>
62
+ demo.script(main):046:0> s.generate
63
+ cp /Users/daf/macbook/workspace/sitebuilder/examples/homepage/source/homepage.css /Users/daf/macbook/workspace/sitebuilder/examples/homepage/dest
64
+ => #<Dir:0x615a94>
65
+ demo.script(main):047:0>
66
+ demo.script(main):048:0* demo.script(main):048:0>
63
67
 
64
68
 
65
- Sitebuilder 0.0.3
69
+ Sitebuilder 0.0.4
66
70
 
data/doc/demo.script CHANGED
@@ -9,33 +9,39 @@ class Document
9
9
  end
10
10
  end
11
11
 
12
- def mapit(src, tmpl, dst)
13
- template = ''
14
- File.open(tmpl) do |f|
15
- f.readlines.each {|l| template += l }
16
- end
17
- content = ''
18
- File.open(src) do |c|
19
- c.readlines.each {|l| content += l }
12
+ @templatepath =
13
+ swapout = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','source')
14
+ replace = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','dest')
15
+
16
+ #This is just a templating action - for real use, you'd need to process markup from "content" as well...
17
+ class TemplateAction < SiteBuilder::Action
18
+ def mapit(src, tmpl, dst)
19
+ template = ''
20
+ File.open(tmpl) do |f|
21
+ f.readlines.each {|l| template += l }
22
+ end
23
+ content = ''
24
+ File.open(src) do |c|
25
+ c.readlines.each {|l| content += l }
26
+ end
27
+ e = ERB.new template
28
+ document = Document.new(content)
29
+ File.open(dst,'w') do |f|
30
+ f.puts e.result(binding)
31
+ end
20
32
  end
21
- e = ERB.new template
22
- document = Document.new(content)
23
- File.open(dst,'w') do |f|
24
- f.puts e.result(binding)
33
+
34
+ def convert(s, r)
35
+ templatepath = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','template.rhtml')
36
+ mapit(s.path, templatepath, File.join(r,s.extnless+'.html'))
25
37
  end
26
38
  end
27
- templatepath = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','template.rhtml')
28
- swapout = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','source')
29
- replace = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','dest')
30
39
 
31
40
  s = SiteBuilder::SiteGenerator.new(swapout,replace)
32
- s.add_action('.art') do |s,r|
33
- mapit(s.path,templatepath,File.join(r,s.extnless+'.html'))
34
- end
35
-
36
- s.add_action('.idx') {|s,r| `cp #{s.path} #{r}`; puts "index template #{s.path}\n\t\t #{r}"}
37
- s.add_action('.png') {|s,r| `cp #{s.path} #{r}`; puts "png copy #{s.path}\n\t\t #{r}"}
38
- s.add_action('.css') {|s,r| `cp #{s.path} #{r}`; puts "css copy #{s.path}\n\t\t #{r}"}
41
+ s.add_action('.art', TemplateAction.new)
39
42
 
40
- SiteBuilder::DirEntry.new(swapout).traverse(s)
43
+ s.add_action('.idx', SiteBuilder::CopyAction.new)
44
+ s.add_action('.png', SiteBuilder::CopyAction.new)
45
+ s.add_action('.css', SiteBuilder::CopyAction.new)
46
+ s.generate
41
47
 
@@ -0,0 +1,21 @@
1
+ module SiteBuilder
2
+ class Action
3
+ def convert(source, destination)
4
+ throw Exception.new("should implement Action#convert")
5
+ end
6
+ end
7
+
8
+ class CopyAction < Action
9
+ def convert(source, destination)
10
+ `cp #{source.path} #{destination}`
11
+ puts "cp #{source.path} #{destination}"
12
+ end
13
+ end
14
+
15
+ class NullAction < Action
16
+ def convert(source, destionation)
17
+ end
18
+ end
19
+
20
+
21
+ end
@@ -1,5 +1,7 @@
1
1
  require 'sitebuilder/filesystem'
2
2
  require 'sitebuilder/string'
3
+ require 'sitebuilder/actions'
4
+ require 'fileutils'
3
5
 
4
6
  module SiteBuilder
5
7
 
@@ -9,18 +11,18 @@ module SiteBuilder
9
11
  class SiteGenerator < Traverser
10
12
 
11
13
  # I set up the source website directory and the destination website directory.
12
- def initialize(source, destination)
14
+ def initialize(source, destination, default_action=NullAction.new)
13
15
  @swapout = source
14
16
  @replace = destination
15
17
  @actions = {}
16
- @actions.default=Proc.new {|s,r| puts "default action source:#{s.path}\n\t\t destination:#{r}"}
18
+ @actions.default = default_action
17
19
  end
18
20
 
19
21
  # internal callback used to handle a source directory
20
22
  def traverse_dir(dir_entry)
21
23
  converted_path = dir_entry.path.clone
22
24
  converted_path.substitute_prefix!(@swapout, @replace)
23
- `mkdir #{converted_path}`
25
+ FileUtils.mkdir_p(converted_path)
24
26
  end
25
27
 
26
28
  # internal callback used to handle a source file
@@ -28,17 +30,17 @@ module SiteBuilder
28
30
  if !file_entry.path.index('.svn')
29
31
  converted_path = file_entry.dirname
30
32
  converted_path.substitute_prefix!(@swapout, @replace) #BUG? - no clone here?
31
- @actions[file_entry.extname].call(file_entry, converted_path)
33
+ @actions[file_entry.extname].convert(file_entry, converted_path)
32
34
  end
33
35
  end
34
-
35
- # Add an action for a given source file extension. The action is given by a block which
36
- # will be executed when traversal finds a matching file system entry matching the
37
- # extension. The block is takes 2 arguments, first the FsEntry representing the source
38
- # file system entry, and the second, a String which is the path to the destination
39
- # directory.
40
- def add_action(extension, &proc)
41
- @actions[extension]=proc
36
+
37
+ def add_action(extension, action)
38
+ @actions[extension]=action
39
+ end
40
+
41
+ # Initiate site generation
42
+ def generate
43
+ DirEntry.new(@swapout).traverse(self)
42
44
  end
43
45
  end
44
46
 
@@ -58,6 +58,7 @@ end
58
58
  def test_fs_entry_from
59
59
  assert_equal SiteBuilder::FileEntry, SiteBuilder::FsEntry.fs_entry_from(TEST_FILEPATH).class
60
60
  assert_equal SiteBuilder::DirEntry, SiteBuilder::FsEntry.fs_entry_from(TESTDATA_DIR).class
61
+ assert_equal SiteBuilder::UnknownEntry, SiteBuilder::FsEntry.fs_entry_from('/dev/null').class
61
62
  end
62
63
 
63
64
  def test_instance_fs_entry_from
@@ -0,0 +1,49 @@
1
+ require 'sitebuilder/sitegenerator'
2
+ require 'sitebuilder/filesystem'
3
+ require 'sitebuilder/actions'
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require 'fileutils'
8
+
9
+ class SitebuilderTest< Test::Unit::TestCase
10
+
11
+ def test_traverse_file_traverses_on_matching_file_extension
12
+ mock_action = mock("an action")
13
+ fixture_file_entry = SiteBuilder::FileEntry.new('/path/to/source/foo/testfilename.test')
14
+ mock_action.expects(:convert).once().with(fixture_file_entry, '/path/to/dest/foo')
15
+
16
+ unit = SiteBuilder::SiteGenerator.new('/path/to/source','/path/to/dest')
17
+ unit.add_action('.test', mock_action)
18
+ unit.traverse_file(fixture_file_entry)
19
+ end
20
+
21
+ def test_traverse_file_doesnt_traverse_on_nonmatching_file_extension
22
+ fixture_file_entry = SiteBuilder::FileEntry.new('/path/to/source/foo/testfilename.nomatch')
23
+ mock_default_action_to_be_called = mock("default action")
24
+ mock_default_action_to_be_called.expects(:convert).once().with(fixture_file_entry, '/path/to/dest/foo')
25
+ mock_action_not_to_be_called = mock("an action")
26
+
27
+ unit = SiteBuilder::SiteGenerator.new('/path/to/source','/path/to/dest', mock_default_action_to_be_called)
28
+
29
+ unit.add_action('.test', mock_action_not_to_be_called)
30
+ unit.traverse_file(fixture_file_entry)
31
+ end
32
+
33
+ def test_traverse_dir_creates_corresponding_directory
34
+ FileUtils.expects(:mkdir_p).once().with('/path/to/dest/foo')
35
+ fixture_dir_entry = SiteBuilder::DirEntry.new('/path/to/source/foo')
36
+ unit = SiteBuilder::SiteGenerator.new('/path/to/source','/path/to/dest')
37
+ unit.traverse_dir(fixture_dir_entry)
38
+ end
39
+
40
+ def test_generate_initiates_sitebuilder_conversion
41
+ unit = SiteBuilder::SiteGenerator.new('/path/to/source','/path/to/dest')
42
+ mock_dir_entry = mock("a mock DirEntry")
43
+ mock_dir_entry.expects(:traverse).once().with(unit)
44
+ SiteBuilder::DirEntry.expects(:new).once().with('/path/to/source').returns(mock_dir_entry)
45
+
46
+ unit.generate
47
+ end
48
+
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitebuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dafydd Rees
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-13 00:00:00 +00:00
12
+ date: 2010-01-28 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.8
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rcov
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.6
44
+ version:
35
45
  description: Static website generator using rule-based translation.
36
46
  email: os@greenbarsoft.co.uk
37
47
  executables: []
@@ -45,8 +55,8 @@ extra_rdoc_files:
45
55
  - doc/demo.rdoc
46
56
  - TODO.rdoc
47
57
  files:
48
- - doc/complex.script
49
58
  - doc/demo.script
59
+ - lib/sitebuilder/actions.rb
50
60
  - lib/sitebuilder/array.rb
51
61
  - lib/sitebuilder/filesystem.rb
52
62
  - lib/sitebuilder/sitegenerator.rb
@@ -55,6 +65,7 @@ files:
55
65
  - test/array_test.rb
56
66
  - test/data/testfile.txt
57
67
  - test/filesystem_test.rb
68
+ - test/sitegenerator_test.rb
58
69
  - test/string_test.rb
59
70
  - CHANGELOG.rdoc
60
71
  - COPYING
@@ -92,4 +103,5 @@ summary: Static site generator
92
103
  test_files:
93
104
  - ./test/array_test.rb
94
105
  - ./test/filesystem_test.rb
106
+ - ./test/sitegenerator_test.rb
95
107
  - ./test/string_test.rb
data/doc/complex.script DELETED
@@ -1,42 +0,0 @@
1
- require 'sitebuilder'
2
- require 'rubygems'
3
- require 'semantictext'
4
- require 'erb'
5
-
6
- class Document
7
- attr_reader :content
8
- def initialize(c)
9
- @content=c
10
- end
11
- end
12
-
13
- def mapit(src, tmpl, dst)
14
- template = ''
15
- File.open(tmpl) do |f|
16
- f.readlines.each {|l| template += l }
17
- end
18
- content = ''
19
- File.open(src) do |c|
20
- c.readlines.each {|l| content += l }
21
- end
22
- e = ERB.new template
23
- document = Document.new(content)
24
- File.open(dst,'w') do |f|
25
- f.puts e.result(binding)
26
- end
27
- end
28
- templatepath = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','template.rhtml')
29
- swapout = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','source')
30
- replace = File.join(ENV['SANDBOX'],'sitebuilder','examples','homepage','dest')
31
-
32
- s = SiteBuilder::SiteGenerator.new(swapout,replace)
33
- s.add_action('.art') do |s,r|
34
- mapit(s.path,templatepath,File.join(r,s.extnless+'.html'))
35
- end
36
-
37
- s.add_action('.idx') {|s,r| `cp #{s.path} #{r}`; puts "index template #{s.path}\n\t\t #{r}"}
38
- s.add_action('.png') {|s,r| `cp #{s.path} #{r}`; puts "png copy #{s.path}\n\t\t #{r}"}
39
- s.add_action('.css') {|s,r| `cp #{s.path} #{r}`; puts "css copy #{s.path}\n\t\t #{r}"}
40
-
41
- SiteBuilder::DirEntry.new(swapout).traverse(s)
42
-