deris 0.1.3 → 0.1.4

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.
@@ -1 +1,8 @@
1
- Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), '*.rb')).each {|f| require f }
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require 'haml'
4
+
5
+ # load the files in dependency order to avoid loads of require statements in each file
6
+ ['subdirectory_list', 'partial_hasher', 'file', 'directory_writer', 'directory', 'project'].each do |f|
7
+ require File.join(File.expand_path(File.dirname(__FILE__)), "#{f}.rb")
8
+ end
@@ -1,28 +1,23 @@
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
1
+ module Deris
2
+
3
+ class Directory
4
+ include PartialHasher
5
+ include DirectoryWriter
6
+ include SubdirectoryList
7
+
8
+ attr_reader :file_name, :partials, :directory
9
+
10
+ def initialize(directory, defaults = {}, depth = 0)
11
+ @directory = directory
12
+ @file_name = ::File.basename(directory)
13
+ @partials = defaults.merge(partials_hash)
14
+ @depth = depth
15
+ end
16
+
17
+ def sub_output(output)
18
+ return ::File.join(output, @file_name), @depth + 1
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -1,33 +1,32 @@
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
1
+ module Deris
2
+
3
+ module DirectoryWriter
4
+
5
+ def write(output)
6
+ unless respond_to?(:sub_directories) and respond_to?(:partials) and respond_to?(:sub_output)
7
+ raise 'need to respond to "sub directories", "partials" and "sub_output" to write'
8
+ end
9
+
10
+ # write out the content from this directory
11
+ write_file output
12
+
13
+ # write out the sub directories
14
+ sub_directories.each do |dir|
15
+ sub_output_dir, sub_depth = sub_output(output)
16
+ Directory.new(dir, partials, sub_depth).write(sub_output_dir)
17
+ end
18
+
19
+ true # don't return anything the client could work with
20
+ end
21
+
22
+ def write_file(output)
23
+ unless respond_to?(:file_name) and respond_to?(:partials)
24
+ raise 'need to respond to "file_name" and "partials" to use write_file'
25
+ end
26
+
27
+ File.new(file_name, partials, @depth).write(output)
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -1,43 +1,52 @@
1
- require 'rubygems'
2
- require 'fileutils'
3
- require 'haml'
4
-
5
- module Deris
6
-
7
- class File
8
-
9
- attr_reader :name
10
-
11
- def initialize(name = 'index', partials = {})
12
- @name = name
13
- @partials = partials
14
- end
15
-
16
- def write(directory)
17
- FileUtils.mkdir(directory) unless ::File.exist? directory
18
- output_path = ::File.join(directory, "#{@name}.html")
19
- ::File.open(output_path, 'w+') do |file|
20
- file.write render
21
- end
22
- end
23
-
24
- def render(template = nil)
25
- if template.nil?
26
- template = @partials[:layout]
27
- else
28
- template = ::File.new(template).read if ::File.exist?(template)
29
- end
30
- haml_engine = Haml::Engine.new(template)
31
- haml_engine.render(self)
32
- end
33
-
34
- def partial(template)
35
- if template.is_a? Symbol
36
- template = @partials[template] || ''
37
- end
38
- render(template)
39
- end
40
-
41
- end
42
-
43
- end
1
+ module Deris
2
+
3
+ class File
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(name = 'index', partials = {}, depth = nil)
8
+ @name = name
9
+ @partials = partials
10
+ @depth = depth || 0
11
+ end
12
+
13
+ def write(directory)
14
+ FileUtils.mkdir(directory) unless ::File.exist? directory
15
+ output_path = ::File.join(directory, "#{@name}.html")
16
+ ::File.open(output_path, 'w+') do |file|
17
+ file.write render
18
+ end
19
+ end
20
+
21
+ def render(template = nil)
22
+ if template.nil?
23
+ template = @partials[:layout]
24
+ else
25
+ template = ::File.new(template).read if ::File.exist?(template)
26
+ end
27
+ haml_engine = Haml::Engine.new(template)
28
+ haml_engine.render(self)
29
+ end
30
+
31
+ def partial(template)
32
+ if template.is_a? Symbol
33
+ template = @partials[template] || ''
34
+ end
35
+ render(template)
36
+ end
37
+
38
+ def url(*segments)
39
+ sections = []
40
+ @depth.times do
41
+ sections << '..'
42
+ end
43
+ segments.each do |segment|
44
+ sections << segment
45
+ end
46
+
47
+ sections.join('/') + '.html'
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -1,27 +1,24 @@
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
1
+ module Deris
2
+
3
+ module PartialHasher
4
+
5
+ def partials_hash
6
+ unless respond_to?(:directory)
7
+ raise 'need to response to "directory" to create a hash of partials'
8
+ end
9
+
10
+ partials = {}
11
+ partial_file_mask = ::File.join(directory, '*.haml')
12
+ partial_files = ::Dir.glob(partial_file_mask)
13
+
14
+ partial_files.each do |file|
15
+ file_sym = ::File.basename(file, '.haml').to_sym
16
+ partials[file_sym] = ::File.new(file).read
17
+ end
18
+
19
+ partials
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -1,46 +1,39 @@
1
- require 'rubygems'
2
- require 'fileutils'
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')
7
-
8
- module Deris
9
-
10
- class Project
11
- include PartialHasher
12
- include DirectoryWriter
13
- include SubdirectoryList
14
-
15
- attr_reader :file_name, :partials, :directory
16
-
17
- def initialize(source, defaults = {})
18
- @source = source
19
- @file_name = 'index'
20
- @directory = ::File.join(@source, '_src')
21
- @partials = defaults.merge(partials_hash)
22
- end
23
-
24
- def write(output)
25
- # adds additional behaviour on top of the DirectoryWriter mixin
26
-
27
- # recreate the output directory
28
- FileUtils.rm_rf(output) if ::File.exists?(output)
29
- FileUtils.mkdir(output)
30
-
31
- # find and copy all static content
32
- static_content_mask = ::File.join(@source, "**")
33
- static_content = Dir[static_content_mask].reject{|path| path =~ /_src$/}
34
- static_content.each{|path| FileUtils.cp_r(path, output)}
35
-
36
- # call the DirectoryWriter mixin
37
- super
38
- end
39
-
40
- def sub_output(output)
41
- output
42
- end
43
-
44
- end
45
-
46
- end
1
+ module Deris
2
+
3
+ class Project
4
+ include PartialHasher
5
+ include DirectoryWriter
6
+ include SubdirectoryList
7
+
8
+ attr_reader :file_name, :partials, :directory
9
+
10
+ def initialize(source, defaults = {})
11
+ @source = source
12
+ @file_name = 'index'
13
+ @directory = ::File.join(@source, '_src')
14
+ @partials = defaults.merge(partials_hash)
15
+ end
16
+
17
+ def write(output)
18
+ # adds additional behaviour on top of the DirectoryWriter mixin
19
+
20
+ # recreate the output directory
21
+ FileUtils.rm_rf(output) if ::File.exists?(output)
22
+ FileUtils.mkdir(output)
23
+
24
+ # find and copy all static content
25
+ static_content_mask = ::File.join(@source, "**")
26
+ static_content = Dir[static_content_mask].reject{|path| path =~ /_src$/}
27
+ static_content.each{|path| FileUtils.cp_r(path, output)}
28
+
29
+ # call the DirectoryWriter mixin
30
+ super
31
+ end
32
+
33
+ def sub_output(output)
34
+ return output, 0 # zero default depth
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,21 +1,18 @@
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
1
+ module Deris
2
+
3
+ module SubdirectoryList
4
+
5
+ def sub_directories
6
+ unless respond_to?(:directory)
7
+ raise 'need to respond to "directory" to list sub directories'
8
+ end
9
+
10
+ sub_directory_mask = ::File.join(directory, '*')
11
+ ::Dir[sub_directory_mask].find_all do |dir|
12
+ ::File.directory?(dir)
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -1,23 +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
-
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
+
@@ -1,2 +1,2 @@
1
- .nested
2
- woot! nested content
1
+ .nested
2
+ woot! nested content
@@ -1,2 +1,2 @@
1
- %p
2
- This is the home page
1
+ %p
2
+ This is the home page
@@ -1,21 +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
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
21
  =partial :subnav
