pith 0.0.7 → 0.0.8

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 CHANGED
@@ -59,13 +59,13 @@ A YAML header can be provided at the top of any template, defining page metadata
59
59
  title: "All about fish"
60
60
  ...
61
61
 
62
- Metadata provided in the header can be referenced by template content, via the "`page`" object:
62
+ Metadata provided in the header can be referenced by template content, via the "`page.meta`" Hash:
63
63
 
64
64
  %html
65
65
  %head
66
- %title= page.title
66
+ %title= page.meta["title"]
67
67
  %body
68
- %h1= page.title
68
+ %h1= page.meta["title"]
69
69
 
70
70
  This is especially useful in "layout" templates (see below).
71
71
 
data/bin/pith CHANGED
@@ -56,8 +56,8 @@ end
56
56
 
57
57
  puts %{Generating to "#{$output_dir}"}
58
58
 
59
- require "pith/project"
60
59
  require "pith/console_logger"
60
+ require "pith/project"
61
61
 
62
62
  @project = Pith::Project.new(:input_dir => $input_dir, :output_dir => $output_dir)
63
63
  @project.logger = Pith::ConsoleLogger.new
@@ -67,15 +67,8 @@ def build
67
67
  end
68
68
 
69
69
  def watch
70
- loop do
71
- begin
72
- build
73
- rescue Exception => e
74
- $stderr.puts "ERROR: #{e}"
75
- e.backtrace.each { |line| $stderr.puts line }
76
- end
77
- sleep($interval)
78
- end
70
+ require "pith/watcher"
71
+ Pith::Watcher.new(project, :interval => $interval).call
79
72
  end
80
73
 
81
74
  def serve
@@ -174,3 +174,18 @@ Scenario: link to an index page
174
174
  """
175
175
  <a href="stuff/">Stuff</a>
176
176
  """
177
+
178
+ Scenario: link to an index page in the same directory
179
+
180
+ Given the "assume_directory_index" flag is enabled
181
+
182
+ And input file "page.html.haml" contains
183
+ """
184
+ = link("index.html", "Index")
185
+ """
186
+
187
+ When I build the site
188
+ Then output file "page.html" should contain
189
+ """
190
+ <a href="./">Index</a>
191
+ """
@@ -44,3 +44,9 @@ Scenario: dot-file
44
44
  """
45
45
  DirectoryIndex index.html
46
46
  """
47
+
48
+ Scenario: extension-less filename
49
+
50
+ Given input file "foo" contains "bar"
51
+ When I build the site
52
+ Then output file "foo" should contain "bar"
@@ -10,14 +10,16 @@ module Pith
10
10
 
11
11
  class Template < Abstract
12
12
 
13
- class UnrecognisedType < StandardError; end
13
+ def self.can_handle?(path)
14
+ path.to_str =~ /\.([^.]+)$/ && Tilt.registered?($1)
15
+ end
14
16
 
15
17
  def initialize(project, path)
18
+ raise(ArgumentError, "#{path} is not a template") unless Template.can_handle?(path)
16
19
  super(project, path)
17
- path.to_s =~ /^(.*)\.(.*)$/
20
+ path.to_str =~ /^(.+)\.(.+)$/ || raise("huh?")
18
21
  @output_path = Pathname($1)
19
22
  @type = $2
20
- raise(UnrecognisedType, @type) unless Tilt.registered?(@type)
21
23
  load
22
24
  end
23
25
 
data/lib/pith/input.rb CHANGED
@@ -7,9 +7,11 @@ module Pith
7
7
  class << self
8
8
 
9
9
  def new(project, path)
10
- Template.new(project, path)
11
- rescue Template::UnrecognisedType
12
- Resource.new(project, path)
10
+ if Template.can_handle?(path)
11
+ Template.new(project, path)
12
+ else
13
+ Resource.new(project, path)
14
+ end
13
15
  end
14
16
 
15
17
  end
data/lib/pith/project.rb CHANGED
@@ -15,18 +15,19 @@ module Pith
15
15
  end
16
16
 
17
17
  attr_reader :input_dir
18
-
19
- attr_accessor :output_dir
20
- attr_accessor :assume_content_negotiation
21
- attr_accessor :assume_directory_index
22
18
 
23
19
  def input_dir=(dir)
24
20
  @input_dir = Pathname(dir)
25
21
  end
26
22
 
