pith 0.0.3 → 0.0.5

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
@@ -1,8 +1,11 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ $: << File.expand_path("../../lib", __FILE__)
4
+
3
5
  require "rubygems"
4
6
  require "optparse"
5
7
  require "pathname"
8
+ require "pith/version"
6
9
 
7
10
  $input_dir = Pathname(".")
8
11
 
@@ -19,6 +22,7 @@ EOF
19
22
 
20
23
  OptionParser.new do |opts|
21
24
  opts.banner = BANNER
25
+ opts.version = Pith::VERSION
22
26
  opts.separator " Options:"
23
27
  opts.on("-i", "--input INPUT_DIR", 'Input directory', ' (default: ".")') do |dir|
24
28
  $input_dir = Pathname(dir)
@@ -37,8 +41,6 @@ unless $output_dir
37
41
  puts %{Generating to "#{$output_dir}"}
38
42
  end
39
43
 
40
- $: << File.expand_path("../../lib", __FILE__)
41
-
42
44
  require "pith/project"
43
45
  require "pith/console_logger"
44
46
 
@@ -46,9 +46,9 @@ Scenario: Layout specified in meta-data
46
46
 
47
47
  Given input file "index.html.haml" contains
48
48
  """
49
- -# ---
50
- -# layout: layouts/_simple.haml
51
- -#...
49
+ ---
50
+ layout: layouts/_simple.haml
51
+ ...
52
52
  blah blah
53
53
  """
54
54
  And input file "layouts/_simple.haml" contains
@@ -7,9 +7,9 @@ Scenario: use meta-data from YAML comment
7
7
 
8
8
  Given input file "page.html.haml" contains
9
9
  """
10
- -# ---
11
- -# title: PAGE TITLE
12
- -# ...
10
+ ---
11
+ title: PAGE TITLE
12
+ ---
13
13
  %h1= meta["title"]
14
14
  """
15
15
 
@@ -18,3 +18,19 @@ Scenario: use meta-data from YAML comment
18
18
  """
19
19
  <h1>PAGE TITLE</h1>
20
20
  """
21
+
22
+ Scenario: corrupt meta-data
23
+
24
+ Given input file "page.html.haml" contains
25
+ """
26
+ ---
27
+ title: "This" is no well-formed YAML
28
+ ...
29
+ %p PAGE BODY
30
+ """
31
+
32
+ When I build the site
33
+ Then output file "page.html" should contain
34
+ """
35
+ <p>PAGE BODY</p>
36
+ """
@@ -95,9 +95,9 @@ Scenario: use "title" meta-data attribute in link
95
95
 
96
96
  And input file "page.html.haml" contains
97
97
  """
98
- -# ---
99
- -# title: "Title from meta-data"
100
- -# ...
98
+ ---
99
+ title: "Title from meta-data"
100
+ ...
101
101
  Target content
102
102
  """
103
103
 
@@ -46,6 +46,9 @@ class InternalLogger
46
46
  write(message)
47
47
  end
48
48
 
49
+ alias :warn :info
50
+ alias :debug :info
51
+
49
52
  def write(message)
50
53
  @messages << message
51
54
  end
@@ -46,6 +46,9 @@ class InternalLogger
46
46
  write(message)
47
47
  end
48
48
 
49
+ alias :warn :info
50
+ alias :debug :info
51
+
49
52
  def write(message)
50
53
  @messages << message
51
54
  end
@@ -1,5 +1,4 @@
1
1
  require "pathname"
2
- require "pith/metadata"
3
2
 
4
3
  module Pith
5
4
  module Input
@@ -25,56 +24,11 @@ module Pith
25
24
  project.output_dir + output_path
26
25
  end
27
26
 