@@ -1,6 +1,5 @@
1
- %ul
2
- %li
3
- %a{:href => 'index.html'} Home
4
- %li
5
- %a{:href => 'morrisons.html'} Morrisons
6
- %li Third
1
+ %ul
2
+ %li
3
+ %a{:href => url(:index)} Home
4
+ %li
5
+ %a{:href => url(:morrisons)} Morrisons
@@ -1,2 +1,2 @@
1
- %p
2
- Freshly baked in store, every day
1
+ %p
2
+ Freshly baked in store, every day
@@ -1,5 +1,5 @@
1
- %p
2
- I enjoy locally sourced produce, particularly fish
3
-
4
- %p
5
- Advertised by Richard Hammond
1
+ %p
2
+ I enjoy locally sourced produce, particularly fish
3
+
4
+ %p
5
+ Advertised by Richard Hammond
@@ -0,0 +1,2 @@
1
+ %p
2
+ Caught locally by fishermen
@@ -1,5 +1,5 @@
1
- %h3 Morrisons
2
-
3
- %ul
4
- %li Sub one
5
- %li Sub two
1
+ %ul
2
+ %li
3
+ %a{:href => url(:morrisons, :bread)} Bread
4
+ %li
5
+ %a{:href => url(:morrisons, :fish)} Fish
@@ -1,3 +1 @@
1
- %ul
2
- %li Sub one
3
- %li Sub two
1
+ Empty
@@ -1,33 +1,41 @@
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
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Deris::Project do
4
+
5
+ let(:output) { File.join(File.dirname(__FILE__), '..', '..', 'output') }
6
+ let(:examples) { File.join(File.dirname(__FILE__), '..', 'examples') }
7
+
8
+ context 'with nested templates' do
9
+
10
+ let(:project) { Deris::Project.new(File.join(examples, 'project')) }
11
+ let(:morrisons_directory) { File.join(output, 'morrisons') }
12
+ let(:morrisons_file) { File.join(output, 'morrisons.html') }
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
+ it 'should have a relative link to "index.html" in "morrisons.html"' do
32
+ File.read(morrisons_file).should include("href='index.html'")
33
+ end
34
+
35
+ it 'should have a relative link to "index.html" in "bread.html"' do
36
+ File.read(bread_file).should include("href='../index.html'")
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'deris')
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new do |spec|
6
+ spec.pattern = File.join(File.dirname(__FILE__), '*_specs', '**', '*.rb')
7
+ end
8
+
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
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-08 00:00:00 +01:00
18
+ date: 2010-06-09 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,13 +42,15 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 27
45
+ hash: 62196465
46
46
  segments:
