deris 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,119 @@
1
+ # Deris
2
+
3
+ A documentation templating engine based on [HAML](http://haml-lang.com/)
4
+
5
+ ## Installation
6
+
7
+ Whenever significant functionality is added to deris a new gem will be added to
8
+ [rubygems](http://rubygems.org/gems/deris) so installation is easy:
9
+
10
+ gem install deris
11
+
12
+ ## Getting started
13
+
14
+ Deris takes and transforms the contents of one directory and transforms and
15
+ writes it out to another directory. Your source directory should be laid out
16
+ something like this:
17
+
18
+ myproject/
19
+ _src/
20
+ layout.haml
21
+
22
+ `_src/layout.haml` is the only file deris expects to exist.
23
+
24
+ Any files and directories within `myproject` that aren't within `_src` will be
25
+ copied over to the output directory. This lets you have static content such as
26
+ CSS files and images.
27
+
28
+ To get deris to generate HTML from this directory you'll want to call it like
29
+ this:
30
+
31
+ require 'rubygems'
32
+ require 'deris'
33
+
34
+ Deris::Project.new('myproject/').write('myoutput/')
35
+
36
+ Which will result in an output like this:
37
+
38
+ myoutput/
39
+ index.html
40
+
41
+ This is because the contents of the `_src` directory are used to create the
42
+ `index.html` for your site.
43
+
44
+ If you want to take advantage of the templating capabilities you will want to
45
+ create a `layout.haml` something like this:
46
+
47
+ -# myproject/_src/layout.haml
48
+ !!! 5
49
+ %html
50
+
51
+ %head
52
+ %title
53
+ Deris example
54
+
55
+ %body
56
+
57
+ %h1 Deris example
58
+
59
+ #content_wrapper
60
+
61
+ #content
62
+ =partial :content
63
+
64
+ You will now want to create a `content.haml` to provide the markup for the
65
+ `:content` partial:
66
+
67
+ -# myproject/_src/content.haml
68
+ %h3 Home page
69
+
70
+ %p
71
+ As this is in the _src directory it will be used to create index.html
72
+
73
+ If you want to add another generated page to the site you need to create a new
74
+ directory under the `_src`:
75
+
76
+ myproject/
77
+ _src/
78
+ morrisons/
79
+ content.haml
80
+ content.haml
81
+ layout.haml
82
+
83
+ When the page is generated it will take the name of the directory, in this case
84
+ that means the file will be called `morrisons.html`. Each directory can override
85
+ the partials from its parent. This means that `morrisons.html` will be created
86
+ by the combination of `_src/layout.haml` and `_src/morrisons/content.haml`.
87
+
88
+ You can nest directories within other directories as well:
89
+
90
+ myproject/
91
+ _src/
92
+ morrisons/
93
+ bread/
94
+ content.haml
95
+ content.haml
96
+ content.haml
97
+ layout.haml
98
+
99
+ Which will result in an output like this:
100
+
101
+ myoutput/
102
+ morrisons/
103
+ bread.html # _src/layout.haml + _src/morrisons/bread/content.haml
104
+ index.html # _src/layout.haml + _src/content.haml
105
+ morrisons.html # _src/layout.haml + _src/morrisons/content.haml
106
+
107
+ You can create URLs relative to the root of your generated content by using the
108
+ `url` helper in your HAML files:
109
+
110
+ %a{:href => url('morrisons/bread.html')} Bread
111
+
112
+ This will look at the current "depth" of the file within your project and
113
+ prepend the correct quantity of `../` to your URL.
114
+
115
+ ## Getting help
116
+
117
+ You can get hold of me [on twitter](http://twitter.com/gshutler), [through a
118
+ message on github](http://github.com/inbox/new/gshutler) or even via ye olde
119
+ email at garry@robustsoftware.co.uk
@@ -35,16 +35,14 @@ module Deris
35
35
  render(template)
36
36
  end
37
37
 
38
- def url(*segments)
38
+ def url(path)
39
39
  sections = []
40
40
  @depth.times do
41
41
  sections << '..'
42
42
  end
43
- segments.each do |segment|
44
- sections << segment
45
- end
43
+ sections << path
46
44
 
47
- sections.join('/') + '.html'
45
+ sections.join('/')
48
46
  end
49
47
 
50
48
  end
@@ -15,7 +15,13 @@ module Deris
15
15
  file_sym = ::File.basename(file, '.haml').to_sym
16
16
  partials[file_sym] = ::File.new(file).read
17
17
  end
18
-
18
+
19
+ # apply the convention where a partial with the same name as the file
20
+ # being output is set as the content partial unless it already exists
21
+ if !partials[:content] and partials[@file_name.to_sym]
22
+ partials[:content] = partials[@file_name.to_sym]
23
+ end
24
+
19
25
  partials
20
26
  end
21
27
 
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Deris::Directory do
4
+
5
+ let(:examples) { File.join(File.dirname(__FILE__), '..', 'examples') }
6
+
7
+ context 'with content defined by convention' do
8
+
9
+ let(:directory) { Deris::Directory.new(File.join(examples, 'contentconvention')) }
10
+ let(:partials) { directory.partials_hash }
11
+
12
+ it 'should have the same value for :content as :contentconvention' do
13
+ partials[:content].should_not be_nil
14
+ partials[:content].should == partials[:contentconvention]
15
+ end
16
+
17
+ end
18
+
19
+ context 'with content defined and a partial matching the convention' do
20
+
21
+ let(:directory) { Deris::Directory.new(File.join(examples, 'contentconventionclash')) }
22
+ let(:partials) { directory.partials_hash }
23
+
24
+ it 'should not overwrite the :content partial with the partial matching the convention' do
25
+ partials[:content].should_not == partials[:contentconventionclash]
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -1,5 +1,5 @@
1
1
  %ul
2
2
  %li
3
- %a{:href => url(:index)} Home
3
+ %a{:href => url('index.html')} Home
4
4
  %li
5
- %a{:href => url(:morrisons)} Morrisons
5
+ %a{:href => url('morrisons.html')} Morrisons
@@ -1,5 +1,5 @@
1
1
  %ul
2
2
  %li
3
- %a{:href => url(:morrisons, :bread)} Bread
3
+ %a{:href => url('morrisons/bread.html')} Bread
4
4
  %li
5
- %a{:href => url(:morrisons, :fish)} Fish
5
+ %a{:href => url('morrisons/fish.html')} Fish
@@ -2,7 +2,21 @@ require 'rake'
2
2
  require 'rubygems'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
+ SPEC_PATTERN = File.join(File.dirname(__FILE__), '*_specs', '**', '*.rb')
6
+
5
7
  RSpec::Core::RakeTask.new do |spec|
6
- spec.pattern = File.join(File.dirname(__FILE__), '*_specs', '**', '*.rb')
8
+ spec.pattern = SPEC_PATTERN
7
9
  end
8
10
 
11
+ namespace :spec do
12
+
13
+ task :doc do
14
+ cmd = ['spec']
15
+ cmd << '-f n'
16
+ cmd += FileList[SPEC_PATTERN].to_a
17
+ cmd = cmd.join(' ')
18
+ system cmd
19
+ end
20
+
21
+
22
+ 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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
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-09 00:00:00 +01:00
18
+ date: 2010-06-14 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -58,8 +58,8 @@ executables: []
58
58
 
59
59
  extensions: []
60
60
 
61
- extra_rdoc_files: []
62
-
61
+ extra_rdoc_files:
62
+ - README.markdown
63
63
  files:
64
64
  - lib/deris.rb
65
65
  - lib/directory.rb
@@ -68,8 +68,13 @@ files:
68
68
  - lib/partial_hasher.rb
69
69
  - lib/project.rb
70
70
  - lib/subdirectory_list.rb
71
+ - README.markdown
71
72
  - tests/project_specs/nested_files.rb
72
73
  - tests/spec_helper.rb
74
+ - tests/directory_specs/content_convention.rb
75
+ - tests/examples/contentconventionclash/contentconventionclash.haml
76
+ - tests/examples/contentconventionclash/content.haml
77
+ - tests/examples/contentconvention/contentconvention.haml
73
78
  - tests/examples/file/nested.haml
74
79
  - tests/examples/file/initial.haml
75
80
  - tests/examples/project/_src/menu.haml
@@ -118,6 +123,10 @@ summary: Simple documentation creation engine based on HAML
118
123
  test_files:
119
124
  - tests/project_specs/nested_files.rb
120
125
  - tests/spec_helper.rb
126
+ - tests/directory_specs/content_convention.rb
127
+ - tests/examples/contentconventionclash/contentconventionclash.haml
128
+ - tests/examples/contentconventionclash/content.haml
129
+ - tests/examples/contentconvention/contentconvention.haml
121
130
  - tests/examples/file/nested.haml
122
131
  - tests/examples/file/initial.haml
123
132
  - tests/examples/project/_src/menu.haml