28
- # Public: Get YAML metadata declared in the header of of a template.
29
- #
30
- # The first line of the template must end with "---". Any preceding characters
31
- # are considered to be a comment prefix, and are stripped from the following
32
- # lines. The metadata block ends when the comment block ends, or a line ending
33
- # with "..." is encountered.
34
- #
35
- # Examples
36
- #
37
- # Given input starting with:
38
- #
39
- # -# ---
40
- # -# published: 2008-09-15
41
- # -# ...
42
- #
43
- # input.meta
44
- # #=> { "published" => "2008-09-15" }
45
- #
46
- # Returns a Hash.
47
- #
48
- def meta
49
- if @metadata.nil?
50
- file.open do |io|
51
- @metadata = Pith::Metadata.extract_from(io).freeze
52
- end
53
- end
54
- @metadata
55
- end
56
-
57
- # Public: Get page title.
58
- #
59
- # The default title is based on the input file-name, sans-extension, capitalised,
60
- # but can be overridden by providing a "title" in the metadata block.
61
- #
62
- # Examples
63
- #
64
- # input.path.to_s
65
- # #=> "some_page.html.haml"
66
- # input.title
67
- # #=> "Some page"
68
- #
69
- def title
70
- meta["title"] || default_title
71
- end
72
-
73
27
  # Public: Generate a corresponding output file.
74
28
  #
75
29
  def build
76
30
  return false if ignorable? || uptodate?
77
- logger.info("%-36s%-14s%s" % [path, "--(#{type})-->", output_path])
31
+ logger.info("%-14s%s" % ["--(#{type})-->", output_path])
78
32
  generate_output
79
33
  end
80
34
 
@@ -1,5 +1,4 @@
1
1
  require "pathname"
2
- require "pith/metadata"
3
2
 
4
3
  module Pith
5
4
  module Input
@@ -25,56 +24,11 @@ module Pith
25
24
  project.output_dir + output_path
26
25
  end
27
26
 
28
- # Public: Get YAML metadata declared in the header of of a template.
29
- #
30
- # The first line of the template must end with "---". Any preceding characters
31
- # are considered to be a comment prefix, and are stripped from the following
32
- # lines. The metadata block ends when the comment block ends, or a line ending
33
- # with "..." is encountered.
34
- #
35
- # Examples
36
- #
37
- # Given input starting with:
38
- #
39
- # -# ---
40
- # -# published: 2008-09-15
41
- # -# ...
42
- #
43
- # input.meta
44
- # #=> { "published" => "2008-09-15" }
45
- #
46
- # Returns a Hash.
47
- #
48
- def meta
49
- if @metadata.nil?
50
- file.open do |io|
51
- @metadata = Pith::Metadata.extract_from(io).freeze
52
- end
53
- end
54
- @metadata
55
- end
56
-
57
- # Public: Get page title.
58
- #
59
- # The default title is based on the input file-name, sans-extension, capitalised,
60
- # but can be overridden by providing a "title" in the metadata block.
61
- #
62
- # Examples
63
- #
64
- # input.path.to_s
65
- # #=> "some_page.html.haml"
66
- # input.title
67
- # #=> "Some page"
68
- #
69
- def title
70
- meta["title"] || default_title
71
- end
72
-
73
27
  # Public: Generate a corresponding output file.
74
28
  #
75
29
  def build
76
30
  return false if ignorable? || uptodate?
77
- logger.info("%-36s%-14s%s" % [path, "--(#{type})-->", output_path])
31
+ logger.info("%-14s%s" % ["--(#{type})-->", output_path])
78
32
  generate_output
79
33
  end
80
34
 
@@ -3,6 +3,7 @@ require "pathname"
3
3
  require "pith/input/abstract"
4
4
  require "pith/render_context"
5
5
  require "tilt"
6
+ require "yaml"
6
7
 
7
8
  module Pith
8
9
  module Input
@@ -17,10 +18,15 @@ module Pith
17
18
  @output_path = Pathname($1)
18
19
  @type = $2
19
20
  raise(UnrecognisedType, @type) unless Tilt.registered?(@type)
21
+ load
20
22
  end
21
23
 
22
24
  attr_reader :output_path, :type
23
25
 
26
+ # Check whether output is up-to-date.
27
+ #
28
+ # Return true unless output needs to be re-generated.
29
+ #
24
30
  def uptodate?
25
31
  all_input_files && FileUtils.uptodate?(output_file, all_input_files)
26
32
  end
@@ -33,19 +39,81 @@ module Pith
33
39
  output_file.open("w") do |out|
34
40
  out.puts(render_context.render(self))
35
41
  end
36
- remember_dependencies(render_context.rendered_inputs)
42
+ remember_dependencies(render_context.referenced_inputs)
37
43
  end
38
44
 
39
45
  # Render this input using Tilt
