pith 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.markdown +29 -0
  2. data/Rakefile +16 -0
  3. data/bin/pith +60 -0
  4. data/cucumber.yml +7 -0
  5. data/features/content_for.feature +29 -0
  6. data/features/content_for.feature~ +29 -0
  7. data/features/haml.feature +24 -0
  8. data/features/haml.feature~ +24 -0
  9. data/features/helpers.feature +23 -0
  10. data/features/ignorance.feature +26 -0
  11. data/features/ignorance.feature~ +26 -0
  12. data/features/include.feature +84 -0
  13. data/features/include.feature~ +84 -0
  14. data/features/incremental_rebuild.feature +24 -0
  15. data/features/layouts.feature +43 -0
  16. data/features/layouts.feature~ +43 -0
  17. data/features/linking.feature +79 -0
  18. data/features/linking.feature~ +79 -0
  19. data/features/metadata.feature +20 -0
  20. data/features/metadata.feature~ +20 -0
  21. data/features/step_definitions/build_steps.rb +46 -0
  22. data/features/step_definitions/build_steps.rb~ +29 -0
  23. data/features/support/env.rb +75 -0
  24. data/features/support/env.rb~ +43 -0
  25. data/features/support/rspec_matchers.rb +5 -0
  26. data/features/textile.feature +29 -0
  27. data/features/textile.feature~ +29 -0
  28. data/features/verbatim.feature +32 -0
  29. data/features/verbatim.feature~ +32 -0
  30. data/lib/pith.rb +1 -0
  31. data/lib/pith.rb~ +2 -0
  32. data/lib/pith/console_logger.rb +20 -0
  33. data/lib/pith/console_logger.rb~ +20 -0
  34. data/lib/pith/input.rb +189 -0
  35. data/lib/pith/input.rb~ +95 -0
  36. data/lib/pith/metadata.rb +26 -0
  37. data/lib/pith/metadata.rb~ +26 -0
  38. data/lib/pith/project.rb +68 -0
  39. data/lib/pith/project.rb~ +50 -0
  40. data/lib/pith/render_context.rb +77 -0
  41. data/lib/pith/render_context.rb~ +66 -0
  42. data/lib/pith/server.rb +42 -0
  43. data/lib/pith/server.rb~ +45 -0
  44. data/lib/pith/version.rb +3 -0
  45. data/lib/pith/version.rb~ +3 -0
  46. data/sample/_layouts/standard.haml +7 -0
  47. data/sample/index.html.haml +8 -0
  48. data/sample/stylesheets/app.css.sass +44 -0
  49. data/spec/pith/metadata_spec.rb +46 -0
  50. data/spec/pith/metadata_spec.rb~ +46 -0
  51. data/spec/pith/project_spec.rb +61 -0
  52. data/spec/spec_helper.rb +27 -0
  53. data/spec/spec_helper.rb~ +0 -0
  54. 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