47
- - 1
48
- - 3
47
+ - 2
49
48
  - 0
50
- version: 1.3.0
51
- type: :runtime
49
+ - 0
50
+ - beta
51
+ - 9
52
+ version: 2.0.0.beta.9
53
+ type: :development
52
54
  version_requirements: *id002
53
55
  description: Simple documentation creation engine based on HAML
54
56
  email: garry@robustsoftware.co.uk
@@ -66,17 +68,19 @@ files:
66
68
  - lib/partial_hasher.rb
67
69
  - lib/project.rb
68
70
  - lib/subdirectory_list.rb
69
- - tests/build_project.rb
70
- - tests/examples/file/initial.haml
71
+ - tests/project_specs/nested_files.rb
72
+ - tests/spec_helper.rb
71
73
  - tests/examples/file/nested.haml
72
- - tests/examples/project/_src/content.haml
73
- - tests/examples/project/_src/layout.haml
74
+ - tests/examples/file/initial.haml
74
75
  - tests/examples/project/_src/menu.haml
76
+ - tests/examples/project/_src/layout.haml
77
+ - tests/examples/project/_src/morrisons/subnav.haml
78
+ - tests/examples/project/_src/morrisons/fish/content.haml
75
79
  - tests/examples/project/_src/morrisons/bread/content.haml
76
80
  - tests/examples/project/_src/morrisons/content.haml
77
- - tests/examples/project/_src/morrisons/subnav.haml
78
81
  - tests/examples/project/_src/subnav.haml
79
- - tests/project_specs/nested_files.rb
82
+ - tests/examples/project/_src/content.haml
83
+ - tests/spec_tasks.rake
80
84
  has_rdoc: true
81
85
  homepage: http://github.com/gshutler/deris
82
86
  licenses: []
@@ -112,14 +116,16 @@ signing_key:
112
116
  specification_version: 3
113
117
  summary: Simple documentation creation engine based on HAML
114
118
  test_files:
115
- - tests/build_project.rb
116
- - tests/examples/file/initial.haml
119
+ - tests/project_specs/nested_files.rb
120
+ - tests/spec_helper.rb
117
121
  - tests/examples/file/nested.haml
118
- - tests/examples/project/_src/content.haml
119
- - tests/examples/project/_src/layout.haml
122
+ - tests/examples/file/initial.haml
120
123
  - tests/examples/project/_src/menu.haml
124
+ - tests/examples/project/_src/layout.haml
125
+ - tests/examples/project/_src/morrisons/subnav.haml
126
+ - tests/examples/project/_src/morrisons/fish/content.haml
121
127
  - tests/examples/project/_src/morrisons/bread/content.haml
122
128
  - tests/examples/project/_src/morrisons/content.haml
123
- - tests/examples/project/_src/morrisons/subnav.haml
124
129
  - tests/examples/project/_src/subnav.haml
125
- - tests/project_specs/nested_files.rb
130
+ - tests/examples/project/_src/content.haml
131
+ - tests/spec_tasks.rake
@@ -1,16 +0,0 @@
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