40
46
  #
41
47
  def render(context, locals = {}, &block)
42
- Tilt.new(file).render(context, locals, &block)
48
+ @tilt_template.render(context, locals, &block)
49
+ end
50
+
51
+ # Public: Get YAML metadata declared in the header of of a template.
52
+ #
53
+ # If the first line of the template starts with "---" it is considered to be
54
+ # the start of a YAML 'document', which is loaded and returned.
55
+ #
56
+ # Examples
57
+ #
58
+ # Given input starting with:
59
+ #
60
+ # ---
61
+ # published: 2008-09-15
62
+ # ...
63
+ # OTHER STUFF
64
+ #
65
+ # input.meta
66
+ # #=> { "published" => "2008-09-15" }
67
+ #
68
+ # Returns a Hash.
69
+ #
70
+ def meta
71
+ @meta
72
+ end
73
+
74
+ # Public: Get page title.
75
+ #
76
+ # The default title is based on the input file-name, sans-extension, capitalised,
77
+ # but can be overridden by providing a "title" in the metadata block.
78
+ #
79
+ # Examples
80
+ #
81
+ # input.path.to_s
82
+ # #=> "some_page.html.haml"
83
+ # input.title
84
+ # #=> "Some page"
85
+ #
86
+ def title
87
+ meta["title"] || default_title
43
88
  end
44
89
 
45
90
  private
46
91
 
47
- def remember_dependencies(rendered_inputs)
48
- @all_input_files = rendered_inputs.map { |input| input.file }
92
+ # Read input file, extracting YAML meta-data header, and template content.
93
+ #
94
+ def load
95
+ @meta = {}
96
+ file.open do |input|
97
+ header = input.gets
98
+ if header =~ /^---/
99
+ while line = input.gets
100
+ break if line =~ /^(---|\.\.\.)/
101
+ header << line
102
+ end
103
+ begin
104
+ @meta = YAML.load(header)
105
+ rescue
106
+ logger.warn "#{file}:1: badly-formed YAML header"
107
+ end
108
+ else
109
+ input.rewind
110
+ end
111
+ @tilt_template = Tilt.new(file, input.lineno + 1) { input.read }
112
+ end
113
+ end
114
+
115
+ def remember_dependencies(referenced_inputs)
116
+ @all_input_files = referenced_inputs.map { |input| input.file }
49
117
  end
50
118
 
51
119
  attr_accessor :all_input_files
@@ -2,38 +2,116 @@ require "fileutils"
2
2
  require "pathname"
3
3
  require "pith/input/abstract"
4
4
  require "pith/render_context"
5
+ require "tilt"
6
+ require "yaml"
5
7
 
6
8
  module Pith
7
9
  module Input
8
10
 
9
11
  class Template < Abstract
10
12
 
13
+ class UnrecognisedType < StandardError; end
14
+
11
15
  def initialize(project, path)
12
16
  super(project, path)
13
17
  path.to_s =~ /^(.*)\.(.*)$/
14
18
  @output_path = Pathname($1)
15
19
  @type = $2
20
+ raise(UnrecognisedType, @type) unless Tilt.registered?(@type)
21
+ load
16
22
  end
17
23
 
18
24
  attr_reader :output_path, :type
19
25
 
26
+ # Check whether output is up-to-date.
27
+ #
28
+ # Return true unless output needs to be re-generated.
29
+ #
20
30
  def uptodate?
21
31
  all_input_files && FileUtils.uptodate?(output_file, all_input_files)
22
32
  end
23
33
 
24
- # Render this input using Tilt
34
+ # Generate output for this template
25
35
  #
26
36
  def generate_output
27
37
  output_file.parent.mkpath
28
38
  render_context = RenderContext.new(project)
29
39
  output_file.open("w") do |out|
30
- out.puts(render_context.render_input(self))
40
+ out.puts(render_context.render(self))
31
41
  end
32
42
  remember_dependencies(render_context.rendered_inputs)
33
43
  end
34
44
 
