deris 0.1.2 → 0.1.3

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/lib/deris.rb CHANGED
@@ -1,2 +1 @@
1
- Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), 'file.rb')).each {|f| require f }
2
- Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), 'project.rb')).each {|f| require f }
1
+ Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), '*.rb')).each {|f| require f }
data/lib/directory.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require ::File.join(::File.dirname(__FILE__), 'partial_hasher')
4
+ require ::File.join(::File.dirname(__FILE__), 'directory_writer')
5
+ require ::File.join(::File.dirname(__FILE__), 'subdirectory_list')
6
+
7
+ module Deris
8
+
9
+ class Directory
10
+ include PartialHasher
11
+ include DirectoryWriter
12
+ include SubdirectoryList
13
+
14
+ attr_reader :file_name, :partials, :directory
15
+
16
+ def initialize(directory, defaults = {})
17
+ @directory = directory
18
+ @file_name = ::File.basename(directory)
19
+ @partials = defaults.merge(partials_hash)
20
+ end
21
+
22
+ def sub_output(output)
23
+ ::File.join(output, @file_name)
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require ::File.join(::File.dirname(__FILE__), 'file')
4
+
5
+ module Deris
6
+
7
+ module DirectoryWriter
8
+
9
+ def write(output)
10
+ unless respond_to?(:sub_directories) and respond_to?(:partials) and respond_to?(:sub_output)
11
+ raise 'need to respond to "sub directories", "partials" and "sub_output" to write'
12
+ end
13
+
14
+ # write out the content from this directory
15
+ write_file output
16
+
17
+ # write out the sub directories
18
+ sub_directories.each do |dir|
19
+ Directory.new(dir, partials).write(sub_output(output))
20
+ end
21
+ end
22
+
23
+ def write_file(output)
24
+ unless respond_to?(:file_name) and respond_to?(:partials)
25
+ raise 'need to respond to "file_name" and "partials" to use write_file'
26
+ end
27
+
28
+ File.new(file_name, partials).write output
29
+ end
30
+
31
+ end
32
+
33
+ end
data/lib/file.rb CHANGED
@@ -14,6 +14,7 @@ module Deris
14
14
  end
15
15
 
16
16
  def write(directory)
17
+ FileUtils.mkdir(directory) unless ::File.exist? directory
17
18
  output_path = ::File.join(directory, "#{@name}.html")
18
19
  ::File.open(output_path, 'w+') do |file|
19
20
  file.write render
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+
4
+ module Deris
5
+
6
+ module PartialHasher
7
+
8
+ def partials_hash
9
+ unless respond_to?(:directory)
10
+ raise 'need to response to "directory" to create a hash of partials'
11
+ end
12
+
13
+ partials = {}
14
+ partial_file_mask = ::File.join(directory, '*.haml')
15
+ partial_files = ::Dir.glob(partial_file_mask)
16
+
17
+ partial_files.each do |file|
18
+ file_sym = ::File.basename(file, '.haml').to_sym
19
+ partials[file_sym] = ::File.new(file).read
20
+ end
21
+
22
+ partials
23
+ end
24
+
25
+ end
26
+
27
+ end
data/lib/project.rb CHANGED
@@ -1,18 +1,29 @@
1
1
  require 'rubygems'
2
2
  require 'fileutils'
3
- require ::File.join(::File.dirname(__FILE__), 'file')
3
+ require ::File.join(::File.dirname(__FILE__), 'directory')
4
+ require ::File.join(::File.dirname(__FILE__), 'partial_hasher')
5
+ require ::File.join(::File.dirname(__FILE__), 'directory_writer')
6
+ require ::File.join(::File.dirname(__FILE__), 'subdirectory_list')
4
7
 
5
8
  module Deris
6
9
 
7
10
  class Project
11
+ include PartialHasher
12
+ include DirectoryWriter
13
+ include SubdirectoryList
14
+
15
+ attr_reader :file_name, :partials, :directory
8
16
 
9
- def initialize(source)
17
+ def initialize(source, defaults = {})
10
18
  @source = source
11
- @source_directory = ::File.join(@source, '_src')
12
- @defaults = partials_from @source_directory
19
+ @file_name = 'index'
20
+ @directory = ::File.join(@source, '_src')
21
+ @partials = defaults.merge(partials_hash)
13
22
  end
