pith 0.0.8 → 0.0.9

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/bin/pith CHANGED
@@ -68,7 +68,7 @@ end
68
68
 
69
69
  def watch
70
70
  require "pith/watcher"
71
- Pith::Watcher.new(project, :interval => $interval).call
71
+ Pith::Watcher.new(@project, :interval => $interval).call
72
72
  end
73
73
 
74
74
  def serve
@@ -10,6 +10,13 @@ Scenario: include a partial
10
10
  When I build the site
11
11
  Then output file "index.html" should contain "<p>blah blah</p>"
12
12
 
13
+ Scenario: include a static resource
14
+
15
+ Given input file "index.html.haml" contains "= include('_fragment.html')"
16
+ And input file "_fragment.html" contains "<p>blah blah</p>"
17
+ When I build the site
18
+ Then output file "index.html" should contain "<p>blah blah</p>"
19
+
13
20
  Scenario: include a partial in the same sub-directory
14
21
 
15
22
  Given input file "subdir/page.html.haml" contains "= include('_fragment.haml')"
@@ -0,0 +1,24 @@
1
+ Feature: support for Markdown
2
+
3
+ I want to build pages using Markdown
4
+ So that I can express content succintly
5
+
6
+ Scenario: Simple Markdown
7
+
8
+ Given input file "article.html.md" contains
9
+ """
10
+ - Yen (¥)
11
+ - Pound (£)
12
+ - Euro (€)
13
+ """
14
+
15
+ When I build the site
16
+
17
+ Then output file "article.html" should contain
18
+ """
19
+ <ul>
20
+ <li>Yen (¥)</li>
21
+ <li>Pound (£)</li>
22
+ <li>Euro (€)</li>
23
+ </ul>
24
+ """
@@ -24,6 +24,16 @@ module Pith
24
24
  output_file.parent.mkpath
25
25
  FileUtils.copy(file, output_file)
26
26
  end
27
+
28
+ # Render this input, for inclusion within templates
29
+ #
30
+ def render(context, locals = {})
31
+ file.read
32
+ end
33
+
34
+ def meta
35
+ {}
36
+ end
27
37
 
28
38
  end
29
39
 
@@ -0,0 +1,50 @@
1
+ require "pith/input"
2
+ require "time"
3
+
4
+ module Pith
5
+ module Plugins
6
+ module Publication
7
+
8
+ module TemplateMethods
9
+
10
+ def published?
11
+ !published_at.nil?
12
+ end
13
+
14
+ def published_at
15
+ parse_date(meta["published"])
16
+ end
17
+
18
+ def updated_at
19
+ parse_date(meta["updated"]) || published_at
20
+ end
21
+
22
+ private
23
+
24
+ def parse_date(date_string)
25
+ Time.parse(date_string) if date_string
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+
34
+ module Pith
35
+ module Input
36
+
37
+ class Abstract
38
+
39
+ def published?
40
+ false
41
+ end
42
+
43
+ end
44
+
45
+ class Template
46
+ include Pith::Plugins::Publication::TemplateMethods
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require "pith/project"
2
+ require "pith/plugins/publication/input"
3
+
4
+ module Pith
5
+
6
+ class Project
7
+
8
+ def published_inputs
9
+ inputs.select { |i| i.published? }.sort_by { |i| i.published_at }
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,2 @@
1
+ require "pith/plugins/publication/input"
2
+ require "pith/plugins/publication/project"
@@ -67,16 +67,22 @@ module Pith
67
67
  def link(target_ref, label = nil)
68
68
  target_path = resolve_reference(target_ref)
69
69
  label ||= begin
70
- input(target_path).title
70
+ target_input = input(target_path)
71
+ record_dependency_on(target_input.file)
72
+ target_input.title
71
73
  rescue ReferenceError
72
74
  "???"
73
75
  end
74
76
  url = relative_url_to(target_path)