45
+ # Render this input using Tilt
46
+ #
47
+ def render(context, locals = {}, &block)
48
+ @tilt_template.render(context, locals, &block)
49
+ end
50
+
51
+ # Public: Get YAML metadata declared in the header of of a template.
52
+ #
53
+ # If the first line of the template starts with "---" it is considered to be
54
+ # the start of a YAML 'document', which is loaded and returned.
55
+ #
56
+ # Examples
57
+ #
58
+ # Given input starting with:
59
+ #
60
+ # ---
61
+ # published: 2008-09-15
62
+ # ...
63
+ # OTHER STUFF
64
+ #
65
+ # input.meta
66
+ # #=> { "published" => "2008-09-15" }
67
+ #
68
+ # Returns a Hash.
69
+ #
70
+ def meta
71
+ @meta
72
+ end
73
+
74
+ # Public: Get page title.
75
+ #
76
+ # The default title is based on the input file-name, sans-extension, capitalised,
77
+ # but can be overridden by providing a "title" in the metadata block.
78
+ #
79
+ # Examples
80
+ #
81
+ # input.path.to_s
82
+ # #=> "some_page.html.haml"
83
+ # input.title
84
+ # #=> "Some page"
85
+ #
86
+ def title
87
+ meta["title"] || default_title
88
+ end
89
+
35
90
  private
36
91
 
92
+ # Read input file, extracting YAML meta-data header, and template content.
93
+ #
94
+ def load
95
+ @meta = {}
96
+ file.open do |input|
97
+ header = input.gets
98
+ if header =~ /^---/
99
+ while line = input.gets
100
+ break if line =~ /^(---|\.\.\.)/
101
+ header << line
102
+ end
103
+ begin
104
+ @meta = YAML.load(header)
105
+ rescue
106
+ logger.warn "#{file}:1: badly-formed YAML header"
107
+ end
108
+ else
109
+ input.rewind
110
+ end
111
+ @tilt_template = Tilt.new(file, input.lineno + 1) { input.read }
112
+ end
113
+ end
114
+
37
115
  def remember_dependencies(rendered_inputs)
38
116
  @all_input_files = rendered_inputs.map { |input| input.file }
39
117
  end
data/lib/pith/input.rb~ CHANGED
@@ -7,11 +7,9 @@ module Pith
7
7
  class << self
8
8
 
9
9
  def new(project, path)
10
- if path.to_s =~ /^(.*)\.(.*)$/ && RenderContext.can_render?($2)
11
- Template.new(project, path)
12
- else
13
- Verbatim.new(project, path)
14
- end
10
+ Template.new(project, path)
11
+ rescue Template::UnrecognisedType
12
+ Verbatim.new(project, path)
15
13
  end
16
14
 
17
15
  end
data/lib/pith/project.rb CHANGED
@@ -14,15 +14,29 @@ module Pith
14
14
  end
15
15
 
16
16
  attr_accessor :input_dir, :output_dir
17
-
17
+
18
+ # Public: get inputs
19
+ #
20
+ # Returns Pith::Input objects representing the files in the input_dir.
21
+ #
22
+ # The list of inputs is cached after first load;
23
+ # call #refresh to discard the cached data.
24
+ #
18
25
  def inputs
19
- Pathname.glob(input_dir + "**/*").map do |input_file|
26
+ @inputs ||= Pathname.glob(input_dir + "**/*").map do |input_file|
20
27
  next if input_file.directory?
21
28
  path = input_file.relative_path_from(input_dir)
22
- input_cache[path]
29
+ find_or_create_input(path)
23
30
  end.compact
24
31
  end
25
-
32
+
33
+ # Public: find an input.
34
+ #
35
+ # path - an path relative to either input_dir or output_dir
36
+ #
37
+ # Returns the first input whose input_path or output_path matches.
38
+ # Returns nil if no match is found.
39
+ #
26
40
  def input(path)
27
41
  path = Pathname(path)
28
42
  inputs.each do |input|
@@ -30,14 +44,23 @@ module Pith
30
44
  end
31
45
  raise ReferenceError, "Can't find #{path.inspect}"
32
46
  end
33
-
47
+
48
+ # Public: build the project, generating output files.
49
+ #
34
50
  def build
51
+ refresh
35
52
  load_config
36
53
  inputs.each do |input|
37
54
  input.build
38
55
  end
39
56
  end
40
57
 
58
+ # Public: discard cached data that is out-of-sync with the file-system.
59
+ #
60
+ def refresh
61
+ @inputs = nil
62
+ end
63
+
41
64
  def logger