14
23
 
15
24
  def write(output)
25
+ # adds additional behaviour on top of the DirectoryWriter mixin
26
+
16
27
  # recreate the output directory
17
28
  FileUtils.rm_rf(output) if ::File.exists?(output)
18
29
  FileUtils.mkdir(output)
@@ -22,40 +33,14 @@ module Deris
22
33
  static_content = Dir[static_content_mask].reject{|path| path =~ /_src$/}
23
34
  static_content.each{|path| FileUtils.cp_r(path, output)}
24
35
 
25
- # generate the index page from defaults
26
- File.new('index', @defaults).write output
27
-
28
- # generate the other pages of the site from sub-directories
29
- source_directories.each do |dir|
30
- partials = partials_from dir
31
- partials = @defaults.merge(partials)
32
- file_name = ::File.basename(dir)
33
- File.new(file_name, partials).write output
34
- end
36
+ # call the DirectoryWriter mixin
37
+ super
35
38
  end
36
39
 
37
- private
38
-
39
- def source_directories
40
- source_directory_mask = ::File.join(@source_directory, '*')
41
- ::Dir[source_directory_mask].find_all do |dir|
42
- ::File.directory?(dir)
43
- end
40
+ def sub_output(output)
41
+ output
44
42
  end
45
-
46
- def partials_from(directory)
47
- partials = {}
48
- partial_file_mask = ::File.join(directory, '*.haml')
49
- partial_files = ::Dir.glob(partial_file_mask)
50
-
51
- partial_files.each do |file|
52
- file_sym = ::File.basename(file, '.haml').to_sym
53
- partials[file_sym] = ::File.new(file).read
54
- end
55
-
56
- partials
57
- end
58
-
43
+
59
44
  end
60
45
 
61
46
  end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+
4
+ module Deris
5
+
6
+ module SubdirectoryList
7
+
8
+ def sub_directories
9
+ unless respond_to?(:directory)
10
+ raise 'need to respond to "directory" to list sub directories'
11
+ end
12
+
13
+ sub_directory_mask = ::File.join(directory, '*')
14
+ ::Dir[sub_directory_mask].find_all do |dir|
15
+ ::File.directory?(dir)
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # work out base paths
4
+ current_dir = File.dirname(__FILE__)
5
+ root_dir = File.join(current_dir, '..')
6
+
7
+ # require the project class
8
+ require File.join(root_dir, 'lib', 'project')
9
+
10
+ # work out paths for test
11
+ project_path = File.join(current_dir, 'examples', 'project')
12
+ output_path = File.join(root_dir, 'output')
13
+
14
+ # create and write out project
15
+ project = Deris::Project.new project_path
16
+ project.write output_path
@@ -0,0 +1,23 @@
1
+ %html
2
+
3
+ %head
4
+ %title
5
+ Documentation
6
+
7
+ %body
8
+
9
+ #menu
10
+ =partial :menu
11
+
12
+ :markdown
13
+ void test()
14
+ {
15
+ return 'some code';
16
+ }
17
+
18
+ #content
19
+ =partial 'examples/file/nested.haml'
20
+
21
+ #subnav
22
+ =partial :subnav
23
+
@@ -0,0 +1,2 @@
1
+ .nested
2
+ woot! nested content
@@ -0,0 +1,2 @@
1
+ %p
2
+ This is the home page
@@ -0,0 +1,21 @@
1
+ !!! 5
2
+ %html
3
+
4
+ %head
5
+ %title
6
+ Deris example
7
+
8
+ %body{:class => name}
9
+
10
+ %h1 Deris example
11
+
12
+ #content_wrapper
13
+
14
+ #menu
15
+ =partial :menu
16
+
17
+ #content
18
+ =partial :content
19
+
20
+ #subnav
21
+ =partial :subnav
@@ -0,0 +1,6 @@
1
+ %ul
2
+ %li
3
+ %a{:href => 'index.html'} Home
4
+ %li
5
+ %a{:href => 'morrisons.html'} Morrisons
6
+ %li Third
@@ -0,0 +1,2 @@
1
+ %p
2
+ Freshly baked in store, every day
@@ -0,0 +1,5 @@
1
+ %p
2
+ I enjoy locally sourced produce, particularly fish
3
+
4
+ %p
5
+ Advertised by Richard Hammond
@@ -0,0 +1,5 @@
1
+ %h3 Morrisons
2
+
3
+ %ul
4
+ %li Sub one
5
+ %li Sub two
@@ -0,0 +1,3 @@
1
+ %ul
2
+ %li Sub one
3
+ %li Sub two
@@ -0,0 +1,33 @@
1
+ require 'spec'
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'project')
3
+
4
+ describe Deris::Project do
5
+
6
+ let(:examples) { File.join(File.dirname(__FILE__), '..', 'examples') }
7
+ let(:output) { File.join(File.dirname(__FILE__), '..', '..', 'output') }
8
+
9
+ context 'with nested templates' do
10
+
11
+ let(:project) { Deris::Project.new(File.join(examples, 'project')) }
12
+ let(:morrisons_directory) { File.join(output, 'morrisons') }
13
+ let(:bread_file) { File.join(morrisons_directory, 'bread.html') }
14
+
15
+ before do
16
+ project.write(output)
17
+ end
18
+
19
+ it 'should create the morrisons directory' do
20
+ File.exist?(morrisons_directory).should be_true
21
+ end
22
+
23
+ it 'should create a file called "bread.html" in the morrisons directory' do
24
+ File.exist?(bread_file).should be_true
25
+ end
26
+
27
+ it 'should have the phrase "Freshly baked in store, every day" in "bread.html"' do
28
+ File.read(bread_file).should =~ /Freshly baked in store, every day/
29
+ end
30
+
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deris
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Garry Shutler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-07 00:00:00 +01:00
18
+ date: 2010-06-08 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,22 @@ dependencies:
34
34
  version: 2.2.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 1
