pith 0.0.2
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/README.markdown +29 -0
- data/Rakefile +16 -0
- data/bin/pith +60 -0
- data/cucumber.yml +7 -0
- data/features/content_for.feature +29 -0
- data/features/content_for.feature~ +29 -0
- data/features/haml.feature +24 -0
- data/features/haml.feature~ +24 -0
- data/features/helpers.feature +23 -0
- data/features/ignorance.feature +26 -0
- data/features/ignorance.feature~ +26 -0
- data/features/include.feature +84 -0
- data/features/include.feature~ +84 -0
- data/features/incremental_rebuild.feature +24 -0
- data/features/layouts.feature +43 -0
- data/features/layouts.feature~ +43 -0
- data/features/linking.feature +79 -0
- data/features/linking.feature~ +79 -0
- data/features/metadata.feature +20 -0
- data/features/metadata.feature~ +20 -0
- data/features/step_definitions/build_steps.rb +46 -0
- data/features/step_definitions/build_steps.rb~ +29 -0
- data/features/support/env.rb +75 -0
- data/features/support/env.rb~ +43 -0
- data/features/support/rspec_matchers.rb +5 -0
- data/features/textile.feature +29 -0
- data/features/textile.feature~ +29 -0
- data/features/verbatim.feature +32 -0
- data/features/verbatim.feature~ +32 -0
- data/lib/pith.rb +1 -0
- data/lib/pith.rb~ +2 -0
- data/lib/pith/console_logger.rb +20 -0
- data/lib/pith/console_logger.rb~ +20 -0
- data/lib/pith/input.rb +189 -0
- data/lib/pith/input.rb~ +95 -0
- data/lib/pith/metadata.rb +26 -0
- data/lib/pith/metadata.rb~ +26 -0
- data/lib/pith/project.rb +68 -0
- data/lib/pith/project.rb~ +50 -0
- data/lib/pith/render_context.rb +77 -0
- data/lib/pith/render_context.rb~ +66 -0
- data/lib/pith/server.rb +42 -0
- data/lib/pith/server.rb~ +45 -0
- data/lib/pith/version.rb +3 -0
- data/lib/pith/version.rb~ +3 -0
- data/sample/_layouts/standard.haml +7 -0
- data/sample/index.html.haml +8 -0
- data/sample/stylesheets/app.css.sass +44 -0
- data/spec/pith/metadata_spec.rb +46 -0
- data/spec/pith/metadata_spec.rb~ +46 -0
- data/spec/pith/project_spec.rb +61 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/spec_helper.rb~ +0 -0
- metadata +166 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: incremental rebuilding
|
2
|
+
|
3
|
+
I want to rebuild just the outputs whose inputs have changed
|
4
|
+
So that that I can bring the project up-to-date efficiently
|
5
|
+
|
6
|
+
Scenario: alter an input, and the output changes
|
7
|
+
|
8
|
+
Given input file "page.html.haml" contains "Old content"
|
9
|
+
And the site is up-to-date
|
10
|
+
|
11
|
+
When I change input file "page.html.haml" to contain "New content"
|
12
|
+
And I rebuild the site
|
13
|
+
|
14
|
+
Then output file "page.html" should be re-generated
|
15
|
+
And output file "page.html" should contain "New content"
|
16
|
+
|
17
|
+
Scenario: don't alter an input, and the output is untouched
|
18
|
+
|
19
|
+
Given input file "page.html.haml" contains "Content"
|
20
|
+
And the site is up-to-date
|
21
|
+
|
22
|
+
When I rebuild the site
|
23
|
+
|
24
|
+
Then output file "page.html" should not be re-generated
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: templates can be used as layouts
|
2
|
+
|
3
|
+
I want to be able to apply a layout
|
4
|
+
So that I can reuse template patterns
|
5
|
+
|
6
|
+
Scenario: Haml template with a layout
|
7
|
+
|
8
|
+
Given input file "index.html.haml" contains
|
9
|
+
"""
|
10
|
+
= include "layouts/_simple.haml" do
|
11
|
+
blah blah
|
12
|
+
"""
|
13
|
+
And input file "layouts/_simple.haml" contains
|
14
|
+
"""
|
15
|
+
%p= yield
|
16
|
+
"""
|
17
|
+
|
18
|
+
When I build the site
|
19
|
+
Then output file "index.html" should contain
|
20
|
+
"""
|
21
|
+
<p>blah blah</p>
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: instance variable assigned within the layed-out block
|
25
|
+
|
26
|
+
Given input file "index.html.haml" contains
|
27
|
+
"""
|
28
|
+
= include "layouts/_with_header.haml" do
|
29
|
+
- @title = "XXX"
|
30
|
+
%p blah blah
|
31
|
+
"""
|
32
|
+
And input file "layouts/_with_header.haml" contains
|
33
|
+
"""
|
34
|
+
%h1= @title
|
35
|
+
= yield
|
36
|
+
"""
|
37
|
+
|
38
|
+
When I build the site
|
39
|
+
Then output file "index.html" should contain
|
40
|
+
"""
|
41
|
+
<h1>XXX</h1>
|
42
|
+
<p>blah blah</p>
|
43
|
+
"""
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: templates can be used as layouts
|
2
|
+
|
3
|
+
I want to be able to apply a layout
|
4
|
+
So that I can reuse template patterns
|
5
|
+
|
6
|
+
Scenario: Haml template with a layout
|
7
|
+
|
8
|
+
Given input file "index.html.haml" contains
|
9
|
+
"""
|
10
|
+
= include "layouts/_simple.haml" do
|
11
|
+
blah blah
|
12
|
+
"""
|
13
|
+
And input file "layouts/_simple.haml" contains
|
14
|
+
"""
|
15
|
+
%p= yield
|
16
|
+
"""
|
17
|
+
|
18
|
+
When I build the site
|
19
|
+
Then output file "index.html" should contain
|
20
|
+
"""
|
21
|
+
<p>blah blah</p>
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: instance variable assigned within the layed-out block
|
25
|
+
|
26
|
+
Given input file "index.html.haml" contains
|
27
|
+
"""
|
28
|
+
= include "layouts/_with_header.haml" do
|
29
|
+
- @title = "XXX"
|
30
|
+
%p blah blah
|
31
|
+
"""
|
32
|
+
And input file "layouts/_with_header.haml" contains
|
33
|
+
"""
|
34
|
+
%h1= @title
|
35
|
+
= yield
|
36
|
+
"""
|
37
|
+
|
38
|
+
When I build the site
|
39
|
+
Then output file "index.html" should contain
|
40
|
+
"""
|
41
|
+
<h1>XXX</h1>
|
42
|
+
<p>blah blah</p>
|
43
|
+
"""
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: linking between files
|
2
|
+
|
3
|
+
I want to be able to link pages easily
|
4
|
+
|
5
|
+
Scenario: link from one top-level page to another
|
6
|
+
|
7
|
+
Given input file "index.html.haml" contains
|
8
|
+
"""
|
9
|
+
= link("page.html", "Page")
|
10
|
+
"""
|
11
|
+
|
12
|
+
When I build the site
|
13
|
+
Then output file "index.html" should contain
|
14
|
+
"""
|
15
|
+
<a href="page.html">Page</a>
|
16
|
+
"""
|
17
|
+
|
18
|
+
Scenario: link from a sub-directory to a root-level page
|
19
|
+
|
20
|
+
Given input file "subdir/page.html.haml" contains
|
21
|
+
"""
|
22
|
+
= link("/help.html", "Help")
|
23
|
+
"""
|
24
|
+
|
25
|
+
When I build the site
|
26
|
+
Then output file "subdir/page.html" should contain
|
27
|
+
"""
|
28
|
+
<a href="../help.html">Help</a>
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: link to an image
|
32
|
+
|
33
|
+
Given input file "subdir/page.html.haml" contains
|
34
|
+
"""
|
35
|
+
%img{:src => href("/logo.png")}
|
36
|
+
"""
|
37
|
+
|
38
|
+
When I build the site
|
39
|
+
Then output file "subdir/page.html" should contain
|
40
|
+
"""
|
41
|
+
<img src='../logo.png' />
|
42
|
+
"""
|
43
|
+
|
44
|
+
Scenario: links within a layout block
|
45
|
+
|
46
|
+
Given input file "subdir/page.html.haml" contains
|
47
|
+
"""
|
48
|
+
= include "/common/_layout.haml" do
|
49
|
+
= link "other.html", "Other page"
|
50
|
+
"""
|
51
|
+
|
52
|
+
And input file "common/_layout.haml" contains
|
53
|
+
"""
|
54
|
+
= yield
|
55
|
+
"""
|
56
|
+
|
57
|
+
When I build the site
|
58
|
+
Then output file "subdir/page.html" should contain
|
59
|
+
"""
|
60
|
+
<a href="other.html">Other page</a>
|
61
|
+
"""
|
62
|
+
|
63
|
+
Scenario: links included from a partial
|
64
|
+
|
65
|
+
Given input file "subdir/page.html.haml" contains
|
66
|
+
"""
|
67
|
+
= include "/common/_partial.haml"
|
68
|
+
"""
|
69
|
+
|
70
|
+
And input file "common/_partial.haml" contains
|
71
|
+
"""
|
72
|
+
%link{ :href=>href("/stylesheets/app.css"), :rel=>"stylesheet", :type=>"text/css" }
|
73
|
+
"""
|
74
|
+
|
75
|
+
When I build the site
|
76
|
+
Then output file "subdir/page.html" should contain
|
77
|
+
"""
|
78
|
+
<link href='../stylesheets/app.css' rel='stylesheet' type='text/css' />
|
79
|
+
"""
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: linking between files
|
2
|
+
|
3
|
+
I want to be able to link pages easily
|
4
|
+
|
5
|
+
Scenario: link from one top-level page to another
|
6
|
+
|
7
|
+
Given input file "index.html.haml" contains
|
8
|
+
"""
|
9
|
+
= link("page.html", "Page")
|
10
|
+
"""
|
11
|
+
|
12
|
+
When I build the site
|
13
|
+
Then output file "index.html" should contain
|
14
|
+
"""
|
15
|
+
<a href="page.html">Page</a>
|
16
|
+
"""
|
17
|
+
|
18
|
+
Scenario: link from a sub-directory to a root-level page
|
19
|
+
|
20
|
+
Given input file "subdir/page.html.haml" contains
|
21
|
+
"""
|
22
|
+
= link("/help.html", "Help")
|
23
|
+
"""
|
24
|
+
|
25
|
+
When I build the site
|
26
|
+
Then output file "subdir/page.html" should contain
|
27
|
+
"""
|
28
|
+
<a href="../help.html">Help</a>
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: link to an image
|
32
|
+
|
33
|
+
Given input file "subdir/page.html.haml" contains
|
34
|
+
"""
|
35
|
+
%img{:src => href("/logo.png")}
|
36
|
+
"""
|
37
|
+
|
38
|
+
When I build the site
|
39
|
+
Then output file "subdir/page.html" should contain
|
40
|
+
"""
|
41
|
+
<img src='../logo.png' />
|
42
|
+
"""
|
43
|
+
|
44
|
+
Scenario: links within a layout block
|
45
|
+
|
46
|
+
Given input file "subdir/page.html.haml" contains
|
47
|
+
"""
|
48
|
+
= include "/common/_layout.haml" do
|
49
|
+
= link "other.html", "Other page"
|
50
|
+
"""
|
51
|
+
|
52
|
+
And input file "common/_layout.haml" contains
|
53
|
+
"""
|
54
|
+
= yield
|
55
|
+
"""
|
56
|
+
|
57
|
+
When I build the site
|
58
|
+
Then output file "subdir/page.html" should contain
|
59
|
+
"""
|
60
|
+
<a href="other.html">Other page</a>
|
61
|
+
"""
|
62
|
+
|
63
|
+
Scenario: links included from a partial
|
64
|
+
|
65
|
+
Given input file "subdir/page.html.haml" contains
|
66
|
+
"""
|
67
|
+
= include "/common/_partial.haml"
|
68
|
+
"""
|
69
|
+
|
70
|
+
And input file "common/_partial.haml" contains
|
71
|
+
"""
|
72
|
+
%link{ :href=>href("/stylesheets/app.css"), :rel=>"stylesheet", :type=>"text/css" }
|
73
|
+
"""
|
74
|
+
|
75
|
+
When I build the site
|
76
|
+
Then output file "subdir/page.html" should contain
|
77
|
+
"""
|
78
|
+
<link href='../stylesheets/app.css' rel='stylesheet' type='text/css' />
|
79
|
+
"""
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: metadata
|
2
|
+
|
3
|
+
I want extract metadata from page source
|
4
|
+
So that I can use it elsewhere
|
5
|
+
|
6
|
+
Scenario: link from one top-level page to another
|
7
|
+
|
8
|
+
Given input file "page.html.haml" contains
|
9
|
+
"""
|
10
|
+
-# ---
|
11
|
+
-# title: PAGE TITLE
|
12
|
+
-# ...
|
13
|
+
%h1= meta["title"]
|
14
|
+
"""
|
15
|
+
|
16
|
+
When I build the site
|
17
|
+
Then output file "page.html" should contain
|
18
|
+
"""
|
19
|
+
<h1>PAGE TITLE</h1>
|
20
|
+
"""
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: metadata
|
2
|
+
|
3
|
+
I want extract metadata from page source
|
4
|
+
So that I can use it elsewhere
|
5
|
+
|
6
|
+
Scenario: link from one top-level page to another
|
7
|
+
|
8
|
+
Given input file "page.html.haml" contains
|
9
|
+
"""
|
10
|
+
-# ---
|
11
|
+
-# title: PAGE TITLE
|
12
|
+
-# ...
|
13
|
+
%h1= meta["title"]
|
14
|
+
"""
|
15
|
+
|
16
|
+
When I build the site
|
17
|
+
Then output file "page.html" should contain
|
18
|
+
"""
|
19
|
+
<h1>PAGE TITLE</h1>
|
20
|
+
"""
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Given /^input file "([^\"]*)" contains "([^\"]*)"$/ do |file_name, content|
|
2
|
+
@inputs.write(file_name, content, :mtime => (Time.now - 5))
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^input file "([^\"]*)" contains$/ do |file_name, content|
|
6
|
+
@inputs.write(file_name, content, :mtime => (Time.now - 5))
|
7
|
+
end
|
8
|
+
|
9
|
+
Given "the site is up-to-date" do
|
10
|
+
When "I build the site"
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I change input file "([^\"]*)" to contain "([^\"]*)"$/ do |file_name, content|
|
14
|
+
@inputs[file_name] = content
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I (?:re)?build the site$/ do
|
18
|
+
@project.logger.clear
|
19
|
+
@project.build
|
20
|
+
end
|
21
|
+
|
22
|
+
class String
|
23
|
+
def clean
|
24
|
+
strip.gsub(/\s+/, ' ')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Then /^output file "([^\"]*)" should contain "([^\"]*)"$/ do |file_name, content|
|
29
|
+
@outputs[file_name].clean.should == content.clean
|
30
|
+
end
|
31
|
+
|
32
|
+
Then /^output file "([^\"]*)" should contain$/ do |file_name, content|
|
33
|
+
@outputs[file_name].clean.should == content.clean
|
34
|
+
end
|
35
|
+
|
36
|
+
Then /^output file "([^\"]*)" should not exist$/ do |file_name|
|
37
|
+
@outputs[file_name].should == nil
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^output file "([^"]*)" should be re\-generated$/ do |file_name|
|
41
|
+
@project.logger.messages.should contain(/--> +#{file_name}/)
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^output file "([^"]*)" should not be re\-generated$/ do |file_name|
|
45
|
+
@project.logger.messages.should_not contain(/--> +#{file_name}/)
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Given /^input file "([^\"]*)" contains "([^\"]*)"$/ do |file_name, content|
|
2
|
+
@inputs[file_name] = content
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^input file "([^\"]*)" contains$/ do |file_name, content|
|
6
|
+
@inputs[file_name] = content
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I build the site$/ do
|
10
|
+
@project.build
|
11
|
+
end
|
12
|
+
|
13
|
+
class String
|
14
|
+
def clean
|
15
|
+
strip.gsub(/\s+/, ' ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^output file "([^\"]*)" should contain "([^\"]*)"$/ do |file_name, content|
|
20
|
+
@outputs[file_name].clean.should == content.clean
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^output file "([^\"]*)" should contain$/ do |file_name, content|
|
24
|
+
@outputs[file_name].clean.should == content.clean
|
25
|
+
end
|
26
|
+
|
27
|
+
Then /^output file "([^\"]*)" should not exist$/ do |file_name|
|
28
|
+
@outputs[file_name].should == nil
|
29
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
class DirHash
|
4
|
+
|
5
|
+
def initialize(dir)
|
6
|
+
@dir = Pathname(dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](file_name)
|
10
|
+
file_path = @dir + file_name
|
11
|
+
file_path.read if file_path.exist?
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(file_name, content)
|
15
|
+
write(file_name, content)
|
16
|
+
end
|
17
|
+
|
18
|
+
def write(file_name, content, options = {})
|
19
|
+
file_path = @dir + file_name
|
20
|
+
file_path.parent.mkpath
|
21
|
+
file_path.open("w") do |io|
|
22
|
+
io << content
|
23
|
+
end
|
24
|
+
if options[:mtime]
|
25
|
+
timestamp = options[:mtime]
|
26
|
+
file_path.utime(timestamp, timestamp)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class InternalLogger
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@messages = []
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :messages
|
39
|
+
|
40
|
+
def clear
|
41
|
+
@messages.clear
|
42
|
+
end
|
43
|
+
|
44
|
+
def info(message, &block)
|
45
|
+
message ||= block.call
|
46
|
+
write(message)
|
47
|
+
end
|
48
|
+
|
49
|
+
def write(message)
|
50
|
+
@messages << message
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
$project_dir = Pathname(__FILE__).expand_path.parent.parent.parent
|
56
|
+
$tmp_dir = $project_dir + "tmp"
|
57
|
+
|
58
|
+
$input_dir = $tmp_dir + "input"
|
59
|
+
|
60
|
+
$output_dir = $tmp_dir + "output"
|
61
|
+
$output_dir.mkpath
|
62
|
+
|
63
|
+
$: << ($project_dir + "lib").to_s
|
64
|
+
require "pith"
|
65
|
+
|
66
|
+
Before do
|
67
|
+
[$input_dir, $output_dir].each do |dir|
|
68
|
+
dir.rmtree if dir.exist?
|
69
|
+
dir.mkpath
|
70
|
+
end
|
71
|
+
@project = Pith::Project.new(:input_dir => $input_dir, :output_dir => $output_dir)
|
72
|
+
@project.logger = InternalLogger.new
|
73
|
+
@inputs = DirHash.new($input_dir)
|
74
|
+
@outputs = DirHash.new($output_dir)
|
75
|
+
end
|