42
65
  @logger ||= Logger.new(nil)
43
66
  end
@@ -63,13 +86,19 @@ module Pith
63
86
  end
64
87
 
65
88
  def input_cache
66
- @input_cache ||= Hash.new do |h, path|
67
- h[path] = Input.new(self, path)
89
+ @input_cache ||= Hash.new do |h, cache_key|
90
+ h[cache_key] = Input.new(self, cache_key.first)
68
91
  end
69
92
  end
70
93
 
94
+ def find_or_create_input(path)
95
+ file = input_dir + path
96
+ cache_key = [path, file.mtime]
97
+ input_cache[cache_key]
98
+ end
99
+
71
100
  end
72
-
101
+
73
102
  class ReferenceError < StandardError; end
74
103
 
75
104
  end
data/lib/pith/project.rb~ CHANGED
@@ -14,15 +14,29 @@ module Pith
14
14
  end
15
15
 
16
16
  attr_accessor :input_dir, :output_dir
17
-
17
+
18
+ # Public: get inputs
19
+ #
20
+ # Returns Pith::Input objects representing the files in the input_dir.
21
+ #
22
+ # The list of inputs is cached after first load;
23
+ # call #refresh to discard the cached data.
24
+ #
18
25
  def inputs
19
- Pathname.glob(input_dir + "**/*").map do |input_file|
26
+ @inputs ||= Pathname.glob(input_dir + "**/*").map do |input_file|
20
27
  next if input_file.directory?
21
28
  path = input_file.relative_path_from(input_dir)
22
- input_cache[path]
29
+ find_or_create_input(path)
23
30
  end.compact
24
31
  end
25
-
32
+
33
+ # Public: find an input.
34
+ #
35
+ # path - an path relative to either input_dir or output_dir
36
+ #
37
+ # Returns the first input whose input_path or output_path matches.
38
+ # Returns nil if no match is found.
39
+ #
26
40
  def input(path)
27
41
  path = Pathname(path)
28
42
  inputs.each do |input|
@@ -30,14 +44,23 @@ module Pith
30
44
  end
31
45
  raise ReferenceError, "Can't find #{path.inspect}"
32
46
  end
33
-
47
+
48
+ # Public: build the project, generating output files.
49
+ #
34
50
  def build
51
+ refresh
35
52
  load_config
36
53
  inputs.each do |input|
37
54
  input.build
38
55
  end
39
56
  end
40
57
 
58
+ # Public: discard cached data that is out-of-sync with the file-system.
59
+ #
60
+ def refresh
61
+ @inputs = nil
62
+ end
63
+
41
64
  def logger
42
65
  @logger ||= Logger.new(nil)
43
66
  end
@@ -63,13 +86,19 @@ module Pith
63
86
  end
64
87
 
65
88
  def input_cache
66
- @input_cache ||= Hash.new do |h, path|
67
- h[path] = Input.new(self, path)
89
+ @input_cache ||= Hash.new do |h, cache_key|
90
+ h[cache_key] = Input.new(self, cache_key.first)
68
91
  end
69
92
  end
70
93
 
94
+ def find_or_create_input(path)
95
+ file = input_dir + path
96
+ cache_key = [path, file.mtime]
97
+ input_cache[cache_key]
98
+ end
99
+
71
100
  end
72
-
101
+
73
102
  class ReferenceError < StandardError; end
74
103
 
75
104
  end
@@ -11,7 +11,7 @@ module Pith
11
11
  def initialize(project)
12
12
  @project = project
13
13
  @input_stack = []
14
- @rendered_inputs = Set.new
14
+ @referenced_inputs = Set.new
15
15
  self.extend(project.helper_module)
16
16
  end
17
17
 
@@ -26,7 +26,6 @@ module Pith
26
26
  end
27
27
 
28
28
  def render(input, locals = {}, &block)
29
- @rendered_inputs << input
30
29
  with_input(input) do
31
30
  result = input.render(self, locals, &block)
32
31
  layout_ref = current_input.meta["layout"]
@@ -35,7 +34,7 @@ module Pith
35
34
  end
36
35
  end
37
36
 
38
- attr_reader :rendered_inputs
37
+ attr_reader :referenced_inputs
39
38
 