48
+ - 3
49
+ - 0
50
+ version: 1.3.0
51
+ type: :runtime
52
+ version_requirements: *id002
37
53
  description: Simple documentation creation engine based on HAML
38
54
  email: garry@robustsoftware.co.uk
39
55
  executables: []
@@ -44,8 +60,23 @@ extra_rdoc_files: []
44
60
 
45
61
  files:
46
62
  - lib/deris.rb
63
+ - lib/directory.rb
64
+ - lib/directory_writer.rb
47
65
  - lib/file.rb
66
+ - lib/partial_hasher.rb
48
67
  - lib/project.rb
68
+ - lib/subdirectory_list.rb
69
+ - tests/build_project.rb
70
+ - tests/examples/file/initial.haml
71
+ - tests/examples/file/nested.haml
72
+ - tests/examples/project/_src/content.haml
73
+ - tests/examples/project/_src/layout.haml
74
+ - tests/examples/project/_src/menu.haml
75
+ - tests/examples/project/_src/morrisons/bread/content.haml
76
+ - tests/examples/project/_src/morrisons/content.haml
77
+ - tests/examples/project/_src/morrisons/subnav.haml
78
+ - tests/examples/project/_src/subnav.haml
79
+ - tests/project_specs/nested_files.rb
49
80
  has_rdoc: true
50
81
  homepage: http://github.com/gshutler/deris
51
82
  licenses: []
@@ -80,5 +111,15 @@ rubygems_version: 1.3.7
80
111
  signing_key:
81
112
  specification_version: 3
82
113
  summary: Simple documentation creation engine based on HAML
83
- test_files: []
84
-
114
+ test_files:
115
+ - tests/build_project.rb
116
+ - tests/examples/file/initial.haml
117
+ - tests/examples/file/nested.haml
118
+ - tests/examples/project/_src/content.haml
119
+ - tests/examples/project/_src/layout.haml
120
+ - tests/examples/project/_src/menu.haml
121
+ - tests/examples/project/_src/morrisons/bread/content.haml
122
+ - tests/examples/project/_src/morrisons/content.haml
123
+ - tests/examples/project/_src/morrisons/subnav.haml
124
+ - tests/examples/project/_src/subnav.haml
125
+ - tests/project_specs/nested_files.rb