23
+ attr_reader :output_dir
24
+
27
25
  def output_dir=(dir)
28
26
  @output_dir = Pathname(dir)
29
27
  end
28
+
29
+ attr_accessor :assume_content_negotiation
30
+ attr_accessor :assume_directory_index
30
31
 
31
32
  # Public: get inputs
32
33
  #
@@ -53,10 +53,11 @@ module Pith
53
53
  end
54
54
 
55
55
  def relative_url_to(target_path)
56
- url = target_path.relative_path_from(page.path.parent)
56
+ url = target_path.relative_path_from(page.path.parent).to_str
57
57
  url = url.sub(/index\.html$/, "") if project.assume_directory_index
58
58
  url = url.sub(/\.html$/, "") if project.assume_content_negotiation
59
- url
59
+ url = "./" if url.empty?
60
+ Pathname(url)
60
61
  end
61
62
 
62
63
  def href(target_ref)
data/lib/pith/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pith
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
@@ -0,0 +1,32 @@
1
+ module Pith
2
+
3
+ class Watcher
4
+
5
+ DEFAULT_INTERVAL = 2
6
+
7
+ def initialize(project, options = {})
8
+ @project = project
9
+ @interval = DEFAULT_INTERVAL
10
+ options.each do |k,v|
11
+ send("#{k}=", v)
12
+ end
13
+ end
14
+
15
+ attr_accessor :project
16
+ attr_accessor :interval
17
+
18
+ def call
19
+ loop do
20
+ begin
21
+ project.build
22
+ rescue Exception => e
23
+ $stderr.puts "ERROR: #{e}"
24
+ e.backtrace.each { |line| $stderr.puts line }
25
+ end
26
+ sleep(interval)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -18,6 +18,28 @@ describe Pith::Input::Template do
18
18
  @project.input(path)
19
19
  end
20
20
 
21
+ describe ".can_handle?" do
22
+
23
+ it "returns true for template paths" do
24
+ Pith::Input::Template.can_handle?("xyz.html.haml").should be_true
25
+ Pith::Input::Template.can_handle?("xyz.html.md").should be_true
26
+ end
27
+
28
+ it "handles directories" do
29
+ Pith::Input::Template.can_handle?("dir/xyz.haml").should be_true
30
+ end
31
+
32
+ it "accepts Pathname objects" do
33
+ Pith::Input::Template.can_handle?(Pathname("xyz.html.haml")).should be_true
34
+ end
35
+
36
+ it "returns false for non-template paths" do
37
+ Pith::Input::Template.can_handle?("foo.html").should be_false
38
+ Pith::Input::Template.can_handle?("foo").should be_false
39
+ end
40
+
41
+ end
42
+
21
43
  describe "#title" do
22
44
 
23
45
  it "is based on last component of filename" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pith
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Williams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-09 00:00:00 +10:00
18
+ date: 2010-09-10 00:00:00 +10:00
19
19
  default_executable: pith
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,9 +50,25 @@ dependencies:
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: rspec
53
+ name: rack
54
54
  prerelease: false
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 19
61
+ segments:
62
+ - 1
63
+ - 1
64
+ - 0
65
+ version: 1.1.0
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
56
72
  none: false
57
73
  requirements:
58
74
  - - ">="
@@ -64,11 +80,11 @@ dependencies:
64
80
  - 9
65
81
  version: 1.2.9
66
82
  type: :development
67
- version_requirements: *id003
83
+ version_requirements: *id004
68
84
  - !ruby/object:Gem::Dependency
69
85
  name: cucumber
70
86
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
72
88
  none: false
73
89
  requirements:
74
90
  - - ">="
@@ -80,7 +96,7 @@ dependencies:
80
96
  - 3
81
97
  version: 0.8.3
82
98
  type: :development
83
- version_requirements: *id004
99
+ version_requirements: *id005
84
100
  description: |
85
101
  Pith builds static websites, using markup/template languages including Haml, Sass, ERb, Liquid, Markdown and Textile.
86
102
 
@@ -113,6 +129,7 @@ files:
113
129
  - lib/pith/server.rb~
114
130
  - lib/pith/version.rb
115
131
  - lib/pith/version.rb~
132
+ - lib/pith/watcher.rb
116
133
  - lib/pith.rb
117
134
  - lib/pith.rb~
118
135
  - sample/_layouts/standard.haml