40
39
  def include(template_ref, locals = {}, &block)
41
40
  content_block = if block_given?
@@ -62,7 +61,7 @@ module Pith
62
61
  def link(target_ref, label = nil)
63
62
  target_path = resolve_path(target_ref)
64
63
  label ||= begin
65
- project.input(target_path).title
64
+ find_input(target_path).title
66
65
  rescue Pith::ReferenceError
67
66
  "???"
68
67
  end
@@ -79,7 +78,14 @@ module Pith
79
78
  current_input.resolve_path(ref)
80
79
  end
81
80
 
81
+ def find_input(path)
82
+ input = project.input(path)
83
+ @referenced_inputs << input if input
84
+ input
85
+ end
86
+
82
87
  def with_input(input)
88
+ @referenced_inputs << input
83
89
  @input_stack.push(input)
84
90
  begin
85
91
  yield
@@ -89,7 +95,8 @@ module Pith
89
95
  end
90
96
 
91
97
  def render_ref(template_ref, locals = {}, &block)
92
- template = project.input(resolve_path(template_ref))
98
+ template_path = resolve_path(template_ref)
99
+ template = find_input(template_path)
93
100
  render(template, locals, &block)
94
101
  end
95
102
 
@@ -8,10 +8,6 @@ module Pith
8
8
 
9
9
  include Tilt::CompileSite
10
10
 
11
- def self.can_render?(extension)
12
- Tilt.registered?(extension)
13
- end
14
-
15
11
  def initialize(project)
16
12
  @project = project
17
13
  @input_stack = []
@@ -29,16 +25,13 @@ module Pith
29
25
  @input_stack.last
30
26
  end
31
27
 
32
- def render_input(input, locals = {}, &block)
28
+ def render(input, locals = {}, &block)
33
29
  @rendered_inputs << input
34
30
  with_input(input) do
35
- rendered = Tilt.new(input.file).render(self, locals, &block)
31
+ result = input.render(self, locals, &block)
36
32
  layout_ref = current_input.meta["layout"]
37
- if layout_ref
38
- render_ref(layout_ref) { rendered }
39
- else
40
- rendered
41
- end
33
+ result = render_ref(layout_ref) { result } if layout_ref
34
+ result
42
35
  end
43
36
  end
44
37
 
@@ -52,6 +45,8 @@ module Pith
52
45
  render_ref(template_ref, locals, &content_block)
53
46
  end
54
47
 
48
+ alias :inside :include
49
+
55
50
  def content_for
56
51
  @content_for_hash ||= Hash.new { "" }
57
52
  end
@@ -95,7 +90,7 @@ module Pith
95
90
 
96
91
  def render_ref(template_ref, locals = {}, &block)
97
92
  template = project.input(resolve_path(template_ref))
98
- render_input(template, locals, &block)
93
+ render(template, locals, &block)
99
94
  end
100
95
 
101
96
  end
data/lib/pith/server.rb CHANGED
@@ -12,7 +12,7 @@ module Pith
12
12
  use Rack::Lint
13
13
  use Pith::Server::AutoBuild, project
14
14
  use Adsf::Rack::IndexFileFinder, :root => project.output_dir
15
- run Rack::File.new(project.output_dir)
15
+ run Rack::Directory.new(project.output_dir)
16
16
  end
17
17
  end
18
18
 
data/lib/pith/server.rb~ CHANGED
@@ -12,7 +12,7 @@ module Pith
12
12
  use Rack::Lint
13
13
  use Pith::Server::AutoBuild, project
14
14
  use Adsf::Rack::IndexFileFinder, :root => project.output_dir
15
- run Rack::File.new(project.output_dir)
15
+ run Rack::Directory.new(project.output_dir)
16
16
  end
17
17
  end
18
18
 
data/lib/pith/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pith
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
data/lib/pith/version.rb~ CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pith
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
@@ -0,0 +1 @@
1
+ dsfsdf
@@ -0,0 +1 @@
1
+
@@ -19,9 +19,9 @@ describe Pith::Input::Abstract do
19
19
 
20
20
  it "can be over-ridden in metadata" do
21
21
  @input_file.open("w") do |i|