75
77
  %{<a href="#{url}">#{label}</a>}
76
78
  end
79
+
80
+ def record_dependency_on(file)
81
+ @dependencies << file
82
+ end
77
83
 
78
84
  private
79
-
85
+
80
86
  def resolve_reference(ref)
81
87
  if ref.respond_to?(:output_path)
82
88
  ref.output_path
@@ -88,12 +94,11 @@ module Pith
88
94
  def input(path)
89
95
  input = project.input(path)
90
96
  raise(ReferenceError, %{Can't find "#{path}"}) if input.nil?
91
- @dependencies << input.file
92
97
  input
93
98
  end
94
99
 
95
100
  def with_input(input)
96
- @dependencies << input.file
101
+ record_dependency_on(input.file)
97
102
  @input_stack.push(input)
98
103
  begin
99
104
  yield
data/lib/pith/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pith
2
- VERSION = "0.0.8".freeze
2
+ VERSION = "0.0.9".freeze
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require "pith/plugins/publication"
3
+
4
+ describe Pith::Plugins::Publication::TemplateMethods do
5
+
6
+ before do
7
+ @template = OpenStruct.new(:meta => {})
8
+ @template.extend(Pith::Plugins::Publication::TemplateMethods)
9
+ end
10
+
11
+ describe "#published_at" do
12
+
13
+ it "defaults to nil" do
14
+ @template.published_at.should be_nil
15
+ end
16
+
17
+ it "is derived by parsing the 'published' meta-field" do
18
+ @template.meta["published"] = "25 Dec 1999 22:30"
19
+ @template.published_at.should == Time.local(1999, 12, 25, 22, 30)
20
+ end
21
+
22
+ end
23
+
24
+ describe "#updated_at" do
25
+
26
+ it "defaults to #published_at" do
27
+ @template.meta["published"] = "25 Dec 1999 22:30"
28
+ @template.updated_at.should == Time.local(1999, 12, 25, 22, 30)
29
+ end
30
+
31
+ it "can be overridden with an 'updated' meta-field" do
32
+ @template.meta["published"] = "25 Dec 1999 22:30"
33
+ @template.meta["published"] = "1 Jan 2000 03:00"
34
+ @template.updated_at.should == Time.local(2000, 1, 1, 3, 0)
35
+ end
36
+
37
+ end
38
+
39
+ end
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
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-10 00:00:00 +10:00
18
+ date: 2010-09-19 00:00:00 +10:00
19
19
  default_executable: pith
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -120,6 +120,9 @@ files:
120
120
  - lib/pith/input.rb~
121
121
  - lib/pith/metadata.rb~
122
122
  - lib/pith/pathname_ext.rb
123
+ - lib/pith/plugins/publication/input.rb
124
+ - lib/pith/plugins/publication/project.rb
125
+ - lib/pith/plugins/publication.rb
123
126
  - lib/pith/project.rb
124
127
  - lib/pith/project.rb~
125
128
  - lib/pith/reference_error.rb
@@ -144,6 +147,7 @@ files:
144
147
  - spec/pith/input/abstract_spec.rb~
145
148
  - spec/pith/input/template_spec.rb
146
149
  - spec/pith/metadata_spec.rb~
150
+ - spec/pith/plugins/publication_spec.rb
147
151
  - spec/pith/project_spec.rb
148
152
  - spec/pith/project_spec.rb~
149
153
  - spec/spec_helper.rb
@@ -163,6 +167,7 @@ files:
163
167
  - features/layouts.feature
164
168
  - features/layouts.feature~
165
169
  - features/linking.feature~
170
+ - features/markdown.feature
166
171
  - features/metadata.feature
167
172
  - features/metadata.feature~
168
173
  - features/relative_linking.feature
@@ -218,6 +223,7 @@ test_files:
218
223
  - spec/pith/input/abstract_spec.rb~
219
224
  - spec/pith/input/template_spec.rb
220
225
  - spec/pith/metadata_spec.rb~
226
+ - spec/pith/plugins/publication_spec.rb
221
227
  - spec/pith/project_spec.rb
222
228
  - spec/pith/project_spec.rb~
223
229
  - spec/spec_helper.rb
@@ -237,6 +243,7 @@ test_files:
237
243
  - features/layouts.feature
238
244
  - features/layouts.feature~
239
245
  - features/linking.feature~
246
+ - features/markdown.feature
240
247
  - features/metadata.feature
241
248
  - features/metadata.feature~
242
249
  - features/relative_linking.feature