22
- i.puts "-# ---"
23
- i.puts "-# title: Blah blah"
24
- i.puts "-# ..."
22
+ i.puts "---"
23
+ i.puts "title: Blah blah"
24
+ i.puts "..."
25
25
  end
26
26
  @project.input("some_page.html").title.should == "Blah blah"
27
27
  end
@@ -19,9 +19,9 @@ describe Pith::Input::Abstract do
19
19
 
20
20
  it "can be over-ridden in metadata" do
21
21
  @input_file.open("w") do |i|
22
- i.puts "-# ---"
23
- i.puts "-# title: Blah blah"
24
- i.puts "-# ..."
22
+ i.puts "---"
23
+ i.puts "title: Blah blah"
24
+ i.puts "..."
25
25
  end
26
26
  @project.input("some_page.html").title.should == "Blah blah"
27
27
  end
@@ -22,12 +22,6 @@ describe Pith::Project do
22
22
  @input.should be_kind_of(Pith::Input::Verbatim)
23
23
  @input.file.should == @input_file
24
24
  end
25
-
26
- it "returns the same Input output every time" do
27
- first_time = @project.input("input.txt")
28
- second_time = @project.input("input.txt")
29
- second_time.should equal(first_time)
30
- end
31
25
 
32
26
  end
33
27
 
@@ -71,4 +65,51 @@ describe Pith::Project do
71
65
 
72
66
  end
73
67
 
68
+ describe "when an input file is unchanged" do
69
+
70
+ before do
71
+ @input_file = $input_dir + "input.html.haml"
72
+ @input_file.touch
73
+ end
74
+
75
+ describe "a second call to #input" do
76
+ it "returns the same Input object" do
77
+
78
+ first_time = @project.input("input.html.haml")
79
+ first_time.should_not be_nil
80
+
81
+ @project.refresh
82
+ second_time = @project.input("input.html.haml")
83
+ second_time.should equal(first_time)
84
+
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ describe "when an input file is changed" do
91
+
92
+ before do
93
+ @input_file = $input_dir + "input.html.haml"
94
+ @input_file.touch(Time.now - 10)
95
+ end
96
+
97
+ describe "a second call to #input" do
98
+ it "returns a different Input object" do
99
+
100
+ first_time = @project.input("input.html.haml")
101
+ first_time.should_not be_nil
102
+
103
+ @input_file.touch(Time.now)
104
+
105
+ @project.refresh
106
+ second_time = @project.input("input.html.haml")
107
+ second_time.should_not be_nil
108
+ second_time.should_not equal(first_time)
109
+
110
+ end
111
+ end
112
+
113
+ end
114
+
74
115
  end
@@ -22,12 +22,6 @@ describe Pith::Project do
22
22
  @input.should be_kind_of(Pith::Input::Verbatim)
23
23
  @input.file.should == @input_file
24
24
  end
25
-
26
- it "returns the same Input output every time" do
27
- first_time = @project.input("input.txt")
28
- second_time = @project.input("input.txt")
29
- second_time.should equal(first_time)
30
- end
31
25
 
32
26
  end
33
27
 
@@ -71,4 +65,51 @@ describe Pith::Project do
71
65
 
72
66
  end
73
67
 
68
+ describe "when an input file is unchanged" do
69
+
70
+ before do
71
+ @input_file = $input_dir + "input.html.haml"
72
+ @input_file.touch
73
+ end
74
+
75
+ describe "a second call to #input" do
76
+ it "returns the same Input object" do
77
+
78
+ first_time = @project.input("input.html.haml")
79
+ first_time.should_not be_nil
80
+
81
+ @project.refresh
82
+ second_time = @project.input("input.html.haml")
83
+ second_time.should equal(first_time)
84
+
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ describe "when an input file is changed" do
91
+
92
+ before do
93
+ @input_file = $input_dir + "input.html.haml"
94
+ @input_file.touch(Time.now - 10)
95
+ end
96
+
97
+ describe "a second call to #input" do
98
+ it "returns a different Input object" do
99
+
100
+ first_time = @project.input("input.html.haml")
101
+ first_time.should_not be_nil
102
+
103
+ @input_file.touch(Time.now)
104
+
105
+ @project.refresh
106
+ second_time = @project.input("input.html.haml")
107
+ second_time.should_not be_nil
108
+ second_time.should_not equal(first_time)
109
+
110
+ end
111
+ end
112
+
113
+ end
114
+
74
115
  end
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,9 @@ require "pathname"
5
5
 
6
6
  class Pathname
7
7
 
8
- def touch
8
+ def touch(mtime = nil)
9
9
  FileUtils.touch(self.to_s)
10
+ utime(mtime, mtime) if mtime
10
11
  end
11
12
 
12
13
  end
data/spec/spec_helper.rb~ CHANGED
@@ -5,8 +5,9 @@ require "pathname"
5
5
 
6
6
  class Pathname
7
7
 
8
- def touch
8
+ def touch(mtime = nil)
9
9
  FileUtils.touch(self.to_s)
10
+ utime(mtime, mtime) if mtime
10
11
  end
11
12
 
12
13
  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: 25
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 5
10
+ version: 0.0.5
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-08-30 00:00:00 +10:00
18
+ date: 2010-09-01 00:00:00 +10:00
19
19
  default_executable: pith
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -102,7 +102,6 @@ files:
102
102
  - lib/pith/input/verbatim.rb~
103
103
  - lib/pith/input.rb
104
104
  - lib/pith/input.rb~
105
- - lib/pith/metadata.rb
106
105
  - lib/pith/metadata.rb~
107
106
  - lib/pith/project.rb
108
107
  - lib/pith/project.rb~
@@ -115,6 +114,8 @@ files:
115
114
  - lib/pith.rb
116
115
  - lib/pith.rb~
117
116
  - sample/_layouts/standard.haml
117
+ - sample/_out/blah/deblah.txt
118
+ - sample/_out/features/stuff.html
118
119
  - sample/_out/index.html
119
120
  - sample/_out/stylesheets/app.css
120
121
  - sample/index.html.haml
@@ -123,7 +124,6 @@ files:
123
124
  - Rakefile
124
125
  - spec/pith/input/abstract_spec.rb
125
126
  - spec/pith/input/abstract_spec.rb~
126
- - spec/pith/metadata_spec.rb
127
127
  - spec/pith/metadata_spec.rb~
128
128
  - spec/pith/project_spec.rb
129
129
  - spec/pith/project_spec.rb~
@@ -198,7 +198,6 @@ test_files:
198
198
  - Rakefile
199
199
  - spec/pith/input/abstract_spec.rb
200
200
  - spec/pith/input/abstract_spec.rb~
201
- - spec/pith/metadata_spec.rb
202
201
  - spec/pith/metadata_spec.rb~
203
202
  - spec/pith/project_spec.rb
204
203
  - spec/pith/project_spec.rb~
data/lib/pith/metadata.rb DELETED
@@ -1,26 +0,0 @@
1
- require "yaml"
2
-
3
- module Pith
4
-
5
- module Metadata
6
-
7
- extend self
8
-
9
- def extract_from(io)
10
- line = io.gets
11
- if line =~ /---$/
12
- metadata_prefix = $`
13
- yaml = ""
14
- while line && line.start_with?(metadata_prefix)
15
- yaml << line[metadata_prefix.size .. -1]
16
- line = io.gets
17
- end
18
- YAML.load(yaml)
19
- else
20
- Hash.new
21
- end
22
- end
23
-
24
- end
25
-
26
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
- require 'stringio'
3
-
4
- require 'pith/metadata'
5
-
6
- describe Pith::Metadata do
7
-
8
- def metadata
9
- Pith::Metadata.extract_from(StringIO.new(@input))
10
- end
11
-
12
- describe "when input contains no YAML metadata" do
13
-
14
- before do
15
- @input = "%p Blah blah"
16
- end
17
-
18
- it "returns an empty Hash" do
19
- metadata.should == {}
20
- end
21
-
22
- end
23
-
24
- describe "when input contains YAML metadata" do
25
-
26
- before do
27
- @input = <<-HAML.gsub(/^ +/, '')
28
- -# ---
29
- -# x: 1
30
- -# y: "2"
31
- -# ...
32
- -# other stuff
33
- HAML
34
- end
35
-
36
- it "extracts the metadata" do
37
- metadata.should == {
38
- "x" => 1,
39
- "y" => "2"
40
- }
41
- end
42
-
43
- end
44
-
45
- end
46
-